12 #include <type_traits> 23 void disconnect(Object *
object);
26 using SlotList = std::list<BoundMethodBase *>;
28 void connect(BoundMethodBase *slot);
29 void disconnect(std::function<
bool(SlotList::iterator &)> match);
37 template<
typename... Args>
47 template<typename T, typename R, std::enable_if_t<std::is_base_of<Object, T>::value> * =
nullptr>
48 void connect(T *obj, R (T::*func)(Args...),
51 Object *
object =
static_cast<Object *
>(obj);
52 SignalBase::connect(
new BoundMethodMember<T, R, Args...>(obj,
object, func, type));
55 template<typename T, typename R, std::enable_if_t<!std::is_base_of<Object, T>::value> * =
nullptr>
57 template<
typename T,
typename R>
59 void connect(T *obj, R (T::*func)(Args...))
61 SignalBase::connect(
new BoundMethodMember<T, R, Args...>(obj,
nullptr, func));
65 template<
typename T,
typename Func,
66 std::enable_if_t<std::is_base_of<Object, T>::value
67 #if __cplusplus >= 201703L 68 && std::is_invocable_v<Func, Args...>
73 Object *
object =
static_cast<Object *
>(obj);
74 SignalBase::connect(
new BoundMethodFunctor<T, void, Func, Args...>(obj,
object, func, type));
77 template<
typename T,
typename Func,
78 std::enable_if_t<!std::is_base_of<Object, T>::value
79 #if __cplusplus >= 201703L 80 && std::is_invocable_v<Func, Args...>
84 template<
typename T,
typename Func>
88 SignalBase::connect(
new BoundMethodFunctor<T, void, Func, Args...>(obj,
nullptr, func));
94 SignalBase::connect(
new BoundMethodStatic<R, Args...>(func));
99 SignalBase::disconnect([]([[maybe_unused]] SlotList::iterator &iter) {
107 SignalBase::disconnect([obj](SlotList::iterator &iter) {
108 return (*iter)->match(obj);
112 template<
typename T,
typename R>
115 SignalBase::disconnect([obj, func](SlotList::iterator &iter) {
116 BoundMethodArgs<R, Args...> *slot =
117 static_cast<BoundMethodArgs<R, Args...
> *>(*iter);
119 if (!slot->match(obj))
128 return static_cast<BoundMethodMember<T, R, Args...
> *>(slot)->match(func);
135 SignalBase::disconnect([func](SlotList::iterator &iter) {
136 BoundMethodArgs<R, Args...> *slot =
137 static_cast<BoundMethodArgs<R, Args...
> *>(*iter);
139 if (!slot->match(
nullptr))
142 return static_cast<BoundMethodStatic<R, Args...
> *>(slot)->match(func);
152 for (BoundMethodBase *slot : slots())
153 static_cast<BoundMethodArgs<
void, Args...
> *>(slot)->activate(args...);
void emit(Args... args)
Emit the signal and call all connected slots.
Definition: signal.h:146
ConnectionType
Connection type for asynchronous communication.
Definition: bound_method.h:19
void connect(T *obj, Func func)
Connect the signal to a function object slot.
Definition: signal.h:86
void disconnect()
Disconnect the signal from all slots.
Definition: signal.h:97
void connect(T *obj, R(T::*func)(Args...))
Connect the signal to a member function slot.
Definition: signal.h:59
void disconnect(T *obj)
Disconnect the signal from all slots of the object.
Definition: signal.h:105
Top-level libcamera namespace.
Definition: bound_method.h:15
void disconnect(R(*func)(Args...))
Disconnect the signal from the slot static function func.
Definition: signal.h:133
void disconnect(T *obj, R(T::*func)(Args...))
Disconnect the signal from the object slot member function func.
Definition: signal.h:113
Generic signal and slot communication mechanism.
Definition: signal.h:38
Method bind and invocation.
If the sender and the receiver live in the same thread, ConnectionTypeDirect is used. Otherwise ConnectionTypeQueued is used.
Definition: bound_method.h:20
void connect(R(*func)(Args...))
Connect the signal to a static function slot.
Definition: signal.h:92