On Thu, Apr 05, 2018 at 12:40:17PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/Makefile.am | 3 ++-
data/org.libvirt.Network.xml | 7 +++++
src/Makefile.am | 3 ++-
src/connect.c | 6 +++++
src/connect.h | 1 +
src/network.c | 64 ++++++++++++++++++++++++++++++++++++++++++++
src/network.h | 9 +++++++
src/util.c | 33 +++++++++++++++++++++++
src/util.h | 15 +++++++++++
9 files changed, 139 insertions(+), 2 deletions(-)
create mode 100644 data/org.libvirt.Network.xml
create mode 100644 src/network.c
create mode 100644 src/network.h
[...]
diff --git a/src/network.c b/src/network.c
new file mode 100644
index 0000000..0d0e992
--- /dev/null
+++ b/src/network.c
@@ -0,0 +1,64 @@
+#include "network.h"
+#include "util.h"
+
+#include <libvirt/libvirt.h>
+
+static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = {
+ { 0 }
+};
+
+static virtDBusGDBusMethodTable virtDBusNetworkMethodTable[] = {
+ { 0 }
+};
+
+static gchar **
+virtDBusNetworkEnumerate(gpointer userData)
+{
+ virtDBusConnect *connect = userData;
+ g_autoptr(virNetworkPtr) networks = NULL;
+ gint num = 0;
+ gchar **ret = NULL;
+
+ if (!virtDBusConnectOpen(connect, NULL))
+ return NULL;
+
+ num = virConnectListAllNetworks(connect->connection, &networks, 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] = virtDBusUtilBusPathForVirNetwork(networks[i],
+ connect->networkPath);
+ }
+
+ return ret;
+}
+
+static GDBusInterfaceInfo *interfaceInfo = NULL;
+
+void
+virtDBusNetworkRegister(virtDBusConnect *connect,
+ GError **error)
The indentation is still off here.
+{
+ connect->networkPath = g_strdup_printf("%s/network",
connect->connectPath);
+
+ if (!interfaceInfo) {
+ interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NETWORK_INTERFACE,
+ error);
+ if (!interfaceInfo)
+ return;
+ }
+
+ virtDBusGDBusRegisterSubtree(connect->bus,
+ connect->networkPath,
+ interfaceInfo,
+ virtDBusNetworkEnumerate,
+ virtDBusNetworkMethodTable,
+ virtDBusNetworkPropertyTable,
+ connect);
+}
diff --git a/src/network.h b/src/network.h
new file mode 100644
index 0000000..fc53b28
--- /dev/null
+++ b/src/network.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "connect.h"
+
+#define VIRT_DBUS_NETWORK_INTERFACE "org.libvirt.Network"
+
+void
+virtDBusNetworkRegister(virtDBusConnect *connect,
+ GError **error);
diff --git a/src/util.c b/src/util.c
index be65172..03a0f10 100644
--- a/src/util.c
+++ b/src/util.c
@@ -151,3 +151,36 @@ virtDBusUtilEnumFromString(const gchar *const *types,
return -1;
}
+
+virNetworkPtr
+virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *networkPath)
And here the indentation is also off.
+{
+ g_autofree gchar *name = NULL;
+ gsize prefixLen = strlen(networkPath) + 1;
+
+ name = virtDBusUtilDecodeUUID(path+prefixLen);
+
+ return virNetworkLookupByUUIDString(connection, name);
+}
+
+gchar *
+virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
+ const gchar *networkPath)
+{
+ gchar uuid[VIR_UUID_STRING_BUFLEN] = "";
+ g_autofree gchar *newUuid = NULL;
+ virNetworkGetUUIDString(network, uuid);
+ newUuid = virtDBusUtilEncodeUUID(uuid);
+ return g_strdup_printf("%s/%s", networkPath, newUuid);
+}
+
+void
+virtDBusUtilVirNetworkListFree(virNetworkPtr *networks)
+{
+ for (gint i = 0; networks[i] != NULL; i += 1)
+ virNetworkFree(networks[i]);
+
+ g_free(networks);
+}
diff --git a/src/util.h b/src/util.h
index c9d9cfd..7bb4ad6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -65,3 +65,18 @@ virtDBusUtilEnumToString(const gchar *const *types,
#define VIRT_DBUS_ENUM_DECL(name) \
const gchar *name ##TypeToString(gint type) G_GNUC_PURE; \
gint name ##TypeFromString(const gchar *type) G_GNUC_PURE;
+
+virNetworkPtr
+virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *networkPath);
And here too.
Pavel