提交 d7c96a72 编写于 作者: C Cole Robinson

events: Pass in UUID as a string

This should not have any functional difference, it's just a step
towards matching on non-uuid string keys
上级 7926c5a5
......@@ -1998,10 +1998,14 @@ virDomainEventStateRegisterID(virConnectPtr conn,
virFreeCallback freecb,
int *callbackID)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virDomainEventsInitialize() < 0)
return -1;
return virObjectEventStateRegisterID(conn, state, dom ? dom->uuid : NULL,
if (dom)
virUUIDFormat(dom->uuid, uuidstr);
return virObjectEventStateRegisterID(conn, state, dom ? uuidstr : NULL,
NULL, NULL,
virDomainEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb),
......@@ -2042,10 +2046,14 @@ virDomainEventStateRegisterClient(virConnectPtr conn,
int *callbackID,
bool remoteID)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virDomainEventsInitialize() < 0)
return -1;
return virObjectEventStateRegisterID(conn, state, dom ? dom->uuid : NULL,
if (dom)
virUUIDFormat(dom->uuid, uuidstr);
return virObjectEventStateRegisterID(conn, state, dom ? uuidstr : NULL,
NULL, NULL,
virDomainEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb),
......@@ -2180,6 +2188,7 @@ virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
{
virDomainQemuMonitorEventData *data = NULL;
virObjectEventCallbackFilter filter = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virDomainEventsInitialize() < 0)
return -1;
......@@ -2220,7 +2229,9 @@ virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
filter = virDomainQemuMonitorEventFilter;
freecb = virDomainQemuMonitorEventCleanup;
return virObjectEventStateRegisterID(conn, state, dom ? dom->uuid : NULL,
if (dom)
virUUIDFormat(dom->uuid, uuidstr);
return virObjectEventStateRegisterID(conn, state, dom ? uuidstr : NULL,
filter, data,
virDomainQemuMonitorEventClass, 0,
VIR_OBJECT_EVENT_CALLBACK(cb),
......
......@@ -150,10 +150,14 @@ virNetworkEventStateRegisterID(virConnectPtr conn,
virFreeCallback freecb,
int *callbackID)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virNetworkEventsInitialize() < 0)
return -1;
return virObjectEventStateRegisterID(conn, state, net ? net->uuid : NULL,
if (net)
virUUIDFormat(net->uuid, uuidstr);
return virObjectEventStateRegisterID(conn, state, net ? uuidstr : NULL,
NULL, NULL,
virNetworkEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb),
......@@ -190,10 +194,14 @@ virNetworkEventStateRegisterClient(virConnectPtr conn,
virFreeCallback freecb,
int *callbackID)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virNetworkEventsInitialize() < 0)
return -1;
return virObjectEventStateRegisterID(conn, state, net ? net->uuid : NULL,
if (net)
virUUIDFormat(net->uuid, uuidstr);
return virObjectEventStateRegisterID(conn, state, net ? uuidstr : NULL,
NULL, NULL,
virNetworkEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb),
......
......@@ -45,7 +45,7 @@ struct _virObjectEventCallback {
virConnectPtr conn;
int remoteID;
bool uuid_filter;
unsigned char uuid[VIR_UUID_BUFLEN];
char *uuid;
virObjectEventCallbackFilter filter;
void *filter_opaque;
virConnectObjectEventGenericCallback cb;
......@@ -138,6 +138,7 @@ virObjectEventCallbackFree(virObjectEventCallbackPtr cb)
return;
virObjectUnref(cb->conn);
VIR_FREE(cb->uuid);
VIR_FREE(cb);
}
......@@ -192,7 +193,7 @@ virObjectEventCallbackListCount(virConnectPtr conn,
virObjectEventCallbackListPtr cbList,
virClassPtr klass,
int eventID,
unsigned char uuid[VIR_UUID_BUFLEN],
const char *uuid,
bool serverFilter)
{
size_t i;
......@@ -209,8 +210,7 @@ virObjectEventCallbackListCount(virConnectPtr conn,
!cb->deleted &&
(!serverFilter ||
(cb->remoteID >= 0 &&
((uuid && cb->uuid_filter &&
memcmp(cb->uuid, uuid, VIR_UUID_BUFLEN) == 0) ||
((uuid && cb->uuid_filter && STREQ(cb->uuid, uuid)) ||
(!uuid && !cb->uuid_filter)))))
ret++;
}
......@@ -326,7 +326,7 @@ virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList)
static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virObjectEventCallbackLookup(virConnectPtr conn,
virObjectEventCallbackListPtr cbList,
unsigned char uuid[VIR_UUID_BUFLEN],
const char *uuid,
virClassPtr klass,
int eventID,
virConnectObjectEventGenericCallback callback,
......@@ -346,8 +346,7 @@ virObjectEventCallbackLookup(virConnectPtr conn,
if (cb->klass == klass &&
cb->eventID == eventID &&
cb->conn == conn &&
((uuid && cb->uuid_filter &&
memcmp(cb->uuid, uuid, VIR_UUID_BUFLEN) == 0) ||
((uuid && cb->uuid_filter && STREQ(cb->uuid, uuid)) ||
(!uuid && !cb->uuid_filter))) {
if (remoteID)
*remoteID = cb->remoteID;
......@@ -381,7 +380,7 @@ virObjectEventCallbackLookup(virConnectPtr conn,
static int
virObjectEventCallbackListAddID(virConnectPtr conn,
virObjectEventCallbackListPtr cbList,
unsigned char uuid[VIR_UUID_BUFLEN],
const char *uuid,
virObjectEventCallbackFilter filter,
void *filter_opaque,
virClassPtr klass,
......@@ -434,7 +433,8 @@ virObjectEventCallbackListAddID(virConnectPtr conn,
* Xen migration. */
if (uuid) {
cb->uuid_filter = true;
memcpy(cb->uuid, uuid, VIR_UUID_BUFLEN);
if (VIR_STRDUP(cb->uuid, uuid) < 0)
goto cleanup;
}
cb->filter = filter;
cb->filter_opaque = filter_opaque;
......@@ -707,8 +707,10 @@ virObjectEventDispatchMatchCallback(virObjectEventPtr event,
* running & shutoff states & ignoring 'name' since
* Xen sometimes renames guests during migration, thus
* leaving 'uuid' as the only truly reliable ID we can use. */
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(event->meta.uuid, uuidstr);
return memcmp(event->meta.uuid, cb->uuid, VIR_UUID_BUFLEN) == 0;
return STREQ(uuidstr, cb->uuid);
}
return true;
}
......@@ -874,7 +876,7 @@ virObjectEventStateFlush(virObjectEventStatePtr state)
int
virObjectEventStateRegisterID(virConnectPtr conn,
virObjectEventStatePtr state,
unsigned char *uuid,
const char *uuid,
virObjectEventCallbackFilter filter,
void *filter_opaque,
virClassPtr klass,
......
......@@ -72,7 +72,7 @@ virClassForObjectEvent(void);
int
virObjectEventStateRegisterID(virConnectPtr conn,
virObjectEventStatePtr state,
unsigned char *uuid,
const char *uuid,
virObjectEventCallbackFilter filter,
void *filter_opaque,
virClassPtr klass,
......
......@@ -183,10 +183,14 @@ virStoragePoolEventStateRegisterID(virConnectPtr conn,
virFreeCallback freecb,
int *callbackID)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virStoragePoolEventsInitialize() < 0)
return -1;
return virObjectEventStateRegisterID(conn, state, pool ? pool->uuid : NULL,
if (pool)
virUUIDFormat(pool->uuid, uuidstr);
return virObjectEventStateRegisterID(conn, state, pool ? uuidstr : NULL,
NULL, NULL,
virStoragePoolEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb),
......@@ -223,10 +227,14 @@ virStoragePoolEventStateRegisterClient(virConnectPtr conn,
virFreeCallback freecb,
int *callbackID)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virStoragePoolEventsInitialize() < 0)
return -1;
return virObjectEventStateRegisterID(conn, state, pool ? pool->uuid : NULL,
if (pool)
virUUIDFormat(pool->uuid, uuidstr);
return virObjectEventStateRegisterID(conn, state, pool ? uuidstr : NULL,
NULL, NULL,
virStoragePoolEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册