14#include <boost/asio/io_context.hpp>
15#include <boost/asio/post.hpp>
17#include <rpc/server.h>
40 template <
typename... Args>
41 explicit Server(Args &&... args);
43 template <
typename FunctorT>
46 template <
typename FunctorT>
50 _server.async_run(worker_threads);
54 #ifdef LIBCARLA_INCLUDED_FROM_UE4
56 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
84 template <
typename C,
typename R,
typename... Args>
87 template <
typename C,
typename R,
typename... Args>
96 template <
typename R,
typename... Args>
108 template <
typename FuncT>
109 static auto WrapSyncCall(boost::asio::io_context &io, FuncT &&functor) {
110 return [&io, functor=std::forward<FuncT>(functor)](
Metadata metadata, Args... args) ->
R {
111 auto task = std::packaged_task<R()>([functor=std::move(functor), args...]() {
112 return functor(args...);
114 if (metadata.IsResponseIgnored()) {
120 auto result = task.get_future();
130 template <
typename FuncT>
133 if (metadata.IsResponseIgnored()) {
137 return functor(args...);
145 template <
typename ... Args>
147 : _server(
std::forward<Args>(args) ...) {
148 _server.suppress_exceptions(
true);
151 template <
typename FunctorT>
159 template <
typename FunctorT>
164 Wrapper::WrapAsyncCall(std::forward<FunctorT>(functor)));
carla::rpc::Response< T > R
An RPC server in which functions can be bind to run synchronously or asynchronously.
void SyncRunFor(time_duration duration)
void AsyncRun(size_t worker_threads)
boost::asio::io_context _sync_io_context
void BindSync(const std::string &name, FunctorT &&functor)
void BindAsync(const std::string &name, FunctorT &&functor)
Positive time duration up to milliseconds resolution.
constexpr auto to_chrono() const
This file contains definitions of common data structures used in traffic manager.
auto MoveHandler(FunctorT &&func)
Hack to trick asio into accepting move-only handlers, if the handler were actually copied it would re...
static auto WrapSyncCall(boost::asio::io_context &io, FuncT &&functor)
Wraps functor into a function type with equivalent signature.
static auto WrapAsyncCall(FuncT &&functor)
Wraps functor into a function type with equivalent signature that handles the metadata sent by the cl...