[libvirt] [dbus PATCH 0/4] New APIs and Domain Lifecycle signal change

* Implemented Suspend and Resume APIs. * Merged all Domain Lifecycle events signals into one signal. * Reused virsh functions for taking the Event Strings names from ENUM. Katerina Koukiou (4): Implement Suspend method for Domain interface. Implement Resume method for Domain interface. Merge all Domain lifecycle signals into one signal called Domain. Introduce functions for translating Events to strings data/org.libvirt.Connect.xml | 54 +++----------------------------------------- data/org.libvirt.Domain.xml | 8 +++++++ m4/virt-compile-warnings.m4 | 3 +++ src/domain.c | 42 ++++++++++++++++++++++++++++++++++ src/events.c | 39 ++------------------------------ src/util.c | 30 ++++++++++++++++++++++++ src/util.h | 30 ++++++++++++++++++++++++ test/test_connect.py | 10 ++++---- test/test_domain.py | 40 +++++++++++++++++++++++++++----- 9 files changed, 156 insertions(+), 100 deletions(-) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 ++++ src/domain.c | 21 +++++++++++++++++++++ test/test_domain.py | 15 +++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 39212ff..f31d078 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -84,6 +84,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainUndefineFlags"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="Suspend"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSuspend"/> + </method> <signal name="DeviceAdded"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventDeviceAddedCallback"/> diff --git a/src/domain.c b/src/domain.c index 4ff9f60..cb13b6b 100644 --- a/src/domain.c +++ b/src/domain.c @@ -450,6 +450,26 @@ virtDBusDomainUndefine(GVariant *inArgs G_GNUC_UNUSED, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusDomainSuspend(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virDomain) domain = NULL; + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (virDomainSuspend(domain) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { { "Name", virtDBusDomainGetName, NULL }, { "UUID", virtDBusDomainGetUUID, NULL }, @@ -472,6 +492,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "Reset", virtDBusDomainReset }, { "Create", virtDBusDomainCreate }, { "Undefine", virtDBusDomainUndefine }, + { "Suspend", virtDBusDomainSuspend }, { 0 } }; diff --git a/test/test_domain.py b/test/test_domain.py index e617b1b..bb1b498 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -67,6 +67,21 @@ class TestDomain(libvirttest.BaseTestClass): self.main_loop() + def test_suspend(self): + def domain_suspended(name, path): + assert name == 'test' + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('DomainSuspended', domain_suspended) + + obj, domain = self.domain() + domain.Suspend() + + state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE) + assert state == 'paused' + + self.main_loop() if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Thu, Mar 29, 2018 at 01:07:55PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 ++++ src/domain.c | 21 +++++++++++++++++++++ test/test_domain.py | 15 +++++++++++++++ 3 files changed, 40 insertions(+)
ACK Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 ++++ src/domain.c | 21 +++++++++++++++++++++ test/test_domain.py | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index f31d078..7679018 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -88,6 +88,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSuspend"/> </method> + <method name="Resume"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainResume"/> + </method> <signal name="DeviceAdded"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventDeviceAddedCallback"/> diff --git a/src/domain.c b/src/domain.c index cb13b6b..a530987 100644 --- a/src/domain.c +++ b/src/domain.c @@ -470,6 +470,26 @@ virtDBusDomainSuspend(GVariant *inArgs G_GNUC_UNUSED, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusDomainResume(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virDomain) domain = NULL; + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (virDomainResume(domain) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { { "Name", virtDBusDomainGetName, NULL }, { "UUID", virtDBusDomainGetUUID, NULL }, @@ -493,6 +513,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "Create", virtDBusDomainCreate }, { "Undefine", virtDBusDomainUndefine }, { "Suspend", virtDBusDomainSuspend }, + { "Resume", virtDBusDomainResume }, { 0 } }; diff --git a/test/test_domain.py b/test/test_domain.py index bb1b498..1433ff5 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -83,5 +83,22 @@ class TestDomain(libvirttest.BaseTestClass): self.main_loop() + def test_resume(self): + def domain_resumed(name, path): + assert name == 'test' + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('DomainResumed', domain_resumed) + + obj, domain = self.domain() + domain.Suspend() + domain.Resume() + + state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE) + assert state == 'running' + + self.main_loop() + if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Thu, Mar 29, 2018 at 01:07:56PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 ++++ src/domain.c | 21 +++++++++++++++++++++ test/test_domain.py | 17 +++++++++++++++++ 3 files changed, 42 insertions(+)
ACK Jano

