Skip to content

Commit

Permalink
[mementar_mulyi] fix instance deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Jun 24, 2024
1 parent 7a249ec commit 74fa3d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/RosInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,16 @@ namespace mementar {
else
Display::info("Mementar is ready");

// occasions_.stop(); // todo verify
occasions_thread.join();
feed_thread.join();
}

void RosInterface::stop()
{
occasions_.stop();
run_ = false;
}

void RosInterface::reset()
{
mut_.lock();
Expand Down
18 changes: 9 additions & 9 deletions src/nodes/mementar_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ void removeUselessSpace(std::string& text)
}
}

std::map<std::string, std::unique_ptr<mementar::RosInterface>> interfaces;
std::map<std::string, mementar::RosInterface*> interfaces;
std::map<std::string, std::thread> interfaces_threads;

mementar::Parameters params;

bool deleteInterface(const std::string& name)
{
interfaces[name]->stop();
usleep(1000);
usleep(200000);

try
{
Expand All @@ -67,6 +67,7 @@ bool deleteInterface(const std::string& name)
}

interfaces_threads.erase(name);
delete interfaces[name];
interfaces.erase(name);

std::cout << name << " STOPPED" << std::endl;
Expand All @@ -91,14 +92,13 @@ bool managerHandle(mementar::compat::mem_ros::ServiceWrapper<mementar::compat::M
}
else
{
auto tmp = std::make_unique<mementar::RosInterface>(params.parameters_.at("directory").getFirst(),
params.parameters_.at("config").getFirst(),
10,
req->param);
auto tmp = new mementar::RosInterface(params.parameters_.at("directory").getFirst(),
params.parameters_.at("config").getFirst(),
10,
req->param);
interfaces[req->param] = tmp;

std::thread th(&mementar::RosInterface::run, tmp.get());

interfaces[req->param] = std::move(tmp);
std::thread th(&mementar::RosInterface::run, tmp);
interfaces_threads[req->param] = std::move(th);

std::cout << req->param << " STARTED" << std::endl;
Expand Down

0 comments on commit 74fa3d7

Please sign in to comment.