26class BoundMethodPackBase
29 virtual ~BoundMethodPackBase() =
default;
32template<
typename R,
typename... Args>
33class BoundMethodPack :
public BoundMethodPackBase
36 BoundMethodPack(
const Args &... args)
46 std::tuple<typename std::remove_reference_t<Args>...> args_;
50template<
typename... Args>
51class BoundMethodPack<void, Args...> :
public BoundMethodPackBase
54 BoundMethodPack(
const Args &... args)
63 std::tuple<typename std::remove_reference_t<Args>...> args_;
70 : obj_(obj), object_(object), connectionType_(type)
73 virtual ~BoundMethodBase() =
default;
75 template<typename T, std::enable_if_t<!std::is_same<Object, T>::value> * =
nullptr>
76 bool match(T *obj) {
return obj == obj_; }
77 bool match(Object *
object) {
return object == object_; }
79 Object *object()
const {
return object_; }
81 virtual void invokePack(BoundMethodPackBase *pack) = 0;
84 bool activatePack(std::shared_ptr<BoundMethodPackBase> pack,
94template<
typename R,
typename... Args>
95class BoundMethodArgs :
public BoundMethodBase
98 using PackType = BoundMethodPack<R, Args...>;
101 template<std::size_t... I,
typename T = R>
102 std::enable_if_t<!std::is_void<T>::value,
void>
103 invokePack(BoundMethodPackBase *pack, std::index_sequence<I...>)
105 PackType *args =
static_cast<PackType *
>(pack);
106 args->ret_ = invoke(std::get<I>(args->args_)...);
109 template<std::size_t... I,
typename T = R>
110 std::enable_if_t<std::is_void<T>::value,
void>
111 invokePack(BoundMethodPackBase *pack, std::index_sequence<I...>)
114 PackType *args [[gnu::unused]] =
static_cast<PackType *
>(pack);
115 invoke(std::get<I>(args->args_)...);
120 : BoundMethodBase(obj, object, type) {}
122 void invokePack(BoundMethodPackBase *pack)
override
124 invokePack(pack, std::make_index_sequence<
sizeof...(Args)>{});
127 virtual R activate(Args... args,
bool deleteMethod =
false) = 0;
128 virtual R invoke(Args... args) = 0;
131template<
typename T,
typename R,
typename Func,
typename... Args>
132class BoundMethodFunctor :
public BoundMethodArgs<R, Args...>
135 using PackType =
typename BoundMethodArgs<R, Args...>::PackType;
137 BoundMethodFunctor(T *obj, Object *
object, Func func,
139 : BoundMethodArgs<R, Args...>(obj, object, type), func_(func)
143 R activate(Args... args,
bool deleteMethod =
false)
override
146 return func_(args...);
148 auto pack = std::make_shared<PackType>(args...);
149 bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
150 return sync ? pack->returnValue() : R();
153 R invoke(Args... args)
override
155 return func_(args...);
162template<
typename T,
typename R,
typename... Args>
163class BoundMethodMember :
public BoundMethodArgs<R, Args...>
166 using PackType =
typename BoundMethodArgs<R, Args...>::PackType;
168 BoundMethodMember(T *obj, Object *
object, R (T::*func)(Args...),
170 : BoundMethodArgs<R, Args...>(obj, object, type), func_(func)
174 bool match(R (T::*func)(Args...))
const {
return func == func_; }
176 R activate(Args... args,
bool deleteMethod =
false)
override
178 if (!this->object_) {
179 T *obj =
static_cast<T *
>(this->obj_);
180 return (obj->*func_)(args...);
183 auto pack = std::make_shared<PackType>(args...);
184 bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
185 return sync ? pack->returnValue() : R();
188 R invoke(Args... args)
override
190 T *obj =
static_cast<T *
>(this->obj_);
191 return (obj->*func_)(args...);
195 R (T::*func_)(Args...);
198template<
typename R,
typename... Args>
199class BoundMethodStatic :
public BoundMethodArgs<R, Args...>
202 BoundMethodStatic(R (*func)(Args...))
208 bool match(R (*func)(Args...))
const {
return func == func_; }
210 R activate(Args... args, [[maybe_unused]]
bool deleteMethod =
false)
override
212 return (*func_)(args...);
215 R invoke(Args...)
override
Top-level libcamera namespace.
Definition: backtrace.h:17
ConnectionType
Connection type for asynchronous communication.
Definition: bound_method.h:19
@ ConnectionTypeQueued
The receiver is invoked asynchronously.
Definition: bound_method.h:22
@ ConnectionTypeDirect
The receiver is invoked immediately and synchronously in the sender's thread.
Definition: bound_method.h:21
@ ConnectionTypeAuto
If the sender and the receiver live in the same thread, ConnectionTypeDirect is used....
Definition: bound_method.h:20
@ ConnectionTypeBlocking
The receiver is invoked synchronously.
Definition: bound_method.h:23