mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 09:13:55 -06:00
tests/qtest: add support for callback to receive QMP events
Currently code must call one of the qtest_qmp_event* functions to fetch events. These are only usable if the immediate caller knows the particular event they want to capture, and are only interested in one specific event type. Adding ability to register an event callback lets the caller capture a range of events over any period of time. Reviewed-by: Juan Quintela <quintela@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20230601161347.1803440-3-berrange@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
28760edcd9
commit
0150e75d01
2 changed files with 57 additions and 4 deletions
|
@ -82,6 +82,8 @@ struct QTestState
|
|||
GString *rx;
|
||||
QTestTransportOps ops;
|
||||
GList *pending_events;
|
||||
QTestQMPEventCallback eventCB;
|
||||
void *eventData;
|
||||
};
|
||||
|
||||
static GHookList abrt_hooks;
|
||||
|
@ -703,8 +705,13 @@ QDict *qtest_qmp_receive(QTestState *s)
|
|||
if (!qdict_get_try_str(response, "event")) {
|
||||
return response;
|
||||
}
|
||||
/* Stash the event for a later consumption */
|
||||
s->pending_events = g_list_append(s->pending_events, response);
|
||||
|
||||
if (!s->eventCB ||
|
||||
!s->eventCB(s, qdict_get_str(response, "event"),
|
||||
response, s->eventData)) {
|
||||
/* Stash the event for a later consumption */
|
||||
s->pending_events = g_list_append(s->pending_events, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -808,6 +815,13 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
void qtest_qmp_set_event_callback(QTestState *s,
|
||||
QTestQMPEventCallback cb, void *opaque)
|
||||
{
|
||||
s->eventCB = cb;
|
||||
s->eventData = opaque;
|
||||
}
|
||||
|
||||
QDict *qtest_qmp_event_ref(QTestState *s, const char *event)
|
||||
{
|
||||
while (s->pending_events) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue