Change in libosmocore[master]: vty: introduce API for the library specific attributes

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

fixeria gerrit-no-reply at lists.osmocom.org
Sun Oct 4 11:38:21 UTC 2020


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20447 )


Change subject: vty: introduce API for the library specific attributes
......................................................................

vty: introduce API for the library specific attributes

See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: I15184569635b3ef7dfe9eeddcc19bf16cc358f66
Related: SYS#4937
---
M include/osmocom/vty/command.h
M src/vty/command.c
2 files changed, 63 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/47/20447/1

diff --git a/include/osmocom/vty/command.h b/include/osmocom/vty/command.h
index 25890a4..92adae9 100644
--- a/include/osmocom/vty/command.h
+++ b/include/osmocom/vty/command.h
@@ -141,6 +141,21 @@
 	CMD_ATTR_LIB_COMMAND	= (1 << 3),
 };
 
+/*! Attributes shared between libraries (up to 32 entries). */
+enum {
+	/* The entries of this enum shall conform the following requirements:
+	 * 1. Naming format: 'OSMO_' + <LIBNAME> + '_LIB_ATTR_' + <ATTRNAME>,
+	 *    where LIBNAME is a short name of the library, e.g. 'ABIS', 'MGCP',
+	 *    and ATTRNAME is a brief name of the attribute, e.g. RTP_CONN_EST;
+	 *    for example: 'OSMO_ABIS_LIB_ATTR_RSL_LINK_UP'.
+	 * 2. Brevity: shortenings and abbreviations are welcome!
+	 * 3. Values are not flags but indexes, unlike CMD_ATTR_*.
+	 * 4. Ordering: new entries added before _OSMO_CORE_LIB_ATTR_COUNT. */
+
+	/* Keep this floating entry last, it's needed for count check. */
+	_OSMO_CORE_LIB_ATTR_COUNT
+};
+
 /*! Structure of a command element */
 struct cmd_element {
 	const char *string;	/*!< Command specification by string. */
diff --git a/src/vty/command.c b/src/vty/command.c
index c7ba9bc..a7359b4 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -630,6 +630,18 @@
 	{ 0, NULL }
 };
 
+/* Description of attributes shared between the lib commands */
+static const char * const cmd_lib_attr_desc[32] = {
+	/* [OSMO_LIBNAME_LIB_ATTR_ATTRNAME] = \
+	 * 	"Brief but meaningful description", */
+};
+
+/* Flag letters of attributes shared between the lib commands.
+ * NOTE: uppercase letters only, the rest is reserved for applications. */
+static const char cmd_lib_attr_letters[32] = {
+	/* [OSMO_LIBNAME_LIB_ATTR_ATTRNAME] =		'X', */
+};
+
 /*
  * Write one cmd_element as XML via a print_func_t.
  */
@@ -661,7 +673,18 @@
 
 	/* Print application specific attributes and their description */
 	if (cmd->usrattr != 0x00) { /* ... if at least one flag is set */
-		print_func(data, "      <attributes scope='application'>%s", newline);
+		const char * const *desc;
+		const char *letters;
+
+		if (cmd->attr & CMD_ATTR_LIB_COMMAND) {
+			print_func(data, "      <attributes scope='library'>%s", newline);
+			letters = &cmd_lib_attr_letters[0];
+			desc = &cmd_lib_attr_desc[0];
+		} else {
+			print_func(data, "      <attributes scope='application'>%s", newline);
+			letters = &host.app_info->usr_attr_letters[0];
+			desc = &host.app_info->usr_attr_desc[0];
+		}
 
 		for (i = 0; i < ARRAY_SIZE(host.app_info->usr_attr_desc); i++) {
 			char *xml_att_desc;
@@ -671,11 +694,11 @@
 			if (~cmd->usrattr & (1 << i))
 				continue;
 
-			xml_att_desc = xml_escape(host.app_info->usr_attr_desc[i]);
+			xml_att_desc = xml_escape(desc[i]);
 			print_func(data, "        <attribute doc='%s'", xml_att_desc);
 			talloc_free(xml_att_desc);
 
-			if ((flag = host.app_info->usr_attr_letters[i]) != '\0')
+			if ((flag = letters[i]) != '\0')
 				print_func(data, " flag='%c'", flag);
 			print_func(data, " />%s", newline);
 		}
@@ -4053,4 +4076,26 @@
 	srand(time(NULL));
 }
 
+/* FIXME: execute this section in the unit test instead */
+static __attribute__((constructor)) void on_dso_load(void)
+{
+	unsigned int i, j;
+
+	/* Check total number of the library specific attributes */
+	OSMO_ASSERT(_OSMO_CORE_LIB_ATTR_COUNT < 32);
+
+	/* Check for duplicates in the list of library specific flags */
+	for (i = 0; i < _OSMO_CORE_LIB_ATTR_COUNT; i++) {
+		if (cmd_lib_attr_letters[i] == '\0')
+			continue;
+
+		/* Only upper case flag letters are allowed for libraries */
+		OSMO_ASSERT(cmd_lib_attr_letters[i] >= 'A');
+		OSMO_ASSERT(cmd_lib_attr_letters[i] <= 'Z');
+
+		for (j = i + 1; j < _OSMO_CORE_LIB_ATTR_COUNT; j++)
+			OSMO_ASSERT(cmd_lib_attr_letters[i] != cmd_lib_attr_letters[j]);
+	}
+}
+
 /*! @} */

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I15184569635b3ef7dfe9eeddcc19bf16cc358f66
Gerrit-Change-Number: 20447
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201004/ce506ddb/attachment.htm>


More information about the gerrit-log mailing list