Update agent as singleton

This commit is contained in:
Antonio cuadros
2021-07-26 13:10:04 +02:00
parent 76c39a39be
commit 7294ba66d7
3 changed files with 158 additions and 146 deletions
+13 -3
View File
@@ -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,
+13 -11
View File
@@ -22,15 +22,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.
@@ -168,7 +159,18 @@ bool Agent::create(
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,11 +181,11 @@ 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()) {
+1 -1
View File
@@ -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