mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 18:05:17 +02:00
Feature/graph manager (#38)
* Initial changes * Working state * Working state * Working state * Working state * Working state * Working state * Added graph listener * Updates * Testing name demangling * Graph manager: reworked * Remove debug trace * Treat errors when freeing rcutils resources * Improve logics for discovering entities * Working state: Micro-ROS graph manager * Fix micro_ros_graph_info typesupport type name * Remove double CMakeLists comment * Remove package.xml commented block * Add missing include * Added CI * Remove GUID_t param from callbacks signature * Add services names and types to micro-ROS graph topic * Differenciate between service server and clients * remove debug traces Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
This commit is contained in:
co-authored by
Pablo Garrido
parent
dce3c25a33
commit
23bcea8efb
@@ -0,0 +1,49 @@
|
||||
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _UROS_AGENT_AGENT_HPP
|
||||
#define _UROS_AGENT_AGENT_HPP
|
||||
|
||||
#include <uxr/agent/AgentInstance.hpp>
|
||||
#include <uxr/agent/middleware/Middleware.hpp>
|
||||
#include <uxr/agent/middleware/utils/Callbacks.hpp>
|
||||
|
||||
#include <agent/graph_manager/graph_manager.hpp>
|
||||
// TODO(jamoralp): class Documentation
|
||||
namespace uros {
|
||||
namespace agent {
|
||||
|
||||
class Agent
|
||||
{
|
||||
public:
|
||||
|
||||
Agent();
|
||||
|
||||
~Agent() = default;
|
||||
|
||||
bool create(
|
||||
int argc,
|
||||
char** argv);
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
|
||||
eprosima::uxr::AgentInstance& xrce_dds_agent_instance_;
|
||||
std::unique_ptr<graph_manager::GraphManager> graph_manager_;
|
||||
};
|
||||
|
||||
} // namespace agent
|
||||
} // namespace uros
|
||||
#endif // _UROS_AGENT_AGENT_HPP
|
||||
@@ -0,0 +1,322 @@
|
||||
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastrtps/Domain.h"
|
||||
#include <fastrtps/TopicDataType.h>
|
||||
#include "fastrtps/attributes/ParticipantAttributes.h"
|
||||
#include "fastrtps/participant/Participant.h"
|
||||
#include "fastrtps/participant/ParticipantListener.h"
|
||||
#include "fastrtps/attributes/PublisherAttributes.h"
|
||||
#include "fastrtps/publisher/Publisher.h"
|
||||
#include <fastrtps/publisher/PublisherListener.h>
|
||||
#include <fastrtps/rtps/common/MatchingInfo.h>
|
||||
|
||||
#include <fastdds/dds/domain/DomainParticipant.hpp>
|
||||
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
|
||||
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
|
||||
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
|
||||
#include <fastdds/dds/publisher/DataWriter.hpp>
|
||||
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
|
||||
#include <fastdds/dds/publisher/Publisher.hpp>
|
||||
#include <fastdds/dds/subscriber/DataReader.hpp>
|
||||
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
|
||||
#include <fastdds/dds/subscriber/SampleInfo.hpp>
|
||||
#include <fastdds/dds/subscriber/Subscriber.hpp>
|
||||
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
|
||||
|
||||
#include "rmw/types.h"
|
||||
#include "rmw/names_and_types.h"
|
||||
#include "rmw/impl/cpp/key_value.hpp"
|
||||
#include "rmw_dds_common/graph_cache.hpp"
|
||||
#include "rmw_fastrtps_shared_cpp/create_rmw_gid.hpp"
|
||||
#include "rmw_fastrtps_shared_cpp/qos.hpp"
|
||||
|
||||
#include "rcutils/types.h"
|
||||
#include "rcutils/types/string_array.h"
|
||||
|
||||
#include "rosidl_typesupport_cpp/message_type_support.hpp"
|
||||
#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h"
|
||||
|
||||
#include "rmw_dds_common/msg/participant_entities_info.hpp"
|
||||
#include "micro_ros_msgs/msg/graph.hpp"
|
||||
#include "micro_ros_msgs/msg/node.hpp"
|
||||
#include "micro_ros_msgs/msg/entity.hpp"
|
||||
|
||||
#include <uxr/agent/types/XRCETypes.hpp>
|
||||
|
||||
#include <agent/graph_manager/graph_typesupport.hpp>
|
||||
#include <agent/utils/demangle.hpp>
|
||||
|
||||
#ifndef _UROS_AGENT_GRAPH_MANAGER_HPP
|
||||
#define _UROS_AGENT_GRAPH_MANAGER_HPP
|
||||
|
||||
namespace uros {
|
||||
namespace agent {
|
||||
namespace graph_manager {
|
||||
|
||||
/**
|
||||
* @brief Class that keeps track of the existing entities in the ROS 2 world,
|
||||
* both coming from micro-ROS or from external ROS 2 applications.
|
||||
*/
|
||||
class GraphManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor.
|
||||
*/
|
||||
GraphManager();
|
||||
|
||||
/**
|
||||
* @brief Default destructor.
|
||||
*/
|
||||
~GraphManager() = default;
|
||||
|
||||
/**
|
||||
* @brief Implementation of the notification logic that updates the micro-ROS graph.
|
||||
*/
|
||||
void publish_microros_graph();
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS participant to the graph tree.
|
||||
* @param participant Pointer to the participant to be added to the graph.
|
||||
*/
|
||||
void add_participant(
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant);
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS participant to the graph tree.
|
||||
* @param guid rtps::GUID_t of the participant to be added.
|
||||
* @param node_name Name of the ROS 2 node associated to the given participant.
|
||||
* @param enclave ROS 2 enclave.
|
||||
*/
|
||||
void add_participant(
|
||||
const eprosima::fastrtps::rtps::GUID_t& guid,
|
||||
const std::string& node_name,
|
||||
const std::string& enclave);
|
||||
|
||||
/**
|
||||
* @brief Removes a DDS participant from the graph tree.
|
||||
* @param guid rtps::GUID_t of the participant to be removed.
|
||||
*/
|
||||
void remove_participant(
|
||||
const eprosima::fastrtps::rtps::GUID_t& guid);
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS datawriter to the graph tree.
|
||||
* @param datawriter_guid rtps::GUID_t of the datawriter to be added.
|
||||
* @param participant Pointer to the participant which owns this datawriter.
|
||||
* @param datawriter Pointer to the datawriter to be added.
|
||||
*/
|
||||
void add_datawriter(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datawriter_guid,
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const eprosima::fastdds::dds::DataWriter* datawriter);
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS datawriter to the graph tree.
|
||||
* @param datawriter_guid rtps::GUID_t of the datawriter to be added.
|
||||
* @param topic_name Name of the topic to which the datawriter sends information to.
|
||||
* @param type_name Type name of the sent topic.
|
||||
* @param participant_guid rtps::GUID_t of the participant which owns this datawriter.
|
||||
* @param writer_qos QOS of the datawriter to be included into the graph tree.
|
||||
*/
|
||||
void add_datawriter(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datawriter_guid,
|
||||
const std::string& topic_name,
|
||||
const std::string& type_name,
|
||||
const eprosima::fastrtps::rtps::GUID_t& participant_guid,
|
||||
const eprosima::fastdds::dds::DataWriterQos& writer_qos);
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS datawriter to the graph tree.
|
||||
* @param datawriter_guid rtps::GUID_t of the datawriter to be added.
|
||||
* @param topic_name Name of the topic to which the datawriter sends information to.
|
||||
* @param type_name Type name of the sent topic.
|
||||
* @param participant_guid rtps::GUID_t of the participant which owns this datawriter.
|
||||
* @param writer_qos QOS of the datawriter to be included into the graph tree.
|
||||
*/
|
||||
void add_datawriter(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datawriter_guid,
|
||||
const std::string& topic_name,
|
||||
const std::string& type_name,
|
||||
const eprosima::fastrtps::rtps::GUID_t& participant_guid,
|
||||
const eprosima::fastdds::dds::WriterQos& writer_qos);
|
||||
|
||||
/**
|
||||
* @brief Removes a DDS datawriter from the graph tree.
|
||||
* @param datawriter_guid rtps::GUID_t of the datawriter to be removed.
|
||||
*/
|
||||
void remove_datawriter(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datawriter_guid);
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS datareader to the graph tree.
|
||||
* @param datareader_guid rtps::GUID_t of the datareader to be added.
|
||||
* @param participant Pointer to the participant which owns this datareader.
|
||||
* @param datareader Pointer to the datareader to be added.
|
||||
*/
|
||||
void add_datareader(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datareader_guid,
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const eprosima::fastdds::dds::DataReader* datareader);
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS datareader to the graph tree.
|
||||
* @param datareader_guid rtps::GUID_t of the datareader to be added.
|
||||
* @param topic_name Name of the topic to which the datareader sends information to.
|
||||
* @param type_name Type name of the sent topic.
|
||||
* @param participant_guid rtps::GUID_t of the participant which owns this datareader.
|
||||
* @param writer_qos QOS of the datareader to be included into the graph tree.
|
||||
*/
|
||||
void add_datareader(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datareader_guid,
|
||||
const std::string& topic_name,
|
||||
const std::string& type_name,
|
||||
const eprosima::fastrtps::rtps::GUID_t& participant_guid,
|
||||
const eprosima::fastdds::dds::DataReaderQos& reader_qos);
|
||||
|
||||
/**
|
||||
* @brief Adds a DDS datareader to the graph tree.
|
||||
* @param datareader_guid rtps::GUID_t of the datareader to be added.
|
||||
* @param topic_name Name of the topic to which the datareader sends information to.
|
||||
* @param type_name Type name of the sent topic.
|
||||
* @param participant_guid rtps::GUID_t of the participant which owns this datareader.
|
||||
* @param writer_qos QOS of the datareader to be included into the graph tree.
|
||||
*/
|
||||
void add_datareader(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datareader_guid,
|
||||
const std::string& topic_name,
|
||||
const std::string& type_name,
|
||||
const eprosima::fastrtps::rtps::GUID_t& participant_guid,
|
||||
const eprosima::fastdds::dds::ReaderQos& reader_qos);
|
||||
|
||||
/**
|
||||
* @brief Removes a DDS datareader from the graph tree.
|
||||
* @param datareader_guid rtps::GUID_t of the datareader to be removed.
|
||||
*/
|
||||
void remove_datareader(
|
||||
const eprosima::fastrtps::rtps::GUID_t& datareader_guid);
|
||||
|
||||
/**
|
||||
* @brief Associates a certain DDS entity with a provided participant.
|
||||
* @param guid rtps::GUID_t identifier of the entity.
|
||||
* @param participant Participant to be associated with.
|
||||
* @param entity_kind Kind of the DDS entity.
|
||||
*/
|
||||
void associate_entity(
|
||||
const eprosima::fastrtps::rtps::GUID_t& entity_guid,
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const dds::xrce::ObjectKind& entity_kind);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Implementation of FastDDS' DomainParticipantListener abstract class.
|
||||
*/
|
||||
class ParticipantListener : public eprosima::fastdds::dds::DomainParticipantListener
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
* @param graph_manager Pointer to the GraphManager object which owns this ParticipantListener.
|
||||
*/
|
||||
ParticipantListener(
|
||||
GraphManager* graph_manager);
|
||||
private:
|
||||
|
||||
template <typename Info>
|
||||
void process_discovery_info(
|
||||
const Info& proxyData);
|
||||
|
||||
void on_participant_discovery(
|
||||
eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override;
|
||||
|
||||
void on_subscriber_discovery(
|
||||
eprosima::fastdds::dds::DomainParticipant* /*participant*/,
|
||||
eprosima::fastrtps::rtps::ReaderDiscoveryInfo&& info) override;
|
||||
|
||||
void on_publisher_discovery(
|
||||
eprosima::fastdds::dds::DomainParticipant* /*participant*/,
|
||||
eprosima::fastrtps::rtps::WriterDiscoveryInfo&& info) override;
|
||||
|
||||
GraphManager* graphManager_from_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Implementation of FastDDS' DomainReaderListener abstract class.
|
||||
*/
|
||||
class DatareaderListener : public eprosima::fastdds::dds::DataReaderListener
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
* @param graph_manager Pointer to the GraphManager object which owns this DataReaderListener.
|
||||
*/
|
||||
DatareaderListener(
|
||||
GraphManager* graph_manager);
|
||||
|
||||
private:
|
||||
|
||||
void on_data_available(
|
||||
eprosima::fastdds::dds::DataReader* /*sub*/) override;
|
||||
|
||||
GraphManager* graphManager_from_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Convert FastDDS QOS object instance to RMW instance.
|
||||
* @param fastdds_qos QOS instance to be converted.
|
||||
* @returns RMW object representation of the given FastDDS QOS.
|
||||
*/
|
||||
template <typename FastDDSQos>
|
||||
const rmw_qos_profile_t fastdds_qos_to_rmw_qos(
|
||||
const FastDDSQos& fastdds_qos);
|
||||
|
||||
/**
|
||||
* @brief Update micro-ROS graph information upon new data
|
||||
* received in the 'ros_discovery_info' topic.
|
||||
*/
|
||||
void update_node_entities_info();
|
||||
|
||||
bool graph_changed_;
|
||||
bool display_on_change_;
|
||||
const char * enclave_;
|
||||
std::thread microros_graph_publisher_;
|
||||
std::mutex mtx_;
|
||||
std::condition_variable cv_;
|
||||
|
||||
rmw_dds_common::GraphCache graphCache_;
|
||||
std::unique_ptr<ParticipantListener> participant_listener_;
|
||||
std::unique_ptr<DatareaderListener> datareader_listener_;
|
||||
|
||||
std::unique_ptr<eprosima::fastdds::dds::TypeSupport> participant_info_typesupport_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::TypeSupport> microros_graph_info_typesupport_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::DomainParticipant> participant_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::Publisher> publisher_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::Subscriber> subscriber_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::Topic> ros_discovery_topic_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::Topic> ros_to_microros_graph_topic_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::DataWriter> ros_discovery_datawriter_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::DataWriter> ros_to_microros_graph_datawriter_;
|
||||
std::unique_ptr<eprosima::fastdds::dds::DataReader> ros_discovery_datareader_;
|
||||
};
|
||||
|
||||
} // namespace graph_manager
|
||||
} // namespace agent
|
||||
} // namespace uros
|
||||
|
||||
#endif // _UROS_AGENT_GRAPH_MANAGER_HPP
|
||||
@@ -0,0 +1,127 @@
|
||||
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_HPP_
|
||||
#define UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_HPP_
|
||||
|
||||
#include "fastrtps/Domain.h"
|
||||
#include <fastrtps/TopicDataType.h>
|
||||
#include "fastrtps/attributes/ParticipantAttributes.h"
|
||||
#include "fastrtps/participant/Participant.h"
|
||||
#include "fastrtps/participant/ParticipantListener.h"
|
||||
#include "fastrtps/attributes/PublisherAttributes.h"
|
||||
#include "fastrtps/publisher/Publisher.h"
|
||||
#include <fastrtps/publisher/PublisherListener.h>
|
||||
#include <fastrtps/rtps/common/MatchingInfo.h>
|
||||
|
||||
#include <fastdds/dds/domain/DomainParticipant.hpp>
|
||||
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
|
||||
|
||||
#include "rmw/types.h"
|
||||
#include "rmw/impl/cpp/key_value.hpp"
|
||||
#include "rmw_dds_common/graph_cache.hpp"
|
||||
#include "rmw_fastrtps_shared_cpp/create_rmw_gid.hpp"
|
||||
#include "rmw_fastrtps_shared_cpp/qos.hpp"
|
||||
|
||||
#include "rcutils/types.h"
|
||||
|
||||
#include "rosidl_typesupport_cpp/message_type_support.hpp"
|
||||
#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h"
|
||||
|
||||
#include "rmw_dds_common/msg/participant_entities_info.hpp"
|
||||
|
||||
#include "micro_ros_msgs/msg/graph.hpp"
|
||||
|
||||
namespace uros {
|
||||
namespace agent {
|
||||
namespace graph_manager {
|
||||
|
||||
/**
|
||||
* @brief Implementation of virtual class eprosima::fastdds::dds::TopicDataType.
|
||||
* Is used to gather and send information about the entities present within a DDS domain,
|
||||
* in the Agent's context.
|
||||
*/
|
||||
class ParticipantEntitiesInfoTypeSupport : public eprosima::fastdds::dds::TopicDataType
|
||||
{
|
||||
public:
|
||||
|
||||
ParticipantEntitiesInfoTypeSupport();
|
||||
|
||||
virtual bool serialize(
|
||||
void* data,
|
||||
eprosima::fastrtps::rtps::SerializedPayload_t* payload) override;
|
||||
|
||||
virtual bool deserialize(
|
||||
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
|
||||
void* data) override;
|
||||
|
||||
virtual std::function<uint32_t()> getSerializedSizeProvider(
|
||||
void* data) override;
|
||||
|
||||
virtual void* createData() override;
|
||||
|
||||
virtual void deleteData(void* data) override;
|
||||
|
||||
virtual bool getKey(
|
||||
void* data,
|
||||
eprosima::fastrtps::rtps::InstanceHandle_t* handle,
|
||||
bool force_md5) override;
|
||||
|
||||
private:
|
||||
|
||||
const message_type_support_callbacks_t* callbacks_;
|
||||
const rosidl_message_type_support_t* type_support_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Implementation of virtual class eprosima::fastdds::dds::TopicDataType.
|
||||
* Is used to send graph information to Micro-ROS.
|
||||
*/
|
||||
class MicrorosGraphInfoTypeSupport : public eprosima::fastdds::dds::TopicDataType
|
||||
{
|
||||
public:
|
||||
|
||||
MicrorosGraphInfoTypeSupport();
|
||||
|
||||
virtual bool serialize(
|
||||
void* data,
|
||||
eprosima::fastrtps::rtps::SerializedPayload_t* payload) override;
|
||||
|
||||
virtual bool deserialize(
|
||||
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
|
||||
void* data) override;
|
||||
|
||||
virtual std::function<uint32_t()> getSerializedSizeProvider(
|
||||
void* data) override;
|
||||
|
||||
virtual void* createData() override;
|
||||
|
||||
virtual void deleteData(void* data) override;
|
||||
|
||||
virtual bool getKey(
|
||||
void* data,
|
||||
eprosima::fastrtps::rtps::InstanceHandle_t* handle,
|
||||
bool force_md5) override;
|
||||
|
||||
private:
|
||||
|
||||
const message_type_support_callbacks_t* callbacks_;
|
||||
const rosidl_message_type_support_t* type_support_;
|
||||
};
|
||||
|
||||
} // namespace graph_manager
|
||||
} // namespace agent
|
||||
} // namespace uros
|
||||
|
||||
#endif // UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_HPP_
|
||||
@@ -0,0 +1,125 @@
|
||||
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef UROS_AGENT_UTILS_DEMANGLE_HPP_
|
||||
#define UROS_AGENT_UTILS_DEMANGLE_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace uros {
|
||||
namespace agent {
|
||||
namespace utils {
|
||||
|
||||
class Demangle
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief Default constructor. Creating instances of this class is not allowed.
|
||||
*/
|
||||
Demangle() = default;
|
||||
|
||||
/**
|
||||
* @brief Default destructor.
|
||||
*/
|
||||
~Demangle() = default;
|
||||
|
||||
/**
|
||||
* @brief Demangle service name for a given topic, prefix and service suffix,
|
||||
* if the topic is part of a service; otherwise, return blank.
|
||||
* @param prefix The ROS service prefix.
|
||||
* @param topic_name Topic to be demangled.
|
||||
* @param suffix The ROS service suffix.
|
||||
* @returns The demangled service name.
|
||||
*/
|
||||
static std::string _demangle_service_from_topic(
|
||||
const std::string& prefix,
|
||||
const std::string& topic_name,
|
||||
const std::string& suffix);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Demangle if passed topic is a ROS topic; otherwise, keep it intact.
|
||||
* @param topic_name Topic to be demangled.
|
||||
* @returns The demangled topic.
|
||||
*/
|
||||
static std::string demangle_if_ros_topic(
|
||||
const std::string& topic_name);
|
||||
|
||||
/**
|
||||
* @brief Demangle if passed type is a ROS type; otherwise, keep it intact.
|
||||
* @param dds_type_string Type to be demangled.
|
||||
* @returns The demangled type.
|
||||
*/
|
||||
static std::string demangle_if_ros_type(
|
||||
const std::string& dds_type_string);
|
||||
|
||||
/**
|
||||
* @brief Demangle topic name for a given topic if it is part of one;
|
||||
* otherwise, return empty.
|
||||
* @param topic_name Topic to be demangled.
|
||||
* @returns The demangled topic name.
|
||||
*/
|
||||
static std::string demangle_ros_topic_from_topic(
|
||||
const std::string& topic_name);
|
||||
|
||||
/**
|
||||
* @brief Demangle the service name for a given topic if it is part of a service;
|
||||
* otherwise, return empty.
|
||||
* @param topic_name Topic to be demangled.
|
||||
* @returns The demangled service name.
|
||||
*/
|
||||
|
||||
static std::string demangle_service_from_topic(
|
||||
const std::string& topic_name);
|
||||
|
||||
/**
|
||||
* @brief Demangle the service name for a given topic if it is part
|
||||
* of a service request; otherwise, return empty.
|
||||
* @param topic_name Topic to be demangled.
|
||||
* @returns The demangled service request name.
|
||||
*/
|
||||
static std::string demangle_service_request_from_topic(
|
||||
const std::string& topic_name);
|
||||
|
||||
/**
|
||||
* @brief Demangle the service name for a given topic if it is part
|
||||
* of a service reply; otherwise, return empty.
|
||||
* @param topic_name Topic to be demangled.
|
||||
* @returns The demangled service reply name.
|
||||
*/
|
||||
static std::string demangle_service_reply_from_topic(
|
||||
const std::string& topic_name);
|
||||
|
||||
/**
|
||||
* @brief Demangle the service type name if it is a ROS srv type; otherwise, return empty.
|
||||
* @param dds_type_name Type to be demangled.
|
||||
* @returns The demangled service type.
|
||||
*/
|
||||
static std::string demangle_service_type_only(
|
||||
const std::string& dds_type_name);
|
||||
|
||||
/**
|
||||
* @brief Generic demangle function, used when ROS names are not mangled.
|
||||
* @param name Generic name to be demangled.
|
||||
* @returns The demangled name.
|
||||
*/
|
||||
static std::string identity_demangle(
|
||||
const std::string& name);
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
} // namespace agent
|
||||
} // namespace uros
|
||||
|
||||
#endif // UROS_AGENT_UTILS_DEMANGLE_HPP_
|
||||
Reference in New Issue
Block a user