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.orgReview at https://gerrit.osmocom.org/2374 ctrl: Allow installation of additional node lookup helpers The existing code assumes that the main application knows about all control command nodes and can thus present one lookup function. As libraries are getting their own control interface handling, this is too restrictive, and we need a way how library code can dynamically register more node lookup helpers. We can now do this by means of a ctrl_lookup_register() function. Change-Id: Ib69908d1c57f5bb721d5496e3b4a5258fca450e3 --- M include/osmocom/ctrl/control_if.h M src/ctrl/control_if.c 2 files changed, 43 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/74/2374/1 diff --git a/include/osmocom/ctrl/control_if.h b/include/osmocom/ctrl/control_if.h index f2af1db..a740a96 100644 --- a/include/osmocom/ctrl/control_if.h +++ b/include/osmocom/ctrl/control_if.h @@ -29,3 +29,5 @@ ctrl_cmd_lookup lookup); struct ctrl_connection *osmo_ctrl_conn_alloc(void *ctx, void *data); int ctrl_cmd_handle(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd, void *data); + +int ctrl_lookup_register(ctrl_cmd_lookup lookup); diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c index f49d639..5730850 100644 --- a/src/ctrl/control_if.c +++ b/src/ctrl/control_if.c @@ -61,6 +61,13 @@ vector ctrl_node_vec; +/* global list of control interface lookup helpers */ +struct lookup_helper { + struct llist_head list; + ctrl_cmd_lookup lookup; +}; +static LLIST_HEAD(ctrl_lookup_helpers); + int ctrl_parse_get_num(vector vline, int i, long *num) { char *token, *tmp; @@ -225,12 +232,21 @@ } for (i=0;i<vector_active(vline);i++) { + struct lookup_helper *lh; int rc; if (ctrl->lookup) rc = ctrl->lookup(data, vline, &node, &cmd->node, &i); else rc = 0; + + if (!rc) { + llist_for_each_entry(lh, &ctrl_lookup_helpers, list) { + rc = lh->lookup(data, vline, &node, &cmd->node, &i); + if (rc) + break; + } + } if (rc == 1) { /* do nothing */ @@ -733,3 +749,28 @@ talloc_free(ctrl); return NULL; } + +/*! \brief Install a lookup helper function for control nodes + * This function is used by e.g. library code to install lookup helpers + * for additional nodes in the control interface. + * \param[in] lookup The lookup helper function + * \retuns - on success; negative on error. + */ +int ctrl_lookup_register(ctrl_cmd_lookup lookup) +{ + struct lookup_helper *lh; + + /* avoid double registration */ + llist_for_each_entry(lh, &ctrl_lookup_helpers, list) { + if (lh->lookup == lookup) + return -EEXIST; + } + + lh = talloc_zero(NULL, struct lookup_helper); + if (!lh) + return -ENOMEM; + + lh->lookup = lookup; + llist_add_tail(&lh->list, &ctrl_lookup_helpers); + return 0; +} -- To view, visit https://gerrit.osmocom.org/2374 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib69908d1c57f5bb721d5496e3b4a5258fca450e3 Gerrit-PatchSet: 1 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org>