From nobody Thu Dec 18 13:44:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522935060426987.4562655547418; Thu, 5 Apr 2018 06:31:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE38FC05CDF9; Thu, 5 Apr 2018 13:30:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBE12821EC; Thu, 5 Apr 2018 13:30:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7E5CC180BADA; Thu, 5 Apr 2018 13:30:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w35DTksk009514 for ; Thu, 5 Apr 2018 09:29:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 143509C073; Thu, 5 Apr 2018 13:29:46 +0000 (UTC) Received: from katerina.brq.redhat.com (ovpn-204-29.brq.redhat.com [10.40.204.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id A034DAB3F3 for ; Thu, 5 Apr 2018 13:29:45 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 5 Apr 2018 15:29:31 +0200 Message-Id: <20180405132934.1420-8-kkoukiou@redhat.com> In-Reply-To: <20180405132934.1420-1-kkoukiou@redhat.com> References: <20180405132934.1420-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus PATCH 07/10] Register Network Lifecycle Events X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 05 Apr 2018 13:30:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Katerina Koukiou Reviewed-by: Pavel Hrdina --- 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 @@ + + + + + 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, } } =20 + for (gint i =3D 0; i < VIR_NETWORK_EVENT_ID_LAST; i +=3D 1) { + if (connect->network_callback_ids[i] >=3D 0) { + if (deregisterEvents) { + virConnectNetworkEventDeregisterAny(connect->connection, + connect->network_callb= ack_ids[i]); + } + connect->network_callback_ids[i] =3D -1; + } + } + virConnectClose(connect->connection); connect->connection =3D NULL; } @@ -431,6 +441,9 @@ virtDBusConnectNew(virtDBusConnect **connectp, for (gint i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i +=3D 1) connect->domain_callback_ids[i] =3D -1; =20 + for (gint i =3D 0; i < VIR_NETWORK_EVENT_ID_LAST; i +=3D 1) + connect->network_callback_ids[i] =3D -1; + connect->bus =3D bus; connect->uri =3D uri; connect->connectPath =3D 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; =20 gint domain_callback_ids[VIR_DOMAIN_EVENT_ID_LAST]; + gint network_callback_ids[VIR_NETWORK_EVENT_ID_LAST]; }; typedef struct virtDBusConnect virtDBusConnect; =20 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 connectio= n G_GNUC_UNUSED, return 0; } =20 +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 =3D 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 =3D opaque; + g_autofree gchar *path =3D NULL; + const gchar *eventStr =3D virtDBusEventsNetworkEventToString(event); + + if (!eventStr) + return 0; + + path =3D virtDBusUtilBusPathForVirNetwork(network, connect->networkPat= h); + + 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 *con= nect, NU= LL); } =20 +static void +virtDBusNetworkEventsRegisterEvent(virtDBusConnect *connect, + gint id, + virConnectNetworkEventGenericCallback c= allback) +{ + g_assert(connect->network_callback_ids[id] =3D=3D -1); + + connect->network_callback_ids[id] =3D virConnectNetworkEventRegisterAn= y(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(virtDBusEv= entsDomainTrayChange)); =20 + virtDBusNetworkEventsRegisterEvent(connect, + VIR_NETWORK_EVENT_ID_LIFECYCLE, + VIR_NETWORK_EVENT_CALLBACK(virtDBus= EventsNetworkLifecycle)); } --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list