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.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
tests/qtest/libqtest.c | 20 ++++++++++++++++++--
tests/qtest/libqtest.h | 37 +++++++++++++++++++++++++++++++++++--
2 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 603c26d955..1534177fc1 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -82,6 +82,8 @@ struct QTestState
GString *rx;
QTestTransportOps ops;
GList *pending_events;
+ QTestQMPEventCallback eventCB;
+ void *eventData;
};
static GHookList abrt_hooks;
@@ -703,8 +705,14 @@ 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);
+ } else {
+ /* Stash the event for a later consumption */
+ s->pending_events = g_list_append(s->pending_events, response);
+ }
}
}
@@ -808,6 +816,14 @@ 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;
+}
+
+