提交 bc7b3043 编写于 作者: C Cédric Bosdonnat 提交者: Daniel P. Berrange

Create virDomainEventDiskChange to get rid of the huge union

上级 0ac4c9ed
...@@ -91,6 +91,8 @@ static virClassPtr virDomainEventWatchdogClass; ...@@ -91,6 +91,8 @@ static virClassPtr virDomainEventWatchdogClass;
static virClassPtr virDomainEventIOErrorClass; static virClassPtr virDomainEventIOErrorClass;
static virClassPtr virDomainEventGraphicsClass; static virClassPtr virDomainEventGraphicsClass;
static virClassPtr virDomainEventBlockJobClass; static virClassPtr virDomainEventBlockJobClass;
static virClassPtr virDomainEventDiskChangeClass;
static void virObjectEventDispose(void *obj); static void virObjectEventDispose(void *obj);
static void virDomainEventDispose(void *obj); static void virDomainEventDispose(void *obj);
static void virDomainEventLifecycleDispose(void *obj); static void virDomainEventLifecycleDispose(void *obj);
...@@ -99,6 +101,7 @@ static void virDomainEventWatchdogDispose(void *obj); ...@@ -99,6 +101,7 @@ static void virDomainEventWatchdogDispose(void *obj);
static void virDomainEventIOErrorDispose(void *obj); static void virDomainEventIOErrorDispose(void *obj);
static void virDomainEventGraphicsDispose(void *obj); static void virDomainEventGraphicsDispose(void *obj);
static void virDomainEventBlockJobDispose(void *obj); static void virDomainEventBlockJobDispose(void *obj);
static void virDomainEventDiskChangeDispose(void *obj);
struct _virObjectEvent { struct _virObjectEvent {
virObject parent; virObject parent;
...@@ -111,12 +114,6 @@ struct _virDomainEvent { ...@@ -111,12 +114,6 @@ struct _virDomainEvent {
virObjectMeta meta; virObjectMeta meta;
union { union {
struct {
char *oldSrcPath;
char *newSrcPath;
char *devAlias;
int reason;
} diskChange;
struct { struct {
char *devAlias; char *devAlias;
int reason; int reason;
...@@ -189,6 +186,18 @@ struct _virDomainEventGraphics { ...@@ -189,6 +186,18 @@ struct _virDomainEventGraphics {
typedef struct _virDomainEventGraphics virDomainEventGraphics; typedef struct _virDomainEventGraphics virDomainEventGraphics;
typedef virDomainEventGraphics *virDomainEventGraphicsPtr; typedef virDomainEventGraphics *virDomainEventGraphicsPtr;
struct _virDomainEventDiskChange {
virDomainEvent parent;
char *oldSrcPath;
char *newSrcPath;
char *devAlias;
int reason;
};
typedef struct _virDomainEventDiskChange virDomainEventDiskChange;
typedef virDomainEventDiskChange *virDomainEventDiskChangePtr;
static int virObjectEventOnceInit(void) static int virObjectEventOnceInit(void)
{ {
if (!(virObjectEventClass = if (!(virObjectEventClass =
...@@ -239,6 +248,12 @@ static int virObjectEventOnceInit(void) ...@@ -239,6 +248,12 @@ static int virObjectEventOnceInit(void)
sizeof(virDomainEventBlockJob), sizeof(virDomainEventBlockJob),
virDomainEventBlockJobDispose))) virDomainEventBlockJobDispose)))
return -1; return -1;
if (!(virDomainEventDiskChangeClass =
virClassNew(virDomainEventClass,
"virDomainEventDiskChange",
sizeof(virDomainEventDiskChange),
virDomainEventDiskChangeDispose)))
return -1;
return 0; return 0;
} }
...@@ -271,11 +286,6 @@ static void virDomainEventDispose(void *obj) ...@@ -271,11 +286,6 @@ static void virDomainEventDispose(void *obj)
switch (virObjectEventGetEventID(event)) { switch (virObjectEventGetEventID(event)) {
case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
VIR_FREE(event->data.diskChange.oldSrcPath);
VIR_FREE(event->data.diskChange.newSrcPath);
VIR_FREE(event->data.diskChange.devAlias);
break;
case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE: case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
VIR_FREE(event->data.trayChange.devAlias); VIR_FREE(event->data.trayChange.devAlias);
break; break;
...@@ -349,6 +359,16 @@ static void virDomainEventBlockJobDispose(void *obj) ...@@ -349,6 +359,16 @@ static void virDomainEventBlockJobDispose(void *obj)
VIR_FREE(event->path); VIR_FREE(event->path);
} }
static void virDomainEventDiskChangeDispose(void *obj)
{
virDomainEventDiskChangePtr event = obj;
VIR_DEBUG("obj=%p", event);
VIR_FREE(event->oldSrcPath);
VIR_FREE(event->newSrcPath);
VIR_FREE(event->devAlias);
}
/** /**
* virObjectEventCallbackListFree: * virObjectEventCallbackListFree:
* @list: event callback list head * @list: event callback list head
...@@ -1249,35 +1269,35 @@ virDomainEventPtr virDomainEventControlErrorNewFromObj(virDomainObjPtr obj) ...@@ -1249,35 +1269,35 @@ virDomainEventPtr virDomainEventControlErrorNewFromObj(virDomainObjPtr obj)
return ev; return ev;
} }
static virDomainEventPtr static
virDomainEventDiskChangeNew(int id, const char *name, virDomainEventPtr virDomainEventDiskChangeNew(int id, const char *name,
unsigned char *uuid, unsigned char *uuid,
const char *oldSrcPath, const char *oldSrcPath,
const char *newSrcPath, const char *newSrcPath,
const char *devAlias, int reason) const char *devAlias, int reason)
{ {
virDomainEventPtr ev; virDomainEventDiskChangePtr ev;
if (virObjectEventInitialize() < 0) if (virObjectEventInitialize() < 0)
return NULL; return NULL;
if (!(ev = virDomainEventNew(virDomainEventClass, if (!(ev = virDomainEventNew(virDomainEventDiskChangeClass,
VIR_DOMAIN_EVENT_ID_DISK_CHANGE, VIR_DOMAIN_EVENT_ID_DISK_CHANGE,
id, name, uuid))) id, name, uuid)))
return NULL; return NULL;
if (VIR_STRDUP(ev->data.diskChange.devAlias, devAlias) < 0) if (VIR_STRDUP(ev->devAlias, devAlias) < 0)
goto error; goto error;
if (VIR_STRDUP(ev->data.diskChange.oldSrcPath, oldSrcPath) < 0) if (VIR_STRDUP(ev->oldSrcPath, oldSrcPath) < 0)
goto error; goto error;
if (VIR_STRDUP(ev->data.diskChange.newSrcPath, newSrcPath) < 0) if (VIR_STRDUP(ev->newSrcPath, newSrcPath) < 0)
goto error; goto error;
ev->data.diskChange.reason = reason; ev->reason = reason;
return ev; return (virDomainEventPtr)ev;
error: error:
virObjectUnref(ev); virObjectUnref(ev);
...@@ -1671,13 +1691,18 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn, ...@@ -1671,13 +1691,18 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
} }
case VIR_DOMAIN_EVENT_ID_DISK_CHANGE: case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
{
virDomainEventDiskChangePtr diskChangeEvent;
diskChangeEvent = (virDomainEventDiskChangePtr)event;
((virConnectDomainEventDiskChangeCallback)cb)(conn, dom, ((virConnectDomainEventDiskChangeCallback)cb)(conn, dom,
event->data.diskChange.oldSrcPath, diskChangeEvent->oldSrcPath,
event->data.diskChange.newSrcPath, diskChangeEvent->newSrcPath,
event->data.diskChange.devAlias, diskChangeEvent->devAlias,
event->data.diskChange.reason, diskChangeEvent->reason,
cbopaque); cbopaque);
goto cleanup; goto cleanup;
}
case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE: case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
((virConnectDomainEventTrayChangeCallback)cb)(conn, dom, ((virConnectDomainEventTrayChangeCallback)cb)(conn, dom,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册