On 12.12.2013 19:04, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The event namespace concept is mostly redundant information.
With the re-written dispatcher, the namespace is only used
for equality comparisons between event IDs. This can be solved
by just comparing virClassPtr instances instead.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/conf/domain_event.c | 11 +++++++++--
src/conf/network_event.c | 15 +++++++++------
src/conf/object_event.c | 17 ++++++++++++-----
src/conf/object_event.h | 11 +++--------
src/conf/object_event_private.h | 2 ++
5 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index a9c499e..e5f5796 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 3173e68..3819702 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 96c719c..aeee6d5 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++;
@@ -537,6 +542,8 @@ virObjectEventDispatchMatchCallback(virObjectEventPtr event,
return 0;
if (cb->deleted)
return 0;
+ if (!virObjectIsClass(event, cb->klass))
+ return 0;
Yep. since cb->klass must be non-null at this point this won't crash
anymore.
ACK
Michal