Class GraphCache
Defined in File graph_cache.hpp
Class Documentation
-
class rmw_dds_common::GraphCache
Graph cache data structure.
Manages relationships between participants, nodes, and topics.
Public Types
-
using DemangleFunctionT = std::function<std::string(const std::string&)>
Callable used to demangle a name.
-
using NodeEntitiesInfoSeq = decltype(std::declval<rmw_dds_common::msg::ParticipantEntitiesInfo>().node_entities_info_seq)
-
using EntityGidToInfo = std::map<rmw_gid_t, EntityInfo, Compare_rmw_gid_t>
-
using ParticipantToNodesMap = std::map<rmw_gid_t, ParticipantInfo, Compare_rmw_gid_t>
-
using GidSeq = decltype(std::declval<rmw_dds_common::msg::NodeEntitiesInfo>().writer_gid_seq)
Public Functions
-
template<typename CallbackT>
inline void set_on_change_callback(CallbackT &&callback) Set a callback that will be called when the state of the object changes.
- Parameters
callback – callback to be called.
-
void clear_on_change_callback()
Clear previously registered “on change” callback.
-
bool add_writer(const rmw_gid_t &writer_gid, const std::string &topic_name, const std::string &type_name, const rmw_gid_t &participant_gid, const rmw_qos_profile_t &qos)
Add a data writer.
- Parameters
writer_gid – GUID of the data writer.
topic_name – Name of the DDS topic for this data writer.
type_name – Type name of the DDS topic for this data writer.
participant_gid – GUID of the participant.
qos – QoS profile of the data writer.
- Returns
true
if the cache was updated,false
if the data writer was already present.
-
bool add_reader(const rmw_gid_t &reader_gid, const std::string &topic_name, const std::string &type_name, const rmw_gid_t &participant_gid, const rmw_qos_profile_t &qos)
Add a data reader based on discovery.
- Parameters
reader_gid – GUID of the The data reader.
topic_name – Name of the DDS topic for this data reader.
type_name – Type name of the DDS topic for this data reader.
participant_gid – GUID of the participant.
qos – QoS profile of the data reader.
- Returns
true
if the cache was updated,false
if the data reader was already present.
-
bool add_entity(const rmw_gid_t &gid, const std::string &topic_name, const std::string &type_name, const rmw_gid_t &participant_gid, const rmw_qos_profile_t &qos, bool is_reader)
Add a data reader or writer.
- Parameters
gid – GUID of the entity.
topic_name – Name of the DDS topic for this data reader.
type_name – Type name of the DDS topic for this entity
participant_gid – GUID of the participant.
qos – QoS profile of the entity.
is_reader – Whether the entity is a data reader or a writer.
- Returns
true
if the cache was updated,false
if the entity was already present.
-
bool remove_writer(const rmw_gid_t &gid)
Remove a data writer.
- Parameters
gid – GUID of the data writer.
- Returns
true
if the cache was updated,false
if the data writer was not present.
-
bool remove_reader(const rmw_gid_t &gid)
Remove a data reader.
- Parameters
gid – GUID of the The data reader.
- Returns
true
if the cache was updated,false
if the data reader was not present.
-
bool remove_entity(const rmw_gid_t &gid, bool is_reader)
Remove a data reader or writer.
- Parameters
gid – GUID of the entity.
is_reader – Whether the entity is a data reader or a writer.
- Returns
true
when a the cache was upated,false
if the entity was not present.
-
void add_participant(const rmw_gid_t &participant_gid, const std::string &enclave)
Add a participant.
- Parameters
participant_gid – GUID of the participant.
enclave – Name of the enclave.
-
bool remove_participant(const rmw_gid_t &participant_gid)
Remove a participant.
- Parameters
participant_gid – GUID of the participant.
- Returns
true
when a change took place.
-
void update_participant_entities(const rmw_dds_common::msg::ParticipantEntitiesInfo &msg)
Update cached participant info from a
ParticipantEntitiesInfo
message.- Parameters
msg – participant info to update cache from.
-
rmw_dds_common::msg::ParticipantEntitiesInfo add_node(const rmw_gid_t &participant_gid, const std::string &node_name, const std::string &node_namespace)
Add a node to the graph.
- Parameters
participant_gid – GUID of the participant.
node_name – Name of the node to be added.
node_namespace – Namespace of the node to be added.
- Returns
Message to update other caches.
-
rmw_dds_common::msg::ParticipantEntitiesInfo remove_node(const rmw_gid_t &participant_gid, const std::string &node_name, const std::string &node_namespace)
Remove a node from the graph.
- Parameters
participant_gid – GUID of the participant.
node_name – Name of the node to be removed.
node_namespace – Namespace of the node to be removed.
- Returns
Message to update other caches.
-
rmw_dds_common::msg::ParticipantEntitiesInfo associate_writer(const rmw_gid_t &writer_gid, const rmw_gid_t &participant_gid, const std::string &node_name, const std::string &node_namespace)
Associate a data writer with a node.
- Parameters
writer_gid – GUID of the data writer.
participant_gid – GUID of the participant.
node_name – Name of the target node.
node_namespace – Namespace of the target node.
- Returns
Message to update other caches.
-
rmw_dds_common::msg::ParticipantEntitiesInfo dissociate_writer(const rmw_gid_t &writer_gid, const rmw_gid_t &participant_gid, const std::string &node_name, const std::string &node_namespace)
Dissociate a data writer from a node.
- Parameters
writer_gid – GUID of the data writer.
participant_gid – GUID of the participant.
node_name – Name of the target node.
node_namespace – Namespace of the target node.
- Returns
Message to update other caches.
-
rmw_dds_common::msg::ParticipantEntitiesInfo associate_reader(const rmw_gid_t &reader_gid, const rmw_gid_t &participant_gid, const std::string &node_name, const std::string &node_namespace)
Associate a data reader with a node.
- Parameters
reader_gid – GUID of the data reader.
participant_gid – GUID of the participant.
node_name – Name of the target node.
node_namespace – Namespace of target node.
- Returns
Message to update other caches.
-
rmw_dds_common::msg::ParticipantEntitiesInfo dissociate_reader(const rmw_gid_t &reader_gid, const rmw_gid_t &participant_gid, const std::string &node_name, const std::string &node_namespace)
Dissociate a data reader from a node.
- Parameters
reader_gid – GUID of the data reader.
participant_gid – GUID of the participant.
node_name – Name of the target node.
node_namespace – Namespace of target node.
- Returns
Message to update other caches.
-
rmw_ret_t get_writer_count(const std::string &topic_name, size_t *count) const
Get the number of data writers for a DDS topic.
- Parameters
topic_name – [in] Name of the DDS topic.
count – [out] Number of data writers.
- Returns
RMW_RET_INVALID_ARGUMENT if count is
nullptr
, or- Returns
RMW_RET_ERROR if an unexpected error take place, or
- Returns
RMW_RET_OK.
-
rmw_ret_t get_reader_count(const std::string &topic_name, size_t *count) const
Get the number of data readers for a DDS topic.
- Parameters
topic_name – [in] Name of the DDS topic.
count – [out] Number of data readers.
- Returns
RMW_RET_INVALID_ARGUMENT if count is
nullptr
, or- Returns
RMW_RET_ERROR if an unexpected error take place, or
- Returns
RMW_RET_OK.
-
rmw_ret_t get_writers_info_by_topic(const std::string &topic_name, DemangleFunctionT demangle_type, rcutils_allocator_t *allocator, rmw_topic_endpoint_info_array_t *endpoints_info) const
Get an array with information about the data writers for a DDS topic.
- Parameters
topic_name – [in] Name of the DDS topic.
demangle_type – [in] Function to demangle DDS topic type names.
allocator – [in] To allocate memory when populating
endpoints_info
.endpoints_info – [out] A zero initialized topic endpoint information array to be populated with data writers’ info.
- Returns
RMW_RET_INVALID_ARGUMENT if count is
nullptr
, or- Returns
RMW_RET_ERROR if an unexpected error take place, or
- Returns
RMW_RET_OK.
-
rmw_ret_t get_readers_info_by_topic(const std::string &topic_name, DemangleFunctionT demangle_type, rcutils_allocator_t *allocator, rmw_topic_endpoint_info_array_t *endpoints_info) const
Get an array with information about the data readers for a DDS topic.
- Parameters
topic_name – [in] Name of the DDS topic.
demangle_type – [in] Function to demangle DDS topic type names.
allocator – [in] To allocate memory when populating
endpoints_info
.endpoints_info – [out] A zero initialized topic endpoint information array to be populated with data readers’ info.
- Returns
RMW_RET_INVALID_ARGUMENT if count is
nullptr
, or- Returns
RMW_RET_ERROR if an unexpected error take place, or
- Returns
RMW_RET_OK.
-
rmw_ret_t get_names_and_types(DemangleFunctionT demangle_topic, DemangleFunctionT demangle_type, rcutils_allocator_t *allocator, rmw_names_and_types_t *topic_names_and_types) const
Get all topic names and types.
- Parameters
demangle_topic – [in] Function to demangle DDS topic names.
demangle_type – [in] Function to demangle DDS topic type names.
allocator – [in] To allocate memory when populating
topic_names_and_types
.topic_names_and_types – [inout] A zero initialized names and types collection to be populated with the result.
- Returns
RMW_RET_INVALID_ARGUMENT if an argument is invalid, or
- Returns
RMW_RET_BAD_ALLOC if an allocation failed, or
- Returns
RMW_RET_ERROR if an unexpected error happened, or
- Returns
RMW_RET_OK.
-
rmw_ret_t get_writer_names_and_types_by_node(const std::string &node_name, const std::string &namespace_, DemangleFunctionT demangle_topic, DemangleFunctionT demangle_type, rcutils_allocator_t *allocator, rmw_names_and_types_t *topic_names_and_types) const
Get topic names and types for all data writers associated to a node.
- Parameters
node_name – [in] Name of the node.
namespace_ – [in] Namespace of the node.
demangle_topic – [in] Function to demangle DDS topic names.
demangle_type – [in] Function to demangle DDS topic type names.
allocator – [in] To allocate memory when populating
topic_names_and_types
.topic_names_and_types – [inout] A zero initialized names and types collection to be populated with the result.
- Returns
RMW_RET_NODE_NAME_NON_EXISTENT if the node doesn’t exist, or
- Returns
RMW_RET_INVALID_ARGUMENT if an argument is invalid, or
- Returns
RMW_RET_BAD_ALLOC if an allocation failed, or
- Returns
RMW_RET_ERROR if an unexpected error happened, or
- Returns
RMW_RET_OK.
-
rmw_ret_t get_reader_names_and_types_by_node(const std::string &node_name, const std::string &namespace_, DemangleFunctionT demangle_topic, DemangleFunctionT demangle_type, rcutils_allocator_t *allocator, rmw_names_and_types_t *topic_names_and_types) const
Get the topic names and types for all data readers associated to a node.
- Parameters
node_name – [in] Name of the node.
namespace_ – [in] Namespace of the node.
demangle_topic – [in] Function to demangle DDS topic names.
demangle_type – [in] Function to demangle DDS topic type names.
allocator – [in] To allocate memory when populating
topic_names_and_types
.topic_names_and_types – [inout] A zero initialized names and types collection to be populated with the result.
- Returns
RMW_RET_NODE_NAME_NON_EXISTENT if the node doesn’t exist, or
- Returns
RMW_RET_INVALID_ARGUMENT if an argument is invalid, or
- Returns
RMW_RET_BAD_ALLOC if an allocation failed, or
- Returns
RMW_RET_ERROR if an unexpected error happened, or
- Returns
RMW_RET_OK.
-
size_t get_number_of_nodes() const
Get the number of nodes that have been discovered.
-
rmw_ret_t get_node_names(rcutils_string_array_t *node_names, rcutils_string_array_t *node_namespaces, rcutils_string_array_t *enclaves, rcutils_allocator_t *allocator) const
Get the names, namespaces, and enclaves of all nodes.
- Parameters
node_names – [inout] A zero initialized string array to be populated with node names.
node_namespaces – [inout] A zero initialized string array to be populated with node namespaces. Each item in this array corresponds to the item at the same position in
node_names
.enclaves – [inout] A zero initialized string array to be populated with node enclaves. Each item in this array corresponds to the item at the same position in
node_names
. Ifnullptr
, it will be ignored.allocator – [in] To allocate memory when populating
node_names
,node_namespaces
, andenclaves
.
- Returns
RMW_RET_INVALID_ARGUMENT if an argument is invalid, or
- Returns
RMW_RET_BAD_ALLOC if an allocation failed, or
- Returns
RMW_RET_ERROR if an unexpected error occurred, or
- Returns
RMW_RET_OK.
-
using DemangleFunctionT = std::function<std::string(const std::string&)>