made some stuff static

sipo
Ondřej Hruška 7 years ago
parent 8768dc31ab
commit 85dd77311b
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 3
      framework/settings.c
  2. 123
      framework/unit_registry.c

@ -273,6 +273,9 @@ void settings_load_ini_key(const char *restrict section, const char *restrict ke
// dbg("[%s] %s = %s", section, key, value); // dbg("[%s] %s = %s", section, key, value);
static char namebuf[INI_KEY_MAX]; static char namebuf[INI_KEY_MAX];
// SYSTEM and UNITS files must be separate.
// Init functions are run for first key in the section.
if (streq(section, "SYSTEM")) { if (streq(section, "SYSTEM")) {
if (SystemSettings.pristine) { if (SystemSettings.pristine) {

@ -23,8 +23,8 @@ struct ureg_entry {
UregEntry *next; UregEntry *next;
}; };
UregEntry *ureg_head = NULL; static UregEntry *ureg_head = NULL;
UregEntry *ureg_tail = NULL; static UregEntry *ureg_tail = NULL;
// --- // ---
@ -33,8 +33,10 @@ struct ulist_entry {
UlistEntry *next; UlistEntry *next;
}; };
UlistEntry *ulist_head = NULL; static UlistEntry *ulist_head = NULL;
UlistEntry *ulist_tail = NULL; static UlistEntry *ulist_tail = NULL;
static int32_t unit_count = -1;
// --- // ---
@ -79,21 +81,6 @@ static void free_le_unit(UlistEntry *le)
} }
} }
/** Remove a unit and update links appropriately */
static void remove_unit_from_list(UlistEntry *restrict le, UlistEntry *restrict parent)
{
if (parent == NULL) {
ulist_head = le->next;
} else {
parent->next = le->next;
}
// Fix tail potentially pointing to the removed entry
if (ulist_tail == le) {
ulist_tail = parent;
}
}
/** Add unit to the list, updating references as needed */ /** Add unit to the list, updating references as needed */
static void add_unit_to_list(UlistEntry *le) static void add_unit_to_list(UlistEntry *le)
{ {
@ -106,28 +93,6 @@ static void add_unit_to_list(UlistEntry *le)
ulist_tail = le; ulist_tail = le;
} }
/** Find a unit in the list */
static UlistEntry *find_unit(const Unit *unit, UlistEntry **pParent)
{
UlistEntry *le = ulist_head;
UlistEntry *parent = NULL;
while (le != NULL) {
if (&le->unit == unit) {
if (pParent != NULL) {
*pParent = parent;
}
return le;
}
parent = le;
le = le->next;
}
dbg("!! Unit was not found in registry");
*pParent = NULL;
return NULL;
}
// create a unit instance (not yet loading or initing - just pre-init) // create a unit instance (not yet loading or initing - just pre-init)
Unit *ureg_instantiate(const char *driver_name) Unit *ureg_instantiate(const char *driver_name)
{ {
@ -173,39 +138,6 @@ Unit *ureg_instantiate(const char *driver_name)
return NULL; return NULL;
} }
// remove before init()
void ureg_clean_failed(Unit *unit)
{
dbg("Removing failed unit from registry...");
UlistEntry *le;
UlistEntry *parent;
le = find_unit(unit, &parent);
if (!le) return;
clean_failed_unit(&le->unit);
remove_unit_from_list(le, parent);
free(le);
}
// remove after successful init()
void ureg_remove_unit(Unit *unit)
{
dbg("Cleaning & removing unit from registry...");
UlistEntry *le;
UlistEntry *parent;
le = find_unit(unit, &parent);
if (!le) return;
free_le_unit(le);
remove_unit_from_list(le, parent);
free(le);
}
void ureg_save_units(PayloadBuilder *pb) void ureg_save_units(PayloadBuilder *pb)
{ {
assert_param(pb->ok); assert_param(pb->ok);
@ -242,6 +174,7 @@ bool ureg_load_units(PayloadParser *pp)
char typebuf[16]; char typebuf[16];
assert_param(pp->ok); assert_param(pp->ok);
unit_count = -1; // reset the counter
// Check units list marker byte // Check units list marker byte
if (pp_char(pp) != 'U') return false; if (pp_char(pp) != 'U') return false;
@ -250,10 +183,10 @@ bool ureg_load_units(PayloadParser *pp)
(void)version; // version can affect the format (void)version; // version can affect the format
{ // units list { // units list
uint16_t unit_count = pp_u16(pp); uint16_t count = pp_u16(pp);
dbg("Units to load: %d", (int) unit_count); dbg("Units to load: %d", (int) count);
for (uint32_t j = 0; j < unit_count; j++) { for (uint32_t j = 0; j < count; j++) {
// We're now unpacking a single unit // We're now unpacking a single unit
// Marker that this is a unit - it could get out of alignment if structure changed // Marker that this is a unit - it could get out of alignment if structure changed
@ -312,11 +245,14 @@ void ureg_remove_all_units(void)
} }
ulist_head = ulist_tail = NULL; ulist_head = ulist_tail = NULL;
unit_count = -1;
} }
/** Create unit instances from the [UNITS] overview section */ /** Create unit instances from the [UNITS] overview section */
bool ureg_instantiate_by_ini(const char *restrict driver_name, const char *restrict names) bool ureg_instantiate_by_ini(const char *restrict driver_name, const char *restrict names)
{ {
unit_count = -1; // reset the counter
UregEntry *re = ureg_head; UregEntry *re = ureg_head;
while (re != NULL) { while (re != NULL) {
if (streq(re->driver->name, driver_name)) { if (streq(re->driver->name, driver_name)) {
@ -424,22 +360,6 @@ static void export_unit_do(UlistEntry *li, IniWriter *iw)
pUnit->driver->cfgWriteIni(pUnit, iw); pUnit->driver->cfgWriteIni(pUnit, iw);
} }
// unit to INI
void ureg_export_unit(uint32_t index, IniWriter *iw)
{
UlistEntry *li = ulist_head;
uint32_t count = 0;
while (li != NULL) {
if (count == index) {
export_unit_do(li, iw);
return;
}
count++;
li = li->next;
}
}
// unit to INI // unit to INI
void ureg_build_ini(IniWriter *iw) void ureg_build_ini(IniWriter *iw)
{ {
@ -497,15 +417,18 @@ void ureg_build_ini(IniWriter *iw)
// count units // count units
uint32_t ureg_get_num_units(void) uint32_t ureg_get_num_units(void)
{ {
// TODO keep this in a variable if (unit_count == -1) {
UlistEntry *li = ulist_head; // TODO keep this in a variable
uint32_t count = 0; UlistEntry *li = ulist_head;
while (li != NULL) { uint32_t count = 0;
count++; while (li != NULL) {
li = li->next; count++;
li = li->next;
}
unit_count = count;
} }
return count; return (uint32_t) unit_count;
} }
/** Deliver message to it's destination unit */ /** Deliver message to it's destination unit */

Loading…
Cancel
Save