The libcamera internal headers are located in src/libcamera/include/. The directory is added to the compiler headers search path with a meson include_directories() directive, and internal headers are included with (e.g. for the internal semaphore.h header) #include "semaphore.h" All was well, until libcxx decided to implement the C++20 synchronization library. The __threading_support header gained a #include <semaphore.h> to include the pthread's semaphore support. As include_directories() adds src/libcamera/include/ to the compiler search path with -I, the internal semaphore.h is included instead of the pthread version. Needless to say, the compiler isn't happy. Three options have been considered to fix this issue: - Use -iquote instead of -I. The -iquote option instructs gcc to only consider the header search path for headers included with the "" version. Meson unfortunately doesn't support this option. - Rename the internal semaphore.h header. This was deemed to be the beginning of a long whack-a-mole game, where namespace clashes with system libraries would appear over time (possibly dependent on particular system configurations) and would need to be constantly fixed. - Move the internal headers to another directory to create a unique namespace through path components. This causes lots of churn in all the existing source files through the all project. The first option would be best, but isn't available to us due to missing support in meson. Even if -iquote support was added, we would need to fix the problem before a new version of meson containing the required support would be released. The third option is thus the only practical solution available. Bite the bullet, and do it, moving headers to include/libcamera/internal/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
142 lines
3.8 KiB
C++
142 lines
3.8 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* event_notifier.cpp - File descriptor event notifier
|
|
*/
|
|
|
|
#include <libcamera/event_notifier.h>
|
|
|
|
#include <libcamera/camera_manager.h>
|
|
#include <libcamera/event_dispatcher.h>
|
|
|
|
#include "libcamera/internal/message.h"
|
|
#include "libcamera/internal/thread.h"
|
|
|
|
/**
|
|
* \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 setEnable() 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 setEnable() 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 setEnable()
|
|
*/
|
|
|
|
/**
|
|
* \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 */
|