libcamera  v0.3.2+116-83c5ad0f
Supporting cameras in Linux since 2019
Public Member Functions | List of all members
libcamera::Signal< Args > Class Template Reference

Generic signal and slot communication mechanism. More...

Inherits libcamera::SignalBase.

Public Member Functions

template<typename T , typename R >
void connect (T *obj, R(T::*func)(Args...))
 Connect the signal to a member function slot. More...
 
template<typename T , typename Func >
void connect (T *obj, Func func)
 Connect the signal to a function object slot. More...
 
template<typename R >
void connect (R(*func)(Args...))
 Connect the signal to a static function slot. More...
 
void disconnect ()
 Disconnect the signal from all slots. More...
 
template<typename T >
void disconnect (T *obj)
 Disconnect the signal from all slots of the object. More...
 
template<typename T , typename R >
void disconnect (T *obj, R(T::*func)(Args...))
 Disconnect the signal from the object slot member function func. More...
 
template<typename R >
void disconnect (R(*func)(Args...))
 Disconnect the signal from the slot static function func. More...
 
void emit (Args... args)
 Emit the signal and call all connected slots. More...
 

Detailed Description

template<typename... Args>
class libcamera::Signal< Args >

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-6/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.

When a slot belongs to an instance of the Object class, the slot is called in the context of the thread that the object is bound to. If the signal is emitted from the same thread, the slot will be called synchronously, before Signal::emit() returns. If the signal is emitted from a different thread, the slot will be called asynchronously from the object's thread's event loop, after the Signal::emit() function returns, with a copy of the signal's arguments. The emitter shall thus ensure that any pointer or reference passed through the signal will remain valid after the signal is emitted.

Duplicate connections between a signal and a slot are not expected and use of the Object class to manage signals will enforce this restriction.

Member Function Documentation

◆ connect() [1/3]

template<typename... Args>
template<typename T , typename R >
libcamera::Signal< Args >::connect ( T *  object,
R(T::*)(Args...)  func 
)
inline

Connect the signal to a member function slot.

Parameters
[in]objectThe slot object pointer
[in]funcThe slot member function

If the typename T inherits from Object, the signal will be automatically disconnected from the func slot of object when object is destroyed. Otherwise the caller shall disconnect signals manually before destroying object.

Thread Safety:
This function is thread-safe.

◆ connect() [2/3]

template<typename... Args>
template<typename T , typename Func >
libcamera::Signal< Args >::connect ( T *  object,
Func  func 
)
inline

Connect the signal to a function object slot.

Parameters
[in]objectThe slot object pointer
[in]funcThe function object

If the typename T inherits from Object, the signal will be automatically disconnected from the func slot of object when object is destroyed. Otherwise the caller shall disconnect signals manually before destroying object.

The function object is typically a lambda function, but may be any object that satisfies the FunctionObject named requirements. The types of the function object arguments shall match the types of the signal arguments.

No matching disconnect() function exist, as it wouldn't be possible to pass to a disconnect() function the same lambda that was passed to connect(). The connection created by this function can not be removed selectively if the signal is connected to multiple slots of the same receiver, but may be otherwise be removed using the disconnect(T *object) function.

Thread Safety:
This function is thread-safe.

◆ connect() [3/3]

template<typename... Args>
template<typename R >
libcamera::Signal< Args >::connect ( R(*)(Args...)  func)
inline

Connect the signal to a static function slot.

Parameters
[in]funcThe slot static function
Thread Safety:
This function is thread-safe.

◆ disconnect() [1/4]

template<typename... Args>
libcamera::Signal< Args >::disconnect ( )
inline

Disconnect the signal from all slots.

Thread Safety:
This function is thread-safe.

◆ disconnect() [2/4]

template<typename... Args>
template<typename T >
libcamera::Signal< Args >::disconnect ( T *  object)
inline

Disconnect the signal from all slots of the object.

Parameters
[in]objectThe object pointer whose slots to disconnect
Thread Safety:
This function is thread-safe.

◆ disconnect() [3/4]

template<typename... Args>
template<typename T , typename R >
libcamera::Signal< Args >::disconnect ( T *  object,
R(T::*)(Args...)  func 
)
inline

Disconnect the signal from the object slot member function func.

Parameters
[in]objectThe object pointer whose slots to disconnect
[in]funcThe slot member function to disconnect
Thread Safety:
This function is thread-safe.

◆ disconnect() [4/4]

template<typename... Args>
template<typename R >
libcamera::Signal< Args >::disconnect ( R(*)(Args...)  func)
inline

Disconnect the signal from the slot static function func.

Parameters
[in]funcThe slot static function to disconnect
Thread Safety:
This function is thread-safe.

◆ emit()

template<typename... Args>
libcamera::Signal< Args >::emit ( Args...  args)
inline

Emit the signal and call all connected slots.

Parameters
argsThe arguments passed to the 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.

This function is not thread-safe, but thread-safety is guaranteed against concurrent connect() and disconnect() calls.


The documentation for this class was generated from the following files: