13 #ifndef __PROCESS_DISPATCH_HPP__ 14 #define __PROCESS_DISPATCH_HPP__ 86 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>> f_(
104 template <
typename R>
107 template <
typename F>
113 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>> f_(
119 promise->associate(std::move(
f)());
135 template <
typename R>
138 template <
typename F>
144 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>> f_(
150 promise->set(std::move(
f)());
173 template <
typename T>
176 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>>
f(
179 assert(process !=
nullptr);
180 T* t =
dynamic_cast<T*
>(
process);
181 assert(t !=
nullptr);
188 template <
typename T>
194 template <
typename T>
205 #define FORWARD(Z, N, DATA) std::forward<A ## N>(a ## N) 206 #define MOVE(Z, N, DATA) std::move(a ## N) 207 #define DECL(Z, N, DATA) typename std::decay<A ## N>::type&& a ## N 209 #define TEMPLATE(Z, N, DATA) \ 210 template <typename T, \ 211 ENUM_PARAMS(N, typename P), \ 212 ENUM_PARAMS(N, typename A)> \ 215 void (T::*method)(ENUM_PARAMS(N, P)), \ 216 ENUM_BINARY_PARAMS(N, A, &&a)) \ 218 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>> f( \ 219 new lambda::CallableOnce<void(ProcessBase*)>( \ 221 [method](ENUM(N, DECL, _), ProcessBase* process) { \ 222 assert(process != nullptr); \ 223 T* t = dynamic_cast<T*>(process); \ 224 assert(t != nullptr); \ 225 (t->*method)(ENUM(N, MOVE, _)); \ 227 ENUM(N, FORWARD, _), \ 230 internal::dispatch(pid, std::move(f), &typeid(method)); \ 233 template <typename T, \ 234 ENUM_PARAMS(N, typename P), \ 235 ENUM_PARAMS(N, typename A)> \ 237 const Process<T>& process, \ 238 void (T::*method)(ENUM_PARAMS(N, P)), \ 239 ENUM_BINARY_PARAMS(N, A, &&a)) \ 241 dispatch(process.self(), method, ENUM(N, FORWARD, _)); \ 244 template <typename T, \ 245 ENUM_PARAMS(N, typename P), \ 246 ENUM_PARAMS(N, typename A)> \ 248 const Process<T>* process, \ 249 void (T::*method)(ENUM_PARAMS(N, P)), \ 250 ENUM_BINARY_PARAMS(N, A, &&a)) \ 252 dispatch(process->self(), method, ENUM(N, FORWARD, _)); \ 261 template <
typename R,
typename T>
267 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>>
f(
271 assert(process !=
nullptr);
272 T* t =
dynamic_cast<T*
>(
process);
273 assert(t !=
nullptr);
274 promise->associate((t->*method)());
284 template <
typename R,
typename T>
290 template <
typename R,
typename T>
296 #define TEMPLATE(Z, N, DATA) \ 297 template <typename R, \ 299 ENUM_PARAMS(N, typename P), \ 300 ENUM_PARAMS(N, typename A)> \ 301 Future<R> dispatch( \ 303 Future<R> (T::*method)(ENUM_PARAMS(N, P)), \ 304 ENUM_BINARY_PARAMS(N, A, &&a)) \ 306 std::unique_ptr<Promise<R>> promise(new Promise<R>()); \ 307 Future<R> future = promise->future(); \ 309 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>> f( \ 310 new lambda::CallableOnce<void(ProcessBase*)>( \ 312 [method](std::unique_ptr<Promise<R>> promise, \ 314 ProcessBase* process) { \ 315 assert(process != nullptr); \ 316 T* t = dynamic_cast<T*>(process); \ 317 assert(t != nullptr); \ 318 promise->associate( \ 319 (t->*method)(ENUM(N, MOVE, _))); \ 321 std::move(promise), \ 322 ENUM(N, FORWARD, _), \ 325 internal::dispatch(pid, std::move(f), &typeid(method)); \ 330 template <typename R, \ 332 ENUM_PARAMS(N, typename P), \ 333 ENUM_PARAMS(N, typename A)> \ 334 Future<R> dispatch( \ 335 const Process<T>& process, \ 336 Future<R> (T::*method)(ENUM_PARAMS(N, P)), \ 337 ENUM_BINARY_PARAMS(N, A, &&a)) \ 339 return dispatch(process.self(), method, ENUM(N, FORWARD, _)); \ 342 template <typename R, \ 344 ENUM_PARAMS(N, typename P), \ 345 ENUM_PARAMS(N, typename A)> \ 346 Future<R> dispatch( \ 347 const Process<T>* process, \ 348 Future<R> (T::*method)(ENUM_PARAMS(N, P)), \ 349 ENUM_BINARY_PARAMS(N, A, &&a)) \ 351 return dispatch(process->self(), method, ENUM(N, FORWARD, _)); \ 360 template <
typename R,
typename T>
366 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>>
f(
370 assert(process !=
nullptr);
371 T* t =
dynamic_cast<T*
>(
process);
372 assert(t !=
nullptr);
373 promise->set((t->*method)());
383 template <
typename R,
typename T>
389 template <
typename R,
typename T>
395 #define TEMPLATE(Z, N, DATA) \ 396 template <typename R, \ 398 ENUM_PARAMS(N, typename P), \ 399 ENUM_PARAMS(N, typename A)> \ 400 Future<R> dispatch( \ 402 R (T::*method)(ENUM_PARAMS(N, P)), \ 403 ENUM_BINARY_PARAMS(N, A, &&a)) \ 405 std::unique_ptr<Promise<R>> promise(new Promise<R>()); \ 406 Future<R> future = promise->future(); \ 408 std::unique_ptr<lambda::CallableOnce<void(ProcessBase*)>> f( \ 409 new lambda::CallableOnce<void(ProcessBase*)>( \ 411 [method](std::unique_ptr<Promise<R>> promise, \ 413 ProcessBase* process) { \ 414 assert(process != nullptr); \ 415 T* t = dynamic_cast<T*>(process); \ 416 assert(t != nullptr); \ 417 promise->set((t->*method)(ENUM(N, MOVE, _))); \ 419 std::move(promise), \ 420 ENUM(N, FORWARD, _), \ 423 internal::dispatch(pid, std::move(f), &typeid(method)); \ 428 template <typename R, \ 430 ENUM_PARAMS(N, typename P), \ 431 ENUM_PARAMS(N, typename A)> \ 432 Future<R> dispatch( \ 433 const Process<T>& process, \ 434 R (T::*method)(ENUM_PARAMS(N, P)), \ 435 ENUM_BINARY_PARAMS(N, A, &&a)) \ 437 return dispatch(process.self(), method, ENUM(N, FORWARD, _)); \ 440 template <typename R, \ 442 ENUM_PARAMS(N, typename P), \ 443 ENUM_PARAMS(N, typename A)> \ 444 Future<R> dispatch( \ 445 const Process<T>* process, \ 446 R (T::*method)(ENUM_PARAMS(N, P)), \ 447 ENUM_BINARY_PARAMS(N, A, &&a)) \ 449 return dispatch(process->self(), method, ENUM(N, FORWARD, _)); \ 466 -> decltype(internal::Dispatch<R>()(pid, std::forward<F>(
f)))
468 return internal::Dispatch<R>()(pid, std::forward<F>(
f));
473 #endif // __PROCESS_DISPATCH_HPP__
F && f
Definition: defer.hpp:270
Future< R > operator()(const UPID &pid, F &&f)
Definition: dispatch.hpp:108
internal::Partial< typename std::decay< F >::type, typename std::decay< Args >::type... > partial(F &&f, Args &&...args)
Definition: lambda.hpp:364
REPEAT_FROM_TO(1, 13, TEMPLATE, _) class AsyncExecutorProcess
Definition: async.hpp:63
void operator()(const UPID &pid, F &&f)
Definition: dispatch.hpp:84
Definition: process.hpp:72
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
Protocol< PromiseRequest, PromiseResponse > promise
void dispatch(const UPID &pid, std::unique_ptr< lambda::CallableOnce< void(ProcessBase *)>> f, const Option< const std::type_info * > &functionType=None())
Definition: dispatch.hpp:73
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: attributes.hpp:24
Future< R > operator()(const UPID &pid, F &&f)
Definition: dispatch.hpp:139
Definition: executor.hpp:48
PID< T > self() const
Returns the PID of the process.
Definition: process.hpp:514
Try< uint32_t > type(const std::string &path)
#define TEMPLATE(Z, N, DATA)
Definition: dispatch.hpp:395
Definition: process.hpp:505
Definition: lambda.hpp:414
Definition: future.hpp:58