[PATCH 5/8] qemu: Extract generic part from qemuMonitorJSONGetDeviceProps()

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

 



Querying properties for devices and objects is identical except
for the specific QMP command that needs to be called.

Take the existing qemuMonitorJSONGetDeviceProps(), scrub all the
device-specific parts, thus turning it into the generic helper
qemuMonitorJSONGetProps(), which is then used to reimplement the
original function and will be used again once object properties
are needed.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/qemu/qemu_monitor_json.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index eb32811cd1..141873a705 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6058,9 +6058,11 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
 #undef MAKE_SET_CMD
 
 
-int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
-                                  const char *type,
-                                  char ***props)
+static int
+qemuMonitorJSONGetProps(qemuMonitorPtr mon,
+                        const char *type,
+                        char ***props,
+                        const char *impl)
 {
     int ret = -1;
     virJSONValuePtr cmd;
@@ -6072,7 +6074,7 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
 
     *props = NULL;
 
-    if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
+    if (!(cmd = qemuMonitorJSONMakeCommand(impl,
                                            "s:typename", type,
                                            NULL)))
         return -1;
@@ -6090,8 +6092,9 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
 
     if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
         (n = virJSONValueArraySize(data)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("device-list-properties reply data was not an array"));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("%s reply data was not an array"),
+                       impl);
         goto cleanup;
     }
 
@@ -6104,8 +6107,9 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
         const char *tmp;
 
         if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("device-list-properties reply data was missing 'name'"));
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("%s reply data was missing 'name'"),
+                           impl);
             goto cleanup;
         }
 
@@ -6125,6 +6129,16 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
 }
 
 
+int
+qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
+                              const char *type,
+                              char ***props)
+{
+    return qemuMonitorJSONGetProps(mon, type, props,
+                                   "device-list-properties");
+}
+
+
 char *
 qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
 {
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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