Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 13 +++++++++++++ src/connect.h | 1 + src/events.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 137e67b..3828832 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -339,6 +339,13 @@ <arg name="network" type="o"/> <arg name="event" type="i"/> </signal> + <signal name="NodeDeviceEvent"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virConnectNodeDeviceEventLifecycleCallback"/> + <arg name="dev" type="o"/> + <arg name="event" type="i"/> + <arg name="detail" type="i"/> + </signal> <signal name="SecretEvent"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectSecretEventLifecycleCallback"/> diff --git a/src/connect.c b/src/connect.c index 919172a..1c27768 100644 --- a/src/connect.c +++ b/src/connect.c @@ -65,6 +65,16 @@ virtDBusConnectClose(virtDBusConnect *connect, } } + for (gint i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { + if (connect->devCallbackIds[i] >= 0) { + if (deregisterEvents) { + virConnectNetworkEventDeregisterAny(connect->connection, + connect->devCallbackIds[i]); + } + connect->devCallbackIds[i] = -1; + } + } + for (gint i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { if (connect->secretCallbackIds[i] >= 0) { if (deregisterEvents) { @@ -1744,6 +1754,9 @@ virtDBusConnectNew(virtDBusConnect **connectp, for (gint i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) connect->networkCallbackIds[i] = -1; + for (gint i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) + connect->devCallbackIds[i] = -1; + for (gint i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) connect->secretCallbackIds[i] = -1; diff --git a/src/connect.h b/src/connect.h index 3b62edd..a864041 100644 --- a/src/connect.h +++ b/src/connect.h @@ -24,6 +24,7 @@ struct virtDBusConnect { gint domainCallbackIds[VIR_DOMAIN_EVENT_ID_LAST]; gint networkCallbackIds[VIR_NETWORK_EVENT_ID_LAST]; + gint devCallbackIds[VIR_NODE_DEVICE_EVENT_ID_LAST]; gint secretCallbackIds[VIR_SECRET_EVENT_ID_LAST]; gint storagePoolCallbackIds[VIR_STORAGE_POOL_EVENT_ID_LAST]; }; diff --git a/src/events.c b/src/events.c index b51664f..60cbecd 100644 --- a/src/events.c +++ b/src/events.c @@ -567,6 +567,29 @@ virtDBusEventsNetworkEvent(virConnectPtr connection G_GNUC_UNUSED, return 0; } +static gint +virtDBusEventsNodeDeviceEvent(virConnectPtr connection G_GNUC_UNUSED, + virNodeDevicePtr dev, + gint event, + gint detail, + gpointer opaque) +{ + virtDBusConnect *connect = opaque; + g_autofree gchar *path = NULL; + + path = virtDBusUtilBusPathForVirNodeDevice(dev, connect->devPath); + + g_dbus_connection_emit_signal(connect->bus, + NULL, + connect->connectPath, + VIRT_DBUS_CONNECT_INTERFACE, + "NodeDeviceEvent", + g_variant_new("(oii)", path, event, detail), + NULL); + + return 0; +} + static gint virtDBusEventsSecretEvent(virConnectPtr connection G_GNUC_UNUSED, virSecretPtr secret, @@ -666,6 +689,21 @@ virtDBusEventsRegisterNetworkEvent(virtDBusConnect *connect, NULL); } +static void +virtDBusEventsRegisterNodeDeviceEvent(virtDBusConnect *connect, + gint id, + virConnectNodeDeviceEventGenericCallback callback) +{ + g_assert(connect->devCallbackIds[id] == -1); + + connect->devCallbackIds[id] = virConnectNodeDeviceEventRegisterAny(connect->connection, + NULL, + id, + VIR_NODE_DEVICE_EVENT_CALLBACK(callback), + connect, + NULL); +} + static void virtDBusEventsRegisterSecretEvent(virtDBusConnect *connect, gint id, @@ -791,6 +829,10 @@ virtDBusEventsRegister(virtDBusConnect *connect) VIR_NETWORK_EVENT_ID_LIFECYCLE, VIR_NETWORK_EVENT_CALLBACK(virtDBusEventsNetworkEvent)); + virtDBusEventsRegisterNodeDeviceEvent(connect, + VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE, + VIR_NODE_DEVICE_EVENT_CALLBACK(virtDBusEventsNodeDeviceEvent)); + virtDBusEventsRegisterSecretEvent(connect, VIR_SECRET_EVENT_ID_LIFECYCLE, VIR_SECRET_EVENT_CALLBACK(virtDBusEventsSecretEvent)); -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list