mirror of https://gerrit.osmocom.org/libosmocore
fsm: Update the name as well if the id is updated and accept NULL
If the name stays the same the log messages will still log with the old id. Since we can now change the id we need to update the name as well. NULL as id was allowed before so we should allow that as well. Change-Id: I6b01eb10b8a05fee3e4a5cdefdcf3ce9f79545b4
This commit is contained in:
parent
d86055b431
commit
04a2a3231f
36
src/fsm.c
36
src/fsm.c
|
@ -214,9 +214,30 @@ int osmo_fsm_inst_update_id(struct osmo_fsm_inst *fi, const char *id)
|
||||||
}
|
}
|
||||||
osmo_talloc_replace_string(fi, (char **)&fi->id, id);
|
osmo_talloc_replace_string(fi, (char **)&fi->id, id);
|
||||||
|
|
||||||
|
if (fi->name)
|
||||||
|
talloc_free((void*)fi->name);
|
||||||
|
|
||||||
|
if (!fsm_log_addr) {
|
||||||
|
fi->name = talloc_asprintf(fi, "%s(%s)", fi->fsm->name, id);
|
||||||
|
} else {
|
||||||
|
fi->name = talloc_asprintf(fi, "%s(%s)[%p]", fi->fsm->name, id, fi);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
|
||||||
|
if (fi->id)
|
||||||
|
talloc_free((void*)fi->id);
|
||||||
|
fi->id = NULL;
|
||||||
|
if (fi->name)
|
||||||
|
talloc_free((void*)fi->name);
|
||||||
|
|
||||||
|
if (!fsm_log_addr) {
|
||||||
|
fi->name = talloc_asprintf(fi, "%s", fi->fsm->name);
|
||||||
|
} else {
|
||||||
|
fi->name = talloc_asprintf(fi, "%s[%p]", fi->fsm->name, fi);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! allocate a new instance of a specified FSM
|
/*! allocate a new instance of a specified FSM
|
||||||
|
@ -244,19 +265,6 @@ struct osmo_fsm_inst *osmo_fsm_inst_alloc(struct osmo_fsm *fsm, void *ctx, void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fsm_log_addr) {
|
|
||||||
if (id)
|
|
||||||
fi->name = talloc_asprintf(fi, "%s(%s)", fsm->name, id);
|
|
||||||
else
|
|
||||||
fi->name = talloc_asprintf(fi, "%s", fsm->name);
|
|
||||||
} else {
|
|
||||||
if (id)
|
|
||||||
fi->name = talloc_asprintf(fi, "%s(%s)[%p]", fsm->name,
|
|
||||||
id, fi);
|
|
||||||
else
|
|
||||||
fi->name = talloc_asprintf(fi, "%s[%p]", fsm->name, fi);
|
|
||||||
}
|
|
||||||
|
|
||||||
INIT_LLIST_HEAD(&fi->proc.children);
|
INIT_LLIST_HEAD(&fi->proc.children);
|
||||||
INIT_LLIST_HEAD(&fi->proc.child);
|
INIT_LLIST_HEAD(&fi->proc.child);
|
||||||
llist_add(&fi->list, &fsm->instances);
|
llist_add(&fi->list, &fsm->instances);
|
||||||
|
|
|
@ -196,6 +196,10 @@ int main(int argc, char **argv)
|
||||||
finst = foo();
|
finst = foo();
|
||||||
OSMO_ASSERT(osmo_fsm_inst_find_by_id(&fsm, "my_id") == finst);
|
OSMO_ASSERT(osmo_fsm_inst_find_by_id(&fsm, "my_id") == finst);
|
||||||
OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "Test_FSM(my_id)") == finst);
|
OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "Test_FSM(my_id)") == finst);
|
||||||
|
OSMO_ASSERT(osmo_fsm_inst_update_id(finst, "another_id") == 0);
|
||||||
|
OSMO_ASSERT(osmo_fsm_inst_find_by_id(&fsm, "another_id") == finst);
|
||||||
|
OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "Test_FSM(another_id)") == finst);
|
||||||
|
OSMO_ASSERT(osmo_fsm_inst_update_id(finst, "my_id") == 0);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
osmo_select_main(0);
|
osmo_select_main(0);
|
||||||
|
|
Loading…
Reference in New Issue