Change in ...libosmocore[master]: tdef: Introduce API osmo_tdef_set()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Sat Sep 7 22:29:07 UTC 2019


pespin has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/libosmocore/+/15418 )

Change subject: tdef: Introduce API osmo_tdef_set()
......................................................................

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
---
M include/osmocom/core/tdef.h
M src/tdef.c
2 files changed, 21 insertions(+), 0 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/core/tdef.h b/include/osmocom/core/tdef.h
index 566f5dd..a1ad4cc 100644
--- a/include/osmocom/core/tdef.h
+++ b/include/osmocom/core/tdef.h
@@ -97,6 +97,7 @@
 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 40a9900..dfb47f6 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 @@
 	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

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15418
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id56a1226d724a374f04231df85fe5b49ffd2c43c
Gerrit-Change-Number: 15418
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190907/ef5367aa/attachment.htm>


More information about the gerrit-log mailing list