libcamera  v0.0.0+3-3b6e2d50-dirty (2022-01-27T16:18:04+08:00)
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_BASE_EVENT_DISPATCHER_POLL_H__
8 #define __LIBCAMERA_BASE_EVENT_DISPATCHER_POLL_H__
9 
10 #include <list>
11 #include <map>
12 #include <vector>
13 
14 #include <libcamera/base/private.h>
15 
17 
18 struct pollfd;
19 
20 namespace libcamera {
21 
22 class EventNotifier;
23 class Timer;
24 
26 {
27 public:
30 
31  void registerEventNotifier(EventNotifier *notifier);
32  void unregisterEventNotifier(EventNotifier *notifier);
33 
34  void registerTimer(Timer *timer);
35  void unregisterTimer(Timer *timer);
36 
37  void processEvents();
38  void interrupt();
39 
40 private:
41  struct EventNotifierSetPoll {
42  short events() const;
43  EventNotifier *notifiers[3];
44  };
45 
46  int poll(std::vector<struct pollfd> *pollfds);
47  void processInterrupt(const struct pollfd &pfd);
48  void processNotifiers(const std::vector<struct pollfd> &pollfds);
49  void processTimers();
50 
51  std::map<int, EventNotifierSetPoll> notifiers_;
52  std::list<Timer *> timers_;
53  int eventfd_;
54 
55  bool processingEvents_;
56 };
57 
58 } /* namespace libcamera */
59 
60 #endif /* __LIBCAMERA_BASE_EVENT_DISPATCHER_POLL_H__ */
A poll-based event dispatcher.
Definition: event_dispatcher_poll.h:26
void registerTimer(Timer *timer)
Register a timer.
Definition: event_dispatcher_poll.cpp:115
void unregisterEventNotifier(EventNotifier *notifier)
Unregister an event notifier.
Definition: event_dispatcher_poll.cpp:82
void unregisterTimer(Timer *timer)
Unregister a timer.
Definition: event_dispatcher_poll.cpp:127
void interrupt()
Interrupt any running processEvents() call as soon as possible.
Definition: event_dispatcher_poll.cpp:176
void registerEventNotifier(EventNotifier *notifier)
Register an event notifier.
Definition: event_dispatcher_poll.cpp:67
void processEvents()
Wait for and process pending events.
Definition: event_dispatcher_poll.cpp:144
Interface to manage the libcamera events and timers.
Definition: event_dispatcher.h:20
Notify of activity on a file descriptor.
Definition: event_notifier.h:20
Single-shot timer interface.
Definition: timer.h:23
Top-level libcamera namespace.
Definition: bound_method.h:15