diff options
Diffstat (limited to 'include/libcamera/internal')
-rw-r--r-- | include/libcamera/internal/event_dispatcher.h | 35 | ||||
-rw-r--r-- | include/libcamera/internal/event_dispatcher_poll.h | 2 | ||||
-rw-r--r-- | include/libcamera/internal/event_notifier.h | 48 | ||||
-rw-r--r-- | include/libcamera/internal/meson.build | 3 | ||||
-rw-r--r-- | include/libcamera/internal/timer.h | 49 |
5 files changed, 136 insertions, 1 deletions
diff --git a/include/libcamera/internal/event_dispatcher.h b/include/libcamera/internal/event_dispatcher.h new file mode 100644 index 00000000..cb06bf20 --- /dev/null +++ b/include/libcamera/internal/event_dispatcher.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * event_dispatcher.h - Event dispatcher + */ +#ifndef __LIBCAMERA_EVENT_DISPATCHER_H__ +#define __LIBCAMERA_EVENT_DISPATCHER_H__ + +#include <vector> + +namespace libcamera { + +class EventNotifier; +class Timer; + +class EventDispatcher +{ +public: + virtual ~EventDispatcher(); + + virtual void registerEventNotifier(EventNotifier *notifier) = 0; + virtual void unregisterEventNotifier(EventNotifier *notifier) = 0; + + virtual void registerTimer(Timer *timer) = 0; + virtual void unregisterTimer(Timer *timer) = 0; + + virtual void processEvents() = 0; + + virtual void interrupt() = 0; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_EVENT_DISPATCHER_H__ */ diff --git a/include/libcamera/internal/event_dispatcher_poll.h b/include/libcamera/internal/event_dispatcher_poll.h index 39d9be52..33de051d 100644 --- a/include/libcamera/internal/event_dispatcher_poll.h +++ b/include/libcamera/internal/event_dispatcher_poll.h @@ -11,7 +11,7 @@ #include <map> #include <vector> -#include <libcamera/event_dispatcher.h> +#include "libcamera/internal/event_dispatcher.h" struct pollfd; diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/internal/event_notifier.h new file mode 100644 index 00000000..a37b02ee --- /dev/null +++ b/include/libcamera/internal/event_notifier.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * event_notifier.h - File descriptor event notifier + */ +#ifndef __LIBCAMERA_EVENT_NOTIFIER_H__ +#define __LIBCAMERA_EVENT_NOTIFIER_H__ + +#include <libcamera/object.h> +#include <libcamera/signal.h> + +namespace libcamera { + +class Message; + +class EventNotifier : public Object +{ +public: + enum Type { + Read, + Write, + Exception, + }; + + EventNotifier(int fd, Type type, Object *parent = nullptr); + virtual ~EventNotifier(); + + Type type() const { return type_; } + int fd() const { return fd_; } + + bool enabled() const { return enabled_; } + void setEnabled(bool enable); + + Signal<EventNotifier *> activated; + +protected: + void message(Message *msg) override; + +private: + int fd_; + Type type_; + bool enabled_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_EVENT_NOTIFIER_H__ */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 6500fe2a..7cde023f 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -18,7 +18,9 @@ libcamera_internal_headers = files([ 'device_enumerator.h', 'device_enumerator_sysfs.h', 'device_enumerator_udev.h', + 'event_dispatcher.h', 'event_dispatcher_poll.h', + 'event_notifier.h', 'file.h', 'formats.h', 'ipa_context_wrapper.h', @@ -36,6 +38,7 @@ libcamera_internal_headers = files([ 'semaphore.h', 'sysfs.h', 'thread.h', + 'timer.h', 'utils.h', 'v4l2_controls.h', 'v4l2_device.h', diff --git a/include/libcamera/internal/timer.h b/include/libcamera/internal/timer.h new file mode 100644 index 00000000..f55fe3c0 --- /dev/null +++ b/include/libcamera/internal/timer.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * timer.h - Generic timer + */ +#ifndef __LIBCAMERA_TIMER_H__ +#define __LIBCAMERA_TIMER_H__ + +#include <chrono> +#include <stdint.h> + +#include <libcamera/object.h> +#include <libcamera/signal.h> + +namespace libcamera { + +class Message; + +class Timer : public Object +{ +public: + Timer(Object *parent = nullptr); + ~Timer(); + + void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); } + void start(std::chrono::milliseconds duration); + void start(std::chrono::steady_clock::time_point deadline); + void stop(); + bool isRunning() const; + + std::chrono::steady_clock::time_point deadline() const { return deadline_; } + + Signal<Timer *> timeout; + +protected: + void message(Message *msg) override; + +private: + void registerTimer(); + void unregisterTimer(); + + bool running_; + std::chrono::steady_clock::time_point deadline_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_TIMER_H__ */ |