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;
|
~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(
|
bool create(
|
||||||
int argc,
|
int argc,
|
||||||
char** argv);
|
char** argv);
|
||||||
@@ -41,26 +65,25 @@ public:
|
|||||||
void add_callbacks();
|
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
|
bool started = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename AgentType>
|
template<typename AgentType>
|
||||||
class AgentAPI : Agent
|
class AgentAPI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AgentAPI() : Agent(){};
|
AgentAPI()
|
||||||
|
: agent_instance_(agent_instance_.getInstance())
|
||||||
|
{};
|
||||||
|
|
||||||
~AgentAPI() = default;
|
~AgentAPI() = default;
|
||||||
|
|
||||||
void create(uint16_t port)
|
void create(uint16_t port)
|
||||||
{
|
{
|
||||||
xrce_dds_agent_instance_API.configure(port);
|
xrce_dds_agent_instance_API.configure(port);
|
||||||
add_callbacks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void create(std::string dev, const std::string baudrate);
|
void create(std::string dev, const std::string baudrate);
|
||||||
@@ -74,6 +97,7 @@ public:
|
|||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
agent_instance_.add_callbacks();
|
||||||
xrce_dds_agent_instance_API.run();
|
xrce_dds_agent_instance_API.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,25 +107,24 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Agent& agent_instance_;
|
||||||
eprosima::uxr::AgentInstanceAPI<AgentType> xrce_dds_agent_instance_API;
|
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)
|
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);
|
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)
|
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);
|
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)
|
template<> inline UXR_AGENT_EXPORT void AgentAPI<eprosima::uxr::PseudoTerminalAgent>::create(const std::string baudrate)
|
||||||
{
|
{
|
||||||
xrce_dds_agent_instance_API.configure(baudrate);
|
xrce_dds_agent_instance_API.configure(baudrate);
|
||||||
add_callbacks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace agent
|
} // namespace agent
|
||||||
|
|||||||
@@ -29,17 +29,13 @@ bool Agent::create(
|
|||||||
int argc,
|
int argc,
|
||||||
char** argv)
|
char** argv)
|
||||||
{
|
{
|
||||||
bool result = xrce_dds_agent_instance_.create(argc, argv);
|
return xrce_dds_agent_instance_.create(argc, argv);
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
add_callbacks();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::add_callbacks()
|
void Agent::add_callbacks()
|
||||||
{
|
{
|
||||||
|
if (!started)
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Add CREATE_PARTICIPANT callback.
|
* Add CREATE_PARTICIPANT callback.
|
||||||
*/
|
*/
|
||||||
@@ -108,7 +104,6 @@ void Agent::add_callbacks()
|
|||||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
const eprosima::fastdds::dds::DataWriter* datawriter) -> void
|
const eprosima::fastdds::dds::DataWriter* datawriter) -> void
|
||||||
{
|
{
|
||||||
|
|
||||||
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
// 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::Kind::FASTDDS,
|
||||||
eprosima::uxr::middleware::CallbackKind::DELETE_DATAREADER,
|
eprosima::uxr::middleware::CallbackKind::DELETE_DATAREADER,
|
||||||
std::move(on_delete_datareader));
|
std::move(on_delete_datareader));
|
||||||
|
|
||||||
|
started = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::run()
|
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 agent
|
||||||
} // namespace uros
|
} // namespace uros
|
||||||
#endif // _UROS_AGENT_AGENT_CPP
|
#endif // _UROS_AGENT_AGENT_CPP
|
||||||
Reference in New Issue
Block a user