[PATCH v2 04/13] virsh-interface: Add a static helper virshInterfaceStringHelper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It will be helpful to get the desired string of interface name/mac in a
consistent way.

Signed-off-by: Lin Ma <lma@xxxxxxxx>
---
 tools/virsh-completer-interface.c | 25 ++++++++++++++++---------
 tools/virsh-completer-interface.h |  3 +++
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/tools/virsh-completer-interface.c b/tools/virsh-completer-interface.c
index 8028db8746..407021485f 100644
--- a/tools/virsh-completer-interface.c
+++ b/tools/virsh-completer-interface.c
@@ -25,16 +25,16 @@
 #include "virsh.h"
 #include "virstring.h"
 
-char **
-virshInterfaceNameCompleter(vshControl *ctl,
-                            const vshCmd *cmd G_GNUC_UNUSED,
-                            unsigned int flags)
+static char **
+virshInterfaceStringHelper(vshControl *ctl,
+                           const vshCmd *cmd G_GNUC_UNUSED,
+                           unsigned int flags,
+                           virInterfaceStringCallback cb)
 {
     virshControlPtr priv = ctl->privData;
     virInterfacePtr *ifaces = NULL;
     int nifaces = 0;
     size_t i = 0;
-    char **ret = NULL;
     VIR_AUTOSTRINGLIST tmp = NULL;
 
     virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
@@ -50,15 +50,22 @@ virshInterfaceNameCompleter(vshControl *ctl,
     tmp = g_new0(char *, nifaces + 1);
 
     for (i = 0; i < nifaces; i++) {
-        const char *name = virInterfaceGetName(ifaces[i]);
+        const char *name = (cb)(ifaces[i]);
 
         tmp[i] = g_strdup(name);
     }
 
-    ret = g_steal_pointer(&tmp);
-
     for (i = 0; i < nifaces; i++)
         virInterfaceFree(ifaces[i]);
     g_free(ifaces);
-    return ret;
+
+    return g_steal_pointer(&tmp);
+}
+
+char **
+virshInterfaceNameCompleter(vshControl *ctl,
+                            const vshCmd *cmd,
+                            unsigned int flags)
+{
+    return virshInterfaceStringHelper(ctl, cmd, flags, virInterfaceGetName);
 }
diff --git a/tools/virsh-completer-interface.h b/tools/virsh-completer-interface.h
index 893dee5a6b..32da01e766 100644
--- a/tools/virsh-completer-interface.h
+++ b/tools/virsh-completer-interface.h
@@ -22,6 +22,9 @@
 
 #include "vsh.h"
 
+typedef const char *
+(*virInterfaceStringCallback)(virInterfacePtr iface);
+
 char ** virshInterfaceNameCompleter(vshControl *ctl,
                                     const vshCmd *cmd,
                                     unsigned int flags);
-- 
2.26.0





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux