diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-09-05 13:30:48 +0200 |
---|---|---|
committer | pespin <pespin@sysmocom.de> | 2019-09-07 22:29:06 +0000 |
commit | 77cd10f0db6ebd0e3a5b6d8136470bc4adccdd57 (patch) | |
tree | 323455333ff2bc0bbcb237f4d860e241f7cfaf2f /src | |
parent | 994df263faecc280b0ebf47f2309d48b0dd9a329 (diff) |
tdef: Introduce API osmo_tdef_set()
This API is already useful for users willing to set a given timer to a
given value. It will also contain code later that checks for value being
inside valid range for that timer.
Related: OS#4190
Change-Id: Id56a1226d724a374f04231df85fe5b49ffd2c43c
Diffstat (limited to 'src')
-rw-r--r-- | src/tdef.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -25,6 +25,7 @@ */ #include <limits.h> +#include <errno.h> #include <osmocom/core/fsm.h> #include <osmocom/core/tdef.h> @@ -210,6 +211,25 @@ struct osmo_tdef *osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T) return NULL; } +/*! Set value in entry matching T, converting val from val_unit to unit of T. + * \param[in] tdefs Array of timer definitions, last entry being fully zero. + * \param[in] T Timer number to set the value for. + * \param[in] val The new timer value to set. + * \param[in] val_unit Units of value in parameter val. + * \return 0 on success, negative on error. + */ +int osmo_tdef_set(struct osmo_tdef *tdefs, int T, unsigned long val, enum osmo_tdef_unit val_unit) +{ + struct osmo_tdef *t; + osmo_tdef_for_each(t, tdefs) { + if (t->T == T) { + t->val = osmo_tdef_round(val, val_unit, t->unit); + return 0; + } + } + return -EEXIST; +} + /*! Using osmo_tdef for osmo_fsm_inst: find a given state's osmo_tdef_state_timeout entry. * * The timeouts_array shall contain exactly 32 elements, regardless whether only some of them are actually populated |