Patchwork [v1,13/21] qapi: add command registration/lookup functions

login
register
mail settings
Submitter Michael Roth
Date June 1, 2011, 5:24 p.m.
Message ID <1306949089-15597-14-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/98306/
State New
Headers show

Comments

Michael Roth - June 1, 2011, 5:24 p.m.
Registration/lookup functions for that provide a lookup table for
dispatching QMP commands.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qapi/qmp-registry.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 qapi/qmp-registry.c

Patch

diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c
new file mode 100644
index 0000000..f870244
--- /dev/null
+++ b/qapi/qmp-registry.c
@@ -0,0 +1,27 @@ 
+#include "qapi/qmp-core.h"
+
+static QTAILQ_HEAD(, QmpCommand) qmp_commands =
+    QTAILQ_HEAD_INITIALIZER(qmp_commands);
+
+void qmp_register_command(const char *name, QmpCommandFunc *fn)
+{
+    QmpCommand *cmd = qemu_mallocz(sizeof(*cmd));
+
+    cmd->name = name;
+    cmd->type = QCT_NORMAL;
+    cmd->fn = fn;
+    QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
+}
+
+QmpCommand *qmp_find_command(const char *name)
+{
+    QmpCommand *i;
+
+    QTAILQ_FOREACH(i, &qmp_commands, node) {
+        if (strcmp(i->name, name) == 0) {
+            return i;
+        }
+    }
+    return NULL;
+}
+