On Thu, Apr 05, 2018 at 03:29:31PM +0200, Katerina Koukiou wrote:
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...
This should point to virConnectNetworkEventLifecycleCallback.
+ <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];
Same as for domain, networkCallbackIds.
};
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";
+}
I missed this while reviewing the domain event changes, but this
function is no longer needed because we check the return value for NULL
in order to not emit any signal if we cannot translate it into string.
Whit this function it will never happen because it returns "unknown"
in that case. So we can remove it.
+
+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);
Here we can use virtDBusEventsNetworkEventTypeToString directly.
Reviewed-by: Pavel Hrdina <phrdina(a)redhat.com>