diff --git a/micro_ros_agent/cmake/Config.cmake.in b/micro_ros_agent/cmake/Config.cmake.in new file mode 100644 index 0000000..cecf44e --- /dev/null +++ b/micro_ros_agent/cmake/Config.cmake.in @@ -0,0 +1,32 @@ +# Copyright 2016 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. + +set(@PROJECT_NAME@_VERSION @PROJECT_VERSION@) + +@PACKAGE_INIT@ + +if(MSVC OR MSVC_IDE) + set_and_check(@PROJECT_NAME@_BIN_DIR "@PACKAGE_BIN_INSTALL_DIR@") +endif() +set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") +set_and_check(@PROJECT_NAME@_DATA_DIR "@PACKAGE_DATA_INSTALL_DIR@") + +foreach(d @_deps@) + list(GET d 0 _name) + list(GET d 1 _version) + find_package(${_name} ${_version} REQUIRED) +endforeach() + +include(${@PROJECT_NAME@_DATA_DIR}/@PROJECT_NAME@/cmake/@PROJECT_NAME@Targets.cmake) diff --git a/micro_ros_agent/include/agent/Agent.hpp b/micro_ros_agent/include/agent/Agent.hpp index f5f22f3..f47ff6e 100644 --- a/micro_ros_agent/include/agent/Agent.hpp +++ b/micro_ros_agent/include/agent/Agent.hpp @@ -38,14 +38,67 @@ public: void run(); + void add_callbacks(); + private: eprosima::uxr::AgentInstance& xrce_dds_agent_instance_; std::map> graph_manager_map_; std::shared_ptr find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id); + void remove_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id); // TODO: check grap_manager on agent closing }; +template +class AgentAPI : Agent +{ +public: + AgentAPI() : Agent(){}; + + ~AgentAPI() = default; + + void create(uint16_t port) + { + xrce_dds_agent_instance_API.configure(port); + add_callbacks(); + } + + void create(std::string dev, const std::string baudrate); + void create(std::vector devs, const std::string baudrate); + void create(const std::string baudrate); + + void run() + { + xrce_dds_agent_instance_API.run(); + } + + void stop() + { + xrce_dds_agent_instance_API.stop(); + } + +private: + eprosima::uxr::AgentInstanceAPI xrce_dds_agent_instance_API; +}; + +template<> inline UXR_AGENT_EXPORT void AgentAPI::create(std::string dev, const std::string baudrate) +{ + xrce_dds_agent_instance_API.configure(dev, baudrate); + add_callbacks(); +} + +template<> inline UXR_AGENT_EXPORT void AgentAPI::create(std::vector devs, const std::string baudrate) +{ + xrce_dds_agent_instance_API.configure(devs, baudrate); + add_callbacks(); +} + +template<> inline UXR_AGENT_EXPORT void AgentAPI::create(const std::string baudrate) +{ + xrce_dds_agent_instance_API.configure(baudrate); + add_callbacks(); +} + } // namespace agent } // namespace uros #endif // _UROS_AGENT_AGENT_HPP \ No newline at end of file diff --git a/micro_ros_agent/src/agent/Agent.cpp b/micro_ros_agent/src/agent/Agent.cpp index 87ef3cf..7af6cac 100644 --- a/micro_ros_agent/src/agent/Agent.cpp +++ b/micro_ros_agent/src/agent/Agent.cpp @@ -32,6 +32,14 @@ bool Agent::create( bool result = xrce_dds_agent_instance_.create(argc, argv); if (result) { + add_callbacks(); + } + + return result; +} + +void Agent::add_callbacks() +{ /** * Add CREATE_PARTICIPANT callback. */ @@ -166,9 +174,6 @@ bool Agent::create( eprosima::uxr::Middleware::Kind::FASTDDS, eprosima::uxr::middleware::CallbackKind::DELETE_DATAREADER, std::move(on_delete_datareader)); - } - - return result; } void Agent::run() @@ -193,6 +198,17 @@ auto it = graph_manager_map_.find(domain_id); } } +void Agent::remove_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id) +{ + auto it = graph_manager_map_.find(domain_id); + + if (it != graph_manager_map_.end()) + { + it->second = nullptr; + graph_manager_map_.erase(it); + } +} + } // namespace agent } // namespace uros #endif // _UROS_AGENT_AGENT_CPP \ No newline at end of file