diff --git a/include/mementar/API/mementar/ActionsPublisher.h b/include/mementar/API/mementar/ActionsPublisher.h index 2241f8d..9e3f057 100644 --- a/include/mementar/API/mementar/ActionsPublisher.h +++ b/include/mementar/API/mementar/ActionsPublisher.h @@ -18,11 +18,20 @@ namespace mementar { void insertEnd(const std::string& name, time_t end_stamp = time(nullptr)); void insertEnd(const std::string& name, compat::mem_ros::Time end_stamp = compat::mem_ros::Node::get().currentTime()); + /// @brief Register a callback function to get notifications from the feeder. + /// @param callback is the callback function taking a string. + void registerFeederNotificationCallback(const std::function& callback) { feeder_notification_callback_ = callback; } + private: + std::function feeder_notification_callback_; + compat::mem_ros::Publisher pub_; + compat::mem_ros::Subscriber feeder_notif_sub_; void publish(const std::string& name, time_t start_stamp, time_t end_stamp); void publish(const std::string& name, compat::mem_ros::Time start_stamp, compat::mem_ros::Time end_stamp); + + void feederNotificationCallback(const compat::mem_ros::MessageWrapper& msg); }; } // namespace mementar diff --git a/include/mementar/API/mementar/ActionsSubscriber.h b/include/mementar/API/mementar/ActionsSubscriber.h index 93c7889..d464e51 100644 --- a/include/mementar/API/mementar/ActionsSubscriber.h +++ b/include/mementar/API/mementar/ActionsSubscriber.h @@ -15,10 +15,7 @@ namespace mementar { { public: ActionsSubscriber(const std::function& callback, - const std::string& name = "", - bool spin_thread = true); - ActionsSubscriber(const std::function& callback, - bool spin_thread); + const std::string& name = ""); bool subscribeToStart(const std::string& name, size_t count = -1); bool subscribeToEnd(const std::string& name, size_t count = -1); diff --git a/include/mementar/API/mementar/OccasionsPublisher.h b/include/mementar/API/mementar/OccasionsPublisher.h index fc72c09..6c869b9 100644 --- a/include/mementar/API/mementar/OccasionsPublisher.h +++ b/include/mementar/API/mementar/OccasionsPublisher.h @@ -14,12 +14,23 @@ namespace mementar { public: OccasionsPublisher(const std::string& name = ""); - void insert(const Fact& fact, time_t stamp = time(nullptr)); + void insert(const Fact& fact, mementar::compat::mem_ros::Time stamp = compat::mem_ros::Node::get().currentTime()); + void insert(const Fact& fact, time_t end_stamp); + + /// @brief Register a callback function to get notifications from the feeder. + /// @param callback is the callback function taking a string. + void registerFeederNotificationCallback(const std::function& callback) { feeder_notification_callback_ = callback; } private: + std::function feeder_notification_callback_; + compat::mem_ros::Publisher pub_; + compat::mem_ros::Subscriber feeder_notif_sub_; + + void publish(const std::string& str, mementar::compat::mem_ros::Time stamp = compat::mem_ros::Node::get().currentTime()); + void publish(const std::string& str, time_t end_stamp); - void publish(const std::string& str, time_t stamp = time(nullptr)); + void feederNotificationCallback(const compat::mem_ros::MessageWrapper& msg); }; } // namespace mementar diff --git a/include/mementar/API/mementar/OccasionsSubscriber.h b/include/mementar/API/mementar/OccasionsSubscriber.h index 6854098..27209cf 100644 --- a/include/mementar/API/mementar/OccasionsSubscriber.h +++ b/include/mementar/API/mementar/OccasionsSubscriber.h @@ -14,8 +14,7 @@ namespace mementar { class OccasionsSubscriber { public: - OccasionsSubscriber(const std::function& callback, const std::string& name = "", bool spin_thread = true); - OccasionsSubscriber(const std::function& callback, bool spin_thread); + OccasionsSubscriber(const std::function& callback, const std::string& name = ""); ~OccasionsSubscriber(); bool subscribe(const Fact& pattern, size_t count = -1); diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index d45e5bb..4923f90 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -62,7 +62,6 @@ namespace mementar { void ontoStampedKnowledgeCallback(const compat::mem_ros::MessageWrapper& msg); void ontoExplanationKnowledgeCallback(const compat::mem_ros::MessageWrapper& msg); - // todo: do not return bool bool managerInstanceHandle(compat::mem_ros::ServiceWrapper& req, compat::mem_ros::ServiceWrapper& res); diff --git a/include/mementar/compat/ros.h b/include/mementar/compat/ros.h index fed1597..8061143 100644 --- a/include/mementar/compat/ros.h +++ b/include/mementar/compat/ros.h @@ -80,8 +80,6 @@ namespace mementar::compat { template inline auto makeResponse() { return Response_(); } - // todo: RequestType, ResponseType - #elif MEME_ROS_VERSION == 2 using namespace ::mementar::msg; using namespace ::mementar::srv; @@ -253,8 +251,6 @@ namespace mementar::compat { { auto& node = Node::get(); - printf("[Publisher '%s'] Create\n", topic_name.c_str()); - #if MEME_ROS_VERSION == 1 handle_ = node.handle_.advertise(topic_name, queue_size); #elif MEME_ROS_VERSION == 2 @@ -265,8 +261,6 @@ namespace mementar::compat { void publish(const T& message) { - printf("[Publisher '%s'] Create\n", name_.c_str()); - #if MEME_ROS_VERSION == 1 handle_.publish(message); #elif MEME_ROS_VERSION == 2 @@ -302,8 +296,6 @@ namespace mementar::compat { { auto& node = Node::get(); - printf("[Subscriber '%s'] Create\n", topic_name.c_str()); - #if MEME_ROS_VERSION == 1 handle_ = node.handle_.subscribe(topic_name, queue_size, callback, ptr); #elif MEME_ROS_VERSION == 2 @@ -331,8 +323,6 @@ namespace mementar::compat { { auto& node = Node::get(); - printf("[Service '%s'] Create\n", service_name.c_str()); - #if MEME_ROS_VERSION == 1 handle_ = node.handle_.advertiseService(service_name, callback); #elif MEME_ROS_VERSION == 2 @@ -352,8 +342,6 @@ namespace mementar::compat { { auto& node = Node::get(); - printf("[Service '%s'] Create\n", service_name.c_str()); - #if MEME_ROS_VERSION == 1 handle_ = node.handle_.advertiseService(service_name, callback, ptr); #elif MEME_ROS_VERSION == 2 @@ -388,8 +376,6 @@ namespace mementar::compat { { auto& node = Node::get(); - printf("[Client '%s'] Create\n", service_name.c_str()); - #if MEME_ROS_VERSION == 1 handle_ = node.handle_.serviceClient(service_name, true); #elif MEME_ROS_VERSION == 2 @@ -399,8 +385,6 @@ namespace mementar::compat { RosStatus_e call(const mementar::compat::RequestType& req, mementar::compat::ResponseType& res) { - printf("[Client '%s'] Call\n", name_.c_str()); - using namespace std::chrono_literals; auto status = RosStatus_e::ros_status_failure; @@ -442,7 +426,6 @@ namespace mementar::compat { bool wait(double timeout) { - printf("[Client '%s'] Wait\n", name_.c_str()); #if MEME_ROS_VERSION == 1 return handle_.waitForExistence(ros::Duration(timeout)); #elif MEME_ROS_VERSION == 2 diff --git a/include/mementar/graphical/mementarGUI/mementargui.h b/include/mementar/graphical/mementarGUI/mementargui.h index 94cf85a..044999a 100644 --- a/include/mementar/graphical/mementarGUI/mementargui.h +++ b/include/mementar/graphical/mementarGUI/mementargui.h @@ -8,7 +8,7 @@ #include "include/mementar/graphical/mementarGUI/CallBackTimer.h" #include "include/mementar/graphical/mementarGUI/QCheckBoxExtended.h" -#include "mementar/API/mementar/TimelineManipulator.h" +#include "mementar/API/mementar/TimelinesManipulator.h" #include "mementar/compat/ros.h" namespace Ui { // NOLINT @@ -30,11 +30,10 @@ class MementarGUI : public QMainWindow private: Ui::MementarGUI* ui_; - mementar::TimelineManipulator meme_; + mementar::TimelinesManipulator timelines_; + mementar::TimelineManipulator* timeline_; + bool multi_usage_; - std::map>> facts_publishers_; - std::map>> actions_publishers_; - std::map>> feeder_notifications_subs_; std::string feeder_notifications_; int time_source_; @@ -74,15 +73,17 @@ public slots: void timesourceChangedSlot(int index); void currentTimeEditingFinishedSlot(); - void feederCallback(const std_msgs_compat::String& msg); + void feederCallback(const std::string& msg); void feederAddSlot(); void feederDelSlot(); void feederCommitSlot(); void feederCheckoutSlot(); - void createPublisher(const std::string& instance_ns); + + bool updateTimelinePtr(); signals: - void feederSetHtmlSignal(QString); + void feederSetHtmlSignal(QString t1); + void feederScrollSignal(QString t1); void setTimeSignal(QString); }; diff --git a/src/API/mementar/ActionsPublisher.cpp b/src/API/mementar/ActionsPublisher.cpp index f003903..9d9eb55 100644 --- a/src/API/mementar/ActionsPublisher.cpp +++ b/src/API/mementar/ActionsPublisher.cpp @@ -7,7 +7,10 @@ namespace mementar { - ActionsPublisher::ActionsPublisher(const std::string& name) : pub_(name.empty() ? "mementar/insert_action" : "mementar/insert_action/" + name, 1000) {} + ActionsPublisher::ActionsPublisher(const std::string& name) : feeder_notification_callback_([](auto& msg) { (void)msg; }), + pub_(name.empty() ? "mementar/insert_action" : "mementar/insert_action/" + name, 1000), + feeder_notif_sub_(name.empty() ? "mementar/feeder_notifications" : "mementar/feeder_notifications/" + name, 1000, &ActionsPublisher::feederNotificationCallback, this) + {} void ActionsPublisher::insert(const std::string& name, time_t start_stamp, time_t end_stamp) { @@ -49,4 +52,9 @@ namespace mementar { pub_.publish(msg); } + void ActionsPublisher::feederNotificationCallback(const compat::mem_ros::MessageWrapper& msg) + { + feeder_notification_callback_(msg->data); + } + } // namespace mementar diff --git a/src/API/mementar/ActionsSubscriber.cpp b/src/API/mementar/ActionsSubscriber.cpp index e12f99f..6890073 100644 --- a/src/API/mementar/ActionsSubscriber.cpp +++ b/src/API/mementar/ActionsSubscriber.cpp @@ -10,15 +10,8 @@ namespace mementar { ActionsSubscriber::ActionsSubscriber(const std::function& callback, - const std::string& name, - bool spin_thread) - : OccasionsSubscriber([this](const Fact& fact) { this->privateCallback(fact); }, name, spin_thread), - callback_(callback) - {} - - ActionsSubscriber::ActionsSubscriber(const std::function& callback, - bool spin_thread) - : OccasionsSubscriber([this](const Fact& fact) { this->privateCallback(fact); }, spin_thread), + const std::string& name) + : OccasionsSubscriber([this](const Fact& fact) { this->privateCallback(fact); }, name), callback_(callback) {} diff --git a/src/API/mementar/OccasionsPublisher.cpp b/src/API/mementar/OccasionsPublisher.cpp index 22a7275..514897a 100644 --- a/src/API/mementar/OccasionsPublisher.cpp +++ b/src/API/mementar/OccasionsPublisher.cpp @@ -4,23 +4,46 @@ #include #include "mementar/API/mementar/Fact.h" +#include "mementar/compat/ros.h" namespace mementar { - OccasionsPublisher::OccasionsPublisher(const std::string& name) - : pub_((name.empty()) ? "mementar/insert_fact_stamped" : "mementar/insert_fact_stamped/" + name, 1000) {} + OccasionsPublisher::OccasionsPublisher(const std::string& name) : feeder_notification_callback_([](auto& msg) { (void)msg; }), + pub_((name.empty()) ? "mementar/insert_fact_stamped" : "mementar/insert_fact_stamped/" + name, 1000), + feeder_notif_sub_(name.empty() ? "mementar/feeder_notifications" : "mementar/feeder_notifications/" + name, 1000, &OccasionsPublisher::feederNotificationCallback, this) + {} + + void OccasionsPublisher::insert(const Fact& fact, compat::mem_ros::Time stamp) + { + publish(fact(), stamp); + } void OccasionsPublisher::insert(const Fact& fact, time_t stamp) { publish(fact(), stamp); } + void OccasionsPublisher::publish(const std::string& str, compat::mem_ros::Time stamp) + { + compat::StampedString msg; + msg.data = str; + msg.stamp.seconds = stamp.seconds(); + msg.stamp.nanoseconds = stamp.nanoseconds(); + pub_.publish(msg); + } + void OccasionsPublisher::publish(const std::string& str, time_t stamp) { compat::StampedString msg; msg.data = str; msg.stamp.seconds = stamp; + msg.stamp.nanoseconds = 0; pub_.publish(msg); } + void OccasionsPublisher::feederNotificationCallback(const compat::mem_ros::MessageWrapper& msg) + { + feeder_notification_callback_(msg->data); + } + } // namespace mementar diff --git a/src/API/mementar/OccasionsSubscriber.cpp b/src/API/mementar/OccasionsSubscriber.cpp index fe3181a..3ba5693 100644 --- a/src/API/mementar/OccasionsSubscriber.cpp +++ b/src/API/mementar/OccasionsSubscriber.cpp @@ -10,35 +10,16 @@ namespace mementar { - OccasionsSubscriber::OccasionsSubscriber(const std::function& callback, const std::string& name, bool spin_thread) + OccasionsSubscriber::OccasionsSubscriber(const std::function& callback, const std::string& name) : sub_(name.empty() ? "mementar/occasions" : "mementar/occasions/" + name, 1000, &OccasionsSubscriber::occasionCallback, this), client_subscribe_(name.empty() ? "mementar/subscribe" : "mementar/subscribe/" + name), client_cancel_(name.empty() ? "mementar/unsubscribe" : "mementar/unsubscribe/" + name), callback_(callback) - { - (void)spin_thread; - - /*if (spin_thread) { - need_to_terminate_ = false; - spin_thread_ = std::thread(std::bind(&OccasionsSubscriber::spinThread, this)); - } else { - spin_thread_ = {}; - }*/ - } - - OccasionsSubscriber::OccasionsSubscriber(const std::function& callback, bool spin_thread) - : OccasionsSubscriber(callback, "", spin_thread) {} + {} OccasionsSubscriber::~OccasionsSubscriber() { cancel(); - // todo - // sub_.shutdown(); - /*if (spin_thread_) { - need_to_terminate_ = true; - spin_thread_->join(); - delete spin_thread_; - }*/ } bool OccasionsSubscriber::subscribe(const Fact& pattern, size_t count) diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 6c2ea85..7b1de9e 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -115,15 +115,12 @@ namespace mementar { std::thread occasions_thread(&OccasionsManager::run, &occasions_); std::thread feed_thread(&RosInterface::feedThread, this); - // ROS_DEBUG("%s mementar ready", name_.c_str()); - - while(compat::mem_ros::Node::ok() && isRunning()) - { - // todo - // ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(0.1)); - } + if(name_.empty() == false) + Display::info("Mementar " + name_ + " is ready"); + else + Display::info("Mementar is ready"); - occasions_.stop(); + // occasions_.stop(); // todo verify occasions_thread.join(); feed_thread.join(); } diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index a8ff2c6..ce8a3d9 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -93,6 +93,7 @@ MementarGUI::MementarGUI(QWidget* parent) : QMainWindow(parent), ui_(new Ui::Mem QObject::connect(ui_->static_tab_widget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChangedSlot(int))); QObject::connect(this, SIGNAL(feederSetHtmlSignal(QString)), ui_->feeder_info_edittext, SLOT(setHtml(QString)), Qt::BlockingQueuedConnection); + QObject::connect(this, SIGNAL(feederScrollSignal(QString)), ui_->feeder_info_edittext, SLOT(scrollToAnchor(QString)), Qt::BlockingQueuedConnection); QObject::connect(this, SIGNAL(setTimeSignal(QString)), ui_->static_current_time_editline, SLOT(setText(QString)), Qt::BlockingQueuedConnection); QObject::connect(ui_->static_current_time_editline, SIGNAL(editingFinished()), this, SLOT(currentTimeEditingFinishedSlot())); } @@ -106,9 +107,18 @@ void MementarGUI::init() { timesourceChangedSlot(0); - facts_publishers_["_"] = std::make_unique>("/mementar/insert_fact_stamped", QUEU_SIZE); - actions_publishers_["_"] = std::make_unique>("/mementar/insert_action", QUEU_SIZE); - feeder_notifications_subs_["_"] = std::make_unique>("mementar/feeder_notifications", QUEU_SIZE, &MementarGUI::feederCallback, this); + if(timelines_.waitInit(1) == false) + { + timeline_ = new mementar::TimelineManipulator(); + timeline_->action_feeder_.registerFeederNotificationCallback([this](auto msg) { this->feederCallback(msg); }); + timeline_->fact_feeder_.registerFeederNotificationCallback([this](auto msg) { this->feederCallback(msg); }); + multi_usage_ = false; + } + else + { + timeline_ = nullptr; + multi_usage_ = true; + } } void MementarGUI::wait() @@ -153,20 +163,24 @@ void MementarGUI::factButtonHoverLeaveSlot() void MementarGUI::actionButtonClickedSlot() { - auto service_name = ui_->static_instance_name_editline->text().toStdString(); - - mementar::ActionClient client(service_name); + if(ui_->static_instance_name_editline->text().toStdString().find('=') != std::string::npos) + { + displayErrorInfo("Instance name cannot have the symbol = : \'" + ui_->static_instance_name_editline->text().toStdString() + "\'\n Once an instance copy has been performed, use the new instance name."); + return; + } - auto q_text = dynamic_cast(sender())->text(); - auto q_param = ui_->action_parameter_editline->text(); + const std::string action = dynamic_cast(sender())->text().toStdString(); + const std::string param = ui_->action_parameter_editline->text().toStdString(); + if(updateTimelinePtr() == false) + return; - QString text = q_text + " : " + ui_->action_parameter_editline->text(); + const QString text = dynamic_cast(sender())->text() + " : " + ui_->action_parameter_editline->text(); ui_->action_description_textedit->setText(text); - auto response = client.call(q_text.toStdString(), q_param.toStdString()); - const int err = client.getErrorCode(); + auto response = timeline_->actions_.call(action, param); + const int err = timeline_->actions_.getErrorCode(); if(err == -1) - displayErrorInfo(service_name + " client call failed"); + displayErrorInfo("client call failed"); else { start(); @@ -181,20 +195,25 @@ void MementarGUI::actionButtonClickedSlot() void MementarGUI::factButtonClickedSlot() { - std::string service_name = ui_->static_instance_name_editline->text().toStdString(); - - mementar::FactClient client(service_name); + if(ui_->static_instance_name_editline->text().toStdString().find('=') != std::string::npos) + { + displayErrorInfo("Instance name cannot have the symbol = : \'" + ui_->static_instance_name_editline->text().toStdString() + "\'\n Once an instance copy has been performed, use the new instance name."); + return; + } - auto q_text = dynamic_cast(sender())->text(); - auto q_param = ui_->fact_parameter_editline->text(); + const std::string action = dynamic_cast(sender())->text().toStdString(); + const std::string param = ui_->fact_parameter_editline->text().toStdString(); + if(updateTimelinePtr() == false) + return; - QString text = q_text + " : " + ui_->fact_parameter_editline->text(); + const QString text = dynamic_cast(sender())->text() + " : " + ui_->fact_parameter_editline->text(); ui_->fact_description_textedit->setText(text); - auto response = client.call(q_text.toStdString(), q_param.toStdString()); - const int err = client.getErrorCode(); + auto response = timeline_->facts_.call(action, param); + const int err = timeline_->facts_.getErrorCode(); + if(err == -1) - displayErrorInfo(service_name + " client call failed"); + displayErrorInfo("client call failed"); else { start(); @@ -209,6 +228,8 @@ void MementarGUI::factButtonClickedSlot() void MementarGUI::nameEditingFinishedSlot() { + if(updateTimelinePtr() == false) + return; } void MementarGUI::displayErrorInfo(const std::string& text) @@ -225,11 +246,12 @@ void MementarGUI::displayErrorInfo(const std::string& text) void MementarGUI::displayInstancesList() { - auto values = meme_.manager_.list(); + auto res_vect = timelines_.list(); + const int err = timelines_.getErrorCode(); std::string html; - if(meme_.manager_.getErrorCode() == -1) + if(err == -1) { html = "" "" - "

" + - feeder_notifications_ + "

"; + const std::string html = "" + "" + "

" + + feeder_notifications_ + R"(

)"; - ui_->feeder_info_edittext->moveCursor(QTextCursor::End); feederSetHtmlSignal(QString::fromStdString(html)); - ui_->feeder_info_edittext->ensureCursorVisible(); + feederScrollSignal("scrollToMe"); } void MementarGUI::feederAddSlot() { + if(updateTimelinePtr() == false) + return; + std::string subject = ui_->feeder_subject_editline->text().toStdString(); std::string predicat = ui_->feeder_property_editline->text().toStdString(); std::string object = ui_->feeder_object_editline->text().toStdString(); @@ -545,31 +536,21 @@ void MementarGUI::feederAddSlot() } else { - std::string instance_ns = ui_->static_instance_name_editline->text().toStdString(); - if(instance_ns.empty()) - instance_ns = "_"; - createPublisher(instance_ns); if((predicat.empty()) && (object.empty())) - { - mementar::compat::MementarAction msg; - msg.name = subject; - msg.start_stamp = current_time_; - msg.end_stamp.seconds = 0; - msg.end_stamp.nanoseconds = 0; - actions_publishers_[instance_ns]->publish(msg); - } + timeline_->action_feeder_.insert(subject, mementar::compat::mem_ros::Time(current_time_.seconds, current_time_.nanoseconds)); else { - mementar::compat::StampedString msg; - msg.data = "[ADD]" + subject + "|" + predicat + "|" + object; - msg.stamp = current_time_; - facts_publishers_[instance_ns]->publish(msg); + mementar::Fact fact(subject, predicat, object, true); + timeline_->fact_feeder_.insert(fact, mementar::compat::mem_ros::Time(current_time_.seconds, current_time_.nanoseconds)); } } } void MementarGUI::feederDelSlot() { + if(updateTimelinePtr() == false) + return; + std::string subject = ui_->feeder_subject_editline->text().toStdString(); std::string predicat = ui_->feeder_property_editline->text().toStdString(); std::string object = ui_->feeder_object_editline->text().toStdString(); @@ -580,74 +561,54 @@ void MementarGUI::feederDelSlot() } else { - std::string instance_ns = ui_->static_instance_name_editline->text().toStdString(); - if(instance_ns.empty()) - instance_ns = "_"; - createPublisher(instance_ns); if((predicat.empty()) && (object.empty())) - { - mementar::compat::MementarAction msg; - msg.name = subject; - msg.start_stamp.seconds = 0; - msg.start_stamp.nanoseconds = 0; - msg.end_stamp = current_time_; - actions_publishers_[instance_ns]->publish(msg); - } + timeline_->action_feeder_.insertEnd(subject, mementar::compat::mem_ros::Time(current_time_.seconds, current_time_.nanoseconds)); else { - mementar::compat::StampedString msg; - msg.data = "[DEL]" + subject + "|" + predicat + "|" + object; - msg.stamp = current_time_; - facts_publishers_[instance_ns]->publish(msg); + mementar::Fact fact(subject, predicat, object, false); + timeline_->fact_feeder_.insert(fact, mementar::compat::mem_ros::Time(current_time_.seconds, current_time_.nanoseconds)); } } } void MementarGUI::feederCommitSlot() { - mementar::compat::StampedString msg; - msg.data = "[commit]" + ui_->feeder_commit_name_editline->text().toStdString() + "|"; - std::string instance_ns = ui_->static_instance_name_editline->text().toStdString(); - if(instance_ns.empty()) - instance_ns = "_"; - createPublisher(instance_ns); - facts_publishers_[instance_ns]->publish(msg); + if(updateTimelinePtr() == false) + return; + + // timeline_->fact_feeder_.commit(ui_->feeder_commit_name_editline->text().toStdString()); } void MementarGUI::feederCheckoutSlot() { - mementar::compat::StampedString msg; - msg.data = "[checkout]" + ui_->feeder_commit_name_editline->text().toStdString() + "|"; - std::string instance_ns = ui_->static_instance_name_editline->text().toStdString(); - if(instance_ns.empty()) - instance_ns = "_"; - createPublisher(instance_ns); - facts_publishers_[instance_ns]->publish(msg); + if(updateTimelinePtr() == false) + return; + + // timeline_->fact_feeder_.checkout(ui_->feeder_commit_name_editline->text().toStdString()); } -void MementarGUI::createPublisher(const std::string& instance_ns) +bool MementarGUI::updateTimelinePtr() { - if(facts_publishers_.find(instance_ns) == facts_publishers_.end()) - { - facts_publishers_[instance_ns] = std::make_unique>( - "mementar/insert_fact_stamped/" + instance_ns, QUEU_SIZE); + if(multi_usage_ == false) + return true; - while(mementar::compat::mem_ros::Node::ok() && (facts_publishers_[instance_ns]->getNumSubscribers() == 0)) - { - // todo - // ros::spinOnce(); - } - } - - if(actions_publishers_.find(instance_ns) == actions_publishers_.end()) + const std::string instance_name = ui_->static_instance_name_editline->text().toStdString(); + timeline_ = timelines_.get(instance_name); + if(timeline_ == nullptr) { - actions_publishers_[instance_ns] = std::make_unique>( - "mementar/insert_action/" + instance_ns, QUEU_SIZE); - - while(mementar::compat::mem_ros::Node::ok() && (actions_publishers_[instance_ns]->getNumSubscribers() == 0)) + auto intances_name = timelines_.list(); + if(std::find(intances_name.begin(), intances_name.end(), instance_name) != intances_name.end()) { - // todo - // ros::spinOnce(); + timelines_.add(instance_name); + timeline_ = timelines_.get(instance_name); + if(timeline_ != nullptr) + return true; } + + if(instance_name.empty() == false) + displayErrorInfo("Instance " + instance_name + " does not exist"); + return false; } + else + return true; }