From cb45af8a9eba68a0da2fa9435a4ce82bbdf80f50 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 13 Nov 2020 06:14:49 +0200 Subject: cam: event_loop: Add support for file descriptor events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend the EventLoop class to support watching file descriptors for read and write events. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- src/cam/event_loop.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/cam/event_loop.h') diff --git a/src/cam/event_loop.h b/src/cam/event_loop.h index ba3ba3a4..57bb6fb3 100644 --- a/src/cam/event_loop.h +++ b/src/cam/event_loop.h @@ -8,6 +8,7 @@ #define __CAM_EVENT_LOOP_H__ #include +#include #include #include @@ -18,6 +19,11 @@ struct event_base; class EventLoop { public: + enum EventType { + Read = 1, + Write = 2, + }; + EventLoop(); ~EventLoop(); @@ -28,13 +34,27 @@ public: void callLater(const std::function &func); + void addEvent(int fd, EventType type, + const std::function &handler); + private: + struct Event { + Event(const std::function &callback); + ~Event(); + + static void dispatch(int fd, short events, void *arg); + + std::function callback_; + struct event *event_; + }; + static EventLoop *instance_; struct event_base *base_; int exitCode_; std::list> calls_; + std::list> events_; std::mutex lock_; static void dispatchCallback(evutil_socket_t fd, short flags, -- cgit v1.2.1