Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name to data storage to hold pipeline name #482

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add name to data storage to hold pipeline name
Levi-Armstrong committed Jul 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 2004f23f3677d079b00231ba623d086cbb8f502a
Original file line number Diff line number Diff line change
@@ -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<std::string, tesseract_common::AnyPoly> data_;
};

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
@@ -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 <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_);
}

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
@@ -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
@@ -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);
}

@@ -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);
}