[dbus PATCH v2] Add 'Version' property for virConnectGetVersion

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

 



---
 data/org.libvirt.Connect.xml |  4 ++++
 src/connect.c                | 25 ++++++++++++++++++++++++-
 test/test_connect.py         |  9 +++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index e47c2f5..56a1126 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -3,6 +3,10 @@
 
 <node name="/org/libvirt/connect">
   <interface name="org.libvirt.Connect">
+    <property name="Version" type="t" access="read">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectGetVersion"/>
+    </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 bf97cd5..8898e6d 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -80,6 +80,24 @@ virtDBusConnectOpen(virtDBusConnect *connect,
     return TRUE;
 }
 
+static void
+virtDBusConnectGetVersion(const gchar *objectPath G_GNUC_UNUSED,
+                          gpointer userData,
+                          GVariant **value,
+                          GError **error)
+{
+    virtDBusConnect *connect = userData;
+    gulong hvVer;
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    if (virConnectGetVersion(connect->connection, &hvVer) < 0)
+        return virtDBusUtilSetLastVirtError(error);
+
+    *value = g_variant_new("t", hvVer);
+}
+
 static void
 virtDBusConnectListDomains(GVariant *inArgs,
                            GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -177,6 +195,11 @@ virtDBusConnectDefineXML(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
+    { "Version", virtDBusConnectGetVersion, NULL },
+    { NULL, NULL, NULL }
+};
+
 static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "ListDomains", virtDBusConnectListDomains },
     { "CreateXML", virtDBusConnectCreateXML },
@@ -228,7 +251,7 @@ virtDBusConnectNew(virtDBusConnect **connectp,
                                 connect->connectPath,
                                 interfaceInfo,
                                 virtDBusConnectMethodTable,
-                                NULL,
+                                virtDBusConnectPropertyTable,
                                 connect);
 
     virtDBusDomainRegister(connect, error);
diff --git a/test/test_connect.py b/test/test_connect.py
index a52140c..01d4d41 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -2,6 +2,7 @@
 
 import dbus
 import libvirttest
+import pytest
 
 
 class TestConnect(libvirttest.BaseTestClass):
@@ -53,6 +54,14 @@ class TestConnect(libvirttest.BaseTestClass):
 
         self.main_loop()
 
+    @pytest.mark.parametrize("property_name,expected_type", [
+        ("Version", dbus.UInt64),
+    ])
+    def test_connect_properties_return_type(self, property_name, expected_type):
+        obj = self.bus.get_object('org.libvirt', '/org/libvirt/Test')
+        props = obj.GetAll('org.libvirt.Connect', dbus_interface=dbus.PROPERTIES_IFACE)
+        assert isinstance(props[property_name], expected_type)
+
 
 if __name__ == '__main__':
     libvirttest.run()
-- 
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