--- src/conf/domain_event.c | 102 ++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index b0c9050..0c38352 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -79,6 +79,8 @@ struct _virObjectEventCallback { static virClassPtr virObjectEventClass; +static virClassPtr virClassForObjectEvent(void); + static virClassPtr virDomainEventLifecycleClass; static virClassPtr virDomainEventRTCChangeClass; static virClassPtr virDomainEventWatchdogClass; @@ -211,62 +213,76 @@ static int virObjectEventOnceInit(void) sizeof(virObjectEvent), virObjectEventDispose))) return -1; + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virObjectEvent) + +virClassPtr virClassForObjectEvent(void) +{ + if (virObjectEventInitialize() < 0) + return NULL; + return virObjectEventClass; +} + +static int virDomainEventsOnceInit(void) +{ if (!(virDomainEventLifecycleClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventLifecycle", sizeof(virDomainEventLifecycle), virDomainEventLifecycleDispose))) return -1; if (!(virDomainEventRTCChangeClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventRTCChange", sizeof(virDomainEventRTCChange), virDomainEventRTCChangeDispose))) return -1; if (!(virDomainEventWatchdogClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventWatchdog", sizeof(virDomainEventWatchdog), virDomainEventWatchdogDispose))) return -1; if (!(virDomainEventIOErrorClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventIOError", sizeof(virDomainEventIOError), virDomainEventIOErrorDispose))) return -1; if (!(virDomainEventGraphicsClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventGraphics", sizeof(virDomainEventGraphics), virDomainEventGraphicsDispose))) return -1; if (!(virDomainEventBlockJobClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventBlockJob", sizeof(virDomainEventBlockJob), virDomainEventBlockJobDispose))) return -1; if (!(virDomainEventDiskChangeClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventDiskChange", sizeof(virDomainEventDiskChange), virDomainEventDiskChangeDispose))) return -1; if (!(virDomainEventTrayChangeClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventTrayChange", sizeof(virDomainEventTrayChange), virDomainEventTrayChangeDispose))) return -1; if (!(virDomainEventBalloonChangeClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventBalloonChange", sizeof(virDomainEventBalloonChange), virDomainEventBalloonChangeDispose))) return -1; if (!(virDomainEventDeviceRemovedClass = virClassNew( - virObjectEventClass, + virClassForObjectEvent(), "virDomainEventDeviceRemoved", sizeof(virDomainEventDeviceRemoved), virDomainEventDeviceRemovedDispose))) @@ -274,13 +290,13 @@ static int virObjectEventOnceInit(void) return 0; } -VIR_ONCE_GLOBAL_INIT(virObjectEvent) +VIR_ONCE_GLOBAL_INIT(virDomainEvents) static int virObjectEventGetEventID(void *anyobj) { virObjectEventPtr obj = anyobj; - if (!virObjectIsClass(obj, virObjectEventClass)) { + if (!virObjectIsClass(obj, virClassForObjectEvent())) { VIR_WARN("Object %p (%s) is not a virObjectEvent instance", obj, obj ? virClassName(obj->parent.klass) : "(unknown)"); return -1; @@ -905,7 +921,7 @@ void *virDomainEventLifecycleNew(int id, const char *name, { virDomainEventLifecyclePtr event; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(event = virObjectEventNew(virDomainEventLifecycleClass, @@ -939,30 +955,30 @@ void *virDomainEventLifecycleNewFromDef(virDomainDefPtr def, int type, int detai void *virDomainEventRebootNew(int id, const char *name, const unsigned char *uuid) { - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - return virObjectEventNew(virObjectEventClass, + return virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_REBOOT, id, name, uuid); } void *virDomainEventRebootNewFromDom(virDomainPtr dom) { - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - return virObjectEventNew(virObjectEventClass, + return virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_REBOOT, dom->id, dom->name, dom->uuid); } void *virDomainEventRebootNewFromObj(virDomainObjPtr obj) { - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - return virObjectEventNew(virObjectEventClass, + return virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_REBOOT, obj->def->id, obj->def->name, obj->def->uuid); } @@ -972,7 +988,7 @@ void *virDomainEventRTCChangeNewFromDom(virDomainPtr dom, { virDomainEventRTCChangePtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventRTCChangeClass, @@ -989,7 +1005,7 @@ void *virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj, { virDomainEventRTCChangePtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventRTCChangeClass, @@ -1007,7 +1023,7 @@ void *virDomainEventWatchdogNewFromDom(virDomainPtr dom, int action) { virDomainEventWatchdogPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventWatchdogClass, @@ -1023,7 +1039,7 @@ void *virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int action) { virDomainEventWatchdogPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventWatchdogClass, @@ -1046,7 +1062,7 @@ static void *virDomainEventIOErrorNewFromDomImpl(int event, { virDomainEventIOErrorPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventIOErrorClass, event, @@ -1073,7 +1089,7 @@ static void *virDomainEventIOErrorNewFromObjImpl(int event, { virDomainEventIOErrorPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventIOErrorClass, event, @@ -1144,7 +1160,7 @@ void *virDomainEventGraphicsNewFromDom(virDomainPtr dom, { virDomainEventGraphicsPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventGraphicsClass, @@ -1173,7 +1189,7 @@ void *virDomainEventGraphicsNewFromObj(virDomainObjPtr obj, { virDomainEventGraphicsPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventGraphicsClass, @@ -1200,7 +1216,7 @@ void * virDomainEventBlockJobNew(int id, const char *name, unsigned char *uuid, { virDomainEventBlockJobPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventBlockJobClass, @@ -1240,10 +1256,10 @@ void *virDomainEventControlErrorNewFromDom(virDomainPtr dom) { virObjectEventPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - if (!(ev = virObjectEventNew(virObjectEventClass, + if (!(ev = virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_CONTROL_ERROR, dom->id, dom->name, dom->uuid))) return NULL; @@ -1255,10 +1271,10 @@ void *virDomainEventControlErrorNewFromObj(virDomainObjPtr obj) { virObjectEventPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - if (!(ev = virObjectEventNew(virObjectEventClass, + if (!(ev = virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_CONTROL_ERROR, obj->def->id, obj->def->name, obj->def->uuid))) @@ -1275,7 +1291,7 @@ void *virDomainEventDiskChangeNew(int id, const char *name, { virDomainEventDiskChangePtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventDiskChangeClass, @@ -1331,7 +1347,7 @@ void *virDomainEventTrayChangeNew(int id, const char *name, { virDomainEventTrayChangePtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventTrayChangeClass, @@ -1375,10 +1391,10 @@ static void *virDomainEventPMWakeupNew(int id, const char *name, { virObjectEventPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - if (!(ev = virObjectEventNew(virObjectEventClass, + if (!(ev = virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_PMWAKEUP, id, name, uuid))) return NULL; @@ -1403,10 +1419,10 @@ static void *virDomainEventPMSuspendNew(int id, const char *name, { virObjectEventPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - if (!(ev = virObjectEventNew(virObjectEventClass, + if (!(ev = virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_PMSUSPEND, id, name, uuid))) return NULL; @@ -1431,10 +1447,10 @@ static void *virDomainEventPMSuspendDiskNew(int id, const char *name, { virObjectEventPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; - if (!(ev = virObjectEventNew(virObjectEventClass, + if (!(ev = virObjectEventNew(virClassForObjectEvent(), VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK, id, name, uuid))) return NULL; @@ -1458,7 +1474,7 @@ void *virDomainEventBalloonChangeNewFromDom(virDomainPtr dom, { virDomainEventBalloonChangePtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventBalloonChangeClass, @@ -1475,7 +1491,7 @@ void *virDomainEventBalloonChangeNewFromObj(virDomainObjPtr obj, { virDomainEventBalloonChangePtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventBalloonChangeClass, @@ -1495,7 +1511,7 @@ static void *virDomainEventDeviceRemovedNew(int id, { virDomainEventDeviceRemovedPtr ev; - if (virObjectEventInitialize() < 0) + if (virDomainEventsInitialize() < 0) return NULL; if (!(ev = virObjectEventNew(virDomainEventDeviceRemovedClass, -- 1.8.4.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list