A mapping from {bus_name: interface} with sugar for error checking with nice error messages during access.
Note that this class is shallow-const. A user of a const LcmBuses object cannot add or remove buses, but can retrieve a non-const DrakeLcmInterface pointer and then "modify" the object it points to by subscribing to a channel.
#include <drake/systems/lcm/lcm_buses.h>
Public Member Functions | |
LcmBuses () | |
Constructs an empty mapping. More... | |
~LcmBuses () | |
int | size () const |
Returns the total number of buses. More... | |
drake::lcm::DrakeLcmInterface * | Find (std::string_view description_of_caller, const std::string &bus_name) const |
Finds the bus of the given name, or throws if there is no such bus. More... | |
std::vector< std::string_view > | GetAllBusNames () const |
Returns a list of all known bus_name keys. More... | |
void | Add (std::string bus_name, drake::lcm::DrakeLcmInterface *) |
Adds a bus. More... | |
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable | |
LcmBuses (const LcmBuses &)=default | |
LcmBuses & | operator= (const LcmBuses &)=default |
LcmBuses (LcmBuses &&)=default | |
LcmBuses & | operator= (LcmBuses &&)=default |
Static Public Attributes | |
static constexpr char | kLcmUrlMemqNull [] = "memq://null" |
A magic LCM URL sentinel value for the "null" LCM interface. More... | |
LcmBuses | ( | ) |
Constructs an empty mapping.
~LcmBuses | ( | ) |
void Add | ( | std::string | bus_name, |
drake::lcm::DrakeLcmInterface * | |||
) |
Adds a bus.
Throws if the bus is nullptr, or if there was already a bus of the same name.
drake::lcm::DrakeLcmInterface* Find | ( | std::string_view | description_of_caller, |
const std::string & | bus_name | ||
) | const |
Finds the bus of the given name, or throws if there is no such bus.
The return value is an alias into memory owned elsewhere (typically by a DiagramBuilder or a Diagram) and is never nullptr.
description_of_caller | is a noun phrase that will be used when creating an error message. A typical value would be something like "Camera 5", "Robot controller", "The default visualizer", or etc. |
std::vector<std::string_view> GetAllBusNames | ( | ) | const |
Returns a list of all known bus_name keys.
int size | ( | ) | const |
Returns the total number of buses.
|
static |
A magic LCM URL sentinel value for the "null" LCM interface.
In some cases, LCM messages are unwanted but we need to pass around a well-formed DrakeLcmParams or DrakeLcmInterface object. Instead of passing nullptr
objects, instead we pass an object set to use this URL. For example, this URL is used when ApplyLcmBusConfig() is given a nullopt
DrakeLcmParams. The expectation is that interfaces with this URL will not even be pumped (i.e., no calls to HandleSubscriptions).