[PATCH 09/34] Create virDomainEventLifecycle to start removing the huge union

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

 



---
 src/conf/domain_event.c | 65 ++++++++++++++++++++++++++++++++++---------------
 src/conf/domain_event.h |  8 +++---
 2 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index ff4f69a..a69ce11 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -76,10 +76,14 @@ struct _virObjectEventCallback {
     int deleted;
 };
 
+
+
 static virClassPtr virObjectEventClass;
 static virClassPtr virDomainEventClass;
+static virClassPtr virDomainEventLifecycleClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
+static void virDomainEventLifecycleDispose(void *obj);
 
 struct _virObjectEvent {
     virObject parent;
@@ -93,10 +97,6 @@ struct _virDomainEvent {
 
     union {
         struct {
-            int type;
-            int detail;
-        } lifecycle;
-        struct {
             long long offset;
         } rtcChange;
         struct {
@@ -140,6 +140,16 @@ struct _virDomainEvent {
     } data;
 };
 
+struct _virDomainEventLifecycle {
+    virDomainEvent parent;
+
+    int type;
+    int detail;
+};
+typedef struct _virDomainEventLifecycle virDomainEventLifecycle;
+typedef virDomainEventLifecycle *virDomainEventLifecyclePtr;
+
+
 static int virObjectEventOnceInit(void)
 {
     if (!(virObjectEventClass = virClassNew(virClassForObject(),
@@ -152,6 +162,12 @@ static int virObjectEventOnceInit(void)
                                              sizeof(virDomainEvent),
                                              virDomainEventDispose)))
         return -1;
+    if (!(virDomainEventLifecycleClass = virClassNew(
+                                             virDomainEventClass,
+                                             "virDomainEventLifecycle",
+                                             sizeof(virDomainEventLifecycle),
+                                             virDomainEventLifecycleDispose)))
+        return -1;
     return 0;
 }
 
@@ -235,6 +251,12 @@ static void virDomainEventDispose(void *obj)
     VIR_FREE(event->meta.name);
 }
 
+static void virDomainEventLifecycleDispose(void *obj)
+{
+    virDomainEventLifecyclePtr event = obj;
+    VIR_DEBUG("obj=%p", event);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -764,37 +786,37 @@ static void *virDomainEventNewInternal(virClassPtr klass,
     return event;
 }
 
-virDomainEventPtr virDomainEventNew(int id, const char *name,
+void *virDomainEventNew(int id, const char *name,
                                     const unsigned char *uuid,
                                     int type, int detail)
 {
-    virDomainEventPtr event;
+    virDomainEventLifecyclePtr event;
 
     if (virObjectEventInitialize() < 0)
         return NULL;
 
-    if (!(event = virDomainEventNewInternal(virDomainEventClass,
-                                      VIR_DOMAIN_EVENT_ID_LIFECYCLE,
-                                      id, name, uuid)))
+    if (!(event = virDomainEventNewInternal(virDomainEventLifecycleClass,
+                                            VIR_DOMAIN_EVENT_ID_LIFECYCLE,
+                                            id, name, uuid)))
         return NULL;
 
-    event->data.lifecycle.type = type;
-    event->data.lifecycle.detail = detail;
+    event->type = type;
+    event->detail = detail;
 
     return event;
 }
 
-virDomainEventPtr virDomainEventNewFromDom(virDomainPtr dom, int type, int detail)
+void *virDomainEventNewFromDom(virDomainPtr dom, int type, int detail)
 {
     return virDomainEventNew(dom->id, dom->name, dom->uuid, type, detail);
 }
 
-virDomainEventPtr virDomainEventNewFromObj(virDomainObjPtr obj, int type, int detail)
+void *virDomainEventNewFromObj(virDomainObjPtr obj, int type, int detail)
 {
     return virDomainEventNewFromDef(obj->def, type, detail);
 }
 
-virDomainEventPtr virDomainEventNewFromDef(virDomainDefPtr def, int type, int detail)
+void *virDomainEventNewFromDef(virDomainDefPtr def, int type, int detail)
 {
     return virDomainEventNew(def->id, def->name, def->uuid, type, detail);
 }
@@ -1454,11 +1476,16 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
 
     switch ((virDomainEventID) eventID) {
     case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
-        ((virConnectDomainEventCallback)cb)(conn, dom,
-                                            event->data.lifecycle.type,
-                                            event->data.lifecycle.detail,
-                                            cbopaque);
-        goto cleanup;
+        {
+            virDomainEventLifecyclePtr lifecycleEvent;
+           
+            lifecycleEvent = (virDomainEventLifecyclePtr)event;
+            ((virConnectDomainEventCallback)cb)(conn, dom,
+                                                lifecycleEvent->type,
+                                                lifecycleEvent->detail,
+                                                cbopaque);
+            goto cleanup;
+        }
 
     case VIR_DOMAIN_EVENT_ID_REBOOT:
         (cb)(conn, dom,
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 8b9409a..04b846e 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -50,10 +50,10 @@ typedef virObjectEventQueue *virObjectEventQueuePtr;
 typedef struct _virObjectEventState virObjectEventState;
 typedef virObjectEventState *virObjectEventStatePtr;
 
-virDomainEventPtr virDomainEventNew(int id, const char *name, const unsigned char *uuid, int type, int detail);
-virDomainEventPtr virDomainEventNewFromDom(virDomainPtr dom, int type, int detail);
-virDomainEventPtr virDomainEventNewFromObj(virDomainObjPtr obj, int type, int detail);
-virDomainEventPtr virDomainEventNewFromDef(virDomainDefPtr def, int type, int detail);
+void *virDomainEventNew(int id, const char *name, const unsigned char *uuid, int type, int detail);
+void *virDomainEventNewFromDom(virDomainPtr dom, int type, int detail);
+void *virDomainEventNewFromObj(virDomainObjPtr obj, int type, int detail);
+void *virDomainEventNewFromDef(virDomainDefPtr def, int type, int detail);
 
 virDomainEventPtr virDomainEventRebootNew(int id, const char *name, const unsigned char *uuid);
 virDomainEventPtr virDomainEventRebootNewFromDom(virDomainPtr dom);
-- 
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]