mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-08 22:15:21 +00:00
Create virDomainEventTrayChange to get rid of the huge union
This commit is contained in:
parent
bc7b304336
commit
8d53d6ab74
@ -92,6 +92,7 @@ static virClassPtr virDomainEventIOErrorClass;
|
|||||||
static virClassPtr virDomainEventGraphicsClass;
|
static virClassPtr virDomainEventGraphicsClass;
|
||||||
static virClassPtr virDomainEventBlockJobClass;
|
static virClassPtr virDomainEventBlockJobClass;
|
||||||
static virClassPtr virDomainEventDiskChangeClass;
|
static virClassPtr virDomainEventDiskChangeClass;
|
||||||
|
static virClassPtr virDomainEventTrayChangeClass;
|
||||||
|
|
||||||
static void virObjectEventDispose(void *obj);
|
static void virObjectEventDispose(void *obj);
|
||||||
static void virDomainEventDispose(void *obj);
|
static void virDomainEventDispose(void *obj);
|
||||||
@ -102,6 +103,7 @@ 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);
|
static void virDomainEventDiskChangeDispose(void *obj);
|
||||||
|
static void virDomainEventTrayChangeDispose(void *obj);
|
||||||
|
|
||||||
struct _virObjectEvent {
|
struct _virObjectEvent {
|
||||||
virObject parent;
|
virObject parent;
|
||||||
@ -114,10 +116,6 @@ struct _virDomainEvent {
|
|||||||
virObjectMeta meta;
|
virObjectMeta meta;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct {
|
|
||||||
char *devAlias;
|
|
||||||
int reason;
|
|
||||||
} trayChange;
|
|
||||||
struct {
|
struct {
|
||||||
/* In unit of 1024 bytes */
|
/* In unit of 1024 bytes */
|
||||||
unsigned long long actual;
|
unsigned long long actual;
|
||||||
@ -197,6 +195,15 @@ struct _virDomainEventDiskChange {
|
|||||||
typedef struct _virDomainEventDiskChange virDomainEventDiskChange;
|
typedef struct _virDomainEventDiskChange virDomainEventDiskChange;
|
||||||
typedef virDomainEventDiskChange *virDomainEventDiskChangePtr;
|
typedef virDomainEventDiskChange *virDomainEventDiskChangePtr;
|
||||||
|
|
||||||
|
struct _virDomainEventTrayChange {
|
||||||
|
virDomainEvent parent;
|
||||||
|
|
||||||
|
char *devAlias;
|
||||||
|
int reason;
|
||||||
|
};
|
||||||
|
typedef struct _virDomainEventTrayChange virDomainEventTrayChange;
|
||||||
|
typedef virDomainEventTrayChange *virDomainEventTrayChangePtr;
|
||||||
|
|
||||||
|
|
||||||
static int virObjectEventOnceInit(void)
|
static int virObjectEventOnceInit(void)
|
||||||
{
|
{
|
||||||
@ -254,6 +261,12 @@ static int virObjectEventOnceInit(void)
|
|||||||
sizeof(virDomainEventDiskChange),
|
sizeof(virDomainEventDiskChange),
|
||||||
virDomainEventDiskChangeDispose)))
|
virDomainEventDiskChangeDispose)))
|
||||||
return -1;
|
return -1;
|
||||||
|
if (!(virDomainEventTrayChangeClass =
|
||||||
|
virClassNew(virDomainEventClass,
|
||||||
|
"virDomainEventTrayChange",
|
||||||
|
sizeof(virDomainEventTrayChange),
|
||||||
|
virDomainEventTrayChangeDispose)))
|
||||||
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,9 +299,6 @@ static void virDomainEventDispose(void *obj)
|
|||||||
|
|
||||||
switch (virObjectEventGetEventID(event)) {
|
switch (virObjectEventGetEventID(event)) {
|
||||||
|
|
||||||
case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
|
|
||||||
VIR_FREE(event->data.trayChange.devAlias);
|
|
||||||
break;
|
|
||||||
case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
|
case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
|
||||||
VIR_FREE(event->data.deviceRemoved.devAlias);
|
VIR_FREE(event->data.deviceRemoved.devAlias);
|
||||||
break;
|
break;
|
||||||
@ -369,6 +379,14 @@ static void virDomainEventDiskChangeDispose(void *obj)
|
|||||||
VIR_FREE(event->devAlias);
|
VIR_FREE(event->devAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void virDomainEventTrayChangeDispose(void *obj)
|
||||||
|
{
|
||||||
|
virDomainEventTrayChangePtr event = obj;
|
||||||
|
VIR_DEBUG("obj=%p", event);
|
||||||
|
|
||||||
|
VIR_FREE(event->devAlias);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virObjectEventCallbackListFree:
|
* virObjectEventCallbackListFree:
|
||||||
* @list: event callback list head
|
* @list: event callback list head
|
||||||
@ -1332,22 +1350,22 @@ virDomainEventTrayChangeNew(int id, const char *name,
|
|||||||
const char *devAlias,
|
const char *devAlias,
|
||||||
int reason)
|
int reason)
|
||||||
{
|
{
|
||||||
virDomainEventPtr ev;
|
virDomainEventTrayChangePtr ev;
|
||||||
|
|
||||||
if (virObjectEventInitialize() < 0)
|
if (virObjectEventInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ev = virDomainEventNew(virDomainEventClass,
|
if (!(ev = virDomainEventNew(virDomainEventTrayChangeClass,
|
||||||
VIR_DOMAIN_EVENT_ID_TRAY_CHANGE,
|
VIR_DOMAIN_EVENT_ID_TRAY_CHANGE,
|
||||||
id, name, uuid)))
|
id, name, uuid)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (VIR_STRDUP(ev->data.trayChange.devAlias, devAlias) < 0)
|
if (VIR_STRDUP(ev->devAlias, devAlias) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ev->data.trayChange.reason = reason;
|
ev->reason = reason;
|
||||||
|
|
||||||
return ev;
|
return (virDomainEventPtr)ev;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectUnref(ev);
|
virObjectUnref(ev);
|
||||||
@ -1705,11 +1723,16 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
|
case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
|
||||||
((virConnectDomainEventTrayChangeCallback)cb)(conn, dom,
|
{
|
||||||
event->data.trayChange.devAlias,
|
virDomainEventTrayChangePtr trayChangeEvent;
|
||||||
event->data.trayChange.reason,
|
|
||||||
cbopaque);
|
trayChangeEvent = (virDomainEventTrayChangePtr)event;
|
||||||
goto cleanup;
|
((virConnectDomainEventTrayChangeCallback)cb)(conn, dom,
|
||||||
|
trayChangeEvent->devAlias,
|
||||||
|
trayChangeEvent->reason,
|
||||||
|
cbopaque);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
|
case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
|
||||||
((virConnectDomainEventPMWakeupCallback)cb)(conn, dom, 0, cbopaque);
|
((virConnectDomainEventPMWakeupCallback)cb)(conn, dom, 0, cbopaque);
|
||||||
|
Loading…
Reference in New Issue
Block a user