diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index a9c499e6ae8011804385c3959922d4baff5b83c0..e5f57967e6dc619d5f1f57d6503547546d21d087 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -442,6 +442,7 @@ virDomainEventCallbackListAdd(virConnectPtr conn, virFreeCallback freecb) { return virObjectEventCallbackListAddID(conn, cbList, NULL, NULL, 0, + virDomainEventClass, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_OBJECT_EVENT_CALLBACK(callback), opaque, freecb, NULL); @@ -1372,6 +1373,9 @@ virDomainEventStateRegister(virConnectPtr conn, { int ret = -1; + if (virDomainEventsInitialize() < 0) + return -1; + virObjectEventStateLock(state); if ((state->callbacks->count == 0) && @@ -1426,14 +1430,17 @@ virDomainEventStateRegisterID(virConnectPtr conn, virFreeCallback freecb, int *callbackID) { + if (virDomainEventsInitialize() < 0) + return -1; + if (dom) return virObjectEventStateRegisterID(conn, state, dom->uuid, dom->name, - dom->id, eventID, + dom->id, virDomainEventClass, eventID, VIR_OBJECT_EVENT_CALLBACK(cb), opaque, freecb, callbackID); else return virObjectEventStateRegisterID(conn, state, NULL, NULL, 0, - eventID, + virDomainEventClass, eventID, VIR_OBJECT_EVENT_CALLBACK(cb), opaque, freecb, callbackID); } diff --git a/src/conf/network_event.c b/src/conf/network_event.c index 3173e68384f823785992f14867c152671599e459..3819702ace40582791b5402a514cb14bdbbb8ca2 100644 --- a/src/conf/network_event.c +++ b/src/conf/network_event.c @@ -97,7 +97,7 @@ virNetworkEventDispatchDefaultFunc(virConnectPtr conn, if (!net) return; - switch ((virNetworkEventID) (event->eventID &0xFF)) { + switch ((virNetworkEventID)event->eventID) { case VIR_NETWORK_EVENT_ID_LIFECYCLE: { virNetworkEventLifecyclePtr networkLifecycleEvent; @@ -146,14 +146,18 @@ virNetworkEventStateRegisterID(virConnectPtr conn, virFreeCallback freecb, int *callbackID) { - int nsEventID = (VIR_EVENT_NAMESPACE_NETWORK << 8) + eventID; + if (virNetworkEventsInitialize() < 0) + return -1; + if (net) return virObjectEventStateRegisterID(conn, state, - net->uuid, net->name, 0, nsEventID, + net->uuid, net->name, 0, + virNetworkEventClass, eventID, cb, opaque, freecb, callbackID); else return virObjectEventStateRegisterID(conn, state, - NULL, NULL, 0, nsEventID, + NULL, NULL, 0, + virNetworkEventClass, eventID, cb, opaque, freecb, callbackID); } @@ -164,14 +168,13 @@ virNetworkEventLifecycleNew(const char *name, int detail) { virNetworkEventLifecyclePtr event; - int eventId = (VIR_EVENT_NAMESPACE_NETWORK << 8) + VIR_NETWORK_EVENT_ID_LIFECYCLE; if (virNetworkEventsInitialize() < 0) return NULL; if (!(event = virObjectEventNew(virNetworkEventLifecycleClass, virNetworkEventDispatchDefaultFunc, - eventId, + VIR_NETWORK_EVENT_ID_LIFECYCLE, 0, name, uuid))) return NULL; diff --git a/src/conf/object_event.c b/src/conf/object_event.c index 1d184842800c658e41087a8222c6d1b48eb87313..6b5238fc17bec0174509268fc05007a1f2c54646 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -230,6 +230,7 @@ virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList) * @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 + * @klass: the base event class * @eventID: the event ID * @callback: the callback to add * @opaque: opaque data tio pass to callback @@ -243,6 +244,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn, unsigned char uuid[VIR_UUID_BUFLEN], const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback callback, void *opaque, @@ -261,6 +263,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn, /* check if we already have this callback on our list */ for (i = 0; i < cbList->count; i++) { if (cbList->callbacks[i]->cb == VIR_OBJECT_EVENT_CALLBACK(callback) && + cbList->callbacks[i]->klass == klass && cbList->callbacks[i]->eventID == eventID && cbList->callbacks[i]->conn == conn && ((uuid && cbList->callbacks[i]->meta && @@ -277,6 +280,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn, goto error; event->conn = conn; event->cb = callback; + event->klass = klass; event->eventID = eventID; event->opaque = opaque; event->freecb = freecb; @@ -302,7 +306,8 @@ virObjectEventCallbackListAddID(virConnectPtr conn, event->callbackID = cbList->nextID++; for (i = 0; i < cbList->count; i++) { - if (cbList->callbacks[i]->eventID == eventID && + if (cbList->callbacks[i]->klass == klass && + cbList->callbacks[i]->eventID == eventID && cbList->callbacks[i]->conn == conn && !cbList->callbacks[i]->deleted) ret++; @@ -540,6 +545,8 @@ virObjectEventDispatchMatchCallback(virObjectEventPtr event, return 0; if (cb->deleted) return 0; + if (!virObjectIsClass(event, cb->klass)) + return 0; if (cb->eventID != virObjectEventGetEventID(event)) return 0; @@ -655,6 +662,7 @@ virObjectEventStateFlush(virObjectEventStatePtr state) * virObjectEventStateRegisterID: * @conn: connection to associate with callback * @state: domain event state + * @klass: the base event class * @eventID: ID of the event type to register for * @cb: function to remove from event * @opaque: data blob to pass to callback @@ -672,6 +680,7 @@ virObjectEventStateRegisterID(virConnectPtr conn, unsigned char *uuid, const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback cb, void *opaque, @@ -694,7 +703,8 @@ virObjectEventStateRegisterID(virConnectPtr conn, } ret = virObjectEventCallbackListAddID(conn, state->callbacks, - uuid, name, id, eventID, cb, opaque, freecb, + uuid, name, id, klass, eventID, + cb, opaque, freecb, callbackID); if (ret == -1 && @@ -769,9 +779,6 @@ virObjectEventStateEventID(virConnectPtr conn, virObjectEventStateLock(state); ret = virObjectEventCallbackListEventID(conn, state->callbacks, callbackID); - /* Callers don't need to know we are namespacing the event Ids */ - if (ret >= 0) - ret = (0xFF & ret); virObjectEventStateUnlock(state); return ret; } diff --git a/src/conf/object_event.h b/src/conf/object_event.h index 50cfe19237cb0dcd925926e1a74504b0a8bb3b62..23ecb348dbd7ff08df8ebf67e0e21d76f7d1196a 100644 --- a/src/conf/object_event.h +++ b/src/conf/object_event.h @@ -24,17 +24,11 @@ #include "internal.h" +#include "virobject.h" + #ifndef __OBJECT_EVENT_H__ # define __OBJECT_EVENT_H__ -/** Event IDs are computed in the following way: - virEventNamespaceID << 8 + vir*EventId - */ -typedef enum { - VIR_EVENT_NAMESPACE_DOMAIN = 0, /* 0 to keep value of virDomainEventId unchanged */ - VIR_EVENT_NAMESPACE_NETWORK = 1, -} virEventNamespaceID; - typedef struct _virObjectEventCallback virObjectEventCallback; typedef virObjectEventCallback *virObjectEventCallbackPtr; @@ -78,12 +72,13 @@ virObjectEventStateRegisterID(virConnectPtr conn, unsigned char *uuid, const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback cb, void *opaque, virFreeCallback freecb, int *callbackID) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(7); + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(8); int virObjectEventStateDeregisterID(virConnectPtr conn, virObjectEventStatePtr state, diff --git a/src/conf/object_event_private.h b/src/conf/object_event_private.h index f18277a8d8ae7b12899b22ec81f16fbbdd7cd9ca..89c76752189c4cda616a88f80cee8e43fa012a9c 100644 --- a/src/conf/object_event_private.h +++ b/src/conf/object_event_private.h @@ -60,6 +60,7 @@ struct _virObjectEventState { struct _virObjectEventCallback { int callbackID; + virClassPtr klass; int eventID; virConnectPtr conn; virObjectMetaPtr meta; @@ -94,6 +95,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn, unsigned char *uuid, const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback callback, void *opaque,