提交 1ee803e5 编写于 作者: C Cédric Bosdonnat 提交者: Daniel P. Berrange

Renamed virDomainEventCallbackList* to virObjectEventCallbackList*

Keep the legacy Domain lifecycle event functions as is.
上级 146434ef
...@@ -43,11 +43,13 @@ typedef virObjectMeta *virObjectMetaPtr; ...@@ -43,11 +43,13 @@ typedef virObjectMeta *virObjectMetaPtr;
typedef struct _virObjectEventQueue virObjectEventQueue; typedef struct _virObjectEventQueue virObjectEventQueue;
typedef virObjectEventQueue *virObjectEventQueuePtr; typedef virObjectEventQueue *virObjectEventQueuePtr;
struct _virDomainEventCallbackList { struct _virObjectEventCallbackList {
unsigned int nextID; unsigned int nextID;
unsigned int count; unsigned int count;
virObjectEventCallbackPtr *callbacks; virObjectEventCallbackPtr *callbacks;
}; };
typedef struct _virObjectEventCallbackList virObjectEventCallbackList;
typedef virObjectEventCallbackList *virObjectEventCallbackListPtr;
struct _virObjectEventQueue { struct _virObjectEventQueue {
unsigned int count; unsigned int count;
...@@ -56,7 +58,7 @@ struct _virObjectEventQueue { ...@@ -56,7 +58,7 @@ struct _virObjectEventQueue {
struct _virObjectEventState { struct _virObjectEventState {
/* The list of domain event callbacks */ /* The list of domain event callbacks */
virDomainEventCallbackListPtr callbacks; virObjectEventCallbackListPtr callbacks;
/* The queue of object events */ /* The queue of object events */
virObjectEventQueuePtr queue; virObjectEventQueuePtr queue;
/* Timer for flushing events queue */ /* Timer for flushing events queue */
...@@ -132,13 +134,13 @@ struct _virDomainEvent { ...@@ -132,13 +134,13 @@ struct _virDomainEvent {
}; };
/** /**
* virDomainEventCallbackListFree: * virObjectEventCallbackListFree:
* @list: event callback list head * @list: event callback list head
* *
* Free the memory in the domain event callback list * Free the memory in the domain event callback list
*/ */
static void static void
virDomainEventCallbackListFree(virDomainEventCallbackListPtr list) virObjectEventCallbackListFree(virObjectEventCallbackListPtr list)
{ {
size_t i; size_t i;
if (!list) if (!list)
...@@ -161,11 +163,11 @@ virDomainEventCallbackListFree(virDomainEventCallbackListPtr list) ...@@ -161,11 +163,11 @@ virDomainEventCallbackListFree(virDomainEventCallbackListPtr list)
* @cbList: the list * @cbList: the list
* @callback: the callback to remove * @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 static int
virDomainEventCallbackListRemove(virConnectPtr conn, virDomainEventCallbackListRemove(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
virConnectDomainEventCallback callback) virConnectDomainEventCallback callback)
{ {
int ret = 0; int ret = 0;
...@@ -207,16 +209,16 @@ virDomainEventCallbackListRemove(virConnectPtr conn, ...@@ -207,16 +209,16 @@ virDomainEventCallbackListRemove(virConnectPtr conn,
/** /**
* virDomainEventCallbackListRemoveID: * virObjectEventCallbackListRemoveID:
* @conn: pointer to the connection * @conn: pointer to the connection
* @cbList: the list * @cbList: the list
* @callback: the callback to remove * @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 static int
virDomainEventCallbackListRemoveID(virConnectPtr conn, virObjectEventCallbackListRemoveID(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
int callbackID) int callbackID)
{ {
int ret = 0; int ret = 0;
...@@ -258,7 +260,7 @@ virDomainEventCallbackListRemoveID(virConnectPtr conn, ...@@ -258,7 +260,7 @@ virDomainEventCallbackListRemoveID(virConnectPtr conn,
static int static int
virDomainEventCallbackListMarkDelete(virConnectPtr conn, virDomainEventCallbackListMarkDelete(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
virConnectDomainEventCallback callback) virConnectDomainEventCallback callback)
{ {
int ret = 0; int ret = 0;
...@@ -283,8 +285,8 @@ virDomainEventCallbackListMarkDelete(virConnectPtr conn, ...@@ -283,8 +285,8 @@ virDomainEventCallbackListMarkDelete(virConnectPtr conn,
static int static int
virDomainEventCallbackListMarkDeleteID(virConnectPtr conn, virObjectEventCallbackListMarkDeleteID(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
int callbackID) int callbackID)
{ {
int ret = 0; int ret = 0;
...@@ -308,7 +310,7 @@ virDomainEventCallbackListMarkDeleteID(virConnectPtr conn, ...@@ -308,7 +310,7 @@ virDomainEventCallbackListMarkDeleteID(virConnectPtr conn,
static int static int
virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList) virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList)
{ {
int old_count = cbList->count; int old_count = cbList->count;
int n; int n;
...@@ -338,20 +340,25 @@ virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList) ...@@ -338,20 +340,25 @@ virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList)
/** /**
* virDomainEventCallbackListAddID: * virObjectEventCallbackListAddID:
* @conn: pointer to the connection * @conn: pointer to the connection
* @cbList: the list * @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 * @eventID: the event ID
* @callback: the callback to add * @callback: the callback to add
* @opaque: opaque data tio pass to callback * @opaque: opaque data tio pass to callback
* @callbackID: filled with callback ID * @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 static int
virDomainEventCallbackListAddID(virConnectPtr conn, virObjectEventCallbackListAddID(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
virDomainPtr dom, unsigned char uuid[VIR_UUID_BUFLEN],
const char *name,
int id,
int eventID, int eventID,
virConnectDomainEventGenericCallback callback, virConnectDomainEventGenericCallback callback,
void *opaque, void *opaque,
...@@ -372,10 +379,10 @@ virDomainEventCallbackListAddID(virConnectPtr conn, ...@@ -372,10 +379,10 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
if (cbList->callbacks[i]->cb == VIR_DOMAIN_EVENT_CALLBACK(callback) && if (cbList->callbacks[i]->cb == VIR_DOMAIN_EVENT_CALLBACK(callback) &&
cbList->callbacks[i]->eventID == eventID && cbList->callbacks[i]->eventID == eventID &&
cbList->callbacks[i]->conn == conn && cbList->callbacks[i]->conn == conn &&
((dom && cbList->callbacks[i]->meta && ((uuid && cbList->callbacks[i]->meta &&
memcmp(cbList->callbacks[i]->meta->uuid, memcmp(cbList->callbacks[i]->meta->uuid,
dom->uuid, VIR_UUID_BUFLEN) == 0) || uuid, VIR_UUID_BUFLEN) == 0) ||
(!dom && !cbList->callbacks[i]->meta))) { (!uuid && !cbList->callbacks[i]->meta))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("event callback already tracked")); _("event callback already tracked"));
return -1; return -1;
...@@ -390,13 +397,13 @@ virDomainEventCallbackListAddID(virConnectPtr conn, ...@@ -390,13 +397,13 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
event->opaque = opaque; event->opaque = opaque;
event->freecb = freecb; event->freecb = freecb;
if (dom) { if (name && uuid && id > 0) {
if (VIR_ALLOC(event->meta) < 0) if (VIR_ALLOC(event->meta) < 0)
goto error; goto error;
if (VIR_STRDUP(event->meta->name, dom->name) < 0) if (VIR_STRDUP(event->meta->name, name) < 0)
goto error; goto error;
memcpy(event->meta->uuid, dom->uuid, VIR_UUID_BUFLEN); memcpy(event->meta->uuid, uuid, VIR_UUID_BUFLEN);
event->meta->id = dom->id; event->meta->id = id;
} }
/* Make space on list */ /* Make space on list */
...@@ -440,16 +447,16 @@ error: ...@@ -440,16 +447,16 @@ error:
* @callback: the callback to add * @callback: the callback to add
* @opaque: opaque data tio pass to callback * @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 static int
virDomainEventCallbackListAdd(virConnectPtr conn, virDomainEventCallbackListAdd(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
virConnectDomainEventCallback callback, virConnectDomainEventCallback callback,
void *opaque, void *opaque,
virFreeCallback freecb) virFreeCallback freecb)
{ {
return virDomainEventCallbackListAddID(conn, cbList, NULL, return virObjectEventCallbackListAddID(conn, cbList, NULL, NULL, 0,
VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_ID_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(callback), VIR_DOMAIN_EVENT_CALLBACK(callback),
opaque, freecb, NULL); opaque, freecb, NULL);
...@@ -458,8 +465,8 @@ virDomainEventCallbackListAdd(virConnectPtr conn, ...@@ -458,8 +465,8 @@ virDomainEventCallbackListAdd(virConnectPtr conn,
static int static int
virDomainEventCallbackListEventID(virConnectPtr conn, virObjectEventCallbackListEventID(virConnectPtr conn,
virDomainEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
int callbackID) int callbackID)
{ {
size_t i; size_t i;
...@@ -602,7 +609,7 @@ virObjectEventStateFree(virObjectEventStatePtr state) ...@@ -602,7 +609,7 @@ virObjectEventStateFree(virObjectEventStatePtr state)
if (!state) if (!state)
return; return;
virDomainEventCallbackListFree(state->callbacks); virObjectEventCallbackListFree(state->callbacks);
virObjectEventQueueFree(state->queue); virObjectEventQueueFree(state->queue);
if (state->timer != -1) if (state->timer != -1)
...@@ -1397,7 +1404,7 @@ static int virDomainEventDispatchMatchCallback(virDomainEventPtr event, ...@@ -1397,7 +1404,7 @@ static int virDomainEventDispatchMatchCallback(virDomainEventPtr event,
static void static void
virDomainEventDispatch(virDomainEventPtr event, virDomainEventDispatch(virDomainEventPtr event,
virDomainEventCallbackListPtr callbacks, virObjectEventCallbackListPtr callbacks,
virDomainEventDispatchFunc dispatch, virDomainEventDispatchFunc dispatch,
void *opaque) void *opaque)
{ {
...@@ -1422,7 +1429,7 @@ virDomainEventDispatch(virDomainEventPtr event, ...@@ -1422,7 +1429,7 @@ virDomainEventDispatch(virDomainEventPtr event,
static void static void
virObjectEventQueueDispatch(virObjectEventQueuePtr queue, virObjectEventQueueDispatch(virObjectEventQueuePtr queue,
virDomainEventCallbackListPtr callbacks, virObjectEventCallbackListPtr callbacks,
virDomainEventDispatchFunc dispatch, virDomainEventDispatchFunc dispatch,
void *opaque) void *opaque)
{ {
...@@ -1496,7 +1503,7 @@ virObjectEventStateFlush(virObjectEventStatePtr state) ...@@ -1496,7 +1503,7 @@ virObjectEventStateFlush(virObjectEventStatePtr state)
state); state);
/* Purge any deleted callbacks */ /* Purge any deleted callbacks */
virDomainEventCallbackListPurgeMarked(state->callbacks); virObjectEventCallbackListPurgeMarked(state->callbacks);
state->isDispatching = false; state->isDispatching = false;
virObjectEventStateUnlock(state); virObjectEventStateUnlock(state);
...@@ -1594,9 +1601,14 @@ virDomainEventStateRegisterID(virConnectPtr conn, ...@@ -1594,9 +1601,14 @@ virDomainEventStateRegisterID(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
ret = virDomainEventCallbackListAddID(conn, state->callbacks, if (dom == NULL)
dom, eventID, cb, opaque, freecb, ret = virObjectEventCallbackListAddID(conn, state->callbacks, NULL,
callbackID); NULL, 0, eventID, cb,
opaque, freecb, callbackID);
else
ret = virObjectEventCallbackListAddID(conn, state->callbacks, dom->uuid,
dom->name, dom->id, eventID, cb,
opaque, freecb, callbackID);
if (ret == -1 && if (ret == -1 &&
state->callbacks->count == 0 && state->callbacks->count == 0 &&
...@@ -1668,10 +1680,10 @@ virObjectEventStateDeregisterID(virConnectPtr conn, ...@@ -1668,10 +1680,10 @@ virObjectEventStateDeregisterID(virConnectPtr conn,
virObjectEventStateLock(state); virObjectEventStateLock(state);
if (state->isDispatching) if (state->isDispatching)
ret = virDomainEventCallbackListMarkDeleteID(conn, ret = virObjectEventCallbackListMarkDeleteID(conn,
state->callbacks, callbackID); state->callbacks, callbackID);
else else
ret = virDomainEventCallbackListRemoveID(conn, ret = virObjectEventCallbackListRemoveID(conn,
state->callbacks, callbackID); state->callbacks, callbackID);
if (state->callbacks->count == 0 && if (state->callbacks->count == 0 &&
...@@ -1705,7 +1717,7 @@ virObjectEventStateEventID(virConnectPtr conn, ...@@ -1705,7 +1717,7 @@ virObjectEventStateEventID(virConnectPtr conn,
int ret; int ret;
virObjectEventStateLock(state); virObjectEventStateLock(state);
ret = virDomainEventCallbackListEventID(conn, ret = virObjectEventCallbackListEventID(conn,
state->callbacks, callbackID); state->callbacks, callbackID);
virObjectEventStateUnlock(state); virObjectEventStateUnlock(state);
return ret; return ret;
......
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
typedef struct _virObjectEventCallback virObjectEventCallback; typedef struct _virObjectEventCallback virObjectEventCallback;
typedef virObjectEventCallback *virObjectEventCallbackPtr; typedef virObjectEventCallback *virObjectEventCallbackPtr;
typedef struct _virDomainEventCallbackList virDomainEventCallbackList;
typedef virDomainEventCallbackList *virDomainEventCallbackListPtr;
/** /**
* Dispatching domain events that come in while * Dispatching domain events that come in while
* in a call / response rpc * in a call / response rpc
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册