Skip to content

Commit

Permalink
Add name to data storage to hold pipeline name
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jul 24, 2024
1 parent 8ff54de commit 376a16d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<std::string, tesseract_common::AnyPoly> data_;
};

Expand Down
17 changes: 15 additions & 2 deletions tesseract_task_composer/core/src/task_composer_data_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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); }
Expand All @@ -171,6 +183,7 @@ template <class Archive>
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_);
}

Expand Down
3 changes: 3 additions & 0 deletions tesseract_task_composer/core/src/task_composer_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
#include <tesseract_task_composer/core/task_composer_executor.h>
#include <tesseract_task_composer/core/task_composer_future.h>
#include <tesseract_task_composer/core/task_composer_node.h>
#include <tesseract_task_composer/core/task_composer_data_storage.h>
#include <tesseract_task_composer/core/task_composer_plugin_factory.h>

namespace tesseract_planning
Expand Down Expand Up @@ -129,6 +130,7 @@ std::unique_ptr<TaskComposerFuture> 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);
}

Expand All @@ -141,6 +143,7 @@ std::unique_ptr<TaskComposerFuture> 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);
}

Expand Down

0 comments on commit 376a16d

Please sign in to comment.