Instead of having multiple signals regarding to domain events, like DomainStarted, DomainUndefined etc, we will have only one called Domain, 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@redhat.com> --- data/org.libvirt.Connect.xml | 54 +++----------------------------------------- src/events.c | 26 ++++++++++----------- test/test_connect.py | 10 ++++---- test/test_domain.py | 20 +++++++--------- 4 files changed, 27 insertions(+), 83 deletions(-) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f24dff4..6810422 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="Domain"> <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 dada55f..62f3729 100644 --- a/src/events.c +++ b/src/events.c @@ -12,51 +12,49 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, gpointer opaque) { virtDBusConnect *connect = opaque; - const gchar *signal = NULL; - const gchar *name; + const gchar *event_type = NULL; g_autofree gchar *path = NULL; switch (event) { case VIR_DOMAIN_EVENT_DEFINED: - signal = "DomainDefined"; + event_type = "DomainDefined"; break; case VIR_DOMAIN_EVENT_UNDEFINED: - signal = "DomainUndefined"; + event_type = "DomainUndefined"; break; case VIR_DOMAIN_EVENT_STARTED: - signal = "DomainStarted"; + event_type = "DomainStarted"; break; case VIR_DOMAIN_EVENT_SUSPENDED: - signal = "DomainSuspended"; + event_type = "DomainSuspended"; break; case VIR_DOMAIN_EVENT_RESUMED: - signal = "DomainResumed"; + event_type = "DomainResumed"; break; case VIR_DOMAIN_EVENT_STOPPED: - signal = "DomainStopped"; + event_type = "DomainStopped"; break; case VIR_DOMAIN_EVENT_SHUTDOWN: - signal = "DomainShutdown"; + event_type = "DomainShutdown"; break; case VIR_DOMAIN_EVENT_PMSUSPENDED: - signal = "DomainPMSuspended"; + event_type = "DomainPMSuspended"; break; case VIR_DOMAIN_EVENT_CRASHED: - signal = "DomainCrashed"; + event_type = "DomainCrashed"; break; default: return 0; } - name = virDomainGetName(domain); path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath); g_dbus_connection_emit_signal(connect->bus, NULL, connect->connectPath, VIRT_DBUS_CONNECT_INTERFACE, - signal, - g_variant_new("(so)", name, path), + "Domain", + g_variant_new("(os)", path, event_type), NULL); return 0; diff --git a/test/test_connect.py b/test/test_connect.py index 48e25cb..c7830c5 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('Domain', domain_started, arg2='DomainStarted') 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('Domain', domain_defined, arg2='DomainDefined') 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..7dbc971 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('Domain', domain_stopped, arg2='DomainStopped') 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('Domain', domain_undefined, arg2='DomainUndefined') _, 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('Domain', domain_suspended, arg2='DomainSuspended') 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('Domain', domain_resumed, arg2='DomainResumed') obj, domain = self.domain() domain.Suspend() -- 2.15.0

