[dbus PATCH 01/15] Introduce Interface Interface

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

 



Signed-off-by: Anya Harter <aharter@xxxxxxxxxx>
---
 data/Makefile.am               |  1 +
 data/org.libvirt.Interface.xml |  7 +++
 src/Makefile.am                |  2 +
 src/connect.c                  |  6 +++
 src/connect.h                  |  1 +
 src/interface.c                | 86 ++++++++++++++++++++++++++++++++++
 src/interface.h                |  9 ++++
 src/util.c                     | 35 ++++++++++++++
 src/util.h                     | 15 ++++++
 9 files changed, 162 insertions(+)
 create mode 100644 data/org.libvirt.Interface.xml
 create mode 100644 src/interface.c
 create mode 100644 src/interface.h

diff --git a/data/Makefile.am b/data/Makefile.am
index 7b523da..35a0bbd 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -33,6 +33,7 @@ polkit_DATA = \
 interfaces_files = \
 	org.libvirt.Connect.xml \
 	org.libvirt.Domain.xml \
+	org.libvirt.Interface.xml \
 	org.libvirt.Network.xml \
 	org.libvirt.NodeDevice.xml \
 	org.libvirt.NWFilter.xml \
diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml
new file mode 100644
index 0000000..93fa32f
--- /dev/null
+++ b/data/org.libvirt.Interface.xml
@@ -0,0 +1,7 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd";>
+
+<node name="/org/libvirt/interface">
+  <interface name="org.libvirt.Interface">
+  </interface>
+</node>
diff --git a/src/Makefile.am b/src/Makefile.am
index b5bf129..d0e8f0d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,6 +41,8 @@ libvirt_dbus_SOURCES = \
 	events.h \
 	gdbus.c \
 	gdbus.h \
+	interface.c \
+	interface.h \
 	main.c \
 	network.c \
 	network.h \
diff --git a/src/connect.c b/src/connect.c
index 9ebceaa..b10533a 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -1,6 +1,7 @@
 #include "connect.h"
 #include "domain.h"
 #include "events.h"
+#include "interface.h"
 #include "network.h"
 #include "nodedev.h"
 #include "nwfilter.h"
@@ -1810,6 +1811,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
 
     g_free(connect->nodeDevPath);
     g_free(connect->domainPath);
+    g_free(connect->interfacePath);
     g_free(connect->networkPath);
     g_free(connect->nwfilterPath);
     g_free(connect->secretPath);
@@ -1869,6 +1871,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
     if (error && *error)
         return;
 
+    virtDBusInterfaceRegister(connect, error);
+    if (error && *error)
+        return;
+
     virtDBusNetworkRegister(connect, error);
     if (error && *error)
         return;
