[PATCH 13/34] Created virDomainEventWatchdog to get rid of the huge union

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/conf/domain_event.c | 56 ++++++++++++++++++++++++++++++++++---------------
 src/conf/domain_event.h |  4 ++--
 2 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 31699b1..8d08d2f 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -82,10 +82,12 @@ static virClassPtr virObjectEventClass;
 static virClassPtr virDomainEventClass;
 static virClassPtr virDomainEventLifecycleClass;
 static virClassPtr virDomainEventRTCChangeClass;
+static virClassPtr virDomainEventWatchdogClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
 static void virDomainEventLifecycleDispose(void *obj);
 static void virDomainEventRTCChangeDispose(void *obj);
+static void virDomainEventWatchdogDispose(void *obj);
 
 struct _virObjectEvent {
     virObject parent;
@@ -99,9 +101,6 @@ struct _virDomainEvent {
 
     union {
         struct {
-            int action;
-        } watchdog;
-        struct {
             char *srcPath;
             char *devAlias;
             int action;
@@ -156,6 +155,14 @@ struct _virDomainEventRTCChange {
 typedef struct _virDomainEventRTCChange virDomainEventRTCChange;
 typedef virDomainEventRTCChange *virDomainEventRTCChangePtr;
 
+struct _virDomainEventWatchdog {
+    virDomainEvent parent;
+
+    int action;
+};
+typedef struct _virDomainEventWatchdog virDomainEventWatchdog;
+typedef virDomainEventWatchdog *virDomainEventWatchdogPtr;
+
 static int virObjectEventOnceInit(void)
 {
     if (!(virObjectEventClass = virClassNew(virClassForObject(),
@@ -180,6 +187,12 @@ static int virObjectEventOnceInit(void)
                                              sizeof(virDomainEventRTCChange),
                                              virDomainEventRTCChangeDispose)))
         return -1;
+    if (!(virDomainEventWatchdogClass = virClassNew(
+                                             virDomainEventClass,
+                                             "virDomainEventWatchdog",
+                                             sizeof(virDomainEventWatchdog),
+                                             virDomainEventWatchdogDispose)))
+        return -1;
     return 0;
 }
 
@@ -275,6 +288,12 @@ static void virDomainEventRTCChangeDispose(void *obj)
     VIR_DEBUG("obj=%p", event);
 }
 
+static void virDomainEventWatchdogDispose(void *obj)
+{
+    virDomainEventWatchdogPtr event = obj;
+    VIR_DEBUG("obj=%p", event);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -908,38 +927,36 @@ void *virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj,
     return ev;
 }
 
-virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom,
-                                                   int action)
+void *virDomainEventWatchdogNewFromDom(virDomainPtr dom, int action)
 {
-    virDomainEventPtr ev;
+    virDomainEventWatchdogPtr ev;
 
     if (virObjectEventInitialize() < 0)
         return NULL;
 
-    if (!(ev = virDomainEventNew(virDomainEventClass,
+    if (!(ev = virDomainEventNew(virDomainEventWatchdogClass,
                                  VIR_DOMAIN_EVENT_ID_WATCHDOG,
                                  dom->id, dom->name, dom->uuid)))
         return NULL;
 
-    ev->data.watchdog.action = action;
+    ev->action = action;
 
     return ev;
 }
-virDomainEventPtr virDomainEventWatchdogNewFromObj(virDomainObjPtr obj,
-                                                   int action)
+void *virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int action)
 {
-    virDomainEventPtr ev;
+    virDomainEventWatchdogPtr ev;
 
     if (virObjectEventInitialize() < 0)
         return NULL;
 
-    if (!(ev = virDomainEventNew(virDomainEventClass,
+    if (!(ev = virDomainEventNew(virDomainEventWatchdogClass,
                                  VIR_DOMAIN_EVENT_ID_WATCHDOG,
                                  obj->def->id, obj->def->name,
                                  obj->def->uuid)))
         return NULL;
 
-    ev->data.watchdog.action = action;
+    ev->action = action;
 
     return ev;
 }
@@ -1524,10 +1541,15 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
         }
 
     case VIR_DOMAIN_EVENT_ID_WATCHDOG:
-        ((virConnectDomainEventWatchdogCallback)cb)(conn, dom,
-                                                    event->data.watchdog.action,
-                                                    cbopaque);
-        goto cleanup;
+        {
+            virDomainEventWatchdogPtr watchdogEvent;
+
+            watchdogEvent = (virDomainEventWatchdogPtr)event;
+            ((virConnectDomainEventWatchdogCallback)cb)(conn, dom,
+                                                        watchdogEvent->action,
+                                                        cbopaque);
+            goto cleanup;
+        }
 
     case VIR_DOMAIN_EVENT_ID_IO_ERROR:
         ((virConnectDomainEventIOErrorCallback)cb)(conn, dom,
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 7c16a48..b51ec97 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -72,8 +72,8 @@ virDomainEventPtr virDomainEventRebootNewFromObj(virDomainObjPtr obj);
 void *virDomainEventRTCChangeNewFromDom(virDomainPtr dom, long long offset);
 void *virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj, long long offset);
 
-virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom, int action);
-virDomainEventPtr virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int action);
+void *virDomainEventWatchdogNewFromDom(virDomainPtr dom, int action);
+void *virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int action);
 
 virDomainEventPtr virDomainEventIOErrorNewFromDom(virDomainPtr dom,
                                                   const char *srcPath,
-- 
1.8.4.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]