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;
if (cb->eventID != virObjectEventGetEventID(event))
return 0;
@@ -652,6 +659,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
@@ -669,6 +677,7 @@ virObjectEventStateRegisterID(virConnectPtr conn,
unsigned char *uuid,
const char *name,
int id,
+ virClassPtr klass,
int eventID,
virConnectObjectEventGenericCallback cb,
void *opaque,
@@ -691,7 +700,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 &&
@@ -766,9 +776,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 f18277a..89c7675 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,
--
1.8.3.1