mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 09:55:15 +02:00
Update callbacks on AgentAPI
This commit is contained in:
@@ -32,6 +32,30 @@ public:
|
||||
|
||||
~Agent() = default;
|
||||
|
||||
/**
|
||||
* @brief Agent class shall not be copy constructible.
|
||||
*/
|
||||
UXR_AGENT_EXPORT Agent(
|
||||
const Agent &) = delete;
|
||||
|
||||
UXR_AGENT_EXPORT Agent(
|
||||
Agent &&) = delete;
|
||||
|
||||
/**
|
||||
* @brief Agent class shall not be copy assignable.
|
||||
*/
|
||||
UXR_AGENT_EXPORT Agent& operator =(
|
||||
const Agent &) = delete;
|
||||
|
||||
UXR_AGENT_EXPORT Agent& operator =(
|
||||
Agent &&) = delete;
|
||||
|
||||
static Agent& getInstance()
|
||||
{
|
||||
static Agent instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool create(
|
||||
int argc,
|
||||
char** argv);
|
||||
@@ -41,26 +65,25 @@ public:
|
||||
void add_callbacks();
|
||||
|
||||
private:
|
||||
|
||||
eprosima::uxr::AgentInstance& xrce_dds_agent_instance_;
|
||||
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);
|
||||
void remove_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id); // TODO: check grap_manager on agent closing
|
||||
bool started = false;
|
||||
};
|
||||
|
||||
template<typename AgentType>
|
||||
class AgentAPI : Agent
|
||||
class AgentAPI
|
||||
{
|
||||
public:
|
||||
AgentAPI() : Agent(){};
|
||||
AgentAPI()
|
||||
: agent_instance_(agent_instance_.getInstance())
|
||||
{};
|
||||
|
||||
~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);
|
||||
@@ -74,34 +97,34 @@ public:
|
||||
|
||||
void run()
|
||||
{
|
||||
agent_instance_.add_callbacks();
|
||||
xrce_dds_agent_instance_API.run();
|
||||
}
|
||||
|
||||
|
||||
void stop()
|
||||
{
|
||||
xrce_dds_agent_instance_API.stop();
|
||||
}
|
||||
|
||||
private:
|
||||
Agent& agent_instance_;
|
||||
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
|
||||
|
||||
@@ -29,17 +29,13 @@ bool Agent::create(
|
||||
int argc,
|
||||
char** argv)
|
||||
{
|
||||
bool result = xrce_dds_agent_instance_.create(argc, argv);
|
||||
if (result)
|
||||
{
|
||||
add_callbacks();
|
||||
}
|
||||
|
||||
return result;
|
||||
return xrce_dds_agent_instance_.create(argc, argv);
|
||||
}
|
||||
|
||||
void Agent::add_callbacks()
|
||||
{
|
||||
if (!started)
|
||||
{
|
||||
/**
|
||||
* Add CREATE_PARTICIPANT callback.
|
||||
*/
|
||||
@@ -108,7 +104,6 @@ void Agent::add_callbacks()
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const eprosima::fastdds::dds::DataWriter* datawriter) -> void
|
||||
{
|
||||
|
||||
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||
|
||||
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||
@@ -174,6 +169,9 @@ void Agent::add_callbacks()
|
||||
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||
eprosima::uxr::middleware::CallbackKind::DELETE_DATAREADER,
|
||||
std::move(on_delete_datareader));
|
||||
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Agent::run()
|
||||
@@ -198,17 +196,6 @@ 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
|
||||
Reference in New Issue
Block a user