From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> The event namespace concept is redundant since the same information is available by looking at the class hierarchy of the events. Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/conf/domain_event.c | 18 ++++++++++++++++-- src/conf/domain_event.h | 2 ++ src/conf/network_event.c | 22 ++++++++++++++++------ src/conf/network_event.h | 3 +++ src/conf/object_event.c | 28 +++++++++++++++------------- src/conf/object_event.h | 11 +++-------- src/conf/object_event_private.h | 2 ++ 7 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 64035f7..03164dc 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -437,6 +437,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); @@ -1366,6 +1367,9 @@ virDomainEventStateRegister(virConnectPtr conn, { int ret = -1; + if (virDomainEventsInitialize() < 0) + return -1; + virObjectEventStateLock(state); if ((state->callbacks->count == 0) && @@ -1420,14 +1424,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); } @@ -1468,3 +1475,10 @@ virDomainEventStateDeregister(virConnectPtr conn, virObjectEventStateUnlock(state); return ret; } + + +virClassPtr +virDomainEventGetBaseClass(void) +{ + return virDomainEventClass; +} diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index 30156ed..5433950 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -30,6 +30,8 @@ # include "object_event.h" # include "domain_conf.h" +virClassPtr +virDomainEventGetBaseClass(void); virObjectEventPtr virDomainEventLifecycleNew(int id, diff --git a/src/conf/network_event.c b/src/conf/network_event.c index b1312b7..3108fea 100644 --- a/src/conf/network_event.c +++ b/src/conf/network_event.c @@ -98,7 +98,7 @@ virNetworkEventDispatchDefaultFunc(virConnectPtr conn, if (!net) return; - switch ((virNetworkEventID) (event->eventID &0xFF)) { + switch ((virNetworkEventID)event->eventID) { case VIR_NETWORK_EVENT_ID_LIFECYCLE: { virNetworkEventLifecyclePtr networkLifecycleEvent; @@ -147,14 +147,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); } @@ -165,13 +169,12 @@ 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, - eventId, + VIR_NETWORK_EVENT_ID_LIFECYCLE, 0, name, uuid))) return NULL; @@ -180,3 +183,10 @@ virNetworkEventLifecycleNew(const char *name, return (virObjectEventPtr)event; } + + +virClassPtr +virNetworkEventGetBaseClass(void) +{ + return virNetworkEventClass; +} diff --git a/src/conf/network_event.h b/src/conf/network_event.h index 1eef771..5b3b933 100644 --- a/src/conf/network_event.h +++ b/src/conf/network_event.h @@ -27,6 +27,9 @@ #ifndef __NETWORK_EVENT_H__ # define __NETWORK_EVENT_H__ +virClassPtr +virNetworkEventGetBaseClass(void); + int virNetworkEventStateRegisterID(virConnectPtr conn, virObjectEventStatePtr state, diff --git a/src/conf/object_event.c b/src/conf/object_event.c index ec00aaf..964dccf 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -227,6 +227,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 @@ -240,6 +241,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn, unsigned char uuid[VIR_UUID_BUFLEN], const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback callback, void *opaque, @@ -258,6 +260,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 && @@ -274,6 +277,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn, goto error; event->conn = conn; event->cb = callback; + event->klass = klass; event->eventID = eventID; event->opaque = opaque; event->freecb = freecb; @@ -299,7 +303,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++; @@ -542,6 +547,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; @@ -633,22 +640,17 @@ virObjectEventStateDispatchFunc(virConnectPtr conn, void *opaque) { virObjectEventStatePtr state = opaque; - virEventNamespaceID namespace = (event->eventID & 0xFF00) >> 8; /* Drop the lock whle dispatching, for sake of re-entrancy */ virObjectEventStateUnlock(state); - switch (namespace) { - case VIR_EVENT_NAMESPACE_DOMAIN: + if (virObjectIsClass(event, virDomainEventGetBaseClass())) virDomainEventDispatchDefaultFunc(conn, event, VIR_DOMAIN_EVENT_CALLBACK(cb), cbopaque, NULL); - break; - case VIR_EVENT_NAMESPACE_NETWORK: + else if (virObjectIsClass(event, virNetworkEventGetBaseClass())) virNetworkEventDispatchDefaultFunc(conn, event, VIR_NETWORK_EVENT_CALLBACK(cb), cbopaque, NULL); - break; - default: + else VIR_ERROR(_("Unknown event namespace to dispatch")); - } virObjectEventStateLock(state); } @@ -686,6 +688,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 @@ -703,6 +706,7 @@ virObjectEventStateRegisterID(virConnectPtr conn, unsigned char *uuid, const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback cb, void *opaque, @@ -725,7 +729,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 && @@ -800,9 +805,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 50cfe19..211defb 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,6 +72,7 @@ virObjectEventStateRegisterID(virConnectPtr conn, unsigned char *uuid, const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback cb, void *opaque, diff --git a/src/conf/object_event_private.h b/src/conf/object_event_private.h index f41f432..f1cc60a 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; @@ -87,6 +88,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn, unsigned char *uuid, const char *name, int id, + virClassPtr klass, int eventID, virConnectObjectEventGenericCallback callback, void *opaque, -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list