<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/22322">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty/fsm_vty: Add vty_out_fsm2() + vty_out_fsm_inst2() with prefix<br><br>Callers other than "show fsm" / "show fsm-instances" may want to<br>indent the output.<br><br>Change-Id: I10e01ef91116369868cdb878a99634c8681728af<br>---<br>M include/osmocom/vty/misc.h<br>M src/vty/fsm_vty.c<br>2 files changed, 48 insertions(+), 26 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/22/22322/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/vty/misc.h b/include/osmocom/vty/misc.h</span><br><span>index 2ad9650..ea31c5b 100644</span><br><span>--- a/include/osmocom/vty/misc.h</span><br><span>+++ b/include/osmocom/vty/misc.h</span><br><span>@@ -28,7 +28,9 @@</span><br><span> struct osmo_fsm;</span><br><span> struct osmo_fsm_inst;</span><br><span> void vty_out_fsm(struct vty *vty, struct osmo_fsm *fsm);</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_out_fsm2(struct vty *vty, const char *prefix, struct osmo_fsm *fsm);</span><br><span> void vty_out_fsm_inst(struct vty *vty, struct osmo_fsm_inst *fsmi);</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_out_fsm_inst2(struct vty *vty, const char *prefix, struct osmo_fsm_inst *fsmi);</span><br><span> void osmo_fsm_vty_add_cmds(void);</span><br><span> void osmo_talloc_vty_add_cmds(void);</span><br><span> </span><br><span>diff --git a/src/vty/fsm_vty.c b/src/vty/fsm_vty.c</span><br><span>index 3169ee7..83a8e79 100644</span><br><span>--- a/src/vty/fsm_vty.c</span><br><span>+++ b/src/vty/fsm_vty.c</span><br><span>@@ -51,60 +51,80 @@</span><br><span> </span><br><span> /*! Print information about a FSM [class] to the given VTY</span><br><span>  *  \param vty The VTY to which to print</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] prefix prefix to print at start of each line (typically indenting)</span><br><span>  *  \param[in] fsm The FSM class to print</span><br><span>  */</span><br><span style="color: hsl(0, 100%, 40%);">-void vty_out_fsm(struct vty *vty, struct osmo_fsm *fsm)</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_out_fsm2(struct vty *vty, const char *prefix, struct osmo_fsm *fsm)</span><br><span> {</span><br><span>  unsigned int i;</span><br><span>      const struct value_string *evt_name;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        vty_out(vty, "FSM Name: '%s', Log Subsys: '%s'%s", fsm->name,</span><br><span style="color: hsl(120, 100%, 40%);">+    vty_out(vty, "%sFSM Name: '%s', Log Subsys: '%s'%s", prefix, fsm->name,</span><br><span>                 log_category_name(fsm->log_subsys), VTY_NEWLINE);</span><br><span>         /* list the events */</span><br><span>        if (fsm->event_names) {</span><br><span>           for (evt_name = fsm->event_names; evt_name->str != NULL; evt_name++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                    vty_out(vty, " Event %02u (0x%08x): '%s'%s", evt_name->value,</span><br><span style="color: hsl(120, 100%, 40%);">+                    vty_out(vty, "%s Event %02u (0x%08x): '%s'%s", prefix, evt_name->value,</span><br><span>                                 (1 << evt_name->value), evt_name->str, VTY_NEWLINE);</span><br><span>             }</span><br><span>    } else</span><br><span style="color: hsl(0, 100%, 40%);">-          vty_out(vty, " No event names are defined for this FSM! Please fix!%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+               vty_out(vty, "%s No event names are defined for this FSM! Please fix!%s", prefix, VTY_NEWLINE);</span><br><span> </span><br><span>        /* list the states */</span><br><span style="color: hsl(0, 100%, 40%);">-   vty_out(vty, " Number of States: %u%s", fsm->num_states, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+   vty_out(vty, "%s Number of States: %u%s", prefix, fsm->num_states, VTY_NEWLINE);</span><br><span>        for (i = 0; i < fsm->num_states; i++) {</span><br><span>                const struct osmo_fsm_state *state = &fsm->states[i];</span><br><span style="color: hsl(0, 100%, 40%);">-            vty_out(vty, "  State %-20s InEvtMask: 0x%08x, OutStateMask: 0x%08x%s",</span><br><span style="color: hsl(120, 100%, 40%);">+             vty_out(vty, "%s  State %-20s InEvtMask: 0x%08x, OutStateMask: 0x%08x%s", prefix,</span><br><span>                  state->name, state->in_event_mask, state->out_state_mask,</span><br><span>                   VTY_NEWLINE);</span><br><span>        }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Print information about a FSM [class] to the given VTY</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param vty The VTY to which to print</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] fsm The FSM class to print</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_out_fsm(struct vty *vty, struct osmo_fsm *fsm)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  vty_out_fsm2(vty, "", fsm);</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%);">+/*! Print a FSM instance to the given VTY</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param vty The VTY to which to print</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] prefix prefix to print at start of each line (typically indenting)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] fsmi The FSM instance to print</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_out_fsm_inst2(struct vty *vty, const char *prefix, struct osmo_fsm_inst *fsmi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    struct osmo_fsm_inst *child;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        vty_out(vty, "%sFSM Instance Name: '%s', ID: '%s'%s", prefix,</span><br><span style="color: hsl(120, 100%, 40%);">+               fsmi->name, fsmi->id, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+     vty_out(vty, "%s Log-Level: '%s', State: '%s'%s", prefix,</span><br><span style="color: hsl(120, 100%, 40%);">+           log_level_str(fsmi->log_level),</span><br><span style="color: hsl(120, 100%, 40%);">+            osmo_fsm_state_name(fsmi->fsm, fsmi->state),</span><br><span style="color: hsl(120, 100%, 40%);">+            VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (fsmi->T)</span><br><span style="color: hsl(120, 100%, 40%);">+               vty_out(vty, "%s Timer: %u%s", prefix, fsmi->T, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (fsmi->proc.parent) {</span><br><span style="color: hsl(120, 100%, 40%);">+           vty_out(vty, "%s Parent: '%s', Term-Event: '%s'%s", prefix,</span><br><span style="color: hsl(120, 100%, 40%);">+                 fsmi->proc.parent->name,</span><br><span style="color: hsl(120, 100%, 40%);">+                        osmo_fsm_event_name(fsmi->proc.parent->fsm,</span><br><span style="color: hsl(120, 100%, 40%);">+                                         fsmi->proc.parent_term_event),</span><br><span style="color: hsl(120, 100%, 40%);">+                 VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+     llist_for_each_entry(child, &fsmi->proc.children, proc.child) {</span><br><span style="color: hsl(120, 100%, 40%);">+                vty_out(vty, "%s Child: '%s'%s", prefix, child->name, VTY_NEWLINE);</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> /*! Print a FSM instance to the given VTY</span><br><span>  *  \param vty The VTY to which to print</span><br><span>  *  \param[in] fsmi The FSM instance to print</span><br><span>  */</span><br><span> void vty_out_fsm_inst(struct vty *vty, struct osmo_fsm_inst *fsmi)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-      struct osmo_fsm_inst *child;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    vty_out(vty, "FSM Instance Name: '%s', ID: '%s'%s",</span><br><span style="color: hsl(0, 100%, 40%);">-           fsmi->name, fsmi->id, VTY_NEWLINE);</span><br><span style="color: hsl(0, 100%, 40%);">-       vty_out(vty, " Log-Level: '%s', State: '%s'%s",</span><br><span style="color: hsl(0, 100%, 40%);">-               log_level_str(fsmi->log_level),</span><br><span style="color: hsl(0, 100%, 40%);">-              osmo_fsm_state_name(fsmi->fsm, fsmi->state),</span><br><span style="color: hsl(0, 100%, 40%);">-              VTY_NEWLINE);</span><br><span style="color: hsl(0, 100%, 40%);">-   if (fsmi->T)</span><br><span style="color: hsl(0, 100%, 40%);">-         vty_out(vty, " Timer: %u%s", fsmi->T, VTY_NEWLINE);</span><br><span style="color: hsl(0, 100%, 40%);">-        if (fsmi->proc.parent) {</span><br><span style="color: hsl(0, 100%, 40%);">-             vty_out(vty, " Parent: '%s', Term-Event: '%s'%s",</span><br><span style="color: hsl(0, 100%, 40%);">-                     fsmi->proc.parent->name,</span><br><span style="color: hsl(0, 100%, 40%);">-                  osmo_fsm_event_name(fsmi->proc.parent->fsm,</span><br><span style="color: hsl(0, 100%, 40%);">-                                           fsmi->proc.parent_term_event),</span><br><span style="color: hsl(0, 100%, 40%);">-                   VTY_NEWLINE);</span><br><span style="color: hsl(0, 100%, 40%);">-   }</span><br><span style="color: hsl(0, 100%, 40%);">-       llist_for_each_entry(child, &fsmi->proc.children, proc.child) {</span><br><span style="color: hsl(0, 100%, 40%);">-          vty_out(vty, " Child: '%s'%s", child->name, VTY_NEWLINE);</span><br><span style="color: hsl(0, 100%, 40%);">-  }</span><br><span style="color: hsl(120, 100%, 40%);">+     vty_out_fsm_inst2(vty, "", fsmi);</span><br><span> }</span><br><span> </span><br><span> #define SH_FSM_STR      SHOW_STR "Show information about finite state machines\n"</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/22322">change 22322</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/+/22322"/><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: I10e01ef91116369868cdb878a99634c8681728af </div>
<div style="display:none"> Gerrit-Change-Number: 22322 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>