Patchwork [08/21] qom: add plug_create QMP command

login
register
mail settings
Submitter Anthony Liguori
Date July 25, 2011, 1:44 a.m.
Message ID <1311558293-5855-9-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/106594/
State New
Headers show

Comments

Anthony Liguori - July 25, 2011, 1:44 a.m.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 monitor.c       |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx |   27 +++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)

Patch

diff --git a/monitor.c b/monitor.c
index 718935b..8406b5b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -62,6 +62,12 @@ 
 #endif
 #include "ui/qemu-spice.h"
 
+#include "qemu/plug.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi/qmp-output-visitor.h"
+
+#include <glib.h>
+
 //#define DEBUG
 //#define DEBUG_COMPLETION
 
@@ -1020,6 +1026,49 @@  static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return 0;
 }
 
+static GSList *global_plug_list;
+
+static int do_plug_create(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    const char *id = qdict_get_str(qdict, "id");
+    const char *type = qdict_get_str(qdict, "type");
+    QmpInputVisitor *qiv;
+    Visitor *v;
+    const QDictEntry *e;
+    TypeInstance *inst;
+    Plug *plug;
+
+    inst = type_new(type, id);
+    if (inst == NULL) {
+        return -1;
+    }
+
+    plug = PLUG(inst);
+
+    global_plug_list = g_slist_prepend(global_plug_list, plug);
+
+    qiv = qmp_input_visitor_new((QObject *)QOBJECT(qdict));
+    v = qmp_input_get_visitor(qiv);
+
+    for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
+        Error *local_err = NULL;
+
+        if (strcmp(e->key, "id") == 0 || strcmp(e->key, "type") == 0) {
+            continue;
+        }
+
+        plug_set_property(plug, e->key, v, &local_err);
+        if (local_err) {
+            error_free(local_err);
+            return -1;
+        }
+    }
+
+    qmp_input_visitor_cleanup(qiv);
+
+    return 0;
+}
+
 #ifdef CONFIG_VNC
 static int change_vnc_password(const char *password)
 {
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 54e313c..c86d396 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -85,6 +85,33 @@  Example:
 EQMP
 
     {
+        .name       = "plug_create",
+        .args_type  = "device:O",
+        .params     = "type=value,id=value[,prop=value][,...]",
+        .help       = "create a plug",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_plug_create,
+    },
+
+SQMP
+plug_create
+-----------
+
+Create a plug.
+
+Arguments:
+
+- type: typename of object (json-string)
+- id: name of object (json-string)
+- object properties
+
+Notes:
+
+ (1) id MUST not contain the sequence "::"
+
+EQMP
+
+    {
         .name       = "eject",
         .args_type  = "force:-f,device:B",
         .params     = "[-f] device",