RIP virDomainEvent union. All data are now stored in each
virObjectEvent subclass.
---
src/conf/domain_event.c | 75 +++++++++++++++++++++++++++++--------------------
src/conf/domain_event.h | 4 +--
2 files changed, 46 insertions(+), 33 deletions(-)
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index ac7828e..4bd81d9 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -89,6 +89,7 @@ static virClassPtr virDomainEventBlockJobClass;
static virClassPtr virDomainEventDiskChangeClass;
static virClassPtr virDomainEventTrayChangeClass;
static virClassPtr virDomainEventBalloonChangeClass;
+static virClassPtr virDomainEventDeviceRemovedClass;
static void virObjectEventDispose(void *obj);
static void virDomainEventDispose(void *obj);
@@ -101,6 +102,7 @@ static void virDomainEventBlockJobDispose(void *obj);
static void virDomainEventDiskChangeDispose(void *obj);
static void virDomainEventTrayChangeDispose(void *obj);
static void virDomainEventBalloonChangeDispose(void *obj);
+static void virDomainEventDeviceRemovedDispose(void *obj);
struct _virObjectEvent {
virObject parent;
@@ -111,12 +113,6 @@ struct _virDomainEvent {
virObjectEvent parent;
virObjectMeta meta;
-
- union {
- struct {
- char *devAlias;
- } deviceRemoved;
- } data;
};
struct _virDomainEventLifecycle {
@@ -206,6 +202,14 @@ struct _virDomainEventBalloonChange {
typedef struct _virDomainEventBalloonChange virDomainEventBalloonChange;
typedef virDomainEventBalloonChange *virDomainEventBalloonChangePtr;
+struct _virDomainEventDeviceRemoved {
+ virDomainEvent parent;
+
+ char *devAlias;
+};
+typedef struct _virDomainEventDeviceRemoved virDomainEventDeviceRemoved;
+typedef virDomainEventDeviceRemoved *virDomainEventDeviceRemovedPtr;
+
static int virObjectEventOnceInit(void)
{
@@ -273,6 +277,12 @@ static int virObjectEventOnceInit(void)
sizeof(virDomainEventBalloonChange),
virDomainEventBalloonChangeDispose)))
return -1;
+ if (!(virDomainEventDeviceRemovedClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventDeviceRemoved",
+ sizeof(virDomainEventDeviceRemoved),
+ virDomainEventDeviceRemovedDispose)))
+ return -1;
return 0;
}
@@ -306,13 +316,6 @@ static void virDomainEventDispose(void *obj)
if (!event)
return;
- switch (virObjectEventGetEventID(event)) {
-
- case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
- VIR_FREE(event->data.deviceRemoved.devAlias);
- break;
- }
-
VIR_FREE(event->meta.name);
}
@@ -402,6 +405,14 @@ static void virDomainEventBalloonChangeDispose(void *obj)
VIR_DEBUG("obj=%p", event);
}
+static void virDomainEventDeviceRemovedDispose(void *obj)
+{
+ virDomainEventDeviceRemovedPtr event = obj;
+ VIR_DEBUG("obj=%p", event);
+
+ VIR_FREE(event->devAlias);
+}
+
/**
* virObjectEventCallbackListFree:
* @list: event callback list head
@@ -1529,23 +1540,22 @@ void *virDomainEventBalloonChangeNewFromObj(virDomainObjPtr obj,
return ev;
}
-static virDomainEventPtr
-virDomainEventDeviceRemovedNew(int id,
- const char *name,
- unsigned char *uuid,
- const char *devAlias)
+static void *virDomainEventDeviceRemovedNew(int id,
+ const char *name,
+ unsigned char *uuid,
+ const char *devAlias)
{
- virDomainEventPtr ev;
+ virDomainEventDeviceRemovedPtr ev;
if (virObjectEventInitialize() < 0)
return NULL;
- if (!(ev = virDomainEventNew(virDomainEventClass,
+ if (!(ev = virDomainEventNew(virDomainEventDeviceRemovedClass,
VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
id, name, uuid)))
return NULL;
- if (VIR_STRDUP(ev->data.deviceRemoved.devAlias, devAlias) < 0)
+ if (VIR_STRDUP(ev->devAlias, devAlias) < 0)
goto error;
return ev;
@@ -1555,17 +1565,15 @@ error:
return NULL;
}
-virDomainEventPtr
-virDomainEventDeviceRemovedNewFromObj(virDomainObjPtr obj,
- const char *devAlias)
+void *virDomainEventDeviceRemovedNewFromObj(virDomainObjPtr obj,
+ const char *devAlias)
{
return virDomainEventDeviceRemovedNew(obj->def->id, obj->def->name,
obj->def->uuid, devAlias);
}
-virDomainEventPtr
-virDomainEventDeviceRemovedNewFromDom(virDomainPtr dom,
- const char *devAlias)
+void *virDomainEventDeviceRemovedNewFromDom(virDomainPtr dom,
+ const char *devAlias)
{
return virDomainEventDeviceRemovedNew(dom->id, dom->name, dom->uuid,
devAlias);
@@ -1769,10 +1777,15 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
goto cleanup;
case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
- ((virConnectDomainEventDeviceRemovedCallback)cb)(conn, dom,
-
event->data.deviceRemoved.devAlias,
- cbopaque);
- goto cleanup;
+ {
+ virDomainEventDeviceRemovedPtr deviceRemovedEvent;
+
+ deviceRemovedEvent = (virDomainEventDeviceRemovedPtr)event;
+ ((virConnectDomainEventDeviceRemovedCallback)cb)(conn, dom,
+
deviceRemovedEvent->devAlias,
+ cbopaque);
+ goto cleanup;
+ }
case VIR_DOMAIN_EVENT_ID_LAST:
break;
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index f4a344c..f13c716 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -145,9 +145,9 @@ void *virDomainEventBalloonChangeNewFromObj(virDomainObjPtr obj,
unsigned long l
virDomainEventPtr virDomainEventPMSuspendDiskNewFromObj(virDomainObjPtr obj);
virDomainEventPtr virDomainEventPMSuspendDiskNewFromDom(virDomainPtr dom);
-virDomainEventPtr virDomainEventDeviceRemovedNewFromObj(virDomainObjPtr obj,
+void *virDomainEventDeviceRemovedNewFromObj(virDomainObjPtr obj,
const char *devAlias);
-virDomainEventPtr virDomainEventDeviceRemovedNewFromDom(virDomainPtr dom,
+void *virDomainEventDeviceRemovedNewFromDom(virDomainPtr dom,
const char *devAlias);
void virObjectEventStateFree(virObjectEventStatePtr state);
--
1.8.4.2