for testing the new qemu specific regiater API

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

 



From: ShaoHe Feng <shaohef@xxxxxxxxxxxxxxxxxx>

this patch is just used to the new register API

add two command, register-event and deregister-event in virsh in order to test the new API.

there will come an  "RESUME" events when qemu domains are started.

virish starts a qemu domain and to catch "RESUME" event.
virsh# register-event RESUME
virsh# start domain

Signed-off-by: ShaoHe Feng <shaohef@xxxxxxxxxxxxxxxxxx>
---
 tools/virsh.c |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 3654589..392768f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -36,6 +36,7 @@
 
 #include <libxml/parser.h>
 #include <libxml/tree.h>
+#include <libxml/uri.h>
 #include <libxml/xpath.h>
 #include <libxml/xmlsave.h>
 
@@ -53,6 +54,8 @@
 #include "memory.h"
 #include "xml.h"
 #include "libvirt/libvirt-qemu.h"
+#include "libvirt/libvirt.h"
+#include "datatypes.h"
 #include "virfile.h"
 #include "event_poll.h"
 #include "configmake.h"
@@ -11976,6 +11979,107 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+static const vshCmdInfo info_deregevent[] = {
+    {"help", N_("deregister an qemu event")},
+    {"desc", N_("you please input you eventID, that the register-event returns.")},
+    {NULL, NULL}
+};
+static const vshCmdOptDef opts_deregevent[] = {
+    {"eventID", VSH_OT_INT, VSH_OFLAG_REQ, N_("deregister qemu spici eventID ")},
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdDeregisterEvent(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    bool ret = false;
+    int eventID = -1;
+    int retEventID = -1;
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if (vshCommandOptInt(cmd, "eventID", &eventID) < 0) {
+        vshError(ctl, "%s", _("Please specify valid eventID"));
+        return false;
+    }
+    if (eventID < 0) {
+        fprintf(stdout, "please input a positive Int\n");
+        return false;
+    }
+
+    if ((retEventID = virConnectDomainQemuEventDeregister(ctl->conn, eventID)) < 0) {
+       fprintf(stdout, "eventID: %d Deregister error.\n", eventID);
+       return false;
+    }
+    fprintf(stdout, "event Deregister success, the remote callbackID is %d.\n", retEventID);
+    ret = true;
+ cleanup:
+    return ret;
+}
+
+static const vshCmdInfo info_regevent[] = {
+    {"help", N_("register an qemu event")},
+    {"desc", N_("you please input you event name.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_regevent[] = {
+    {"event", VSH_OT_DATA, VSH_OFLAG_REQ, N_("register qemu spici event ")},
+    {NULL, 0, 0, NULL}
+};
+
+void printRegistEvent(virConnectPtr conn,
+                      virDomainPtr dom,
+                      const char *eventName, /* The JSON event name */
+                      const char *eventArgs, /* The JSON string of args */
+                      void *opaque){
+    char *uriName = virConnectGetURI (conn);
+    fputc('\n', stdout);
+    if (uriName != NULL)
+       fprintf(stdout, "connect URI: %s, ",uriName);
+
+    if (dom != NULL)
+       fprintf(stdout, "dom: %s(%d) receive an event:\n", dom->name, dom->id);
+
+    if (eventName != NULL)
+        fprintf(stdout, "{ event: %s", eventName);
+    if (eventArgs != NULL)
+        fprintf(stdout, ", data: %s }\n", eventArgs);
+    else
+        fprintf(stdout, " }\n");
+    fprintf(stdout, "----------------------------------------------");
+    fputc('\n', stdout);
+}
+
+static bool
+cmdRegisterEvent(vshControl *ctl, const vshCmd *cmd)
+{
+    const char *name = NULL;
+    virDomainPtr dom;
+    bool ret = false;
+    int eventID = -1;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if (vshCommandOptString(cmd, "event", &name) < 0) {
+        vshError(ctl, "%s", _("Please specify valid event name"));
+        return false;
+    }
+
+    dom = NULL;
+    eventID = virConnectDomainQemuEventRegister(ctl->conn, dom, name, printRegistEvent, NULL, NULL);
+    if (eventID < 0) {
+       fprintf(stdout, "%s event register error.\n", name);
+       return false;
+    }
+    fprintf(stdout, "%s event call back ID is %d, you can use it to deregister the event.\n", name, eventID);
+    ret = true;
+ cleanup:
+    return ret;
+}
+
 /*
  * "ttyconsole" command
  */
@@ -15363,6 +15467,8 @@ static const vshCmdDef domManagementCmds[] = {
     {"vcpupin", cmdVcpuPin, opts_vcpupin, info_vcpupin, 0},
     {"version", cmdVersion, opts_version, info_version, 0},
     {"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay, 0},
+    {"register-event", cmdRegisterEvent, opts_regevent, info_regevent, 0},
+    {"deregister-event", cmdDeregisterEvent, opts_deregevent, info_deregevent, 0},
     {NULL, NULL, NULL, NULL, 0}
 };
 
-- 
1.7.5.4

--
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]