On Thu, Mar 29, 2018 at 01:07:57PM +0200, Katerina Koukiou wrote:
Instead of having multiple signals regarding to domain events, like DomainStarted, DomainUndefined etc, we will have only one called Domain, 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.
Any plans to add support for the 'detail' field of virConnectDomainEventCallback?
The tests are adjusted to call correctly connect_to_signal method on the new signal.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 54 +++----------------------------------------- src/events.c | 26 ++++++++++----------- test/test_connect.py | 10 ++++---- test/test_domain.py | 20 +++++++--------- 4 files changed, 27 insertions(+), 83 deletions(-)
diff --git a/src/events.c b/src/events.c index dada55f..62f3729 100644 --- a/src/events.c +++ b/src/events.c @@ -12,51 +12,49 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, gpointer opaque) { virtDBusConnect *connect = opaque; - const gchar *signal = NULL; - const gchar *name; + const gchar *event_type = NULL; g_autofree gchar *path = NULL;
switch (event) { case VIR_DOMAIN_EVENT_DEFINED: - signal = "DomainDefined"; + event_type = "DomainDefined"; break; case VIR_DOMAIN_EVENT_UNDEFINED: - signal = "DomainUndefined"; + event_type = "DomainUndefined"; break; case VIR_DOMAIN_EVENT_STARTED: - signal = "DomainStarted"; + event_type = "DomainStarted"; break; case VIR_DOMAIN_EVENT_SUSPENDED: - signal = "DomainSuspended"; + event_type = "DomainSuspended"; break; case VIR_DOMAIN_EVENT_RESUMED: - signal = "DomainResumed"; + event_type = "DomainResumed"; break; case VIR_DOMAIN_EVENT_STOPPED: - signal = "DomainStopped"; + event_type = "DomainStopped"; break; case VIR_DOMAIN_EVENT_SHUTDOWN: - signal = "DomainShutdown"; + event_type = "DomainShutdown"; break; case VIR_DOMAIN_EVENT_PMSUSPENDED: - signal = "DomainPMSuspended"; + event_type = "DomainPMSuspended"; break; case VIR_DOMAIN_EVENT_CRASHED: - signal = "DomainCrashed"; + event_type = "DomainCrashed"; break; default: return 0;
Converting this to an EnumToString call first would make the commit replacing the char* variable name and the commit dropping the Domain prefix nicer. Jan

On Thu, 2018-03-29 at 15:05 +0200, Ján Tomko wrote:
On Thu, Mar 29, 2018 at 01:07:57PM +0200, Katerina Koukiou wrote:
Instead of having multiple signals regarding to domain events, like DomainStarted, DomainUndefined etc, we will have only one called Domain, 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.
Any plans to add support for the 'detail' field of virConnectDomainEventCallback?
Yes, I guess it's ok to be in different patchset though.
The tests are adjusted to call correctly connect_to_signal method on the new signal.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 54 +++---------------------------- ------------- src/events.c | 26 ++++++++++----------- test/test_connect.py | 10 ++++---- test/test_domain.py | 20 +++++++--------- 4 files changed, 27 insertions(+), 83 deletions(-)
diff --git a/src/events.c b/src/events.c index dada55f..62f3729 100644 --- a/src/events.c +++ b/src/events.c @@ -12,51 +12,49 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, gpointer opaque) { virtDBusConnect *connect = opaque; - const gchar *signal = NULL; - const gchar *name; + const gchar *event_type = NULL; g_autofree gchar *path = NULL;
switch (event) { case VIR_DOMAIN_EVENT_DEFINED: - signal = "DomainDefined"; + event_type = "DomainDefined"; break; case VIR_DOMAIN_EVENT_UNDEFINED: - signal = "DomainUndefined"; + event_type = "DomainUndefined"; break; case VIR_DOMAIN_EVENT_STARTED: - signal = "DomainStarted"; + event_type = "DomainStarted"; break; case VIR_DOMAIN_EVENT_SUSPENDED: - signal = "DomainSuspended"; + event_type = "DomainSuspended"; break; case VIR_DOMAIN_EVENT_RESUMED: - signal = "DomainResumed"; + event_type = "DomainResumed"; break; case VIR_DOMAIN_EVENT_STOPPED: - signal = "DomainStopped"; + event_type = "DomainStopped"; break; case VIR_DOMAIN_EVENT_SHUTDOWN: - signal = "DomainShutdown"; + event_type = "DomainShutdown"; break; case VIR_DOMAIN_EVENT_PMSUSPENDED: - signal = "DomainPMSuspended"; + event_type = "DomainPMSuspended"; break; case VIR_DOMAIN_EVENT_CRASHED: - signal = "DomainCrashed"; + event_type = "DomainCrashed"; break; default: return 0;
Converting this to an EnumToString call first would make the commit replacing the char* variable name and the commit dropping the Domain prefix nicer.
Good point. I reverted the order of the two commits.
Jan

On Thu, Mar 29, 2018 at 05:15:05PM +0200, Katerina Koukiou wrote:
On Thu, 2018-03-29 at 15:05 +0200, Ján Tomko wrote:
On Thu, Mar 29, 2018 at 01:07:57PM +0200, Katerina Koukiou wrote:
Instead of having multiple signals regarding to domain events, like DomainStarted, DomainUndefined etc, we will have only one called Domain, 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.
Any plans to add support for the 'detail' field of virConnectDomainEventCallback?
Yes, I guess it's ok to be in different patchset though.
Given the warning in README.md: NB: at this time, libvirt-dbus is *NOT* considered API/ABI stable. Future releases may still include API/ABI incompatible changes. It's ok for it to be in a different release. Jano

On Thu, Mar 29, 2018 at 01:07:57PM +0200, Katerina Koukiou wrote:
Instead of having multiple signals regarding to domain events, like DomainStarted, DomainUndefined etc, we will have only one called Domain, 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@redhat.com> --- data/org.libvirt.Connect.xml | 54 +++----------------------------------------- src/events.c | 26 ++++++++++----------- test/test_connect.py | 10 ++++---- test/test_domain.py | 20 +++++++--------- 4 files changed, 27 insertions(+), 83 deletions(-)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f24dff4..6810422 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="Domain">
I'm not sure about using "Domain" as the signal name, how about "DomainEvent", "DomainChanded" or "DomainState"? Pavel

On Thu, 2018-03-29 at 15:14 +0200, Pavel Hrdina wrote:
On Thu, Mar 29, 2018 at 01:07:57PM +0200, Katerina Koukiou wrote:
Instead of having multiple signals regarding to domain events, like DomainStarted, DomainUndefined etc, we will have only one called Domain, 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@redhat.com> --- data/org.libvirt.Connect.xml | 54 +++----------------------------- ------------ src/events.c | 26 ++++++++++----------- test/test_connect.py | 10 ++++---- test/test_domain.py | 20 +++++++--------- 4 files changed, 27 insertions(+), 83 deletions(-)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f24dff4..6810422 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="Domain">
I'm not sure about using "Domain" as the signal name, how about "DomainEvent", "DomainChanded" or "DomainState"?
DomainEvent sounds good. Changed.
Pavel

The functions were copied from src/util/virutil.* files from libvirt project. They will be needed for other function of enum to string as well. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- m4/virt-compile-warnings.m4 | 3 +++ src/events.c | 35 +---------------------------------- src/util.c | 30 ++++++++++++++++++++++++++++++ src/util.h | 30 ++++++++++++++++++++++++++++++ test/test_connect.py | 4 ++-- test/test_domain.py | 8 ++++---- 6 files changed, 70 insertions(+), 40 deletions(-) diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index 6ece136..7bc49b2 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -123,6 +123,9 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ # but need to rewrite various areas of code first wantwarn="$wantwarn -Wno-format-truncation" + # Needeed for *EventToString related functions. + wantwarn="$wantwarn -Wno-suggest-attribute=pure" + # This should be < 256 really. Currently we're down to 4096, # but using 1024 bytes sized buffers (mostly for virStrerror) # stops us from going down further diff --git a/src/events.c b/src/events.c index 62f3729..52c53ac 100644 --- a/src/events.c +++ b/src/events.c @@ -12,41 +12,8 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, gpointer opaque) { virtDBusConnect *connect = opaque; - const gchar *event_type = NULL; g_autofree gchar *path = NULL; - switch (event) { - case VIR_DOMAIN_EVENT_DEFINED: - event_type = "DomainDefined"; - break; - case VIR_DOMAIN_EVENT_UNDEFINED: - event_type = "DomainUndefined"; - break; - case VIR_DOMAIN_EVENT_STARTED: - event_type = "DomainStarted"; - break; - case VIR_DOMAIN_EVENT_SUSPENDED: - event_type = "DomainSuspended"; - break; - case VIR_DOMAIN_EVENT_RESUMED: - event_type = "DomainResumed"; - break; - case VIR_DOMAIN_EVENT_STOPPED: - event_type = "DomainStopped"; - break; - case VIR_DOMAIN_EVENT_SHUTDOWN: - event_type = "DomainShutdown"; - break; - case VIR_DOMAIN_EVENT_PMSUSPENDED: - event_type = "DomainPMSuspended"; - break; - case VIR_DOMAIN_EVENT_CRASHED: - event_type = "DomainCrashed"; - break; - default: - return 0; - } - path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath); g_dbus_connection_emit_signal(connect->bus, @@ -54,7 +21,7 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, connect->connectPath, VIRT_DBUS_CONNECT_INTERFACE, "Domain", - g_variant_new("(os)", path, event_type), + g_variant_new("(os)", path, virtDBusDomainEventToString(event)), NULL); return 0; diff --git a/src/util.c b/src/util.c index d6c27f3..9f645d2 100644 --- a/src/util.c +++ b/src/util.c @@ -124,3 +124,33 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains) g_free(domains); } + +const gchar *virEnumToString(const gchar *const*types, + guint ntypes, + gint type) +{ + if (type < 0 || (unsigned)type >= ntypes) + return NULL; + + return types[type]; +} + +VIR_ENUM_DECL(virtDBusDomainEvent) +VIR_ENUM_IMPL(virtDBusDomainEvent, + VIR_DOMAIN_EVENT_LAST, + "Defined", + "Undefined", + "Started", + "Suspended", + "Resumed", + "Stopped", + "Shutdown", + "PMSuspended", + "Crashed") + +const gchar * +virtDBusDomainEventToString(gint event) +{ + const gchar *str = virtDBusDomainEventTypeToString(event); + return str ? str : "unknown"; +} diff --git a/src/util.h b/src/util.h index 4304bac..22cf25e 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,7 @@ #include "gdbus.h" +#define VIR_ENUM_SENTINELS #include <libvirt/libvirt.h> #define VIRT_DBUS_ERROR virtDBusErrorQuark() @@ -37,3 +38,32 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomain, virDomainFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree); + +gint virEnumFromString(const gchar *const*types, + guint ntypes, + const gchar *type); + +const gchar *virEnumToString(const gchar *const*types, + guint ntypes, + gint type); + +# define VIR_ENUM_IMPL(name, lastVal, ...) \ + static const gchar *const name ## TypeList[] = { __VA_ARGS__ }; \ + G_STATIC_ASSERT(G_N_ELEMENTS(name ## TypeList) == lastVal); \ + const gchar *name ## TypeToString(int type) { \ + return virEnumToString(name ## TypeList, \ + G_N_ELEMENTS(name ## TypeList), \ + type); \ + } \ + gint name ## TypeFromString(const gchar *type) { \ + return virEnumFromString(name ## TypeList, \ + G_N_ELEMENTS(name ## TypeList), \ + type); \ + } + +# define VIR_ENUM_DECL(name) \ + const gchar *name ## TypeToString(gint type); \ + gint name ## TypeFromString(const gchar*type); + +const gchar * +virtDBusDomainEventToString(gint event); diff --git a/test/test_connect.py b/test/test_connect.py index c7830c5..8bab625 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -33,7 +33,7 @@ class TestConnect(libvirttest.BaseTestClass): assert isinstance(path, dbus.ObjectPath) self.loop.quit() - self.connect.connect_to_signal('Domain', domain_started, arg2='DomainStarted') + self.connect.connect_to_signal('Domain', domain_started, arg2='Started') path = self.connect.CreateXML(self.minimal_xml, 0) assert isinstance(path, dbus.ObjectPath) @@ -45,7 +45,7 @@ class TestConnect(libvirttest.BaseTestClass): assert isinstance(path, dbus.ObjectPath) self.loop.quit() - self.connect.connect_to_signal('Domain', domain_defined, arg2='DomainDefined') + self.connect.connect_to_signal('Domain', 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 7dbc971..4d03c4b 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -42,7 +42,7 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(path, dbus.ObjectPath) self.loop.quit() - self.connect.connect_to_signal('Domain', domain_stopped, arg2='DomainStopped') + self.connect.connect_to_signal('Domain', domain_stopped, arg2='Stopped') obj, domain = self.domain() domain.Shutdown(0) @@ -57,7 +57,7 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(path, dbus.ObjectPath) self.loop.quit() - self.connect.connect_to_signal('Domain', domain_undefined, arg2='DomainUndefined') + self.connect.connect_to_signal('Domain', domain_undefined, arg2='Undefined') _, domain = self.domain() domain.Shutdown(0) @@ -70,7 +70,7 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(path, dbus.ObjectPath) self.loop.quit() - self.connect.connect_to_signal('Domain', domain_suspended, arg2='DomainSuspended') + self.connect.connect_to_signal('Domain', domain_suspended, arg2='Suspended') obj, domain = self.domain() domain.Suspend() @@ -85,7 +85,7 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(path, dbus.ObjectPath) self.loop.quit() - self.connect.connect_to_signal('Domain', domain_resumed, arg2='DomainResumed') + self.connect.connect_to_signal('Domain', domain_resumed, arg2='Resumed') obj, domain = self.domain() domain.Suspend() -- 2.15.0

On Thu, Mar 29, 2018 at 01:07:58PM +0200, Katerina Koukiou wrote:
The functions were copied from src/util/virutil.* files from libvirt project.
They will be needed for other function of enum to string as well.
This should be split into two patches, one that introduces the new macros and second one that uses them.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- m4/virt-compile-warnings.m4 | 3 +++ src/events.c | 35 +---------------------------------- src/util.c | 30 ++++++++++++++++++++++++++++++ src/util.h | 30 ++++++++++++++++++++++++++++++ test/test_connect.py | 4 ++-- test/test_domain.py | 8 ++++---- 6 files changed, 70 insertions(+), 40 deletions(-)
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index 6ece136..7bc49b2 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -123,6 +123,9 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ # but need to rewrite various areas of code first wantwarn="$wantwarn -Wno-format-truncation"
+ # Needeed for *EventToString related functions. + wantwarn="$wantwarn -Wno-suggest-attribute=pure" +
There is no need to disable this warning, we can use G_GNUC_PURE for the affected functions.
# This should be < 256 really. Currently we're down to 4096, # but using 1024 bytes sized buffers (mostly for virStrerror) # stops us from going down further diff --git a/src/events.c b/src/events.c index 62f3729..52c53ac 100644 --- a/src/events.c +++ b/src/events.c @@ -12,41 +12,8 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, gpointer opaque) { virtDBusConnect *connect = opaque; - const gchar *event_type = NULL; g_autofree gchar *path = NULL;
- switch (event) { - case VIR_DOMAIN_EVENT_DEFINED: - event_type = "DomainDefined"; - break; - case VIR_DOMAIN_EVENT_UNDEFINED: - event_type = "DomainUndefined"; - break; - case VIR_DOMAIN_EVENT_STARTED: - event_type = "DomainStarted"; - break; - case VIR_DOMAIN_EVENT_SUSPENDED: - event_type = "DomainSuspended"; - break; - case VIR_DOMAIN_EVENT_RESUMED: - event_type = "DomainResumed"; - break; - case VIR_DOMAIN_EVENT_STOPPED: - event_type = "DomainStopped"; - break; - case VIR_DOMAIN_EVENT_SHUTDOWN: - event_type = "DomainShutdown"; - break; - case VIR_DOMAIN_EVENT_PMSUSPENDED: - event_type = "DomainPMSuspended"; - break; - case VIR_DOMAIN_EVENT_CRASHED: - event_type = "DomainCrashed"; - break; - default: - return 0; - } - path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
g_dbus_connection_emit_signal(connect->bus, @@ -54,7 +21,7 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, connect->connectPath, VIRT_DBUS_CONNECT_INTERFACE, "Domain", - g_variant_new("(os)", path, event_type), + g_variant_new("(os)", path, virtDBusDomainEventToString(event)), NULL);
return 0; diff --git a/src/util.c b/src/util.c index d6c27f3..9f645d2 100644 --- a/src/util.c +++ b/src/util.c @@ -124,3 +124,33 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains)
g_free(domains); } + +const gchar *virEnumToString(const gchar *const*types, + guint ntypes, + gint type)
Return type should be on a separate line, see HACKING.md and other functions in this file. Even though that this function is copied from libvirt where we use vir* prefix, this package uses virtDBus* prefix and each file has it's own prefix, so in this case the prefix is virtDBusUtil* and the function name should be virtDBusUtilEnumToString.
+{ + if (type < 0 || (unsigned)type >= ntypes) + return NULL; + + return types[type]; +} + +VIR_ENUM_DECL(virtDBusDomainEvent) +VIR_ENUM_IMPL(virtDBusDomainEvent, + VIR_DOMAIN_EVENT_LAST, + "Defined", + "Undefined", + "Started", + "Suspended", + "Resumed", + "Stopped", + "Shutdown", + "PMSuspended", + "Crashed")
This is currently used only in event.c so it should go into top of that file.
+ +const gchar * +virtDBusDomainEventToString(gint event) +{ + const gchar *str = virtDBusDomainEventTypeToString(event); + return str ? str : "unknown"; +}
This one as well and the function name prefix should be fixed.
diff --git a/src/util.h b/src/util.h index 4304bac..22cf25e 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,7 @@
#include "gdbus.h"
+#define VIR_ENUM_SENTINELS #include <libvirt/libvirt.h>
#define VIRT_DBUS_ERROR virtDBusErrorQuark() @@ -37,3 +38,32 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomain, virDomainFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree); + +gint virEnumFromString(const gchar *const*types, + guint ntypes, + const gchar *type); + +const gchar *virEnumToString(const gchar *const*types, + guint ntypes, + gint type);
Same comment for the return type and the function name.
+ +# define VIR_ENUM_IMPL(name, lastVal, ...) \ + static const gchar *const name ## TypeList[] = { __VA_ARGS__ }; \ + G_STATIC_ASSERT(G_N_ELEMENTS(name ## TypeList) == lastVal); \ + const gchar *name ## TypeToString(int type) { \ + return virEnumToString(name ## TypeList, \ + G_N_ELEMENTS(name ## TypeList), \ + type); \ + } \ + gint name ## TypeFromString(const gchar *type) { \ + return virEnumFromString(name ## TypeList, \ + G_N_ELEMENTS(name ## TypeList), \ + type); \ + } + +# define VIR_ENUM_DECL(name) \ + const gchar *name ## TypeToString(gint type); \ + gint name ## TypeFromString(const gchar*type);
There is no need to have the space after '#', that is used in libvirt because the macro is in #ifndef ... #endif block. Both macros should use also the VIRT_DBUS prefix instead of VIR. Pavel

On Thu, Mar 29, 2018 at 02:44:54PM +0200, Pavel Hrdina wrote:
On Thu, Mar 29, 2018 at 01:07:58PM +0200, Katerina Koukiou wrote:
The functions were copied from src/util/virutil.* files from libvirt project.
They will be needed for other function of enum to string as well.
This should be split into two patches, one that introduces the new macros and second one that uses them.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- m4/virt-compile-warnings.m4 | 3 +++ src/events.c | 35 +---------------------------------- src/util.c | 30 ++++++++++++++++++++++++++++++ src/util.h | 30 ++++++++++++++++++++++++++++++ test/test_connect.py | 4 ++-- test/test_domain.py | 8 ++++---- 6 files changed, 70 insertions(+), 40 deletions(-)
diff --git a/src/util.h b/src/util.h index 4304bac..22cf25e 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,7 @@
#include "gdbus.h"
+#define VIR_ENUM_SENTINELS #include <libvirt/libvirt.h>
#define VIRT_DBUS_ERROR virtDBusErrorQuark() @@ -37,3 +38,32 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomain, virDomainFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree); + +gint virEnumFromString(const gchar *const*types, + guint ntypes, + const gchar *type);
The definition of this function is also missing. Jano

On Thu, 2018-03-29 at 15:11 +0200, Ján Tomko wrote:
On Thu, Mar 29, 2018 at 02:44:54PM +0200, Pavel Hrdina wrote:
On Thu, Mar 29, 2018 at 01:07:58PM +0200, Katerina Koukiou wrote:
The functions were copied from src/util/virutil.* files from libvirt project.
They will be needed for other function of enum to string as well.
This should be split into two patches, one that introduces the new macros and second one that uses them.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- m4/virt-compile-warnings.m4 | 3 +++ src/events.c | 35 +---------------------------- ------ src/util.c | 30 ++++++++++++++++++++++++++++++ src/util.h | 30 ++++++++++++++++++++++++++++++ test/test_connect.py | 4 ++-- test/test_domain.py | 8 ++++---- 6 files changed, 70 insertions(+), 40 deletions(-)
diff --git a/src/util.h b/src/util.h index 4304bac..22cf25e 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,7 @@
#include "gdbus.h"
+#define VIR_ENUM_SENTINELS #include <libvirt/libvirt.h>
#define VIRT_DBUS_ERROR virtDBusErrorQuark() @@ -37,3 +38,32 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomain, virDomainFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree); + +gint virEnumFromString(const gchar *const*types, + guint ntypes, + const gchar *type);
The definition of this function is also missing.
Yes, I already realized it when I tried to rename it from the name used in libvirt to something else. Fixed.
Jano

On Thu, 2018-03-29 at 14:44 +0200, Pavel Hrdina wrote:
On Thu, Mar 29, 2018 at 01:07:58PM +0200, Katerina Koukiou wrote:
The functions were copied from src/util/virutil.* files from libvirt project.
They will be needed for other function of enum to string as well.
This should be split into two patches, one that introduces the new macros and second one that uses them.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- m4/virt-compile-warnings.m4 | 3 +++ src/events.c | 35 +------------------------------ ---- src/util.c | 30 ++++++++++++++++++++++++++++++ src/util.h | 30 ++++++++++++++++++++++++++++++ test/test_connect.py | 4 ++-- test/test_domain.py | 8 ++++---- 6 files changed, 70 insertions(+), 40 deletions(-)
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile- warnings.m4 index 6ece136..7bc49b2 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -123,6 +123,9 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ # but need to rewrite various areas of code first wantwarn="$wantwarn -Wno-format-truncation"
+ # Needeed for *EventToString related functions. + wantwarn="$wantwarn -Wno-suggest-attribute=pure" +
There is no need to disable this warning, we can use G_GNUC_PURE for the affected functions.
# This should be < 256 really. Currently we're down to 4096, # but using 1024 bytes sized buffers (mostly for virStrerror) # stops us from going down further diff --git a/src/events.c b/src/events.c index 62f3729..52c53ac 100644 --- a/src/events.c +++ b/src/events.c @@ -12,41 +12,8 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, gpointer opaque) { virtDBusConnect *connect = opaque; - const gchar *event_type = NULL; g_autofree gchar *path = NULL;
- switch (event) { - case VIR_DOMAIN_EVENT_DEFINED: - event_type = "DomainDefined"; - break; - case VIR_DOMAIN_EVENT_UNDEFINED: - event_type = "DomainUndefined"; - break; - case VIR_DOMAIN_EVENT_STARTED: - event_type = "DomainStarted"; - break; - case VIR_DOMAIN_EVENT_SUSPENDED: - event_type = "DomainSuspended"; - break; - case VIR_DOMAIN_EVENT_RESUMED: - event_type = "DomainResumed"; - break; - case VIR_DOMAIN_EVENT_STOPPED: - event_type = "DomainStopped"; - break; - case VIR_DOMAIN_EVENT_SHUTDOWN: - event_type = "DomainShutdown"; - break; - case VIR_DOMAIN_EVENT_PMSUSPENDED: - event_type = "DomainPMSuspended"; - break; - case VIR_DOMAIN_EVENT_CRASHED: - event_type = "DomainCrashed"; - break; - default: - return 0; - } - path = virtDBusUtilBusPathForVirDomain(domain, connect-
domainPath);
g_dbus_connection_emit_signal(connect->bus, @@ -54,7 +21,7 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, connect->connectPath, VIRT_DBUS_CONNECT_INTERFACE, "Domain", - g_variant_new("(os)", path, event_type), + g_variant_new("(os)", path, virtDBusDomainEventToString(event)), NULL);
return 0; diff --git a/src/util.c b/src/util.c index d6c27f3..9f645d2 100644 --- a/src/util.c +++ b/src/util.c @@ -124,3 +124,33 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains)
g_free(domains); } + +const gchar *virEnumToString(const gchar *const*types, + guint ntypes, + gint type)
Return type should be on a separate line, see HACKING.md and other functions in this file.
Even though that this function is copied from libvirt where we use vir* prefix, this package uses virtDBus* prefix and each file has it's own prefix, so in this case the prefix is virtDBusUtil* and the function name should be virtDBusUtilEnumToString.
+{ + if (type < 0 || (unsigned)type >= ntypes) + return NULL; + + return types[type]; +} + +VIR_ENUM_DECL(virtDBusDomainEvent) +VIR_ENUM_IMPL(virtDBusDomainEvent, + VIR_DOMAIN_EVENT_LAST, + "Defined", + "Undefined", + "Started", + "Suspended", + "Resumed", + "Stopped", + "Shutdown", + "PMSuspended", + "Crashed")
This is currently used only in event.c so it should go into top of that file.
+ +const gchar * +virtDBusDomainEventToString(gint event) +{ + const gchar *str = virtDBusDomainEventTypeToString(event); + return str ? str : "unknown"; +}
This one as well and the function name prefix should be fixed.
diff --git a/src/util.h b/src/util.h index 4304bac..22cf25e 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,7 @@
#include "gdbus.h"
+#define VIR_ENUM_SENTINELS #include <libvirt/libvirt.h>
#define VIRT_DBUS_ERROR virtDBusErrorQuark() @@ -37,3 +38,32 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomain, virDomainFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree); + +gint virEnumFromString(const gchar *const*types, + guint ntypes, + const gchar *type); + +const gchar *virEnumToString(const gchar *const*types, + guint ntypes, + gint type);
Same comment for the return type and the function name.
+ +# define VIR_ENUM_IMPL(name, lastVal, ...) \ + static const gchar *const name ## TypeList[] = { __VA_ARGS__ }; \ + G_STATIC_ASSERT(G_N_ELEMENTS(name ## TypeList) == lastVal); \ + const gchar *name ## TypeToString(int type) { \ + return virEnumToString(name ## TypeList, \ + G_N_ELEMENTS(name ## TypeList), \ + type); \ + } \ + gint name ## TypeFromString(const gchar *type) { \ + return virEnumFromString(name ## TypeList, \ + G_N_ELEMENTS(name ## TypeList), \ + type); \ + } + +# define VIR_ENUM_DECL(name) \ + const gchar *name ## TypeToString(gint type); \ + gint name ## TypeFromString(const gchar*type);
There is no need to have the space after '#', that is used in libvirt because the macro is in #ifndef ... #endif block.
Both macros should use also the VIRT_DBUS prefix instead of VIR.
Pavel
All comments fixed in the second patchset. Thanks, Katerina
participants (3)
-
Ján Tomko
-
Katerina Koukiou
-
Pavel Hrdina