summaryrefslogtreecommitdiff
path: root/event_loop.h
diff options
context:
space:
mode:
authorUmang Jain <email@uajain.com>2020-12-04 13:22:23 +0530
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-12-04 10:33:05 +0000
commitb79a04afa753d5cfda47faee9bb4fc7b46c78b01 (patch)
tree3f52d090ddb1fb50a0f4d7e9b6889363753bb294 /event_loop.h
parent14529b6d1c4a6d405b23157eca8a4b0bec632e00 (diff)
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 <email@uajain.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'event_loop.h')
-rw-r--r--event_loop.h45
1 files changed, 45 insertions, 0 deletions
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 <atomic>
+#include <functional>
+#include <list>
+#include <mutex>
+
+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<void()> &func);
+
+private:
+ static EventLoop *instance_;
+
+ static void timeoutTriggered(int fd, short event, void *arg);
+
+ struct event_base *event_;
+ std::atomic<bool> exit_;
+ int exitCode_;
+
+ std::list<std::function<void()>> calls_;
+ std::mutex lock_;
+
+ void interrupt();
+ void dispatchCalls();
+};
+
+#endif /* __SIMPLE_CAM_EVENT_LOOP_H__ */