14#include <boost/asio/io_context.hpp>
15#include <boost/asio/post.hpp>
17#include <rpc/server.h>
43 template <
typename... Args>
44 explicit Server(Args &&... args);
46 template <
typename FunctorT>
49 template <
typename FunctorT>
53 _server.async_run(worker_threads);
57 #ifdef LIBCARLA_INCLUDED_FROM_UE4
59 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
89 template <
typename C,
typename R,
typename... Args>
92 template <
typename C,
typename R,
typename... Args>
101 template <
typename R,
typename... Args>
113 template <
typename FuncT>
114 static auto WrapSyncCall(std::atomic_bool &shutdown_in_progress, boost::asio::io_context &io, FuncT &&functor) {
115 return [&shutdown_in_progress, &io, functor=std::forward<FuncT>(functor)](
Metadata metadata, Args... args) ->
R {
116 auto task = std::packaged_task<R()>([functor=std::move(functor), args...]() {
117 return functor(args...);
119 if (metadata.IsResponseIgnored()) {
125 auto result = task.get_future();
127 std::future_status status;
129 status = result.wait_for(std::chrono::milliseconds(100));
130 }
while (!shutdown_in_progress && (status != std::future_status::ready));
131 if (status == std::future_status::ready) {
134 throw std::runtime_error(
"RPC server is shutting down");
143 template <
typename FuncT>
146 if (metadata.IsResponseIgnored()) {
150 return functor(args...);
158 template <
typename ... Args>
160 : _server(
std::forward<Args>(args) ...) {
161 _server.suppress_exceptions(
true);
164 template <
typename FunctorT>
172 template <
typename FunctorT>
177 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.
std::atomic_bool _shutdown_in_progress
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(std::atomic_bool &shutdown_in_progress, 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...