diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-01-04 21:09:16 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-01-08 16:23:16 +0200 |
commit | d0fd42a4fde6cf29bae760d553d4a4f9b857810f (patch) | |
tree | 4c62ca91c483cd274663d6fb5f31d35bda5cbc8a /src | |
parent | 8b0de29c416c81be2d98b73effe6c7315b1fc1e1 (diff) |
libcamera: Add signal/slot communication mechanism
Introduce a Signal class that allows connecting event sources (signals)
to event listeners (slots) without adding any boilerplate code usually
associated with the observer or listener design patterns.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/meson.build | 1 | ||||
-rw-r--r-- | src/libcamera/signal.cpp | 84 |
2 files changed, 85 insertions, 0 deletions
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 78562299..3ec86e75 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -6,6 +6,7 @@ libcamera_sources = files([ 'media_device.cpp', 'media_object.cpp', 'pipeline_handler.cpp', + 'signal.cpp', ]) libcamera_headers = files([ diff --git a/src/libcamera/signal.cpp b/src/libcamera/signal.cpp new file mode 100644 index 00000000..0fd3bb2a --- /dev/null +++ b/src/libcamera/signal.cpp @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * signal.cpp - Signal & slot implementation + */ + +namespace libcamera { + +/** + * \class Signal + * \brief Generic signal and slot communication mechanism + * + * Signals and slots are a language construct aimed at communication between + * objects through the observer pattern without the need for boilerplate code. + * See http://doc.qt.io/qt-5/signalsandslots.html for more information. + * + * Signals model events that can be observed from objects unrelated to the event + * source. Slots are functions that are called in response to a signal. Signals + * can be connected to and disconnected from slots dynamically at runtime. When + * a signal is emitted, all connected slots are called sequentially in the order + * they have been connected. + * + * Signals are defined with zero, one or more typed parameters. They are emitted + * with a value for each of the parameters, and those values are passed to the + * connected slots. + * + * Slots are normal static or class member functions. In order to be connected + * to a signal, their signature must match the signal type (taking the same + * arguments as the signal and returning void). + * + * Connecting a signal to a slot results in the slot being called with the + * arguments passed to the emit() function when the signal is emitted. Multiple + * slots can be connected to the same signal, and multiple signals can connected + * to the same slot. Duplicate connections between a signal and a slot are + * allowed and result in the slot being called multiple times for the same + * signal emission. + */ + +/** + * \fn Signal::connect(T *object, void(T::*func)(Args...)) + * \brief Connect the signal to a member function slot + * \param object The slot object pointer + * \param func The slot member function + */ + +/** + * \fn Signal::connect(void(*func)(Args...)) + * \brief Connect the signal to a static function slot + * \param func The slot static function + */ + +/** + * \fn Signal::disconnect() + * \brief Disconnect the signal from all slots + */ + +/** + * \fn Signal::disconnect(T *object) + * \brief Disconnect the signal from all slots of the \a object + */ + +/** + * \fn Signal::disconnect(T *object, void(T::*func)(Args...)) + * \brief Disconnect the signal from the \a object slot member function \a func + */ + +/** + * \fn Signal::disconnect(void(*func)(Args...)) + * \brief Disconnect the signal from the slot static function \a func + */ + +/** + * \fn Signal::emit(Args... args) + * \brief Emit the signal and call all connected slots + * + * Emitting a signal calls all connected slots synchronously and sequentially in + * the order the slots have been connected. The arguments passed to the emit() + * function are passed to the slot functions unchanged. If a slot modifies one + * of the arguments (when passed by pointer or reference), the modification is + * thus visible to all subsequently called slots. + */ + +} /* namespace libcamera */ |