mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 18:05:17 +02:00
Initial agent API
This commit is contained 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)
|
||||||
@@ -38,14 +38,67 @@ public:
|
|||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
void add_callbacks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
eprosima::uxr::AgentInstance& xrce_dds_agent_instance_;
|
eprosima::uxr::AgentInstance& xrce_dds_agent_instance_;
|
||||||
std::map<eprosima::fastdds::dds::DomainId_t, std::shared_ptr<graph_manager::GraphManager>> graph_manager_map_;
|
std::map<eprosima::fastdds::dds::DomainId_t, std::shared_ptr<graph_manager::GraphManager>> graph_manager_map_;
|
||||||
|
|
||||||
std::shared_ptr<graph_manager::GraphManager> find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id);
|
std::shared_ptr<graph_manager::GraphManager> 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<typename AgentType>
|
||||||
|
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<std::string> 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<AgentType> xrce_dds_agent_instance_API;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> inline UXR_AGENT_EXPORT void AgentAPI<eprosima::uxr::TermiosAgent>::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<eprosima::uxr::MultiTermiosAgent>::create(std::vector<std::string> devs, const std::string baudrate)
|
||||||
|
{
|
||||||
|
xrce_dds_agent_instance_API.configure(devs, baudrate);
|
||||||
|
add_callbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline UXR_AGENT_EXPORT void AgentAPI<eprosima::uxr::PseudoTerminalAgent>::create(const std::string baudrate)
|
||||||
|
{
|
||||||
|
xrce_dds_agent_instance_API.configure(baudrate);
|
||||||
|
add_callbacks();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace agent
|
} // namespace agent
|
||||||
} // namespace uros
|
} // namespace uros
|
||||||
#endif // _UROS_AGENT_AGENT_HPP
|
#endif // _UROS_AGENT_AGENT_HPP
|
||||||
@@ -31,6 +31,14 @@ bool Agent::create(
|
|||||||
{
|
{
|
||||||
bool result = xrce_dds_agent_instance_.create(argc, argv);
|
bool result = xrce_dds_agent_instance_.create(argc, argv);
|
||||||
if (result)
|
if (result)
|
||||||
|
{
|
||||||
|
add_callbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Agent::add_callbacks()
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Add CREATE_PARTICIPANT callback.
|
* Add CREATE_PARTICIPANT callback.
|
||||||
@@ -168,9 +176,6 @@ bool Agent::create(
|
|||||||
std::move(on_delete_datareader));
|
std::move(on_delete_datareader));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Agent::run()
|
void Agent::run()
|
||||||
{
|
{
|
||||||
return xrce_dds_agent_instance_.run();
|
return xrce_dds_agent_instance_.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 agent
|
||||||
} // namespace uros
|
} // namespace uros
|
||||||
#endif // _UROS_AGENT_AGENT_CPP
|
#endif // _UROS_AGENT_AGENT_CPP
|
||||||
Reference in New Issue
Block a user