summaryrefslogtreecommitdiff
path: root/src/cam/event_loop.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cam/event_loop.h')
-rw-r--r--src/cam/event_loop.h20
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,