mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
qemu: create object for qemu monitor events
Create qemu monitor events as a distinct class to normal domain events, because they will be filtered differently. For ease of review, the logic for filtering by event name is saved for a later patch. * src/conf/domain_event.c (virDomainQemuMonitorEventClass): New class. (virDomainEventsOnceInit): Register it. (virDomainQemuMonitorEventDispose, virDomainQemuMonitorEventNew) (virDomainQemuMonitorEventDispatchFunc) (virDomainQemuMonitorEventStateRegisterID): New functions. * src/conf/domain_event.h (virDomainQemuMonitorEventNew) (virDomainQemuMonitorEventStateRegisterID): New prototypes. * src/libvirt_private.syms (conf/domain_conf.h): Export them.
This commit is contained in:
parent
88996de1c3
commit
8059afca62
@ -49,6 +49,7 @@ static virClassPtr virDomainEventTrayChangeClass;
|
|||||||
static virClassPtr virDomainEventBalloonChangeClass;
|
static virClassPtr virDomainEventBalloonChangeClass;
|
||||||
static virClassPtr virDomainEventDeviceRemovedClass;
|
static virClassPtr virDomainEventDeviceRemovedClass;
|
||||||
static virClassPtr virDomainEventPMClass;
|
static virClassPtr virDomainEventPMClass;
|
||||||
|
static virClassPtr virDomainQemuMonitorEventClass;
|
||||||
|
|
||||||
|
|
||||||
static void virDomainEventDispose(void *obj);
|
static void virDomainEventDispose(void *obj);
|
||||||
@ -63,6 +64,7 @@ static void virDomainEventTrayChangeDispose(void *obj);
|
|||||||
static void virDomainEventBalloonChangeDispose(void *obj);
|
static void virDomainEventBalloonChangeDispose(void *obj);
|
||||||
static void virDomainEventDeviceRemovedDispose(void *obj);
|
static void virDomainEventDeviceRemovedDispose(void *obj);
|
||||||
static void virDomainEventPMDispose(void *obj);
|
static void virDomainEventPMDispose(void *obj);
|
||||||
|
static void virDomainQemuMonitorEventDispose(void *obj);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virDomainEventDispatchDefaultFunc(virConnectPtr conn,
|
virDomainEventDispatchDefaultFunc(virConnectPtr conn,
|
||||||
@ -70,6 +72,12 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
|
|||||||
virConnectObjectEventGenericCallback cb,
|
virConnectObjectEventGenericCallback cb,
|
||||||
void *cbopaque);
|
void *cbopaque);
|
||||||
|
|
||||||
|
static void
|
||||||
|
virDomainQemuMonitorEventDispatchFunc(virConnectPtr conn,
|
||||||
|
virObjectEventPtr event,
|
||||||
|
virConnectObjectEventGenericCallback cb,
|
||||||
|
void *cbopaque);
|
||||||
|
|
||||||
struct _virDomainEvent {
|
struct _virDomainEvent {
|
||||||
virObjectEvent parent;
|
virObjectEvent parent;
|
||||||
|
|
||||||
@ -182,6 +190,17 @@ struct _virDomainEventPM {
|
|||||||
typedef struct _virDomainEventPM virDomainEventPM;
|
typedef struct _virDomainEventPM virDomainEventPM;
|
||||||
typedef virDomainEventPM *virDomainEventPMPtr;
|
typedef virDomainEventPM *virDomainEventPMPtr;
|
||||||
|
|
||||||
|
struct _virDomainQemuMonitorEvent {
|
||||||
|
virObjectEvent parent;
|
||||||
|
|
||||||
|
char *event;
|
||||||
|
long long seconds;
|
||||||
|
unsigned int micros;
|
||||||
|
char *details;
|
||||||
|
};
|
||||||
|
typedef struct _virDomainQemuMonitorEvent virDomainQemuMonitorEvent;
|
||||||
|
typedef virDomainQemuMonitorEvent *virDomainQemuMonitorEventPtr;
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainEventsOnceInit(void)
|
virDomainEventsOnceInit(void)
|
||||||
@ -258,6 +277,12 @@ virDomainEventsOnceInit(void)
|
|||||||
sizeof(virDomainEventPM),
|
sizeof(virDomainEventPM),
|
||||||
virDomainEventPMDispose)))
|
virDomainEventPMDispose)))
|
||||||
return -1;
|
return -1;
|
||||||
|
if (!(virDomainQemuMonitorEventClass =
|
||||||
|
virClassNew(virClassForObjectEvent(),
|
||||||
|
"virDomainQemuMonitorEvent",
|
||||||
|
sizeof(virDomainQemuMonitorEvent),
|
||||||
|
virDomainQemuMonitorEventDispose)))
|
||||||
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,6 +408,16 @@ virDomainEventPMDispose(void *obj)
|
|||||||
VIR_DEBUG("obj=%p", event);
|
VIR_DEBUG("obj=%p", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
virDomainQemuMonitorEventDispose(void *obj)
|
||||||
|
{
|
||||||
|
virDomainQemuMonitorEventPtr event = obj;
|
||||||
|
VIR_DEBUG("obj=%p", event);
|
||||||
|
|
||||||
|
VIR_FREE(event->event);
|
||||||
|
VIR_FREE(event->details);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
virDomainEventNew(virClassPtr klass,
|
virDomainEventNew(virClassPtr klass,
|
||||||
@ -1314,6 +1349,65 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virObjectEventPtr
|
||||||
|
virDomainQemuMonitorEventNew(int id,
|
||||||
|
const char *name,
|
||||||
|
const unsigned char *uuid,
|
||||||
|
const char *event,
|
||||||
|
long long seconds,
|
||||||
|
unsigned int micros,
|
||||||
|
const char *details)
|
||||||
|
{
|
||||||
|
virDomainQemuMonitorEventPtr ev;
|
||||||
|
|
||||||
|
if (virDomainEventsInitialize() < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!(ev = virObjectEventNew(virDomainQemuMonitorEventClass,
|
||||||
|
virDomainQemuMonitorEventDispatchFunc,
|
||||||
|
0, id, name, uuid)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* event is mandatory, details are optional */
|
||||||
|
if (VIR_STRDUP(ev->event, event) <= 0)
|
||||||
|
goto error;
|
||||||
|
ev->seconds = seconds;
|
||||||
|
ev->micros = micros;
|
||||||
|
if (VIR_STRDUP(ev->details, details) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
return (virObjectEventPtr)ev;
|
||||||
|
|
||||||
|
error:
|
||||||
|
virObjectUnref(ev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virDomainQemuMonitorEventDispatchFunc(virConnectPtr conn,
|
||||||
|
virObjectEventPtr event,
|
||||||
|
virConnectObjectEventGenericCallback cb,
|
||||||
|
void *cbopaque)
|
||||||
|
{
|
||||||
|
virDomainPtr dom = virGetDomain(conn, event->meta.name, event->meta.uuid);
|
||||||
|
virDomainQemuMonitorEventPtr qemuMonitorEvent;
|
||||||
|
|
||||||
|
if (!dom)
|
||||||
|
return;
|
||||||
|
dom->id = event->meta.id;
|
||||||
|
|
||||||
|
qemuMonitorEvent = (virDomainQemuMonitorEventPtr)event;
|
||||||
|
((virConnectDomainQemuMonitorEventCallback)cb)(conn, dom,
|
||||||
|
qemuMonitorEvent->event,
|
||||||
|
qemuMonitorEvent->seconds,
|
||||||
|
qemuMonitorEvent->micros,
|
||||||
|
qemuMonitorEvent->details,
|
||||||
|
cbopaque);
|
||||||
|
virDomainFree(dom);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virDomainEventStateRegister:
|
* virDomainEventStateRegister:
|
||||||
* @conn: connection to associate with callback
|
* @conn: connection to associate with callback
|
||||||
@ -1481,3 +1575,53 @@ virDomainEventStateDeregister(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
return virObjectEventStateDeregisterID(conn, state, callbackID);
|
return virObjectEventStateDeregisterID(conn, state, callbackID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virDomainQemuMonitorEventStateRegisterID:
|
||||||
|
* @conn: connection to associate with callback
|
||||||
|
* @state: object event state
|
||||||
|
* @dom: optional domain where event must occur
|
||||||
|
* @event: optional name of event to register for
|
||||||
|
* @cb: function to invoke when event occurs
|
||||||
|
* @opaque: data blob to pass to callback
|
||||||
|
* @freecb: callback to free @opaque
|
||||||
|
* @flags: -1 for client, or set of registration flags on server
|
||||||
|
* @callbackID: filled with callback ID
|
||||||
|
*
|
||||||
|
* Register the function @cb with connection @conn, from @state, for
|
||||||
|
* events of type @eventID.
|
||||||
|
*
|
||||||
|
* Returns: the number of callbacks now registered, or -1 on error
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
|
||||||
|
virObjectEventStatePtr state,
|
||||||
|
virDomainPtr dom,
|
||||||
|
const char *event,
|
||||||
|
virConnectDomainQemuMonitorEventCallback cb,
|
||||||
|
void *opaque,
|
||||||
|
virFreeCallback freecb,
|
||||||
|
unsigned int flags,
|
||||||
|
int *callbackID)
|
||||||
|
{
|
||||||
|
if (virDomainEventsInitialize() < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* FIXME support event filtering */
|
||||||
|
if (flags != -1)
|
||||||
|
virCheckFlags(0, -1);
|
||||||
|
if (event) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("event filtering on '%s' not implemented yet"),
|
||||||
|
event);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return virObjectEventStateRegisterID(conn, state, dom ? dom->uuid : NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
virDomainQemuMonitorEventClass, 0,
|
||||||
|
VIR_OBJECT_EVENT_CALLBACK(cb),
|
||||||
|
opaque, freecb,
|
||||||
|
false, callbackID, false);
|
||||||
|
}
|
||||||
|
@ -219,4 +219,27 @@ virDomainEventStateDeregister(virConnectPtr conn,
|
|||||||
virConnectDomainEventCallback callback)
|
virConnectDomainEventCallback callback)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
||||||
|
|
||||||
|
int
|
||||||
|
virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
|
||||||
|
virObjectEventStatePtr state,
|
||||||
|
virDomainPtr dom,
|
||||||
|
const char *event,
|
||||||
|
virConnectDomainQemuMonitorEventCallback cb,
|
||||||
|
void *opaque,
|
||||||
|
virFreeCallback freecb,
|
||||||
|
unsigned int flags,
|
||||||
|
int *callbackID)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
|
||||||
|
ATTRIBUTE_NONNULL(9);
|
||||||
|
|
||||||
|
virObjectEventPtr
|
||||||
|
virDomainQemuMonitorEventNew(int id,
|
||||||
|
const char *name,
|
||||||
|
const unsigned char *uuid,
|
||||||
|
const char *event,
|
||||||
|
long long seconds,
|
||||||
|
unsigned int micros,
|
||||||
|
const char *details)
|
||||||
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -459,6 +459,8 @@ virDomainEventTrayChangeNewFromDom;
|
|||||||
virDomainEventTrayChangeNewFromObj;
|
virDomainEventTrayChangeNewFromObj;
|
||||||
virDomainEventWatchdogNewFromDom;
|
virDomainEventWatchdogNewFromDom;
|
||||||
virDomainEventWatchdogNewFromObj;
|
virDomainEventWatchdogNewFromObj;
|
||||||
|
virDomainQemuMonitorEventNew;
|
||||||
|
virDomainQemuMonitorEventStateRegisterID;
|
||||||
|
|
||||||
|
|
||||||
# conf/domain_nwfilter.h
|
# conf/domain_nwfilter.h
|
||||||
|
Loading…
Reference in New Issue
Block a user