summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/core/tdef.h1
-rw-r--r--src/tdef.c20
2 files changed, 21 insertions, 0 deletions
diff --git a/include/osmocom/core/tdef.h b/include/osmocom/core/tdef.h
index 566f5dd3..a1ad4ccb 100644
--- a/include/osmocom/core/tdef.h
+++ b/include/osmocom/core/tdef.h
@@ -97,6 +97,7 @@ void osmo_tdefs_reset(struct osmo_tdef *tdefs);
unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit,
long val_if_not_present);
struct osmo_tdef *osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T);
+int osmo_tdef_set(struct osmo_tdef *tdefs, int T, unsigned long val, enum osmo_tdef_unit as_unit);
/*! Using osmo_tdef for osmo_fsm_inst: array entry for a mapping of state numbers to timeout definitions.
* For a usage example, see osmo_tdef_get_state_timeout() and test_tdef_state_timeout() in tdef_test.c. */
diff --git a/src/tdef.c b/src/tdef.c
index 40a99002..dfb47f68 100644
--- a/src/tdef.c
+++ b/src/tdef.c
@@ -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