|
CARLA
|
#include <router.h>
Inheritance diagram for carla::multigpu::Router:Public Types | |
| using | request_observer_type = std::function< void(const Primary *, MultiGPUCommand, const carla::BufferView &)> |
Public Member Functions | |
| void | AsyncRun (size_t worker_threads) |
| PrimaryCommands & | GetCommander () |
| boost::asio::ip::tcp::endpoint | GetLocalEndpoint () const |
| bool | HasClientsConnected () const |
| Any thread: reads a count kept next to the session list, which is itself only touched under the router's mutex. | |
| bool | IsAnySecondaryLoading () |
| Whether a connected secondary sent LOAD_MAP has not yet reported the episode of its latest LOAD_MAP ready (a disconnect also clears it). | |
| bool | IsConnected (const std::weak_ptr< Primary > &server) |
| Whether server is still one of the connected secondary sessions. | |
| Router (uint16_t port) | |
| Router (void) | |
| void | SetCallbacks () |
| void | SetNewConnectionCallback (std::function< void(void)>) |
| void | Stop () |
| void | StopWaitingForSecondaryLoads () |
| std::vector< std::weak_ptr< Primary > > | TakeNewSessions () |
| Sessions connected since the previous call, oldest first. | |
| void | Write (MultiGPUCommand id, Buffer &&buffer) |
| load_map_id_type | WriteLoadMap (std::string_view map, const LoadMapExtras &extras={}) |
| Broadcasts LOAD_MAP tagged with a new load id; each connected secondary counts as loading until it reports that load's episode ready. | |
| std::future< SessionInfo > | WriteToNext (MultiGPUCommand id, Buffer &&buffer) |
| std::future< SessionInfo > | WriteToOne (std::weak_ptr< Primary > server, MultiGPUCommand id, Buffer &&buffer) |
| ~Router () | |
Private Member Functions | |
| void | ClearSessions () |
| void | ConnectSession (std::shared_ptr< Primary > session) |
| void | DisconnectSession (std::shared_ptr< Primary > session) |
| void | HandleResponse (std::shared_ptr< Primary > session, Buffer buffer) |
| Re-arms the new-connection resync if buffer is the secondary's episode-ready marker (checked first, so it can never be misdelivered to a pending promise on the same session); otherwise resolves the pending promise for session with buffer, or logs and drops the data if no request is currently pending on it. | |
| void | RejectAllPending (std::string_view reason) |
| Rejects and clears every currently-pending promise. | |
| void | SendLoadMap (const std::shared_ptr< Primary > &session, std::string_view map, load_map_id_type load_id, const LoadMapExtras &extras) |
| Sends LOAD_MAP to one session. Caller must already hold _mutex. | |
Static Private Member Functions | |
| static void | RejectPromise (std::shared_ptr< std::promise< SessionInfo > > promise, std::string_view reason) |
| Fails a pending request instead of leaving its future unresolved. | |
Private Attributes | |
| std::function< void(void)> | _callback |
| PrimaryCommands | _commander |
| boost::asio::ip::tcp::endpoint | _endpoint |
| load_map_id_type | _last_load_id = 0u |
| std::optional< std::string > | _last_map |
| LoadMapExtras | _last_map_extras |
| std::shared_ptr< Listener > | _listener |
| std::unordered_map< const Primary *, load_map_id_type > | _loading |
| std::mutex | _mutex |
| std::vector< std::weak_ptr< Primary > > | _new_sessions |
| uint32_t | _next |
| ThreadPool | _pool |
| std::unordered_map< Primary *, std::shared_ptr< std::promise< SessionInfo > > > | _promises |
| request_observer_type | _request_observer |
| std::atomic_size_t | _session_count {0u} |
| std::vector< std::shared_ptr< Primary > > | _sessions |
| using carla::multigpu::Router::request_observer_type = std::function<void(const Primary *, MultiGPUCommand, const carla::BufferView &)> |
| carla::multigpu::Router::Router | ( | void | ) |
Definition at line 18 of file router.cpp.
|
explicit |
Definition at line 40 of file router.cpp.
References _endpoint, _listener, _pool, and carla::ThreadPool::io_context().
| carla::multigpu::Router::~Router | ( | ) |
Definition at line 21 of file router.cpp.
References Stop().
| void carla::multigpu::Router::AsyncRun | ( | size_t | worker_threads | ) |
Definition at line 81 of file router.cpp.
References _pool, and carla::ThreadPool::AsyncRun().
Referenced by TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
private |
Definition at line 175 of file router.cpp.
References _loading, _mutex, _new_sessions, _session_count, _sessions, carla::log_info(), and RejectAllPending().
Referenced by Stop().
|
private |
Definition at line 89 of file router.cpp.
References _callback, _last_load_id, _last_map, _last_map_extras, _loading, _mutex, _new_sessions, _session_count, _sessions, DEBUG_ASSERT, carla::log_info(), and SendLoadMap().
|
private |
Definition at line 107 of file router.cpp.
References _loading, _mutex, _promises, _session_count, _sessions, DEBUG_ASSERT, carla::log_info(), and RejectPromise().
|
inline |
| boost::asio::ip::tcp::endpoint carla::multigpu::Router::GetLocalEndpoint | ( | ) | const |
|
private |
Re-arms the new-connection resync if buffer is the secondary's episode-ready marker (checked first, so it can never be misdelivered to a pending promise on the same session); otherwise resolves the pending promise for session with buffer, or logs and drops the data if no request is currently pending on it.
Definition at line 142 of file router.cpp.
References _callback, _loading, _mutex, _promises, carla::Buffer::data(), carla::log_info(), carla::log_warning(), carla::multigpu::ParseEpisodeReadyMessage(), and carla::Buffer::size().
|
inline |
Any thread: reads a count kept next to the session list, which is itself only touched under the router's mutex.
Definition at line 81 of file router.h.
References _session_count.
Referenced by TEST_F().
| bool carla::multigpu::Router::IsAnySecondaryLoading | ( | ) |
Whether a connected secondary sent LOAD_MAP has not yet reported the episode of its latest LOAD_MAP ready (a disconnect also clears it).
Definition at line 243 of file router.cpp.
References _loading, and _mutex.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
| bool carla::multigpu::Router::IsConnected | ( | const std::weak_ptr< Primary > & | server | ) |
Whether server is still one of the connected secondary sessions.
Definition at line 295 of file router.cpp.
|
private |
Rejects and clears every currently-pending promise.
Caller must already hold _mutex.
Definition at line 128 of file router.cpp.
References _promises, and RejectPromise().
Referenced by ClearSessions().
|
staticprivate |
Fails a pending request instead of leaving its future unresolved.
A session can vanish (dead weak_ptr, disconnect, empty router) between the moment a promise is created and the moment a response would have arrived; without this, the caller's std::future::get() blocks forever.
The failure is delivered as a value (a SessionInfo with a null session), never through std::promise::set_exception(): inside the CarlaUnreal process std::rethrow_exception() binds to the libc++abi copy exported by libcarla-ros2-native.so, while exceptions are allocated and caught by libstdc++'s ABI. std::current_exception() then sees a foreign exception and returns null, so the rpc sync-call packaged_task becomes ready with neither a value nor an exception and the rpc thread reads an unconstructed result (SIGSEGV).
Definition at line 135 of file router.cpp.
References carla::log_error().
Referenced by DisconnectSession(), RejectAllPending(), WriteToNext(), and WriteToOne().
|
private |
Sends LOAD_MAP to one session. Caller must already hold _mutex.
Definition at line 208 of file router.cpp.
References _request_observer, carla::BufferView::CreateFrom(), carla::multigpu::CommandHeader::id, carla::multigpu::LOAD_MAP, carla::multigpu::MakeLoadMapPayload(), carla::multigpu::Primary::MakeMessage(), carla::Buffer::size(), and carla::multigpu::CommandHeader::size.
Referenced by ConnectSession(), and WriteLoadMap().
| void carla::multigpu::Router::SetCallbacks | ( | ) |
Definition at line 47 of file router.cpp.
References _commander, _endpoint, _listener, carla::log_info(), and carla::multigpu::PrimaryCommands::set_router().
Referenced by TEST().
| void carla::multigpu::Router::SetNewConnectionCallback | ( | std::function< void(void)> | func | ) |
| void carla::multigpu::Router::Stop | ( | ) |
Definition at line 25 of file router.cpp.
References _listener, _pool, ClearSessions(), and carla::ThreadPool::Stop().
| void carla::multigpu::Router::StopWaitingForSecondaryLoads | ( | ) |
| std::vector< std::weak_ptr< Primary > > carla::multigpu::Router::TakeNewSessions | ( | ) |
Sessions connected since the previous call, oldest first.
Definition at line 301 of file router.cpp.
References _mutex, and _new_sessions.
| void carla::multigpu::Router::Write | ( | MultiGPUCommand | id, |
| Buffer && | buffer | ||
| ) |
Definition at line 188 of file router.cpp.
References _mutex, _sessions, carla::BufferView::CreateFrom(), carla::multigpu::CommandHeader::id, carla::multigpu::Primary::MakeMessage(), and carla::multigpu::CommandHeader::size.
Referenced by TEST_F().
| load_map_id_type carla::multigpu::Router::WriteLoadMap | ( | std::string_view | map, |
| const LoadMapExtras & | extras = {} |
||
| ) |
Broadcasts LOAD_MAP tagged with a new load id; each connected secondary counts as loading until it reports that load's episode ready.
Definition at line 229 of file router.cpp.
References _last_load_id, _last_map, _last_map_extras, _loading, _mutex, _sessions, and SendLoadMap().
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
| std::future< SessionInfo > carla::multigpu::Router::WriteToNext | ( | MultiGPUCommand | id, |
| Buffer && | buffer | ||
| ) |
Definition at line 253 of file router.cpp.
References _mutex, _next, _promises, _request_observer, _sessions, carla::BufferView::CreateFrom(), carla::multigpu::CommandHeader::id, carla::multigpu::Primary::MakeMessage(), RejectPromise(), and carla::multigpu::CommandHeader::size.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
| std::future< SessionInfo > carla::multigpu::Router::WriteToOne | ( | std::weak_ptr< Primary > | server, |
| MultiGPUCommand | id, | ||
| Buffer && | buffer | ||
| ) |
Definition at line 306 of file router.cpp.
References _mutex, _promises, _request_observer, _sessions, carla::BufferView::CreateFrom(), carla::multigpu::CommandHeader::id, carla::multigpu::Primary::MakeMessage(), RejectPromise(), and carla::multigpu::CommandHeader::size.
|
private |
Definition at line 174 of file router.h.
Referenced by ConnectSession(), HandleResponse(), and SetNewConnectionCallback().
|
private |
Definition at line 173 of file router.h.
Referenced by GetCommander(), and SetCallbacks().
|
private |
Definition at line 162 of file router.h.
Referenced by GetLocalEndpoint(), Router(), and SetCallbacks().
|
private |
Definition at line 170 of file router.h.
Referenced by ConnectSession(), and WriteLoadMap().
|
private |
Definition at line 171 of file router.h.
Referenced by ConnectSession(), and WriteLoadMap().
|
private |
Definition at line 172 of file router.h.
Referenced by ConnectSession(), and WriteLoadMap().
|
private |
Definition at line 166 of file router.h.
Referenced by Router(), SetCallbacks(), and Stop().
|
private |
Definition at line 169 of file router.h.
Referenced by ClearSessions(), ConnectSession(), DisconnectSession(), HandleResponse(), IsAnySecondaryLoading(), StopWaitingForSecondaryLoads(), and WriteLoadMap().
|
private |
Definition at line 160 of file router.h.
Referenced by ClearSessions(), ConnectSession(), DisconnectSession(), HandleResponse(), IsAnySecondaryLoading(), IsConnected(), StopWaitingForSecondaryLoads(), TakeNewSessions(), Write(), WriteLoadMap(), WriteToNext(), and WriteToOne().
|
private |
Definition at line 165 of file router.h.
Referenced by ClearSessions(), ConnectSession(), and TakeNewSessions().
|
private |
Definition at line 167 of file router.h.
Referenced by WriteToNext().
|
private |
Definition at line 161 of file router.h.
Referenced by AsyncRun(), Router(), and Stop().
|
private |
Definition at line 168 of file router.h.
Referenced by DisconnectSession(), HandleResponse(), RejectAllPending(), WriteToNext(), and WriteToOne().
|
private |
Definition at line 175 of file router.h.
Referenced by SendLoadMap(), WriteToNext(), and WriteToOne().
|
private |
Definition at line 164 of file router.h.
Referenced by ClearSessions(), ConnectSession(), DisconnectSession(), and HasClientsConnected().
|
private |
Definition at line 163 of file router.h.
Referenced by ClearSessions(), ConnectSession(), DisconnectSession(), IsConnected(), Write(), WriteLoadMap(), WriteToNext(), and WriteToOne().