summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-12-14 18:35:47 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-12-15 11:35:56 +0100
commit5c5c78aacd4cd15e1147c2e5dbb4dc9fca4da7e5 (patch)
tree6cca7da9fd5b792738bb19a85900705174446667
parenta3953e0536a07b571fe3314d6e257db79b2dbe64 (diff)
add value strings for enum osmo_fsm_term_cause and use for logging
-rw-r--r--include/osmocom/core/fsm.h7
-rw-r--r--src/fsm.c14
2 files changed, 20 insertions, 1 deletions
diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h
index 77072ef8..5a679615 100644
--- a/include/osmocom/core/fsm.h
+++ b/include/osmocom/core/fsm.h
@@ -30,6 +30,13 @@ enum osmo_fsm_term_cause {
OSMO_FSM_TERM_TIMEOUT,
};
+extern const struct value_string osmo_fsm_term_cause_names[];
+static inline const char *osmo_fsm_term_cause_name(enum osmo_fsm_term_cause cause)
+{
+ return get_value_string(osmo_fsm_term_cause_names, cause);
+}
+
+
/*! \brief description of a rule in the FSM */
struct osmo_fsm_state {
/*! \brief bit-mask of permitted input events for this state */
diff --git a/src/fsm.c b/src/fsm.c
index dc57e5ee..d251cfdb 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -431,7 +431,8 @@ void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi,
struct osmo_fsm_inst *parent = fi->proc.parent;
uint32_t parent_term_event = fi->proc.parent_term_event;
- LOGPFSMSRC(fi, file, line, "Terminating (cause = %u)\n", cause);
+ LOGPFSMSRC(fi, file, line, "Terminating (cause = %s)\n",
+ osmo_fsm_term_cause_name(cause));
/* iterate over all children */
llist_for_each_entry_safe(child, child2, &fi->proc.children, proc.child) {
@@ -456,4 +457,15 @@ void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi,
file, line);
}
+#define ENUM_VAL_TO_VALUE_STRING(X) { X, #X }
+
+const struct value_string osmo_fsm_term_cause_names[] = {
+ ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_PARENT),
+ ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_REQUEST),
+ ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_REGULAR),
+ ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_ERROR),
+ ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_TIMEOUT),
+ { 0, NULL }
+};
+
/*! @} */