From f9ee72430735f749fb7d8fd4a8fe01ca88dc1f88 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Fri, 25 Jun 2021 02:06:55 +0100 Subject: libcamera/base: Move event_notifier to base Move the event notifier, and associated header updates. Reviewed-by: Hirokazu Honda Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- include/libcamera/base/event_notifier.h | 48 +++++++++ include/libcamera/base/meson.build | 1 + include/libcamera/internal/event_notifier.h | 48 --------- include/libcamera/internal/meson.build | 1 - src/libcamera/base/event_dispatcher_poll.cpp | 3 +- src/libcamera/base/event_notifier.cpp | 141 +++++++++++++++++++++++++++ src/libcamera/base/meson.build | 1 + src/libcamera/device_enumerator_udev.cpp | 2 +- src/libcamera/event_notifier.cpp | 141 --------------------------- src/libcamera/ipc_unixsocket.cpp | 3 +- src/libcamera/meson.build | 1 - src/libcamera/process.cpp | 3 +- src/libcamera/v4l2_device.cpp | 2 +- src/libcamera/v4l2_videodevice.cpp | 2 +- test/event-thread.cpp | 3 +- test/event.cpp | 3 +- test/ipa/ipa_interface_test.cpp | 2 +- 17 files changed, 200 insertions(+), 205 deletions(-) create mode 100644 include/libcamera/base/event_notifier.h delete mode 100644 include/libcamera/internal/event_notifier.h create mode 100644 src/libcamera/base/event_notifier.cpp delete mode 100644 src/libcamera/event_notifier.cpp diff --git a/include/libcamera/base/event_notifier.h b/include/libcamera/base/event_notifier.h new file mode 100644 index 00000000..5aa2784a --- /dev/null +++ b/include/libcamera/base/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_BASE_EVENT_NOTIFIER_H__ +#define __LIBCAMERA_BASE_EVENT_NOTIFIER_H__ + +#include +#include + +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 activated; + +protected: + void message(Message *msg) override; + +private: + int fd_; + Type type_; + bool enabled_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_BASE_EVENT_NOTIFIER_H__ */ diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index 6fc6c138..83c664af 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -7,6 +7,7 @@ libcamera_base_headers = files([ 'class.h', 'event_dispatcher.h', 'event_dispatcher_poll.h', + 'event_notifier.h', 'file.h', 'log.h', 'message.h', diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/internal/event_notifier.h deleted file mode 100644 index 8a6419f2..00000000 --- a/include/libcamera/internal/event_notifier.h +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * event_notifier.h - File descriptor event notifier - */ -#ifndef __LIBCAMERA_INTERNAL_EVENT_NOTIFIER_H__ -#define __LIBCAMERA_INTERNAL_EVENT_NOTIFIER_H__ - -#include -#include - -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 activated; - -protected: - void message(Message *msg) override; - -private: - int fd_; - Type type_; - bool enabled_; -}; - -} /* namespace libcamera */ - -#endif /* __LIBCAMERA_INTERNAL_EVENT_NOTIFIER_H__ */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 60e9775b..16a76ebd 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -22,7 +22,6 @@ libcamera_internal_headers = files([ 'device_enumerator.h', 'device_enumerator_sysfs.h', 'device_enumerator_udev.h', - 'event_notifier.h', 'formats.h', 'ipa_manager.h', 'ipa_module.h', diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp index d76ca7fc..5839373a 100644 --- a/src/libcamera/base/event_dispatcher_poll.cpp +++ b/src/libcamera/base/event_dispatcher_poll.cpp @@ -16,13 +16,12 @@ #include #include +#include #include #include #include #include -#include "libcamera/internal/event_notifier.h" - /** * \file base/event_dispatcher_poll.h */ diff --git a/src/libcamera/base/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp new file mode 100644 index 00000000..fd93c087 --- /dev/null +++ b/src/libcamera/base/event_notifier.cpp @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * event_notifier.cpp - File descriptor event notifier + */ + +#include + +#include +#include +#include + +#include + +/** + * \file event_notifier.h + * \brief File descriptor event notifier + */ + +namespace libcamera { + +/** + * \class EventNotifier + * \brief Notify of activity on a file descriptor + * + * The EventNotifier models a file descriptor event source that can be + * monitored. It is created with the file descriptor to be monitored and the + * type of event, and is enabled by default. It will emit the \ref activated + * signal whenever an event of the monitored type occurs on the file descriptor. + * + * Supported type of events are EventNotifier::Read, EventNotifier::Write and + * EventNotifier::Exception. The type is specified when constructing the + * notifier, and can be retrieved using the type() function. To listen to + * multiple event types on the same file descriptor multiple notifiers must be + * created. + * + * The notifier can be disabled with the setEnabled() function. When the notifier + * is disabled it ignores events and does not emit the \ref activated signal. + * The notifier can then be re-enabled with the setEnabled() function. + * + * Creating multiple notifiers of the same type for the same file descriptor is + * not allowed and results in undefined behaviour. + * + * Notifier events are detected and dispatched from the + * EventDispatcher::processEvents() function. + */ + +/** + * \enum EventNotifier::Type + * Type of file descriptor event to listen for. + * \var EventNotifier::Read + * Data is available to be read from the file descriptor + * \var EventNotifier::Write + * Data can be written to the file descriptor + * \var EventNotifier::Exception + * An exception has occurred on the file descriptor + */ + +/** + * \brief Construct an event notifier with a file descriptor and event type + * \param[in] fd The file descriptor to monitor + * \param[in] type The event type to monitor + * \param[in] parent The parent Object + */ +EventNotifier::EventNotifier(int fd, Type type, Object *parent) + : Object(parent), fd_(fd), type_(type), enabled_(false) +{ + setEnabled(true); +} + +EventNotifier::~EventNotifier() +{ + setEnabled(false); +} + +/** + * \fn EventNotifier::type() + * \brief Retrieve the type of the event being monitored + * \return The type of the event + */ + +/** + * \fn EventNotifier::fd() + * \brief Retrieve the file descriptor being monitored + * \return The file descriptor + */ + +/** + * \fn EventNotifier::enabled() + * \brief Retrieve the notifier state + * \return True if the notifier is enabled, or false otherwise + * \sa setEnabled() + */ + +/** + * \brief Enable or disable the notifier + * \param[in] enable True to enable the notifier, false to disable it + * + * This function enables or disables the notifier. A disabled notifier ignores + * events and does not emit the \ref activated signal. + * + * \context This function is \threadbound. + */ +void EventNotifier::setEnabled(bool enable) +{ + if (enabled_ == enable) + return; + + enabled_ = enable; + + EventDispatcher *dispatcher = thread()->eventDispatcher(); + if (enable) + dispatcher->registerEventNotifier(this); + else + dispatcher->unregisterEventNotifier(this); +} + +/** + * \var EventNotifier::activated + * \brief Signal emitted when the event occurs + * + * This signal is emitted when the event \ref type() occurs on the file + * descriptor monitored by the notifier. The notifier pointer is passed as a + * parameter. + */ + +void EventNotifier::message(Message *msg) +{ + if (msg->type() == Message::ThreadMoveMessage) { + if (enabled_) { + setEnabled(false); + invokeMethod(&EventNotifier::setEnabled, + ConnectionTypeQueued, true); + } + } + + Object::message(msg); +} + +} /* namespace libcamera */ diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build index fb8ed79a..a8b04cfc 100644 --- a/src/libcamera/base/meson.build +++ b/src/libcamera/base/meson.build @@ -5,6 +5,7 @@ libcamera_base_sources = files([ 'bound_method.cpp', 'event_dispatcher.cpp', 'event_dispatcher_poll.cpp', + 'event_notifier.cpp', 'file.cpp', 'log.cpp', 'message.cpp', diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index 4b842773..37a2c5aa 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -17,9 +17,9 @@ #include #include +#include #include -#include "libcamera/internal/event_notifier.h" #include "libcamera/internal/media_device.h" namespace libcamera { diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp deleted file mode 100644 index 784016a9..00000000 --- a/src/libcamera/event_notifier.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * event_notifier.cpp - File descriptor event notifier - */ - -#include "libcamera/internal/event_notifier.h" - -#include - -#include -#include -#include - -/** - * \file event_notifier.h - * \brief File descriptor event notifier - */ - -namespace libcamera { - -/** - * \class EventNotifier - * \brief Notify of activity on a file descriptor - * - * The EventNotifier models a file descriptor event source that can be - * monitored. It is created with the file descriptor to be monitored and the - * type of event, and is enabled by default. It will emit the \ref activated - * signal whenever an event of the monitored type occurs on the file descriptor. - * - * Supported type of events are EventNotifier::Read, EventNotifier::Write and - * EventNotifier::Exception. The type is specified when constructing the - * notifier, and can be retrieved using the type() function. To listen to - * multiple event types on the same file descriptor multiple notifiers must be - * created. - * - * The notifier can be disabled with the setEnabled() function. When the notifier - * is disabled it ignores events and does not emit the \ref activated signal. - * The notifier can then be re-enabled with the setEnabled() function. - * - * Creating multiple notifiers of the same type for the same file descriptor is - * not allowed and results in undefined behaviour. - * - * Notifier events are detected and dispatched from the - * EventDispatcher::processEvents() function. - */ - -/** - * \enum EventNotifier::Type - * Type of file descriptor event to listen for. - * \var EventNotifier::Read - * Data is available to be read from the file descriptor - * \var EventNotifier::Write - * Data can be written to the file descriptor - * \var EventNotifier::Exception - * An exception has occurred on the file descriptor - */ - -/** - * \brief Construct an event notifier with a file descriptor and event type - * \param[in] fd The file descriptor to monitor - * \param[in] type The event type to monitor - * \param[in] parent The parent Object - */ -EventNotifier::EventNotifier(int fd, Type type, Object *parent) - : Object(parent), fd_(fd), type_(type), enabled_(false) -{ - setEnabled(true); -} - -EventNotifier::~EventNotifier() -{ - setEnabled(false); -} - -/** - * \fn EventNotifier::type() - * \brief Retrieve the type of the event being monitored - * \return The type of the event - */ - -/** - * \fn EventNotifier::fd() - * \brief Retrieve the file descriptor being monitored - * \return The file descriptor - */ - -/** - * \fn EventNotifier::enabled() - * \brief Retrieve the notifier state - * \return True if the notifier is enabled, or false otherwise - * \sa setEnabled() - */ - -/** - * \brief Enable or disable the notifier - * \param[in] enable True to enable the notifier, false to disable it - * - * This function enables or disables the notifier. A disabled notifier ignores - * events and does not emit the \ref activated signal. - * - * \context This function is \threadbound. - */ -void EventNotifier::setEnabled(bool enable) -{ - if (enabled_ == enable) - return; - - enabled_ = enable; - - EventDispatcher *dispatcher = thread()->eventDispatcher(); - if (enable) - dispatcher->registerEventNotifier(this); - else - dispatcher->unregisterEventNotifier(this); -} - -/** - * \var EventNotifier::activated - * \brief Signal emitted when the event occurs - * - * This signal is emitted when the event \ref type() occurs on the file - * descriptor monitored by the notifier. The notifier pointer is passed as a - * parameter. - */ - -void EventNotifier::message(Message *msg) -{ - if (msg->type() == Message::ThreadMoveMessage) { - if (enabled_) { - setEnabled(false); - invokeMethod(&EventNotifier::setEnabled, - ConnectionTypeQueued, true); - } - } - - Object::message(msg); -} - -} /* namespace libcamera */ diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp index 14665970..f23eb783 100644 --- a/src/libcamera/ipc_unixsocket.cpp +++ b/src/libcamera/ipc_unixsocket.cpp @@ -12,10 +12,9 @@ #include #include +#include #include -#include "libcamera/internal/event_notifier.h" - /** * \file ipc_unixsocket.h * \brief IPC mechanism based on Unix sockets diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 36f6ddd7..e0c47352 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -15,7 +15,6 @@ libcamera_sources = files([ 'delayed_controls.cpp', 'device_enumerator.cpp', 'device_enumerator_sysfs.cpp', - 'event_notifier.cpp', 'file_descriptor.cpp', 'formats.cpp', 'framebuffer_allocator.cpp', diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index 46338029..4fe4ad57 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -20,11 +20,10 @@ #include #include +#include #include #include -#include "libcamera/internal/event_notifier.h" - /** * \file process.h * \brief Process object diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 334b9b78..98d93a12 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -16,10 +16,10 @@ #include #include +#include #include #include -#include "libcamera/internal/event_notifier.h" #include "libcamera/internal/sysfs.h" /** diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index dc23510b..3d2d99b4 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -21,11 +21,11 @@ #include +#include #include #include -#include "libcamera/internal/event_notifier.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/media_object.h" diff --git a/test/event-thread.cpp b/test/event-thread.cpp index 05c5d26d..57526166 100644 --- a/test/event-thread.cpp +++ b/test/event-thread.cpp @@ -10,11 +10,10 @@ #include #include +#include #include #include -#include "libcamera/internal/event_notifier.h" - #include "test.h" using namespace std; diff --git a/test/event.cpp b/test/event.cpp index aa79da99..c2274344 100644 --- a/test/event.cpp +++ b/test/event.cpp @@ -10,11 +10,10 @@ #include #include +#include #include #include -#include "libcamera/internal/event_notifier.h" - #include "test.h" using namespace std; diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp index 656d8655..ee9f2651 100644 --- a/test/ipa/ipa_interface_test.cpp +++ b/test/ipa/ipa_interface_test.cpp @@ -15,11 +15,11 @@ #include #include +#include #include #include #include "libcamera/internal/device_enumerator.h" -#include "libcamera/internal/event_notifier.h" #include "libcamera/internal/ipa_manager.h" #include "libcamera/internal/ipa_module.h" #include "libcamera/internal/pipeline_handler.h" -- cgit v1.2.1