[virt-tools-list] [virt-viewer][PATCH 3/3] Listen to virNetwork's Lifecycle events
Fabiano Fidêncio
fidencio at redhat.com
Wed Nov 19 04:58:23 UTC 2014
Apart from the usual virDomain's Lifecycle events, we have to listen to
the virNetwork's Lifecycle events in order to get notifications about
libvirt deamon being started/stopped/restarted, which is useful when
connecting to guest through qemu+ssh://
Resolves: rhbz#1164052
https://bugzilla.redhat.com/show_bug.cgi?id=1164052
---
src/virt-viewer.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index bc831dc..989e0c2 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -60,6 +60,7 @@ struct _VirtViewerPrivate {
gboolean reconnect;
gboolean auth_cancelled;
gint domain_event;
+ gint network_event;
};
G_DEFINE_TYPE (VirtViewer, virt_viewer, VIRT_VIEWER_TYPE_APP)
@@ -507,6 +508,38 @@ virt_viewer_domain_event(virConnectPtr conn G_GNUC_UNUSED,
return 0;
}
+static int
+virt_viewer_network_event(virConnectPtr conn G_GNUC_UNUSED,
+ virNetworkPtr net G_GNUC_UNUSED,
+ int event,
+ int detail G_GNUC_UNUSED,
+ void *opaque)
+{
+ VirtViewer *self = opaque;
+ VirtViewerApp *app = VIRT_VIEWER_APP(self);
+ GError *error = NULL;
+
+ g_debug("Got domain event %d %d", event, detail);
+
+ switch (event) {
+ case VIR_NETWORK_EVENT_STOPPED:
+ //virt_viewer_deactivate(self);
+ break;
+
+ case VIR_NETWORK_EVENT_STARTED:
+ virt_viewer_app_activate(app, &error);
+ if (error) {
+ /* we may want to consolidate error reporting in
+ app_activate() instead */
+ g_warning("%s", error->message);
+ g_clear_error(&error);
+ }
+ break;
+ }
+
+ return 0;
+}
+
static void
virt_viewer_conn_event(virConnectPtr conn G_GNUC_UNUSED,
int reason,
@@ -535,6 +568,9 @@ virt_viewer_dispose (GObject *object)
virConnectDomainEventDeregisterAny(priv->conn,
priv->domain_event);
priv->domain_event = -1;
+ virConnectNetworkEventDeregisterAny(priv->conn,
+ priv->network_event);
+ priv->network_event = -1;
}
virConnectUnregisterCloseCallback(priv->conn,
virt_viewer_conn_event);
@@ -830,7 +866,15 @@ virt_viewer_connect(VirtViewerApp *app)
VIR_DOMAIN_EVENT_CALLBACK(virt_viewer_domain_event),
self,
NULL);
- if (priv->domain_event < 0)
+
+ priv->network_event = virConnectNetworkEventRegisterAny(priv->conn,
+ NULL,
+ VIR_NETWORK_EVENT_ID_LIFECYCLE,
+ VIR_NETWORK_EVENT_CALLBACK(virt_viewer_network_event),
+ self,
+ NULL);
+
+ if (priv->domain_event < 0 || priv->network_event < 0)
priv->withEvents = FALSE;
else
priv->withEvents = TRUE;
--
2.1.0
More information about the virt-tools-list
mailing list