Create virDomainEventIOError to get rid of the huge union

This commit is contained in:
Cédric Bosdonnat 2013-11-22 10:15:35 +01:00 committed by Daniel P. Berrange
parent b044091540
commit b223263850

View File

@ -88,11 +88,13 @@ static virClassPtr virDomainEventClass;
static virClassPtr virDomainEventLifecycleClass; static virClassPtr virDomainEventLifecycleClass;
static virClassPtr virDomainEventRTCChangeClass; static virClassPtr virDomainEventRTCChangeClass;
static virClassPtr virDomainEventWatchdogClass; static virClassPtr virDomainEventWatchdogClass;
static virClassPtr virDomainEventIOErrorClass;
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);
static void virDomainEventRTCChangeDispose(void *obj); static void virDomainEventRTCChangeDispose(void *obj);
static void virDomainEventWatchdogDispose(void *obj); static void virDomainEventWatchdogDispose(void *obj);
static void virDomainEventIOErrorDispose(void *obj);
struct _virObjectEvent { struct _virObjectEvent {
virObject parent; virObject parent;
@ -105,12 +107,6 @@ struct _virDomainEvent {
virObjectMeta meta; virObjectMeta meta;
union { union {
struct {
char *srcPath;
char *devAlias;
int action;
char *reason;
} ioError;
struct { struct {
int phase; int phase;
virDomainEventGraphicsAddressPtr local; virDomainEventGraphicsAddressPtr local;
@ -168,6 +164,17 @@ struct _virDomainEventWatchdog {
typedef struct _virDomainEventWatchdog virDomainEventWatchdog; typedef struct _virDomainEventWatchdog virDomainEventWatchdog;
typedef virDomainEventWatchdog *virDomainEventWatchdogPtr; typedef virDomainEventWatchdog *virDomainEventWatchdogPtr;
struct _virDomainEventIOError {
virDomainEvent parent;
char *srcPath;
char *devAlias;
int action;
char *reason;
};
typedef struct _virDomainEventIOError virDomainEventIOError;
typedef virDomainEventIOError *virDomainEventIOErrorPtr;
static int virObjectEventOnceInit(void) static int virObjectEventOnceInit(void)
{ {
if (!(virObjectEventClass = if (!(virObjectEventClass =
@ -200,6 +207,12 @@ static int virObjectEventOnceInit(void)
sizeof(virDomainEventWatchdog), sizeof(virDomainEventWatchdog),
virDomainEventWatchdogDispose))) virDomainEventWatchdogDispose)))
return -1; return -1;
if (!(virDomainEventIOErrorClass =
virClassNew(virDomainEventClass,
"virDomainEventIOError",
sizeof(virDomainEventIOError),
virDomainEventIOErrorDispose)))
return -1;
return 0; return 0;
} }
@ -231,12 +244,6 @@ static void virDomainEventDispose(void *obj)
VIR_DEBUG("obj=%p", event); VIR_DEBUG("obj=%p", event);
switch (virObjectEventGetEventID(event)) { switch (virObjectEventGetEventID(event)) {
case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
case VIR_DOMAIN_EVENT_ID_IO_ERROR:
VIR_FREE(event->data.ioError.srcPath);
VIR_FREE(event->data.ioError.devAlias);
VIR_FREE(event->data.ioError.reason);
break;
case VIR_DOMAIN_EVENT_ID_GRAPHICS: case VIR_DOMAIN_EVENT_ID_GRAPHICS:
if (event->data.graphics.local) { if (event->data.graphics.local) {
@ -298,6 +305,16 @@ static void virDomainEventWatchdogDispose(void *obj)
VIR_DEBUG("obj=%p", event); VIR_DEBUG("obj=%p", event);
} }
static void virDomainEventIOErrorDispose(void *obj)
{
virDomainEventIOErrorPtr event = obj;
VIR_DEBUG("obj=%p", event);
VIR_FREE(event->srcPath);
VIR_FREE(event->devAlias);
VIR_FREE(event->reason);
}
/** /**
* virObjectEventCallbackListFree: * virObjectEventCallbackListFree:
* @list: event callback list head * @list: event callback list head
@ -972,24 +989,24 @@ static virDomainEventPtr virDomainEventIOErrorNewFromDomImpl(int event,
int action, int action,
const char *reason) const char *reason)
{ {
virDomainEventPtr ev; virDomainEventIOErrorPtr ev;
if (virObjectEventInitialize() < 0) if (virObjectEventInitialize() < 0)
return NULL; return NULL;
if (!(ev = virDomainEventNew(virDomainEventClass, event, if (!(ev = virDomainEventNew(virDomainEventIOErrorClass, event,
dom->id, dom->name, dom->uuid))) dom->id, dom->name, dom->uuid)))
return NULL; return NULL;
ev->data.ioError.action = action; ev->action = action;
if (VIR_STRDUP(ev->data.ioError.srcPath, srcPath) < 0 || if (VIR_STRDUP(ev->srcPath, srcPath) < 0 ||
VIR_STRDUP(ev->data.ioError.devAlias, devAlias) < 0 || VIR_STRDUP(ev->devAlias, devAlias) < 0 ||
VIR_STRDUP(ev->data.ioError.reason, reason) < 0) { VIR_STRDUP(ev->reason, reason) < 0) {
virObjectUnref(ev); virObjectUnref(ev);
ev = NULL; ev = NULL;
} }
return ev; return (virDomainEventPtr)ev;
} }
static virDomainEventPtr virDomainEventIOErrorNewFromObjImpl(int event, static virDomainEventPtr virDomainEventIOErrorNewFromObjImpl(int event,
@ -999,25 +1016,25 @@ static virDomainEventPtr virDomainEventIOErrorNewFromObjImpl(int event,
int action, int action,
const char *reason) const char *reason)
{ {
virDomainEventPtr ev; virDomainEventIOErrorPtr ev;
if (virObjectEventInitialize() < 0) if (virObjectEventInitialize() < 0)
return NULL; return NULL;
if (!(ev = virDomainEventNew(virDomainEventClass, event, if (!(ev = virDomainEventNew(virDomainEventIOErrorClass, event,
obj->def->id, obj->def->name, obj->def->id, obj->def->name,
obj->def->uuid))) obj->def->uuid)))
return NULL; return NULL;
ev->data.ioError.action = action; ev->action = action;
if (VIR_STRDUP(ev->data.ioError.srcPath, srcPath) < 0 || if (VIR_STRDUP(ev->srcPath, srcPath) < 0 ||
VIR_STRDUP(ev->data.ioError.devAlias, devAlias) < 0 || VIR_STRDUP(ev->devAlias, devAlias) < 0 ||
VIR_STRDUP(ev->data.ioError.reason, reason) < 0) { VIR_STRDUP(ev->reason, reason) < 0) {
virObjectUnref(ev); virObjectUnref(ev);
ev = NULL; ev = NULL;
} }
return ev; return (virDomainEventPtr)ev;
} }
virDomainEventPtr virDomainEventIOErrorNewFromDom(virDomainPtr dom, virDomainEventPtr virDomainEventIOErrorNewFromDom(virDomainPtr dom,
@ -1556,21 +1573,31 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
} }
case VIR_DOMAIN_EVENT_ID_IO_ERROR: case VIR_DOMAIN_EVENT_ID_IO_ERROR:
((virConnectDomainEventIOErrorCallback)cb)(conn, dom, {
event->data.ioError.srcPath, virDomainEventIOErrorPtr ioErrorEvent;
event->data.ioError.devAlias,
event->data.ioError.action, ioErrorEvent = (virDomainEventIOErrorPtr)event;
cbopaque); ((virConnectDomainEventIOErrorCallback)cb)(conn, dom,
goto cleanup; ioErrorEvent->srcPath,
ioErrorEvent->devAlias,
ioErrorEvent->action,
cbopaque);
goto cleanup;
}
case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON: case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
((virConnectDomainEventIOErrorReasonCallback)cb)(conn, dom, {
event->data.ioError.srcPath, virDomainEventIOErrorPtr ioErrorEvent;
event->data.ioError.devAlias,
event->data.ioError.action, ioErrorEvent = (virDomainEventIOErrorPtr)event;
event->data.ioError.reason, ((virConnectDomainEventIOErrorReasonCallback)cb)(conn, dom,
cbopaque); ioErrorEvent->srcPath,
goto cleanup; ioErrorEvent->devAlias,
ioErrorEvent->action,
ioErrorEvent->reason,
cbopaque);
goto cleanup;
}
case VIR_DOMAIN_EVENT_ID_GRAPHICS: case VIR_DOMAIN_EVENT_ID_GRAPHICS:
((virConnectDomainEventGraphicsCallback)cb)(conn, dom, ((virConnectDomainEventGraphicsCallback)cb)(conn, dom,