2013-11-26 14:10:15 +00:00
|
|
|
/*
|
|
|
|
* object_event.h: object event queue processing helpers
|
|
|
|
*
|
2014-01-02 14:16:49 +00:00
|
|
|
* Copyright (C) 2012-2014 Red Hat, Inc.
|
2013-11-26 14:10:15 +00:00
|
|
|
* Copyright (C) 2008 VirtualIron
|
|
|
|
* Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Ben Guthro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2013-12-11 14:10:34 +00:00
|
|
|
#include "virobject.h"
|
|
|
|
|
2013-11-26 14:10:15 +00:00
|
|
|
#ifndef __OBJECT_EVENT_H__
|
|
|
|
# define __OBJECT_EVENT_H__
|
|
|
|
|
|
|
|
typedef struct _virObjectEventCallback virObjectEventCallback;
|
|
|
|
typedef virObjectEventCallback *virObjectEventCallbackPtr;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatching domain events that come in while
|
|
|
|
* in a call / response rpc
|
|
|
|
*/
|
|
|
|
typedef struct _virObjectEvent virObjectEvent;
|
|
|
|
typedef virObjectEvent *virObjectEventPtr;
|
|
|
|
|
|
|
|
typedef struct _virObjectEventState virObjectEventState;
|
|
|
|
typedef virObjectEventState *virObjectEventStatePtr;
|
|
|
|
|
|
|
|
|
|
|
|
void virObjectEventStateFree(virObjectEventStatePtr state);
|
|
|
|
virObjectEventStatePtr
|
|
|
|
virObjectEventStateNew(void);
|
|
|
|
|
2014-01-02 14:16:49 +00:00
|
|
|
/**
|
2013-11-26 14:10:15 +00:00
|
|
|
* virConnectObjectEventGenericCallback:
|
|
|
|
* @conn: the connection pointer
|
|
|
|
* @obj: the object pointer
|
|
|
|
* @opaque: application specified data
|
|
|
|
*
|
|
|
|
* A generic object event callback handler. Specific events usually
|
|
|
|
* have a customization with extra parameters
|
|
|
|
*/
|
|
|
|
typedef void (*virConnectObjectEventGenericCallback)(virConnectPtr conn,
|
|
|
|
void *obj,
|
|
|
|
void *opaque);
|
|
|
|
|
2014-01-02 14:16:49 +00:00
|
|
|
# define VIR_OBJECT_EVENT_CALLBACK(cb) \
|
|
|
|
((virConnectObjectEventGenericCallback)(cb))
|
2013-11-26 14:10:15 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
virObjectEventStateQueue(virObjectEventStatePtr state,
|
|
|
|
virObjectEventPtr event)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
int
|
|
|
|
virObjectEventStateRegisterID(virConnectPtr conn,
|
|
|
|
virObjectEventStatePtr state,
|
|
|
|
unsigned char *uuid,
|
2013-12-11 14:10:34 +00:00
|
|
|
virClassPtr klass,
|
2013-11-26 14:10:15 +00:00
|
|
|
int eventID,
|
|
|
|
virConnectObjectEventGenericCallback cb,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb,
|
|
|
|
int *callbackID)
|
event: don't turn offline domain into global event
If a user registers for a domain event filtered to a particular
domain, but the persistent domain is offline at the time, then
the code silently failed to set up the filter. As a result,
the event fires for all domains, rather than being filtered.
Network events were immune, since they always passed an id
0 argument.
The key to this patch is realizing that
virObjectEventDispatchMatchCallback() only cared about uuid;
so refusing to create a meta for a negative id is pointless,
and in fact, malloc'ing meta at all was overkill; instead,
just directly store a uuid and a flag of whether to filter.
Note that virObjectEventPtr still needs all fields of meta,
because this is how we reconstruct a virDomainPtr inside the
dispatch handler before calling the end user's callback
pointer with the correct object, even though only the uuid
portion of meta is used in deciding whether a callback
matches the given event. So while uuid is optional for
callbacks, it is mandatory for events.
The change to testDomainCreateXMLMixed is merely on the setup
scenario (as you can't register for a domain unless it is either
running or persistent). I actually first wrote that test for
this patch, then rebased it to also cover a prior patch (commit
4221d64), but had to adjust it for that patch to use Create
instead of Define for setting up the domain long enough to
register the event in order to work around this bug. But while
the setup is changed, the main body of the test is still about
whether creation events fire as expected.
* src/conf/object_event_private.h (_virObjectEventCallback):
Replace meta with uuid and flag.
(virObjectEventCallbackListAddID): Update signature.
* src/conf/object_event.h (virObjectEventStateRegisterID):
Likewise.
* src/conf/object_event_private.h (virObjectEventNew): Document
use of name and uuid in events.
* src/conf/object_event.c (virObjectEventCallbackListAddID): Drop
arguments that don't affect filtering.
(virObjectEventCallbackListRemoveID)
(virObjectEventDispatchMatchCallback)
(virObjectEventStateRegisterID): Update clients.
* src/conf/domain_event.c (virDomainEventCallbackListAdd)
(virDomainEventStateRegisterID): Likewise.
* src/conf/network_event.c (virNetworkEventStateRegisterID):
Likewise.
* tests/objecteventtest.c (testDomainCreateXMLMixed): Enhance test.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-04 00:02:17 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4)
|
|
|
|
ATTRIBUTE_NONNULL(6);
|
2013-11-26 14:10:15 +00:00
|
|
|
int
|
|
|
|
virObjectEventStateDeregisterID(virConnectPtr conn,
|
|
|
|
virObjectEventStatePtr state,
|
|
|
|
int callbackID)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
int
|
|
|
|
virObjectEventStateEventID(virConnectPtr conn,
|
|
|
|
virObjectEventStatePtr state,
|
|
|
|
int callbackID)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
#endif
|