[libvirt] [dbus PATCH v2 11/17] Implement Active property for Interface Interface

Anya Harter aharter at redhat.com
Fri Jul 20 18:34:55 UTC 2018


Signed-off-by: Anya Harter <aharter at redhat.com>
---
 data/org.libvirt.Interface.xml |  5 +++++
 src/interface.c                | 22 ++++++++++++++++++++++
 tests/test_interface.py        |  1 +
 3 files changed, 28 insertions(+)

diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml
index 921e07f..6dd7c68 100644
--- a/data/org.libvirt.Interface.xml
+++ b/data/org.libvirt.Interface.xml
@@ -3,6 +3,11 @@
 
 <node name="/org/libvirt/interface">
   <interface name="org.libvirt.Interface">
+    <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
+    <property name="Active" type="b" access="read">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive"/>
+    </property>
     <property name="MAC" type="s" access="read">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString"/>
diff --git a/src/interface.c b/src/interface.c
index 4caafcf..191b8be 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -70,6 +70,27 @@ virtDBusInterfaceDestroy(GVariant *inArgs,
         virtDBusUtilSetLastVirtError(error);
 }
 
+static void
+virtDBusInterfaceGetActive(const gchar *objectPath,
+                           gpointer userData,
+                           GVariant **value,
+                           GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virInterface) interface = NULL;
+    gint active;
+
+    interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
+    if (!interface)
+        return;
+
+    active = virInterfaceIsActive(interface);
+    if (active < 0)
+        return virtDBusUtilSetLastVirtError(error);
+
+    *value = g_variant_new("b", !!active);
+}
+
 static void
 virtDBusInterfaceGetMAC(const gchar *objectPath,
                         gpointer userData,
@@ -160,6 +181,7 @@ virtDBusInterfaceUndefine(GVariant *inArgs G_GNUC_UNUSED,
 }
 
 static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = {
+    { "Active", virtDBusInterfaceGetActive, NULL },
     { "MAC", virtDBusInterfaceGetMAC, NULL },
     { "Name", virtDBusInterfaceGetName, NULL },
     { 0 }
diff --git a/tests/test_interface.py b/tests/test_interface.py
index 325f889..4c7e3fb 100755
--- a/tests/test_interface.py
+++ b/tests/test_interface.py
@@ -33,6 +33,7 @@ class TestInterface(libvirttest.BaseTestClass):
         props = obj.GetAll('org.libvirt.Interface', dbus_interface=dbus.PROPERTIES_IFACE)
         assert isinstance(props['Name'], dbus.String)
         assert isinstance(props['MAC'], dbus.String)
+        assert isinstance(props['Active'], dbus.Boolean)
 
 if __name__ == '__main__':
     libvirttest.run()
-- 
2.17.1




More information about the libvir-list mailing list