From 4585e6755dd569ab620c711f20a3d45d4ad87216 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 16 Apr 2017 17:23:56 +0200 Subject: osmo_fsm: Lookup functions to find FSM Instance by name or ID Introduce two lookup helper functions to resolve a fsm_instance based on the FSM and name or ID. Also, add related test cases. Change-Id: I707f3ed2795c28a924e64adc612d378c21baa815 --- src/fsm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/fsm.c b/src/fsm.c index 0e2c9be4..7b2be701 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -113,6 +113,30 @@ struct osmo_fsm *osmo_fsm_find_by_name(const char *name) return NULL; } +struct osmo_fsm_inst *osmo_fsm_inst_find_by_name(const struct osmo_fsm *fsm, + const char *name) +{ + struct osmo_fsm_inst *fi; + + llist_for_each_entry(fi, &fsm->instances, list) { + if (!strcmp(name, fi->name)) + return fi; + } + return NULL; +} + +struct osmo_fsm_inst *osmo_fsm_inst_find_by_id(const struct osmo_fsm *fsm, + const char *id) +{ + struct osmo_fsm_inst *fi; + + llist_for_each_entry(fi, &fsm->instances, list) { + if (!strcmp(id, fi->id)) + return fi; + } + return NULL; +} + /*! \brief register a FSM with the core * * A FSM descriptor needs to be registered with the core before any -- cgit v1.2.3