--- data/org.libvirt.Connect.xml | 4 ++++ src/connect.c | 20 ++++++++++++++++++++ test/test_connect.py | 1 + 3 files changed, 25 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 56a1126..a58504d 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -7,6 +7,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectGetVersion"/> </property> + <property name="NumOfDomains" type="u" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectNumOfDomains"/> + </property> <method name="ListDomains"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDomains"/> diff --git a/src/connect.c b/src/connect.c index 8898e6d..3f01dca 100644 --- a/src/connect.c +++ b/src/connect.c @@ -98,6 +98,25 @@ virtDBusConnectGetVersion(const gchar *objectPath G_GNUC_UNUSED, *value = g_variant_new("t", hvVer); } +static void +virtDBusConnectNumOfDomains(const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + gint numdomains; + + if (!virtDBusConnectOpen(connect, error)) + return; + + numdomains = virConnectNumOfDomains(connect->connection); + if (numdomains < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("u", numdomains); +} + static void virtDBusConnectListDomains(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -197,6 +216,7 @@ virtDBusConnectDefineXML(GVariant *inArgs, static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Version", virtDBusConnectGetVersion, NULL }, + { "NumOfDomains", virtDBusConnectNumOfDomains, NULL }, { NULL, NULL, NULL } }; diff --git a/test/test_connect.py b/test/test_connect.py index 02a7161..c40c677 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -56,6 +56,7 @@ class TestConnect(libvirttest.BaseTestClass): @pytest.mark.parametrize("property_name,expected_type", [ ("Version", dbus.UInt64), + ("NumOfDomains", dbus.UInt32), ]) def test_connect_properties_return_type(self, property_name, expected_type): obj = self.bus.get_object('org.libvirt', '/org/libvirt/Test') -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list