libcamera  v0.0.0
Supporting cameras in Linux since 2019
event_dispatcher_poll.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * event_dispatcher_poll.h - Poll-based event dispatcher
6  */
7 #ifndef __LIBCAMERA_INTERNAL_EVENT_DISPATCHER_POLL_H__
8 #define __LIBCAMERA_INTERNAL_EVENT_DISPATCHER_POLL_H__
9 
10 #include <list>
11 #include <map>
12 #include <vector>
13 
15 
16 struct pollfd;
17 
18 namespace libcamera {
19 
20 class EventNotifier;
21 class Timer;
22 
24 {
25 public:
28 
29  void registerEventNotifier(EventNotifier *notifier);
30  void unregisterEventNotifier(EventNotifier *notifier);
31 
32  void registerTimer(Timer *timer);
33  void unregisterTimer(Timer *timer);
34 
35  void processEvents();
36  void interrupt();
37 
38 private:
39  struct EventNotifierSetPoll {
40  short events() const;
41  EventNotifier *notifiers[3];
42  };
43 
44  int poll(std::vector<struct pollfd> *pollfds);
45  void processInterrupt(const struct pollfd &pfd);
46  void processNotifiers(const std::vector<struct pollfd> &pollfds);
47  void processTimers();
48 
49  std::map<int, EventNotifierSetPoll> notifiers_;
50  std::list<Timer *> timers_;
51  int eventfd_;
52 
53  bool processingEvents_;
54 };
55 
56 } /* namespace libcamera */
57 
58 #endif /* __LIBCAMERA_INTERNAL_EVENT_DISPATCHER_POLL_H__ */
A poll-based event dispatcher.
Definition: event_dispatcher_poll.h:24
void registerTimer(Timer *timer)
Register a timer.
Definition: event_dispatcher_poll.cpp:116
void unregisterEventNotifier(EventNotifier *notifier)
Unregister an event notifier.
Definition: event_dispatcher_poll.cpp:83
void unregisterTimer(Timer *timer)
Unregister a timer.
Definition: event_dispatcher_poll.cpp:128
void interrupt()
Interrupt any running processEvents() call as soon as possible.
Definition: event_dispatcher_poll.cpp:177
void registerEventNotifier(EventNotifier *notifier)
Register an event notifier.
Definition: event_dispatcher_poll.cpp:68
void processEvents()
Wait for and process pending events.
Definition: event_dispatcher_poll.cpp:145
Interface to manage the libcamera events and timers.
Definition: event_dispatcher.h:18
Notify of activity on a file descriptor.
Definition: event_notifier.h:18
Single-shot timer interface.
Definition: timer.h:21