But kept the legacy Domain lifecycle event functions as is. --- src/conf/domain_event.c | 87 ++++++++++++++++++++++++++----------------------- src/conf/domain_event.h | 4 +-- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index b29da12..00e20c2 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -40,7 +40,7 @@ struct _virObjectMeta { typedef struct _virObjectMeta virObjectMeta; typedef virObjectMeta *virObjectMetaPtr; -struct _virDomainEventCallbackList { +struct _virObjectEventCallbackList { unsigned int nextID; unsigned int count; virObjectEventCallbackPtr *callbacks; @@ -53,7 +53,7 @@ struct _virObjectEventQueue { struct _virObjectEventState { /* The list of domain event callbacks */ - virDomainEventCallbackListPtr callbacks; + virObjectEventCallbackListPtr callbacks; /* The queue of object events */ virObjectEventQueuePtr queue; /* Timer for flushing events queue */ @@ -129,13 +129,13 @@ struct _virDomainEvent { }; /** - * virDomainEventCallbackListFree: + * virObjectEventCallbackListFree: * @list: event callback list head * * Free the memory in the domain event callback list */ static void -virDomainEventCallbackListFree(virDomainEventCallbackListPtr list) +virObjectEventCallbackListFree(virObjectEventCallbackListPtr list) { size_t i; if (!list) @@ -158,11 +158,11 @@ virDomainEventCallbackListFree(virDomainEventCallbackListPtr list) * @cbList: the list * @callback: the callback to remove * - * Internal function to remove a callback from a virDomainEventCallbackListPtr + * Internal function to remove a callback from a virObjectEventCallbackListPtr */ static int virDomainEventCallbackListRemove(virConnectPtr conn, - virDomainEventCallbackListPtr cbList, + virObjectEventCallbackListPtr cbList, virConnectDomainEventCallback callback) { int ret = 0; @@ -204,16 +204,16 @@ virDomainEventCallbackListRemove(virConnectPtr conn, /** - * virDomainEventCallbackListRemoveID: + * virObjectEventCallbackListRemoveID: * @conn: pointer to the connection * @cbList: the list * @callback: the callback to remove * - * Internal function to remove a callback from a virDomainEventCallbackListPtr + * Internal function to remove a callback from a virObjectEventCallbackListPtr */ static int -virDomainEventCallbackListRemoveID(virConnectPtr conn, - virDomainEventCallbackListPtr cbList, +virObjectEventCallbackListRemoveID(virConnectPtr conn, + virObjectEventCallbackListPtr cbList, int callbackID) { int ret = 0; @@ -255,7 +255,7 @@ virDomainEventCallbackListRemoveID(virConnectPtr conn, static int virDomainEventCallbackListMarkDelete(virConnectPtr conn, - virDomainEventCallbackListPtr cbList, + virObjectEventCallbackListPtr cbList, virConnectDomainEventCallback callback) { int ret = 0; @@ -280,8 +280,8 @@ virDomainEventCallbackListMarkDelete(virConnectPtr conn, static int -virDomainEventCallbackListMarkDeleteID(virConnectPtr conn, - virDomainEventCallbackListPtr cbList, +virObjectEventCallbackListMarkDeleteID(virConnectPtr conn, + virObjectEventCallbackListPtr cbList, int callbackID) { int ret = 0; @@ -305,7 +305,7 @@ virDomainEventCallbackListMarkDeleteID(virConnectPtr conn, static int -virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList) +virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList) { int old_count = cbList->count; int n; @@ -335,20 +335,25 @@ virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList) /** - * virDomainEventCallbackListAddID: + * virObjectEventCallbackListAddID: * @conn: pointer to the connection * @cbList: the list + * @uuid: the uuid of the object to filter on + * @name: the name of the object to filter on + * @id: the ID of the object to filter on * @eventID: the event ID * @callback: the callback to add * @opaque: opaque data tio pass to callback * @callbackID: filled with callback ID * - * Internal function to add a callback from a virDomainEventCallbackListPtr + * Internal function to add a callback from a virObjectEventCallbackListPtr */ static int -virDomainEventCallbackListAddID(virConnectPtr conn, - virDomainEventCallbackListPtr cbList, - virDomainPtr dom, +virObjectEventCallbackListAddID(virConnectPtr conn, + virObjectEventCallbackListPtr cbList, + unsigned char uuid[VIR_UUID_BUFLEN], + const char *name, + int id, int eventID, virConnectDomainEventGenericCallback callback, void *opaque, @@ -369,10 +374,10 @@ virDomainEventCallbackListAddID(virConnectPtr conn, if (cbList->callbacks[i]->cb == VIR_DOMAIN_EVENT_CALLBACK(callback) && cbList->callbacks[i]->eventID == eventID && cbList->callbacks[i]->conn == conn && - ((dom && cbList->callbacks[i]->meta && + ((uuid && cbList->callbacks[i]->meta && memcmp(cbList->callbacks[i]->meta->uuid, - dom->uuid, VIR_UUID_BUFLEN) == 0) || - (!dom && !cbList->callbacks[i]->meta))) { + uuid, VIR_UUID_BUFLEN) == 0) || + (!uuid && !cbList->callbacks[i]->meta))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("event callback already tracked")); return -1; @@ -387,13 +392,13 @@ virDomainEventCallbackListAddID(virConnectPtr conn, event->opaque = opaque; event->freecb = freecb; - if (dom) { + if (name && uuid && id > 0) { if (VIR_ALLOC(event->meta) < 0) goto error; - if (VIR_STRDUP(event->meta->name, dom->name) < 0) + if (VIR_STRDUP(event->meta->name, name) < 0) goto error; - memcpy(event->meta->uuid, dom->uuid, VIR_UUID_BUFLEN); - event->meta->id = dom->id; + memcpy(event->meta->uuid, uuid, VIR_UUID_BUFLEN); + event->meta->id = id; } /* Make space on list */ @@ -437,16 +442,16 @@ error: * @callback: the callback to add * @opaque: opaque data tio pass to callback * - * Internal function to add a callback from a virDomainEventCallbackListPtr + * Internal function to add a callback from a virObjectEventCallbackListPtr */ static int virDomainEventCallbackListAdd(virConnectPtr conn, - virDomainEventCallbackListPtr cbList, + virObjectEventCallbackListPtr cbList, virConnectDomainEventCallback callback, void *opaque, virFreeCallback freecb) { - return virDomainEventCallbackListAddID(conn, cbList, NULL, + return virObjectEventCallbackListAddID(conn, cbList, NULL, NULL, 0, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(callback), opaque, freecb, NULL); @@ -455,8 +460,8 @@ virDomainEventCallbackListAdd(virConnectPtr conn, static int -virDomainEventCallbackListEventID(virConnectPtr conn, - virDomainEventCallbackListPtr cbList, +virObjectEventCallbackListEventID(virConnectPtr conn, + virObjectEventCallbackListPtr cbList, int callbackID) { size_t i; @@ -599,7 +604,7 @@ virObjectEventStateFree(virObjectEventStatePtr state) if (!state) return; - virDomainEventCallbackListFree(state->callbacks); + virObjectEventCallbackListFree(state->callbacks); virObjectEventQueueFree(state->queue); if (state->timer != -1) @@ -1394,7 +1399,7 @@ static int virDomainEventDispatchMatchCallback(virDomainEventPtr event, static void virDomainEventDispatch(virDomainEventPtr event, - virDomainEventCallbackListPtr callbacks, + virObjectEventCallbackListPtr callbacks, virDomainEventDispatchFunc dispatch, void *opaque) { @@ -1419,7 +1424,7 @@ virDomainEventDispatch(virDomainEventPtr event, static void virObjectEventQueueDispatch(virObjectEventQueuePtr queue, - virDomainEventCallbackListPtr callbacks, + virObjectEventCallbackListPtr callbacks, virDomainEventDispatchFunc dispatch, void *opaque) { @@ -1493,7 +1498,7 @@ virObjectEventStateFlush(virObjectEventStatePtr state) state); /* Purge any deleted callbacks */ - virDomainEventCallbackListPurgeMarked(state->callbacks); + virObjectEventCallbackListPurgeMarked(state->callbacks); state->isDispatching = false; virObjectEventStateUnlock(state); @@ -1591,9 +1596,9 @@ virDomainEventStateRegisterID(virConnectPtr conn, goto cleanup; } - ret = virDomainEventCallbackListAddID(conn, state->callbacks, - dom, eventID, cb, opaque, freecb, - callbackID); + ret = virObjectEventCallbackListAddID(conn, state->callbacks, dom->uuid, + dom->name, dom->id, eventID, cb, + opaque, freecb, callbackID); if (ret == -1 && state->callbacks->count == 0 && @@ -1665,10 +1670,10 @@ virObjectEventStateDeregisterID(virConnectPtr conn, virObjectEventStateLock(state); if (state->isDispatching) - ret = virDomainEventCallbackListMarkDeleteID(conn, + ret = virObjectEventCallbackListMarkDeleteID(conn, state->callbacks, callbackID); else - ret = virDomainEventCallbackListRemoveID(conn, + ret = virObjectEventCallbackListRemoveID(conn, state->callbacks, callbackID); if (state->callbacks->count == 0 && @@ -1702,7 +1707,7 @@ virObjectEventStateEventID(virConnectPtr conn, int ret; virObjectEventStateLock(state); - ret = virDomainEventCallbackListEventID(conn, + ret = virObjectEventCallbackListEventID(conn, state->callbacks, callbackID); virObjectEventStateUnlock(state); return ret; diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index c08f770..65a17ad 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -31,8 +31,8 @@ typedef struct _virObjectEventCallback virObjectEventCallback; typedef virObjectEventCallback *virObjectEventCallbackPtr; -typedef struct _virDomainEventCallbackList virDomainEventCallbackList; -typedef virDomainEventCallbackList *virDomainEventCallbackListPtr; +typedef struct _virObjectEventCallbackList virObjectEventCallbackList; +typedef virObjectEventCallbackList *virObjectEventCallbackListPtr; /** * Dispatching domain events that come in while -- 1.8.4.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list