dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/28914 )
Change subject: abis_om2000: move switch-case to function ......................................................................
abis_om2000: move switch-case to function
The switch-case in update_op_state() and update_mo_state() can be split off into functions. This makes to code better readable.
Change-Id: I41f0d9d0d498f6f698c2c959baac50424f5ac317 Related: OS#5634 --- M src/osmo-bsc/abis_om2000.c 1 file changed, 33 insertions(+), 28 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/14/28914/1
diff --git a/src/osmo-bsc/abis_om2000.c b/src/osmo-bsc/abis_om2000.c index 5026b5e..903e06e 100644 --- a/src/osmo-bsc/abis_om2000.c +++ b/src/osmo-bsc/abis_om2000.c @@ -960,6 +960,23 @@ return NULL; }
+/* Derive an OML Availability state from an OM2000 MO state */ +enum abis_nm_avail_state oml_avstate_from_om2k_mostate(uint8_t mo_state, bool has_enabled_state) +{ + switch (mo_state) { + case OM2K_MOSTATE_RESET: + return NM_AVSTATE_POWER_OFF; + case OM2K_MOSTATE_STARTED: + return has_enabled_state ? NM_AVSTATE_OFF_LINE : NM_AVSTATE_OK; + case OM2K_MOSTATE_ENABLED: + return NM_AVSTATE_OK; + case OM2K_MOSTATE_DISABLED: + return NM_AVSTATE_POWER_OFF; + default: + return NM_AVSTATE_DEGRADED; + } +} + static void update_mo_state(struct gsm_bts *bts, struct abis_om2k_mo *mo, uint8_t mo_state) { struct gsm_nm_state *nm_state = mo2nm_state(bts, mo); @@ -987,23 +1004,7 @@ break; }
- switch (mo_state) { - case OM2K_MOSTATE_RESET: - nsd.new_state.availability = NM_AVSTATE_POWER_OFF; - break; - case OM2K_MOSTATE_STARTED: - nsd.new_state.availability = has_enabled_state ? NM_AVSTATE_OFF_LINE : NM_AVSTATE_OK; - break; - case OM2K_MOSTATE_ENABLED: - nsd.new_state.availability = NM_AVSTATE_OK; - break; - case OM2K_MOSTATE_DISABLED: - nsd.new_state.availability = NM_AVSTATE_POWER_OFF; - break; - default: - nsd.new_state.availability = NM_AVSTATE_DEGRADED; - break; - } + nsd.new_state.availability = oml_avstate_from_om2k_mostate(mo_state, has_enabled_state);
/* Update current state before emitting signal: */ nm_state->availability = nsd.new_state.availability; @@ -1011,6 +1012,19 @@ osmo_signal_dispatch(SS_NM, S_NM_STATECHG, &nsd); }
+/* Derive an OML Operational state from an OM2000 OP state */ +enum abis_nm_op_state oml_opstate_from_om2k_opstate(uint8_t op_state) +{ + switch (op_state) { + case 1: + return NM_OPSTATE_ENABLED; + case 0: + return NM_OPSTATE_DISABLED; + default: + return NM_OPSTATE_NULL; + } +} + static void update_op_state(struct gsm_bts *bts, const struct abis_om2k_mo *mo, uint8_t op_state) { struct gsm_nm_state *nm_state = mo2nm_state(bts, mo); @@ -1020,17 +1034,8 @@ return;
new_state = *nm_state; - switch (op_state) { - case 1: - new_state.operational = NM_OPSTATE_ENABLED; - break; - case 0: - new_state.operational = NM_OPSTATE_DISABLED; - break; - default: - new_state.operational = NM_OPSTATE_NULL; - break; - } + + new_state.operational = oml_opstate_from_om2k_opstate(op_state);
nm_state->operational = new_state.operational; }