[dbus PATCH v3 5/5] Merge all Domain lifecycle signals into one signal called Domain.

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

 



Instead of having multiple signals regarding to domain events,
like DomainStarted, DomainUndefined etc, we will have only one
called DomainEvents, and the specific event type will be specified in
the signals arguments.

The domain name argument in not needed in the signal since we can
fetch it from path.

The tests are adjusted to call correctly connect_to_signal method
on the new signal.

Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 data/org.libvirt.Connect.xml | 54 +++-----------------------------------------
 src/events.c                 | 24 +++++++++-----------
 test/test_connect.py         | 10 ++++----
 test/test_domain.py          | 20 +++++++---------
 4 files changed, 26 insertions(+), 82 deletions(-)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index f24dff4..1695100 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -44,59 +44,11 @@
       <arg name="uuid" type="s" direction="in"/>
       <arg name="domain" type="o" direction="out"/>
     </method>
-    <signal name="DomainCrashed">
+    <signal name="DomainEvent">
       <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_CRASHED"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainDefined">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_DEFINED"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainPMSuspended">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_SUSPENDED"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainResumed">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_RESUMED"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainShutdown">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_SHUTDOWN"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainStarted">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_STARTED"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainStopped">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_STOPPED"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainSuspended">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_SUSPENDED"/>
-      <arg name="reason" type="s"/>
-      <arg name="domain" type="o"/>
-    </signal>
-    <signal name="DomainUndefined">
-      <annotation name="org.gtk.GDBus.DocString"
-        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_UNDEFINED"/>
-      <arg name="reason" type="s"/>
+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/>
       <arg name="domain" type="o"/>
+      <arg name="event" type="s"/>
     </signal>
   </interface>
 </node>
diff --git a/src/events.c b/src/events.c
index 1877115..9229063 100644
--- a/src/events.c
+++ b/src/events.c
@@ -7,15 +7,15 @@
 VIRT_DBUS_ENUM_DECL(virtDBusEventsDomainEvent)
 VIRT_DBUS_ENUM_IMPL(virtDBusEventsDomainEvent,
                     VIR_DOMAIN_EVENT_LAST,
-                    "DomainDefined",
-                    "DomainUndefined",
-                    "DomainStarted",
-                    "DomainSuspended",
-                    "DomainResumed",
-                    "DomainStopped",
-                    "DomainShutdown",
-                    "DomainPMSuspended",
-                    "DomainCrashed")
+                    "Defined",
+                    "Undefined",
+                    "Started",
+                    "Suspended",
+                    "Resumed",
+                    "Stopped",
+                    "Shutdown",
+                    "PMSuspended",
+                    "Crashed")
 
 static const gchar *
 virtDBusEventsDomainEventToString(gint event)
@@ -32,18 +32,16 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED,
                               gpointer opaque)
 {
     virtDBusConnect *connect = opaque;
-    const gchar *name;
     g_autofree gchar *path = NULL;
 
-    name = virDomainGetName(domain);
     path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
 
     g_dbus_connection_emit_signal(connect->bus,
                                   NULL,
                                   connect->connectPath,
                                   VIRT_DBUS_CONNECT_INTERFACE,
-                                  virtDBusEventsDomainEventToString(event),
-                                  g_variant_new("(so)", name, path),
+                                  "DomainEvent",
+                                  g_variant_new("(os)", path, virtDBusEventsDomainEventToString(event)),
                                   NULL);
 
     return 0;
diff --git a/test/test_connect.py b/test/test_connect.py
index 48e25cb..e8b9f92 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -29,12 +29,11 @@ class TestConnect(libvirttest.BaseTestClass):
             domain.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE)
 
     def test_create(self):
-        def domain_started(name, path):
-            assert name == 'foo'
+        def domain_started(path, _event):
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainStarted', domain_started)
+        self.connect.connect_to_signal('DomainEvent', domain_started, arg2='Started')
 
         path = self.connect.CreateXML(self.minimal_xml, 0)
         assert isinstance(path, dbus.ObjectPath)
@@ -42,12 +41,11 @@ class TestConnect(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_define(self):
-        def domain_defined(name, path):
-            assert name == 'foo'
+        def domain_defined(path, _event):
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainDefined', domain_defined)
+        self.connect.connect_to_signal('DomainEvent', domain_defined, arg2='Defined')
 
         path = self.connect.DefineXML(self.minimal_xml)
         assert isinstance(path, dbus.ObjectPath)
diff --git a/test/test_domain.py b/test/test_domain.py
index 1433ff5..fa30e7c 100755
--- a/test/test_domain.py
+++ b/test/test_domain.py
@@ -38,12 +38,11 @@ class TestDomain(libvirttest.BaseTestClass):
         domain.Undefine(0)
 
     def test_shutdown(self):
-        def domain_stopped(name, path):
-            assert name == 'test'
+        def domain_stopped(path, _event):
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainStopped', domain_stopped)
+        self.connect.connect_to_signal('DomainEvent', domain_stopped, arg2='Stopped')
 
         obj, domain = self.domain()
         domain.Shutdown(0)
@@ -54,12 +53,11 @@ class TestDomain(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_undefine(self):
-        def domain_undefined(name, path):
-            assert name == 'test'
+        def domain_undefined(path, _event):
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainUndefined', domain_undefined)
+        self.connect.connect_to_signal('DomainEvent', domain_undefined, arg2='Undefined')
 
         _, domain = self.domain()
         domain.Shutdown(0)
@@ -68,12 +66,11 @@ class TestDomain(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_suspend(self):
-        def domain_suspended(name, path):
-            assert name == 'test'
+        def domain_suspended(path, _event):
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainSuspended', domain_suspended)
+        self.connect.connect_to_signal('DomainEvent', domain_suspended, arg2='Suspended')
 
         obj, domain = self.domain()
         domain.Suspend()
@@ -84,12 +81,11 @@ class TestDomain(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_resume(self):
-        def domain_resumed(name, path):
-            assert name == 'test'
+        def domain_resumed(path, _event):
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainResumed', domain_resumed)
+        self.connect.connect_to_signal('DomainEvent', domain_resumed, arg2='Resumed')
 
         obj, domain = self.domain()
         domain.Suspend()
-- 
2.15.0

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