virDomainGetState API uses flags arg, thus we can't leave it
as a property.
Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Domain.xml | 10 +++++----
src/domain.c | 49 ++++++++++++++++++++++++++-------------------
tests/test_domain.py | 9 ++++-----
3 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index bcd0779..9343dbd 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -33,10 +33,6 @@
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedule...
</property>
- <property name="State" type="u" access="read">
- <annotation name="org.gtk.GDBus.DocString"
- value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetState&qu...
- </property>
<property name="Updated" type="b" access="read">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsUpdated&q...
@@ -288,6 +284,12 @@
<arg name="flags" type="u" direction="in"/>
<arg name="SchedulerParameters" type="a{sv}"
direction="out"/>
</method>
+ <method name="GetState">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetState&qu...
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="state" type="(ii)"
direction="out"/>
+ </method>
<method name="GetStats">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainListGetStat...
diff --git a/src/domain.c b/src/domain.c
index eaef68c..06b3f17 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -313,26 +313,6 @@ virtDBusDomainGetSchedulerType(const gchar *objectPath,
*value = g_variant_new("(si)", schedtype, nparams);
}
-static void
-virtDBusDomainGetState(const gchar *objectPath,
- gpointer userData,
- GVariant **value,
- GError **error)
-{
- virtDBusConnect *connect = userData;
- g_autoptr(virDomain) domain = NULL;
- gint state = 0;
-
- domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
- if (!domain)
- return;
-
- if (virDomainGetState(domain, &state, NULL, 0) < 0)
- return virtDBusUtilSetLastVirtError(error);
-
- *value = g_variant_new("u", state);
-}
-
static void
virtDBusDomainGetUpdated(const gchar *objectPath,
gpointer userData,
@@ -1546,6 +1526,33 @@ virtDBusDomainGetSchedulerParameters(GVariant *inArgs,
*outArgs = g_variant_new_tuple(&grecords, 1);
}
+static void
+virtDBusDomainGetState(GVariant *inArgs,
+ GUnixFDList *inFDs G_GNUC_UNUSED,
+ const gchar *objectPath,
+ gpointer userData,
+ GVariant **outArgs,
+ GUnixFDList **outFDs G_GNUC_UNUSED,
+ GError **error)
+{
+ virtDBusConnect *connect = userData;
+ g_autoptr(virDomain) domain = NULL;
+ guint flags;
+ gint state;
+ gint reason;
+
+ g_variant_get(inArgs, "(u)", &flags);
+
+ domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
+ if (!domain)
+ return;
+
+ if (virDomainGetState(domain, &state, &reason, flags) < 0)
+ return virtDBusUtilSetLastVirtError(error);
+
+ *outArgs = g_variant_new("((ii))", state, reason);
+}
+
static void
virtDBusDomainGetStats(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -2865,7 +2872,6 @@ static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = {
{ "OSType", virtDBusDomainGetOsType, NULL },
{ "Persistent", virtDBusDomainGetPersistent, NULL },
{ "SchedulerType", virtDBusDomainGetSchedulerType, NULL},
- { "State", virtDBusDomainGetState, NULL },
{ "Updated", virtDBusDomainGetUpdated, NULL },
{ "UUID", virtDBusDomainGetUUID, NULL },
{ 0 }
@@ -2909,6 +2915,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = {
{ "GetNumaParameters", virtDBusDomainGetNumaParameters },
{ "GetPerfEvents", virtDBusDomainGetPerfEvents },
{ "GetSchedulerParameters", virtDBusDomainGetSchedulerParameters },
+ { "GetState", virtDBusDomainGetState },
{ "GetStats", virtDBusDomainGetStats },
{ "GetTime", virtDBusDomainGetTime },
{ "GetVcpus", virtDBusDomainGetVcpus },
diff --git a/tests/test_domain.py b/tests/test_domain.py
index dfa19ed..511af43 100755
--- a/tests/test_domain.py
+++ b/tests/test_domain.py
@@ -19,7 +19,6 @@ class TestDomain(libvirttest.BaseTestClass):
assert any([isinstance(props['SchedulerType'], dbus.Struct),
isinstance(props['SchedulerType'][0], dbus.String),
isinstance(props['SchedulerType'][1], dbus.Int32)])
- assert isinstance(props['State'], dbus.UInt32)
assert isinstance(props['Updated'], dbus.Boolean)
assert isinstance(props['UUID'], dbus.String)
@@ -59,7 +58,7 @@ class TestDomain(libvirttest.BaseTestClass):
obj, domain = self.domain()
domain.ManagedSave(0)
assert domain.HasManagedSaveImage(0) == dbus.Boolean(True)
- state = obj.Get('org.libvirt.Domain', 'State',
dbus_interface=dbus.PROPERTIES_IFACE)
+ state, _ = domain.GetState(0)
assert state == libvirttest.DomainState.SHUTOFF
domain.ManagedSaveRemove(0)
assert domain.HasManagedSaveImage(0) == dbus.Boolean(False)
@@ -88,7 +87,7 @@ class TestDomain(libvirttest.BaseTestClass):
domain.Suspend()
domain.Resume()
- state = obj.Get('org.libvirt.Domain', 'State',
dbus_interface=dbus.PROPERTIES_IFACE)
+ state, _ = domain.GetState(0)
assert state == libvirttest.DomainState.RUNNING
self.main_loop()
@@ -106,7 +105,7 @@ class TestDomain(libvirttest.BaseTestClass):
obj, domain = self.domain()
domain.Shutdown(0)
- state = obj.Get('org.libvirt.Domain', 'State',
dbus_interface=dbus.PROPERTIES_IFACE)
+ state, _ = domain.GetState(0)
assert state == libvirttest.DomainState.SHUTOFF
self.main_loop()
@@ -124,7 +123,7 @@ class TestDomain(libvirttest.BaseTestClass):
obj, domain = self.domain()
domain.Suspend()
- state = obj.Get('org.libvirt.Domain', 'State',
dbus_interface=dbus.PROPERTIES_IFACE)
+ state, _ = domain.GetState(0)
assert state == libvirttest.DomainState.PAUSED
self.main_loop()
--
2.15.0