This function replaces the manual translation of Event ENUMS.
Note: VIR_ENUM_SENTINELS is needed for VIR_DOMAIN_EVENT_LAST.
Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
src/events.c | 55 +++++++++++++++++++++----------------------------------
src/events.h | 3 +++
src/util.h | 1 +
3 files changed, 25 insertions(+), 34 deletions(-)
diff --git a/src/events.c b/src/events.c
index dada55f..0d6d5fc 100644
--- a/src/events.c
+++ b/src/events.c
@@ -4,6 +4,26 @@
#include <libvirt/libvirt.h>
+VIRT_DBUS_ENUM_DECL(virtDBusEventsDomainEvent)
+VIRT_DBUS_ENUM_IMPL(virtDBusEventsDomainEvent,
+ VIR_DOMAIN_EVENT_LAST,
+ "Defined",
+ "Undefined",
+ "Started",
+ "Suspended",
+ "Resumed",
+ "Stopped",
+ "Shutdown",
+ "PMSuspended",
+ "Crashed")
+
+const gchar *
+virtDBusEventsDomainEventToString(gint event)
+{
+ const gchar *str = virtDBusEventsDomainEventTypeToString(event);
+ return str ? str : "unknown";
+}
+
static gint
virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED,
virDomainPtr domain,
@@ -12,42 +32,9 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED,
gpointer opaque)
{
virtDBusConnect *connect = opaque;
- const gchar *signal = NULL;
const gchar *name;
g_autofree gchar *path = NULL;
- switch (event) {
- case VIR_DOMAIN_EVENT_DEFINED:
- signal = "DomainDefined";
- break;
- case VIR_DOMAIN_EVENT_UNDEFINED:
- signal = "DomainUndefined";
- break;
- case VIR_DOMAIN_EVENT_STARTED:
- signal = "DomainStarted";
- break;
- case VIR_DOMAIN_EVENT_SUSPENDED:
- signal = "DomainSuspended";
- break;
- case VIR_DOMAIN_EVENT_RESUMED:
- signal = "DomainResumed";
- break;
- case VIR_DOMAIN_EVENT_STOPPED:
- signal = "DomainStopped";
- break;
- case VIR_DOMAIN_EVENT_SHUTDOWN:
- signal = "DomainShutdown";
- break;
- case VIR_DOMAIN_EVENT_PMSUSPENDED:
- signal = "DomainPMSuspended";
- break;
- case VIR_DOMAIN_EVENT_CRASHED:
- signal = "DomainCrashed";
- break;
- default:
- return 0;
- }
-
name = virDomainGetName(domain);
path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
@@ -55,7 +42,7 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED,
NULL,
connect->connectPath,
VIRT_DBUS_CONNECT_INTERFACE,
- signal,
+ virtDBusEventsDomainEventToString(event),
g_variant_new("(so)", name, path),
NULL);
diff --git a/src/events.h b/src/events.h
index c234c55..7eb5daa 100644
--- a/src/events.h
+++ b/src/events.h
@@ -4,3 +4,6 @@
void
virtDBusEventsRegister(virtDBusConnect *connect);
+
+const gchar *
+virtDBusEventsDomainEventToString(gint event) G_GNUC_PURE;
diff --git a/src/util.h b/src/util.h
index 61e01c9..203cd62 100644
--- a/src/util.h
+++ b/src/util.h
@@ -2,6 +2,7 @@
#include "gdbus.h"
+#define VIR_ENUM_SENTINELS
#include <libvirt/libvirt.h>
#define VIRT_DBUS_ERROR virtDBusErrorQuark()
--
2.15.0