libei: implement ei_peek_event()

At least for the test suite, I'll need something that allows me to look at an
event without removing it from the event queue. Just the event type isn't
enough, I need things like "what are the caps on the device". Simplest way to
allow this is a peek function that doesn't remove the event from the queue.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-06 13:59:20 +10:00
parent fb03ac78a2
commit 2e4ce7008b
2 changed files with 31 additions and 0 deletions

View file

@ -99,6 +99,8 @@ ei_event_destroy(struct ei_event *event)
static
OBJECT_IMPLEMENT_INIT(ei_event);
static
OBJECT_IMPLEMENT_REF(ei_event);
_public_
OBJECT_IMPLEMENT_UNREF(ei_event);
_public_
@ -468,6 +470,16 @@ ei_get_event(struct ei *ei)
return e;
}
_public_ struct ei_event*
ei_peek_event(struct ei *ei)
{
if (list_empty(&ei->event_queue))
return NULL;
struct ei_event *e = list_first_entry(&ei->event_queue, e, link);
return ei_event_ref(e);
}
_public_ enum ei_event_type
ei_next_event_type(struct ei *ei)
{

View file

@ -175,6 +175,25 @@ ei_dispatch(struct ei *ei);
struct ei_event *
ei_get_event(struct ei *ei);
/**
* Returns the next event in the internal event queue (or NULL) without
* removing that event from the queue, i.e. the next call to ei_get_event()
* will return that same event.
*
* This call is useful for checking whether there is an event and/or what
* type of event it is.
*
* Repeated calls to ei_peek_event() return the same event.
*
* The returned event is refcounted, use ei_event_unref() to drop the
* reference.
*
* A caller must not call ei_get_event() while holding a ref to an event
* returned by ei_peek_event().
*/
struct ei_event *
ei_peek_event(struct ei *ei);
/**
* Return the type of the next event in the event queue or @ref
* EI_EVENT_NONE if none are available. This function does not remove the