mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Create virDomainEventBlockJob to get rid of the huge union
This commit is contained in:
parent
e6b83046b1
commit
0ac4c9edad
@ -90,6 +90,7 @@ static virClassPtr virDomainEventRTCChangeClass;
|
|||||||
static virClassPtr virDomainEventWatchdogClass;
|
static virClassPtr virDomainEventWatchdogClass;
|
||||||
static virClassPtr virDomainEventIOErrorClass;
|
static virClassPtr virDomainEventIOErrorClass;
|
||||||
static virClassPtr virDomainEventGraphicsClass;
|
static virClassPtr virDomainEventGraphicsClass;
|
||||||
|
static virClassPtr virDomainEventBlockJobClass;
|
||||||
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);
|
||||||
@ -97,6 +98,7 @@ static void virDomainEventRTCChangeDispose(void *obj);
|
|||||||
static void virDomainEventWatchdogDispose(void *obj);
|
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);
|
||||||
|
|
||||||
struct _virObjectEvent {
|
struct _virObjectEvent {
|
||||||
virObject parent;
|
virObject parent;
|
||||||
@ -109,11 +111,6 @@ struct _virDomainEvent {
|
|||||||
virObjectMeta meta;
|
virObjectMeta meta;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct {
|
|
||||||
char *path;
|
|
||||||
int type;
|
|
||||||
int status;
|
|
||||||
} blockJob;
|
|
||||||
struct {
|
struct {
|
||||||
char *oldSrcPath;
|
char *oldSrcPath;
|
||||||
char *newSrcPath;
|
char *newSrcPath;
|
||||||
@ -170,6 +167,16 @@ struct _virDomainEventIOError {
|
|||||||
typedef struct _virDomainEventIOError virDomainEventIOError;
|
typedef struct _virDomainEventIOError virDomainEventIOError;
|
||||||
typedef virDomainEventIOError *virDomainEventIOErrorPtr;
|
typedef virDomainEventIOError *virDomainEventIOErrorPtr;
|
||||||
|
|
||||||
|
struct _virDomainEventBlockJob {
|
||||||
|
virDomainEvent parent;
|
||||||
|
|
||||||
|
char *path;
|
||||||
|
int type;
|
||||||
|
int status;
|
||||||
|
};
|
||||||
|
typedef struct _virDomainEventBlockJob virDomainEventBlockJob;
|
||||||
|
typedef virDomainEventBlockJob *virDomainEventBlockJobPtr;
|
||||||
|
|
||||||
struct _virDomainEventGraphics {
|
struct _virDomainEventGraphics {
|
||||||
virDomainEvent parent;
|
virDomainEvent parent;
|
||||||
|
|
||||||
@ -226,6 +233,12 @@ static int virObjectEventOnceInit(void)
|
|||||||
sizeof(virDomainEventGraphics),
|
sizeof(virDomainEventGraphics),
|
||||||
virDomainEventGraphicsDispose)))
|
virDomainEventGraphicsDispose)))
|
||||||
return -1;
|
return -1;
|
||||||
|
if (!(virDomainEventBlockJobClass =
|
||||||
|
virClassNew(virDomainEventClass,
|
||||||
|
"virDomainEventBlockJob",
|
||||||
|
sizeof(virDomainEventBlockJob),
|
||||||
|
virDomainEventBlockJobDispose)))
|
||||||
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,10 +271,6 @@ static void virDomainEventDispose(void *obj)
|
|||||||
|
|
||||||
switch (virObjectEventGetEventID(event)) {
|
switch (virObjectEventGetEventID(event)) {
|
||||||
|
|
||||||
case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
|
|
||||||
VIR_FREE(event->data.blockJob.path);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
|
case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
|
||||||
VIR_FREE(event->data.diskChange.oldSrcPath);
|
VIR_FREE(event->data.diskChange.oldSrcPath);
|
||||||
VIR_FREE(event->data.diskChange.newSrcPath);
|
VIR_FREE(event->data.diskChange.newSrcPath);
|
||||||
@ -332,6 +341,14 @@ static void virDomainEventGraphicsDispose(void *obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void virDomainEventBlockJobDispose(void *obj)
|
||||||
|
{
|
||||||
|
virDomainEventBlockJobPtr event = obj;
|
||||||
|
VIR_DEBUG("obj=%p", event);
|
||||||
|
|
||||||
|
VIR_FREE(event->path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virObjectEventCallbackListFree:
|
* virObjectEventCallbackListFree:
|
||||||
* @list: event callback list head
|
* @list: event callback list head
|
||||||
@ -1156,43 +1173,47 @@ virDomainEventPtr virDomainEventGraphicsNewFromObj(virDomainObjPtr obj,
|
|||||||
return (virDomainEventPtr)ev;
|
return (virDomainEventPtr)ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virDomainEventPtr
|
static
|
||||||
virDomainEventBlockJobNew(int id, const char *name, unsigned char *uuid,
|
virDomainEventPtr virDomainEventBlockJobNew(int id,
|
||||||
const char *path, int type, int status)
|
const char *name,
|
||||||
|
unsigned char *uuid,
|
||||||
|
const char *path,
|
||||||
|
int type,
|
||||||
|
int status)
|
||||||
{
|
{
|
||||||
virDomainEventPtr ev;
|
virDomainEventBlockJobPtr ev;
|
||||||
|
|
||||||
if (virObjectEventInitialize() < 0)
|
if (virObjectEventInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ev = virDomainEventNew(virDomainEventClass,
|
if (!(ev = virDomainEventNew(virDomainEventBlockJobClass,
|
||||||
VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
|
VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
|
||||||
id, name, uuid)))
|
id, name, uuid)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (VIR_STRDUP(ev->data.blockJob.path, path) < 0) {
|
if (VIR_STRDUP(ev->path, path) < 0) {
|
||||||
virObjectUnref(ev);
|
virObjectUnref(ev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ev->data.blockJob.type = type;
|
ev->type = type;
|
||||||
ev->data.blockJob.status = status;
|
ev->status = status;
|
||||||
|
|
||||||
return ev;
|
return (virDomainEventPtr)ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
virDomainEventPtr virDomainEventBlockJobNewFromObj(virDomainObjPtr obj,
|
virDomainEventPtr virDomainEventBlockJobNewFromObj(virDomainObjPtr obj,
|
||||||
const char *path,
|
const char *path,
|
||||||
int type,
|
int type,
|
||||||
int status)
|
int status)
|
||||||
{
|
{
|
||||||
return virDomainEventBlockJobNew(obj->def->id, obj->def->name,
|
return virDomainEventBlockJobNew(obj->def->id, obj->def->name,
|
||||||
obj->def->uuid, path, type, status);
|
obj->def->uuid, path, type, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
virDomainEventPtr virDomainEventBlockJobNewFromDom(virDomainPtr dom,
|
virDomainEventPtr virDomainEventBlockJobNewFromDom(virDomainPtr dom,
|
||||||
const char *path,
|
const char *path,
|
||||||
int type,
|
int type,
|
||||||
int status)
|
int status)
|
||||||
{
|
{
|
||||||
return virDomainEventBlockJobNew(dom->id, dom->name, dom->uuid,
|
return virDomainEventBlockJobNew(dom->id, dom->name, dom->uuid,
|
||||||
path, type, status);
|
path, type, status);
|
||||||
@ -1637,12 +1658,17 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
|
case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
|
||||||
((virConnectDomainEventBlockJobCallback)cb)(conn, dom,
|
{
|
||||||
event->data.blockJob.path,
|
virDomainEventBlockJobPtr blockJobEvent;
|
||||||
event->data.blockJob.type,
|
|
||||||
event->data.blockJob.status,
|
blockJobEvent = (virDomainEventBlockJobPtr)event;
|
||||||
cbopaque);
|
((virConnectDomainEventBlockJobCallback)cb)(conn, dom,
|
||||||
goto cleanup;
|
blockJobEvent->path,
|
||||||
|
blockJobEvent->type,
|
||||||
|
blockJobEvent->status,
|
||||||
|
cbopaque);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
|
case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
|
||||||
((virConnectDomainEventDiskChangeCallback)cb)(conn, dom,
|
((virConnectDomainEventDiskChangeCallback)cb)(conn, dom,
|
||||||
|
@ -104,13 +104,13 @@ virDomainEventPtr virDomainEventControlErrorNewFromDom(virDomainPtr dom);
|
|||||||
virDomainEventPtr virDomainEventControlErrorNewFromObj(virDomainObjPtr obj);
|
virDomainEventPtr virDomainEventControlErrorNewFromObj(virDomainObjPtr obj);
|
||||||
|
|
||||||
virDomainEventPtr virDomainEventBlockJobNewFromObj(virDomainObjPtr obj,
|
virDomainEventPtr virDomainEventBlockJobNewFromObj(virDomainObjPtr obj,
|
||||||
const char *path,
|
const char *path,
|
||||||
int type,
|
int type,
|
||||||
int status);
|
int status);
|
||||||
virDomainEventPtr virDomainEventBlockJobNewFromDom(virDomainPtr dom,
|
virDomainEventPtr virDomainEventBlockJobNewFromDom(virDomainPtr dom,
|
||||||
const char *path,
|
const char *path,
|
||||||
int type,
|
int type,
|
||||||
int status);
|
int status);
|
||||||
|
|
||||||
virDomainEventPtr virDomainEventDiskChangeNewFromObj(virDomainObjPtr obj,
|
virDomainEventPtr virDomainEventDiskChangeNewFromObj(virDomainObjPtr obj,
|
||||||
const char *oldSrcPath,
|
const char *oldSrcPath,
|
||||||
|
Loading…
Reference in New Issue
Block a user