diff --git a/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_data_storage.h b/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_data_storage.h index a46e55b1dc..4f71214351 100644 --- a/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_data_storage.h +++ b/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_data_storage.h @@ -56,12 +56,25 @@ class TaskComposerDataStorage TaskComposerDataStorage(TaskComposerDataStorage&&) noexcept; TaskComposerDataStorage& operator=(TaskComposerDataStorage&&) noexcept; + /** + * @brief Get the name data storage. + * @details This is primarily used to hold the pipeline name + * @return The name + */ + std::string getName() const; + + /** + * @brief Set the name + * @param name The name + */ + void setName(const std::string& name); + /** * @brief Check if key exists * @param key The key to check for * @return True if the key exist, otherwise false */ - bool hasKey(const std::string& key); + bool hasKey(const std::string& key) const; /** * @brief Set data for the provided key @@ -109,6 +122,7 @@ class TaskComposerDataStorage void serialize(Archive& ar, const unsigned int version); // NOLINT mutable std::shared_mutex mutex_; + std::string name_; std::unordered_map data_; }; diff --git a/tesseract_task_composer/core/src/task_composer_data_storage.cpp b/tesseract_task_composer/core/src/task_composer_data_storage.cpp index eced65def5..eca6cb4b25 100644 --- a/tesseract_task_composer/core/src/task_composer_data_storage.cpp +++ b/tesseract_task_composer/core/src/task_composer_data_storage.cpp @@ -81,7 +81,19 @@ TaskComposerDataStorage& TaskComposerDataStorage::operator=(TaskComposerDataStor return *this; } -bool TaskComposerDataStorage::hasKey(const std::string& key) +std::string TaskComposerDataStorage::getName() const +{ + std::shared_lock lock(mutex_); + return name_; +} + +void TaskComposerDataStorage::setName(const std::string& name) +{ + std::unique_lock lock(mutex_); + name_ = name; +} + +bool TaskComposerDataStorage::hasKey(const std::string& key) const { std::shared_lock lock(mutex_); return (data_.find(key) != data_.end()); @@ -162,7 +174,7 @@ bool TaskComposerDataStorage::operator==(const TaskComposerDataStorage& rhs) con std::shared_lock lhs_lock(mutex_, std::defer_lock); std::shared_lock rhs_lock(rhs.mutex_, std::defer_lock); std::scoped_lock lock{ lhs_lock, rhs_lock }; - return (data_ == rhs.data_); + return ((data_ == rhs.data_) && (name_ == rhs.name_)); } bool TaskComposerDataStorage::operator!=(const TaskComposerDataStorage& rhs) const { return !operator==(rhs); } @@ -171,6 +183,7 @@ template void TaskComposerDataStorage::serialize(Archive& ar, const unsigned int /*version*/) { std::unique_lock lock(mutex_); + ar& boost::serialization::make_nvp("name", name_); ar& boost::serialization::make_nvp("data", data_); } diff --git a/tesseract_task_composer/core/src/task_composer_server.cpp b/tesseract_task_composer/core/src/task_composer_server.cpp index 744520b5c8..a414865491 100644 --- a/tesseract_task_composer/core/src/task_composer_server.cpp +++ b/tesseract_task_composer/core/src/task_composer_server.cpp @@ -34,6 +34,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP #include #include #include +#include #include namespace tesseract_planning @@ -129,6 +130,7 @@ std::unique_ptr TaskComposerServer::run(const std::string& t if (t_it == tasks_.end()) throw std::runtime_error("Task with name '" + task_name + "' does not exist!"); + data_storage->setName(task_name); return e_it->second->run(*t_it->second, std::move(data_storage), dotgraph); } @@ -141,6 +143,7 @@ std::unique_ptr TaskComposerServer::run(const TaskComposerNo if (it == executors_.end()) throw std::runtime_error("Executor with name '" + executor_name + "' does not exist!"); + data_storage->setName(node.getName()); return it->second->run(node, std::move(data_storage), dotgraph); }