CARLA
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
carla::multigpu::PrimaryCommands Class Reference

#include <primaryCommands.h>

Classes

struct  Route
 

Public Member Functions

void DisableForROS (stream_id sensor_id)
 
bool EnableForROS (stream_id sensor_id, actor_id sensor_actor_id)
 Returns false if no secondary accepted this sensor or the secondary holding it did not reply; ROS enablement has not happened in that case.
 
void ForgetSensor (stream_id sensor_id)
 Drops the routing of a destroyed sensor so it is never routed again.
 
std::optional< token_type > GetToken (stream_id sensor_id, actor_id sensor_actor_id)
 Returns std::nullopt if no secondary could provide the token (e.g.
 
bool IsEnabledForROS (stream_id sensor_id)
 
 PrimaryCommands ()
 
 PrimaryCommands (std::shared_ptr< Router > router)
 
std::size_t RerouteLostSensors ()
 Routes every sensor whose secondary disconnected to the secondaries connected since the previous call, under the same primary stream id, so clients already subscribed reconnect to it without a new listen().
 
void SendFrameData (carla::Buffer buffer)
 
void SendIsAlive ()
 
void SendLoadMap (std::string map, const LoadMapExtras &extras={})
 
void set_router (std::shared_ptr< Router > router)
 

Private Types

enum class  TokenError { None , NoReply , Refused }
 

Private Member Functions

bool IsRoutedToLiveSecondary (stream_id sensor_id)
 Whether sensor_id is routed to a secondary that is still connected.
 
void RestoreRosAfterReroute (stream_id sensor_id)
 Enables ROS again on the new secondary of a re-routed sensor if it was enabled before.
 
void SendDisableForROS (stream_id sensor_id)
 
bool SendEnableForROS (stream_id sensor_id)
 
std::optional< token_type > SendGetToken (stream_id sensor_id, actor_id sensor_actor_id, const std::weak_ptr< Primary > *target, std::weak_ptr< Primary > &out_session, TokenError &error)
 
bool SendIsEnabledForROS (stream_id sensor_id)
 

Static Private Member Functions

static bool ReadBoolReply (const carla::Buffer &buffer)
 Reads a one-bool reply; buffer must not be empty.
 

Private Attributes

std::mutex _mutex
 
std::shared_ptr< Router > _router
 
std::unordered_map< stream_id, Route > _servers
 
std::unordered_map< stream_id, token_type > _tokens
 

Detailed Description

Definition at line 32 of file primaryCommands.h.

Member Enumeration Documentation

◆ TokenError

Enumerator
None 
NoReply 
Refused 

Definition at line 90 of file primaryCommands.h.

Constructor & Destructor Documentation

◆ PrimaryCommands() [1/2]

carla::multigpu::PrimaryCommands::PrimaryCommands ( )

Definition at line 25 of file primaryCommands.cpp.

◆ PrimaryCommands() [2/2]

carla::multigpu::PrimaryCommands::PrimaryCommands ( std::shared_ptr< Router >  router)

Definition at line 28 of file primaryCommands.cpp.

Member Function Documentation

◆ DisableForROS()

void carla::multigpu::PrimaryCommands::DisableForROS ( stream_id  sensor_id)

Definition at line 235 of file primaryCommands.cpp.

References _mutex, _router, _servers, and SendDisableForROS().

Referenced by TEST_F(), TEST_F(), and TEST_F().

◆ EnableForROS()

bool carla::multigpu::PrimaryCommands::EnableForROS ( stream_id  sensor_id,
actor_id  sensor_actor_id 
)

Returns false if no secondary accepted this sensor or the secondary holding it did not reply; ROS enablement has not happened in that case.

Definition at line 213 of file primaryCommands.cpp.

References _mutex, _servers, EnableForROS(), GetToken(), IsRoutedToLiveSecondary(), carla::log_error(), and SendEnableForROS().

Referenced by EnableForROS(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ ForgetSensor()

void carla::multigpu::PrimaryCommands::ForgetSensor ( stream_id  sensor_id)

Drops the routing of a destroyed sensor so it is never routed again.

Definition at line 300 of file primaryCommands.cpp.

References _mutex, _servers, and _tokens.

Referenced by TEST_F().

◆ GetToken()

std::optional< token_type > carla::multigpu::PrimaryCommands::GetToken ( stream_id  sensor_id,
actor_id  sensor_actor_id 
)

Returns std::nullopt if no secondary could provide the token (e.g.

the selected secondary disconnected with the request in flight, or has no episode loaded). Nothing is cached on failure, so a later call for the same sensor retries. A sensor whose secondary disconnected is routed again here. sensor_actor_id is the primary's id of the sensor actor, which the secondary resolves to its own sensor stream.

Definition at line 175 of file primaryCommands.cpp.

References _mutex, _servers, _tokens, first, IsRoutedToLiveSecondary(), carla::log_debug(), carla::log_warning(), None, Refused, RestoreRosAfterReroute(), and SendGetToken().

Referenced by EnableForROS(), 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().

◆ IsEnabledForROS()

bool carla::multigpu::PrimaryCommands::IsEnabledForROS ( stream_id  sensor_id)

Definition at line 247 of file primaryCommands.cpp.

References _mutex, IsRoutedToLiveSecondary(), and SendIsEnabledForROS().

Referenced by TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ IsRoutedToLiveSecondary()

bool carla::multigpu::PrimaryCommands::IsRoutedToLiveSecondary ( stream_id  sensor_id)
private

Whether sensor_id is routed to a secondary that is still connected.

Caller must hold _mutex.

Definition at line 306 of file primaryCommands.cpp.

References _router, and _servers.

Referenced by EnableForROS(), GetToken(), and IsEnabledForROS().

◆ ReadBoolReply()

bool carla::multigpu::PrimaryCommands::ReadBoolReply ( const carla::Buffer &  buffer)
staticprivate

Reads a one-bool reply; buffer must not be empty.

Definition at line 321 of file primaryCommands.cpp.

References carla::Buffer::data().

Referenced by SendDisableForROS(), SendEnableForROS(), and SendIsEnabledForROS().

◆ RerouteLostSensors()

std::size_t carla::multigpu::PrimaryCommands::RerouteLostSensors ( )

Routes every sensor whose secondary disconnected to the secondaries connected since the previous call, under the same primary stream id, so clients already subscribed reconnect to it without a new listen().

The first new secondary that stays connected takes every lost sensor. A sensor the new secondary refuses is forgotten and routed lazily later; if it disconnects instead, the sensor stays lost for the next one. ROS publishing enabled through EnableForROS() is enabled again. Blocks on round trips; never call it from a Router callback. Returns how many sensors were routed again.

Definition at line 255 of file primaryCommands.cpp.

References _mutex, _router, _servers, _tokens, carla::log_info(), carla::log_warning(), None, NoReply, RestoreRosAfterReroute(), and SendGetToken().

Referenced by 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().

◆ RestoreRosAfterReroute()

void carla::multigpu::PrimaryCommands::RestoreRosAfterReroute ( stream_id  sensor_id)
private

Enables ROS again on the new secondary of a re-routed sensor if it was enabled before.

Caller must hold _mutex.

Definition at line 311 of file primaryCommands.cpp.

References _servers, carla::log_warning(), and SendEnableForROS().

Referenced by GetToken(), and RerouteLostSensors().

◆ SendDisableForROS()

void carla::multigpu::PrimaryCommands::SendDisableForROS ( stream_id  sensor_id)
private

◆ SendEnableForROS()

bool carla::multigpu::PrimaryCommands::SendEnableForROS ( stream_id  sensor_id)
private

◆ SendFrameData()

void carla::multigpu::PrimaryCommands::SendFrameData ( carla::Buffer  buffer)

Definition at line 37 of file primaryCommands.cpp.

References _router, and carla::multigpu::SEND_FRAME.

◆ SendGetToken()

std::optional< token_type > carla::multigpu::PrimaryCommands::SendGetToken ( stream_id  sensor_id,
actor_id  sensor_actor_id,
const std::weak_ptr< Primary > *  target,
std::weak_ptr< Primary > &  out_session,
TokenError &  error 
)
private

◆ SendIsAlive()

void carla::multigpu::PrimaryCommands::SendIsAlive ( )

◆ SendIsEnabledForROS()

bool carla::multigpu::PrimaryCommands::SendIsEnabledForROS ( stream_id  sensor_id)
private

◆ SendLoadMap()

void carla::multigpu::PrimaryCommands::SendLoadMap ( std::string  map,
const LoadMapExtras &  extras = {} 
)

Definition at line 43 of file primaryCommands.cpp.

References _mutex, _router, _servers, and _tokens.

Referenced by TEST_F(), and TEST_F().

◆ set_router()

void carla::multigpu::PrimaryCommands::set_router ( std::shared_ptr< Router >  router)

Definition at line 32 of file primaryCommands.cpp.

References _router.

Referenced by carla::multigpu::Router::SetCallbacks(), and TEST().

Member Data Documentation

◆ _mutex

std::mutex carla::multigpu::PrimaryCommands::_mutex
private

◆ _router

std::shared_ptr<Router> carla::multigpu::PrimaryCommands::_router
private

◆ _servers

std::unordered_map<stream_id, Route> carla::multigpu::PrimaryCommands::_servers
private

◆ _tokens

std::unordered_map<stream_id, token_type> carla::multigpu::PrimaryCommands::_tokens
private

Definition at line 121 of file primaryCommands.h.

Referenced by ForgetSensor(), GetToken(), RerouteLostSensors(), and SendLoadMap().


The documentation for this class was generated from the following files: