<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/20447">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Jenkins Builder: Verified
dexter: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty/command: introduce API for the library specific attributes<br><br>See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.<br><br>Change-Id: I15184569635b3ef7dfe9eeddcc19bf16cc358f66<br>Related: SYS#4937<br>---<br>M include/osmocom/vty/command.h<br>M src/vty/command.c<br>2 files changed, 63 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/vty/command.h b/include/osmocom/vty/command.h</span><br><span>index 49f0bfe..07ec242 100644</span><br><span>--- a/include/osmocom/vty/command.h</span><br><span>+++ b/include/osmocom/vty/command.h</span><br><span>@@ -142,6 +142,21 @@</span><br><span> CMD_ATTR_LIB_COMMAND = (1 << 4),</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Attributes shared between libraries (up to 32 entries). */</span><br><span style="color: hsl(120, 100%, 40%);">+enum {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* The entries of this enum shall conform the following requirements:</span><br><span style="color: hsl(120, 100%, 40%);">+ * 1. Naming format: 'OSMO_' + <LIBNAME> + '_LIB_ATTR_' + <ATTRNAME>,</span><br><span style="color: hsl(120, 100%, 40%);">+ * where LIBNAME is a short name of the library, e.g. 'ABIS', 'MGCP',</span><br><span style="color: hsl(120, 100%, 40%);">+ * and ATTRNAME is a brief name of the attribute, e.g. RTP_CONN_EST;</span><br><span style="color: hsl(120, 100%, 40%);">+ * for example: 'OSMO_ABIS_LIB_ATTR_RSL_LINK_UP'.</span><br><span style="color: hsl(120, 100%, 40%);">+ * 2. Brevity: shortenings and abbreviations are welcome!</span><br><span style="color: hsl(120, 100%, 40%);">+ * 3. Values are not flags but indexes, unlike CMD_ATTR_*.</span><br><span style="color: hsl(120, 100%, 40%);">+ * 4. Ordering: new entries added before _OSMO_CORE_LIB_ATTR_COUNT. */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Keep this floating entry last, it's needed for count check. */</span><br><span style="color: hsl(120, 100%, 40%);">+ _OSMO_CORE_LIB_ATTR_COUNT</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Structure of a command element */</span><br><span> struct cmd_element {</span><br><span> const char *string; /*!< Command specification by string. */</span><br><span>diff --git a/src/vty/command.c b/src/vty/command.c</span><br><span>index cee590b..7752c91 100644</span><br><span>--- a/src/vty/command.c</span><br><span>+++ b/src/vty/command.c</span><br><span>@@ -631,6 +631,18 @@</span><br><span> { 0, NULL }</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Description of attributes shared between the lib commands */</span><br><span style="color: hsl(120, 100%, 40%);">+static const char * const cmd_lib_attr_desc[32] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* [OSMO_LIBNAME_LIB_ATTR_ATTRNAME] = \</span><br><span style="color: hsl(120, 100%, 40%);">+ * "Brief but meaningful description", */</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Flag letters of attributes shared between the lib commands.</span><br><span style="color: hsl(120, 100%, 40%);">+ * NOTE: uppercase letters only, the rest is reserved for applications. */</span><br><span style="color: hsl(120, 100%, 40%);">+static const char cmd_lib_attr_letters[32] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* [OSMO_LIBNAME_LIB_ATTR_ATTRNAME] = 'X', */</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*</span><br><span> * Write one cmd_element as XML via a print_func_t.</span><br><span> */</span><br><span>@@ -662,7 +674,18 @@</span><br><span> </span><br><span> /* Print application specific attributes and their description */</span><br><span> if (cmd->usrattr != 0x00) { /* ... if at least one flag is set */</span><br><span style="color: hsl(0, 100%, 40%);">- print_func(data, " <attributes scope='application'>%s", newline);</span><br><span style="color: hsl(120, 100%, 40%);">+ const char * const *desc;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *letters;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cmd->attr & CMD_ATTR_LIB_COMMAND) {</span><br><span style="color: hsl(120, 100%, 40%);">+ print_func(data, " <attributes scope='library'>%s", newline);</span><br><span style="color: hsl(120, 100%, 40%);">+ letters = &cmd_lib_attr_letters[0];</span><br><span style="color: hsl(120, 100%, 40%);">+ desc = &cmd_lib_attr_desc[0];</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ print_func(data, " <attributes scope='application'>%s", newline);</span><br><span style="color: hsl(120, 100%, 40%);">+ letters = &host.app_info->usr_attr_letters[0];</span><br><span style="color: hsl(120, 100%, 40%);">+ desc = &host.app_info->usr_attr_desc[0];</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> for (i = 0; i < ARRAY_SIZE(host.app_info->usr_attr_desc); i++) {</span><br><span> char *xml_att_desc;</span><br><span>@@ -672,11 +695,11 @@</span><br><span> if (~cmd->usrattr & (1 << i))</span><br><span> continue;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- xml_att_desc = xml_escape(host.app_info->usr_attr_desc[i]);</span><br><span style="color: hsl(120, 100%, 40%);">+ xml_att_desc = xml_escape(desc[i]);</span><br><span> print_func(data, " <attribute doc='%s'", xml_att_desc);</span><br><span> talloc_free(xml_att_desc);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if ((flag = host.app_info->usr_attr_letters[i]) != '\0')</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((flag = letters[i]) != '\0')</span><br><span> print_func(data, " flag='%c'", flag);</span><br><span> print_func(data, " />%s", newline);</span><br><span> }</span><br><span>@@ -4054,4 +4077,26 @@</span><br><span> srand(time(NULL));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* FIXME: execute this section in the unit test instead */</span><br><span style="color: hsl(120, 100%, 40%);">+static __attribute__((constructor)) void on_dso_load(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int i, j;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Check total number of the library specific attributes */</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(_OSMO_CORE_LIB_ATTR_COUNT < 32);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Check for duplicates in the list of library specific flags */</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < _OSMO_CORE_LIB_ATTR_COUNT; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cmd_lib_attr_letters[i] == '\0')</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Only upper case flag letters are allowed for libraries */</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(cmd_lib_attr_letters[i] >= 'A');</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(cmd_lib_attr_letters[i] <= 'Z');</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (j = i + 1; j < _OSMO_CORE_LIB_ATTR_COUNT; j++)</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(cmd_lib_attr_letters[i] != cmd_lib_attr_letters[j]);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! @} */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/20447">change 20447</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/20447"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I15184569635b3ef7dfe9eeddcc19bf16cc358f66 </div>
<div style="display:none"> Gerrit-Change-Number: 20447 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Vadim Yanitskiy <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>