diff --git a/src/connect.h b/src/connect.h
index b81b6a8..f755534 100644
--- a/src/connect.h
+++ b/src/connect.h
@@ -14,6 +14,7 @@ struct virtDBusConnect {
     const gchar *connectPath;
     gchar *nodeDevPath;
     gchar *domainPath;
+    gchar *interfacePath;
     gchar *networkPath;
     gchar *nwfilterPath;
     gchar *secretPath;
diff --git a/src/interface.c b/src/interface.c
new file mode 100644
index 0000000..6dbc702
--- /dev/null
+++ b/src/interface.c
@@ -0,0 +1,86 @@
+#include "interface.h"
+#include "util.h"
+
+#include <libvirt/libvirt.h>
+
+static virInterfacePtr
+virtDBusInterfaceGetVirInterface(virtDBusConnect *connect,
+                                 const gchar *objectPath,
+                                 GError **error)
+{
+    virInterfacePtr interface;
+
+    if (virtDBusConnectOpen(connect, error) < 0)
+        return NULL;
+
+    interface = virtDBusUtilVirInterfaceFromBusPath(connect->connection,
+                                                    objectPath,
+                                                    connect->interfacePath);
+    if (!interface) {
+        virtDBusUtilSetLastVirtError(error);
+        return NULL;
+    }
+
+    return interface;
+}
+
+static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = {
+    { 0 }
+};
+
+static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = {
+    { 0 }
+};
+
+static gchar **
+virtDBusInterfaceEnumerate(gpointer userData)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virInterfacePtr) interfaces = NULL;
+    gint num = 0;
+    gchar **ret = NULL;
+
+    if (!virtDBusConnectOpen(connect, NULL))
+        return NULL;
+
+    num = virConnectListAllInterfaces(connect->connection, &interfaces, 0);
+    if (num < 0)
+        return NULL;
+
+    if (num == 0)
+        return NULL;
+
+    ret = g_new0(gchar *, num + 1);
+
+    for (gint i = 0; i < num; i++) {
+        ret[i] = virtDBusUtilBusPathForVirInterface(interfaces[i],
+                                                    connect->interfacePath);
+    }
+
+    return ret;
+}
+
+static GDBusInterfaceInfo *interfaceInfo;
+
+void
+virtDBusInterfaceRegister(virtDBusConnect *connect,
+                         GError **error)
+{
+    connect->interfacePath = g_strdup_printf("%s/interface",
+                                             connect->connectPath);
+
+    if (!interfaceInfo) {
+        interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_INTERFACE_INTERFACE,
+                                                        error);
+        if (!interfaceInfo)
+            return;
+    }
+
+    virtDBusGDBusRegisterSubtree(connect->bus,
+                                 connect->interfacePath,
+                                 interfaceInfo,
+                                 virtDBusInterfaceEnumerate,
+                                 virtDBusInterfaceMethodTable,
+                                 virtDBusInterfacePropertyTable,
+                                 connect);
+}
diff --git a/src/interface.h b/src/interface.h
new file mode 100644
index 0000000..8e5ee0a
--- /dev/null
+++ b/src/interface.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "connect.h"
+
+#define VIRT_DBUS_INTERFACE_INTERFACE "org.libvirt.Interface"
+
+void
+virtDBusInterfaceRegister(virtDBusConnect *connect,
+                          GError **error);
diff --git a/src/util.c b/src/util.c
index 8c822f2..9e11285 100644
--- a/src/util.c
+++ b/src/util.c
@@ -278,6 +278,41 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains)
     g_free(domains);
 }
 
+virInterfacePtr
+virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection,
+                                    const gchar *path,
+                                    const gchar *interfacePath)
+{
+    g_autofree gchar *macstr = NULL;
+    gsize prefixLen = strlen(interfacePath) + 1;
+
+    macstr = virtDBusUtilDecodeStr(path + prefixLen);
+
+    return virInterfaceLookupByMACString(connection, macstr);
+}
+
+gchar *
+virtDBusUtilBusPathForVirInterface(virInterfacePtr interface,
+                                   const gchar *interfacePath)
+{
+    const gchar *macstr = NULL;
+    g_autofree const gchar *encodedMACStr = NULL;
+
+    macstr = virInterfaceGetMACString(interface);
+    encodedMACStr = virtDBusUtilEncodeStr(macstr);
+
+    return g_strdup_printf("%s/%s", interfacePath, encodedMACStr);
+}
+
+void
+virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces)
+{
+    for (gint i = 0; interfaces[i] != NULL; i++)
+        virInterfaceFree(interfaces[i]);
+
+    g_free(interfaces);
+}
+
 virNetworkPtr
 virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
                                   const gchar *path,
diff --git a/src/util.h b/src/util.h
index a688a3d..b05c2fc 100644
--- a/src/util.h
+++ b/src/util.h
@@ -65,6 +65,21 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecordListFree);
 
+virInterfacePtr
+virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection,
+                                    const gchar *path,
+                                    const gchar *interfacePath);
+
+gchar *
+virtDBusUtilBusPathForVirInterface(virInterfacePtr interface,
+                                   const gchar *interfacePath);
+
+void
+virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterface, virInterfaceFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterfacePtr, virtDBusUtilVirInterfaceListFree);
+
 virNetworkPtr
 virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
                                   const gchar *path,
-- 
2.17.1

--
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