mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 09:55:15 +02:00
Update agent as singleton
This commit is contained in:
@@ -26,11 +26,21 @@ namespace agent {
|
|||||||
|
|
||||||
class Agent
|
class Agent
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
|
|
||||||
Agent();
|
Agent();
|
||||||
|
|
||||||
~Agent() = default;
|
Agent(const Agent &) = delete;
|
||||||
|
|
||||||
|
Agent(Agent &&) = delete;
|
||||||
|
|
||||||
|
Agent& operator =(
|
||||||
|
const Agent &) = delete;
|
||||||
|
|
||||||
|
Agent& operator =(
|
||||||
|
Agent &&) = delete;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Agent& getInstance();
|
||||||
|
|
||||||
bool create(
|
bool create(
|
||||||
int argc,
|
int argc,
|
||||||
|
|||||||
@@ -23,15 +23,6 @@ namespace agent {
|
|||||||
Agent::Agent()
|
Agent::Agent()
|
||||||
: xrce_dds_agent_instance_(xrce_dds_agent_instance_.getInstance())
|
: xrce_dds_agent_instance_(xrce_dds_agent_instance_.getInstance())
|
||||||
{
|
{
|
||||||
}
|
|
||||||
|
|
||||||
bool Agent::create(
|
|
||||||
int argc,
|
|
||||||
char** argv)
|
|
||||||
{
|
|
||||||
bool result = xrce_dds_agent_instance_.create(argc, argv);
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Add CREATE_PARTICIPANT callback.
|
* Add CREATE_PARTICIPANT callback.
|
||||||
*/
|
*/
|
||||||
@@ -166,9 +157,20 @@ bool Agent::create(
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
Agent& Agent::getInstance()
|
||||||
|
{
|
||||||
|
static Agent instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Agent::create(
|
||||||
|
int argc,
|
||||||
|
char** argv)
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
return xrce_dds_agent_instance_.create(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::run()
|
void Agent::run()
|
||||||
@@ -179,12 +181,12 @@ void Agent::run()
|
|||||||
void Agent::stop()
|
void Agent::stop()
|
||||||
{
|
{
|
||||||
xrce_dds_agent_instance_.stop();
|
xrce_dds_agent_instance_.stop();
|
||||||
|
graph_manager_map_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<graph_manager::GraphManager> Agent::find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id)
|
std::shared_ptr<graph_manager::GraphManager> Agent::find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id)
|
||||||
{
|
{
|
||||||
|
auto it = graph_manager_map_.find(domain_id);
|
||||||
auto it = graph_manager_map_.find(domain_id);
|
|
||||||
|
|
||||||
if (it != graph_manager_map_.end()) {
|
if (it != graph_manager_map_.end()) {
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
uros::agent::Agent micro_ros_agent;
|
uros::agent::Agent& micro_ros_agent = micro_ros_agent.getInstance();
|
||||||
|
|
||||||
/** Bypass '--ros-args' flag, as we use our own CLI parser.
|
/** Bypass '--ros-args' flag, as we use our own CLI parser.
|
||||||
* As a workaround for launch files, arguments will be passed from
|
* As a workaround for launch files, arguments will be passed from
|
||||||
|
|||||||
Reference in New Issue
Block a user