Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 6 +++++
src/connect.c | 13 ++++++++++
src/connect.h | 1 +
src/events.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 80 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index d15c2f6..b11dbfb 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -68,5 +68,11 @@
<arg name="domain" type="o"/>
<arg name="event" type="s"/>
</signal>
+ <signal name="NetworkEvent">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-network.html#virConnectNetworkEv...
+ <arg name="network" type="o"/>
+ <arg name="event" type="s"/>
+ </signal>
</interface>
</node>
diff --git a/src/connect.c b/src/connect.c
index 90172e3..a9006a2 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -49,6 +49,16 @@ virtDBusConnectClose(virtDBusConnect *connect,
}
}
+ for (gint i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i += 1) {
+ if (connect->network_callback_ids[i] >= 0) {
+ if (deregisterEvents) {
+ virConnectNetworkEventDeregisterAny(connect->connection,
+
connect->network_callback_ids[i]);
+ }
+ connect->network_callback_ids[i] = -1;
+ }
+ }
+
virConnectClose(connect->connection);
connect->connection = NULL;
}
@@ -431,6 +441,9 @@ virtDBusConnectNew(virtDBusConnect **connectp,
for (gint i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i += 1)
connect->domain_callback_ids[i] = -1;
+ for (gint i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i += 1)
+ connect->network_callback_ids[i] = -1;
+
connect->bus = bus;
connect->uri = uri;
connect->connectPath = connectPath;
diff --git a/src/connect.h b/src/connect.h
index e69898c..e8c757f 100644
--- a/src/connect.h
+++ b/src/connect.h
@@ -18,6 +18,7 @@ struct virtDBusConnect {
GMutex lock;
gint domain_callback_ids[VIR_DOMAIN_EVENT_ID_LAST];
+ gint network_callback_ids[VIR_NETWORK_EVENT_ID_LAST];
};
typedef struct virtDBusConnect virtDBusConnect;
diff --git a/src/events.c b/src/events.c
index 5fa61f5..b4d22a6 100644
--- a/src/events.c
+++ b/src/events.c
@@ -170,6 +170,48 @@ virtDBusEventsDomainDiskChange(virConnectPtr connection
G_GNUC_UNUSED,
return 0;
}
+VIRT_DBUS_ENUM_DECL(virtDBusEventsNetworkEvent)
+VIRT_DBUS_ENUM_IMPL(virtDBusEventsNetworkEvent,
+ VIR_NETWORK_EVENT_LAST,
+ "Defined",
+ "Undefined",
+ "Started",
+ "Stopped")
+
+static const gchar *
+virtDBusEventsNetworkEventToString(gint event)
+{
+ const gchar *str = virtDBusEventsNetworkEventTypeToString(event);
+ return str ? str : "unknown";
+}
+
+static gint
+virtDBusEventsNetworkLifecycle(virConnectPtr connection G_GNUC_UNUSED,
+ virNetworkPtr network,
+ gint event,
+ gint detail G_GNUC_UNUSED,
+ gpointer opaque)
+{
+ virtDBusConnect *connect = opaque;
+ g_autofree gchar *path = NULL;
+ const gchar *eventStr = virtDBusEventsNetworkEventToString(event);
+
+ if (!eventStr)
+ return 0;
+
+ path = virtDBusUtilBusPathForVirNetwork(network, connect->networkPath);
+
+ g_dbus_connection_emit_signal(connect->bus,
+ NULL,
+ connect->connectPath,
+ VIRT_DBUS_CONNECT_INTERFACE,
+ "NetworkEvent",
+ g_variant_new("(os)", path, eventStr),
+ NULL);
+
+ return 0;
+}
+
static void
virtDBusDomainEventsRegisterEvent(virtDBusConnect *connect,
gint id,
@@ -185,6 +227,21 @@ virtDBusDomainEventsRegisterEvent(virtDBusConnect *connect,
NULL);
}
+static void
+virtDBusNetworkEventsRegisterEvent(virtDBusConnect *connect,
+ gint id,
+ virConnectNetworkEventGenericCallback callback)
+{
+ g_assert(connect->network_callback_ids[id] == -1);
+
+ connect->network_callback_ids[id] =
virConnectNetworkEventRegisterAny(connect->connection,
+ NULL,
+ id,
+
VIR_NETWORK_EVENT_CALLBACK(callback),
+ connect,
+ NULL);
+}
+
void
virtDBusEventsRegister(virtDBusConnect *connect)
{
@@ -208,4 +265,7 @@ virtDBusEventsRegister(virtDBusConnect *connect)
VIR_DOMAIN_EVENT_ID_TRAY_CHANGE,
VIR_DOMAIN_EVENT_CALLBACK(virtDBusEventsDomainTrayChange));
+ virtDBusNetworkEventsRegisterEvent(connect,
+ VIR_NETWORK_EVENT_ID_LIFECYCLE,
+
VIR_NETWORK_EVENT_CALLBACK(virtDBusEventsNetworkLifecycle));
}
--
2.15.0