diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-11-13 06:14:49 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-08-05 16:23:10 +0300 |
commit | cb45af8a9eba68a0da2fa9435a4ce82bbdf80f50 (patch) | |
tree | 87ee467771be1f4e3e2abc51e9decfc4b2c25578 /src/cam/event_loop.h | |
parent | 2c18ebb859f54a5f6e620aebc6f3abf3648b7462 (diff) |
cam: event_loop: Add support for file descriptor events
Extend the EventLoop class to support watching file descriptors for
read and write events.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'src/cam/event_loop.h')
-rw-r--r-- | src/cam/event_loop.h | 20 |
1 files changed, 20 insertions, 0 deletions
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 <functional> +#include <memory> #include <list> #include <mutex> @@ -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<void()> &func); + void addEvent(int fd, EventType type, + const std::function<void()> &handler); + private: + struct Event { + Event(const std::function<void()> &callback); + ~Event(); + + static void dispatch(int fd, short events, void *arg); + + std::function<void()> callback_; + struct event *event_; + }; + static EventLoop *instance_; struct event_base *base_; int exitCode_; std::list<std::function<void()>> calls_; + std::list<std::unique_ptr<Event>> events_; std::mutex lock_; static void dispatchCallback(evutil_socket_t fd, short flags, |