[PATCH] libosmocore[master]: Add struct osmo_prim_event_map and osmo_event_for_prim()

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Apr 9 17:53:20 UTC 2017


Review at  https://gerrit.osmocom.org/2278

Add struct osmo_prim_event_map and osmo_event_for_prim()

This can be used to map from an osmo_prim to an osmo_fsm event.

Change-Id: I52350f4ebe97811b2a692e5a69a2cd39a853583c
---
M include/osmocom/core/prim.h
M src/prim.c
2 files changed, 32 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/78/2278/1

diff --git a/include/osmocom/core/prim.h b/include/osmocom/core/prim.h
index 99a71d5..f04e15e 100644
--- a/include/osmocom/core/prim.h
+++ b/include/osmocom/core/prim.h
@@ -57,4 +57,18 @@
 /*! \brief primitive handler callback type */
 typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx);
 
+/*! \brief magic value to be used as final record of \ref
+ * osmo_prim_event_map */
+#define OSMO_NO_EVENT	0xFFFFFFFF
+
+/*! \brief single entry in a SAP/PRIM/OP -> EVENT map */
+struct osmo_prim_event_map {
+	unsigned int sap;	/*!< SAP to match */
+	unsigned int primitive;	/*!< primtiive to match */
+	enum osmo_prim_operation operation; /*!< operation to match */
+	uint32_t event;		/*!< event as result if above match */
+};
+
+uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph,
+			     const struct osmo_prim_event_map *maps);
 /*! @} */
diff --git a/src/prim.c b/src/prim.c
index 3f41c41..5851f6f 100644
--- a/src/prim.c
+++ b/src/prim.c
@@ -10,3 +10,21 @@
 	{ PRIM_OP_CONFIRM,			"confirm" },
 	{ 0, NULL }
 };
+
+/*! \brief resolve the (fsm) event for a given primitive using a map
+ *  \param[in] oph primitive header used as key for match
+ *  \param[in] maps list of mappings from primitive to event
+ *  \returns event determined by map; \ref OSMO_NO_EVENT if no match */
+uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph,
+			     const struct osmo_prim_event_map *maps)
+{
+	const struct osmo_prim_event_map *map;
+
+	for (map = maps; map->event != OSMO_NO_EVENT; map++) {
+		if (map->sap == oph->sap &&
+		    map->primitive == oph->primitive &&
+		    map->operation == oph->operation)
+			return map->event;
+	}
+	return OSMO_NO_EVENT;
+}

-- 
To view, visit https://gerrit.osmocom.org/2278
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I52350f4ebe97811b2a692e5a69a2cd39a853583c
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list