From b79a04afa753d5cfda47faee9bb4fc7b46c78b01 Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Fri, 4 Dec 2020 13:22:23 +0530 Subject: simple-cam: Provide event-loop backed by libevent libcamera moved its EventDispatcher and Timer API to its internal API, since providing an event loop to applications should not be the job of libcamera. Application utility like cam, were ported to use libevent, hence inspired from that, un-break simple-cam by using the similar implementation to replace the EventDispatcher and Timer functionality by libevent. Signed-off-by: Umang Jain Reviewed-by: Kieran Bingham Signed-off-by: Kieran Bingham --- event_loop.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 event_loop.h (limited to 'event_loop.h') diff --git a/event_loop.h b/event_loop.h new file mode 100644 index 0000000..003c3d8 --- /dev/null +++ b/event_loop.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * event_loop.h - Event loop based on cam's + */ +#ifndef __SIMPLE_CAM_EVENT_LOOP_H__ +#define __SIMPLE_CAM_EVENT_LOOP_H__ + +#include +#include +#include +#include + +struct event_base; + +class EventLoop +{ +public: + EventLoop(); + ~EventLoop(); + + void exit(int code = 0); + int exec(); + + void timeout(unsigned int sec); + void callLater(const std::function &func); + +private: + static EventLoop *instance_; + + static void timeoutTriggered(int fd, short event, void *arg); + + struct event_base *event_; + std::atomic exit_; + int exitCode_; + + std::list> calls_; + std::mutex lock_; + + void interrupt(); + void dispatchCalls(); +}; + +#endif /* __SIMPLE_CAM_EVENT_LOOP_H__ */ -- cgit v1.2.1