libcamera: Add a poll-based event dispatcher

Provide a poll-based event dispatcher implementation as convenience for
applications that don't need a custom event loop. The poll-based
dispatcher is automatically instantiated if the application doesn't
provide its own dispatcher.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2019-01-08 16:23:16 +02:00
parent 1a57bcb8d1
commit 8356f8a6ab
5 changed files with 302 additions and 5 deletions
@@ -0,0 +1,50 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* event_dispatcher_poll.h - Poll-based event dispatcher
*/
#ifndef __LIBCAMERA_EVENT_DISPATCHER_POLL_H__
#define __LIBCAMERA_EVENT_DISPATCHER_POLL_H__
#include <libcamera/event_dispatcher.h>
#include <list>
#include <map>
#include <vector>
namespace libcamera {
class EventNotifier;
class Timer;
class EventDispatcherPoll final : public EventDispatcher
{
public:
EventDispatcherPoll();
~EventDispatcherPoll();
void registerEventNotifier(EventNotifier *notifier);
void unregisterEventNotifier(EventNotifier *notifier);
void registerTimer(Timer *timer);
void unregisterTimer(Timer *timer);
void processEvents();
private:
struct EventNotifierSetPoll {
short events() const;
EventNotifier *notifiers[3];
};
std::map<int, EventNotifierSetPoll> notifiers_;
std::list<Timer *> timers_;
void processNotifiers(std::vector<struct pollfd> &pollfds);
void processTimers();
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_EVENT_DISPATCHER_POLL_H__ */