mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-13 17:18:01 +03:00
Remove the event namespace concept
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@redhat.com>
This commit is contained in:
parent
8a4820ab23
commit
dbcc38da15
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user