-
Couldn't load subscription status.
- Fork 372
Resource Manager extension to support management of reference interfaces from chained controllers. #664
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
Resource Manager extension to support management of reference interfaces from chained controllers. #664
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,7 +221,8 @@ class ResourceStorage | |
| { | ||
| available_command_interfaces_.erase(found_it); | ||
| RCUTILS_LOG_DEBUG_NAMED( | ||
| "resource_manager", "(hardware '%s'): '%s' command removed from available list", | ||
| "resource_manager", | ||
| "(hardware '%s'): '%s' command interface removed from available list", | ||
| hardware.get_name().c_str(), interface.c_str()); | ||
| } | ||
| else | ||
|
|
@@ -275,6 +276,7 @@ class ResourceStorage | |
| // TODO(destogl): change this - deimport all things if there is there are interfaces there | ||
| // deimport_non_movement_command_interfaces(hardware); | ||
| // deimport_state_interfaces(hardware); | ||
| // use remove_command_interfaces(hardware); | ||
| } | ||
| return result; | ||
| } | ||
|
|
@@ -429,6 +431,22 @@ class ResourceStorage | |
| void import_command_interfaces(HardwareT & hardware) | ||
| { | ||
| auto interfaces = hardware.export_command_interfaces(); | ||
| hardware_info_map_[hardware.get_name()].command_interfaces = add_command_interfaces(interfaces); | ||
| } | ||
|
|
||
| /// Adds exported command interfaces into internal storage. | ||
| /** | ||
| * Add command interfaces to the internal storage. Command interfaces exported from hardware or | ||
| * chainable controllers are moved to the map with name-interface pairs, the interface names are | ||
| * added to the claimed map and available list's size is increased to reserve storage when | ||
| * interface change theirs status in real-time control loop. | ||
| * | ||
| * \param[interfaces] list of command interface to add into storage. | ||
| * \returns list of interface names that are added into internal storage. The output is used to | ||
| * avoid additional iterations to cache interface names, e.g., for initializing info structures. | ||
| */ | ||
| std::vector<std::string> add_command_interfaces(std::vector<CommandInterface> & interfaces) | ||
destogl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| std::vector<std::string> interface_names; | ||
| interface_names.reserve(interfaces.size()); | ||
| for (auto & interface : interfaces) | ||
|
|
@@ -438,9 +456,25 @@ class ResourceStorage | |
| claimed_command_interface_map_.emplace(std::make_pair(key, false)); | ||
| interface_names.push_back(key); | ||
| } | ||
| hardware_info_map_[hardware.get_name()].command_interfaces = interface_names; | ||
| available_command_interfaces_.reserve( | ||
| available_command_interfaces_.capacity() + interface_names.size()); | ||
|
|
||
| return interface_names; | ||
| } | ||
|
|
||
| /// Removes command interfaces from internal storage. | ||
| /** | ||
| * Command interface are removed from the maps with theirs storage and their claimed status. | ||
| * | ||
| * \param[interface_names] list of command interface names to remove from storage. | ||
| */ | ||
| void remove_command_interfaces(const std::vector<std::string> & interface_names) | ||
destogl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| for (const auto & interface : interface_names) | ||
| { | ||
| command_interface_map_.erase(interface); | ||
| claimed_command_interface_map_.erase(interface); | ||
| } | ||
| } | ||
|
|
||
| // TODO(destogl): Propagate "false" up, if happens in initialize_hardware | ||
|
|
@@ -504,6 +538,8 @@ class ResourceStorage | |
|
|
||
| std::unordered_map<std::string, HardwareComponentInfo> hardware_info_map_; | ||
|
|
||
| std::unordered_map<std::string, std::vector<std::string>> controllers_reference_interfaces_map_; | ||
|
|
||
| /// Storage of all available state interfaces | ||
| std::map<std::string, StateInterface> state_interface_map_; | ||
| /// Storage of all available command interfaces | ||
|
|
@@ -597,6 +633,7 @@ std::vector<std::string> ResourceManager::state_interface_keys() const | |
|
|
||
| std::vector<std::string> ResourceManager::available_state_interfaces() const | ||
| { | ||
| std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_); | ||
| return resource_storage_->available_state_interfaces_; | ||
| } | ||
|
|
||
|
|
@@ -616,7 +653,66 @@ bool ResourceManager::state_interface_is_available(const std::string & name) con | |
| name) != resource_storage_->available_state_interfaces_.end(); | ||
| } | ||
|
|
||
| // CM API | ||
| void ResourceManager::import_controller_reference_interfaces( | ||
| const std::string & controller_name, std::vector<CommandInterface> & interfaces) | ||
| { | ||
| std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_); | ||
| std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_); | ||
| auto interface_names = resource_storage_->add_command_interfaces(interfaces); | ||
| resource_storage_->controllers_reference_interfaces_map_[controller_name] = interface_names; | ||
| } | ||
|
|
||
| std::vector<std::string> ResourceManager::get_controller_reference_interface_names( | ||
| const std::string & controller_name) | ||
| { | ||
| return resource_storage_->controllers_reference_interfaces_map_.at(controller_name); | ||
| } | ||
|
|
||
| void ResourceManager::make_controller_reference_interfaces_available( | ||
| const std::string & controller_name) | ||
| { | ||
| auto interface_names = | ||
| resource_storage_->controllers_reference_interfaces_map_.at(controller_name); | ||
| std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_); | ||
| resource_storage_->available_command_interfaces_.insert( | ||
| resource_storage_->available_command_interfaces_.end(), interface_names.begin(), | ||
| interface_names.end()); | ||
| } | ||
|
|
||
| void ResourceManager::make_controller_reference_interfaces_unavailable( | ||
| const std::string & controller_name) | ||
| { | ||
| auto interface_names = | ||
| resource_storage_->controllers_reference_interfaces_map_.at(controller_name); | ||
|
|
||
| std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_); | ||
| for (const auto & interface : interface_names) | ||
| { | ||
| auto found_it = std::find( | ||
| resource_storage_->available_command_interfaces_.begin(), | ||
| resource_storage_->available_command_interfaces_.end(), interface); | ||
| if (found_it != resource_storage_->available_command_interfaces_.end()) | ||
| { | ||
| resource_storage_->available_command_interfaces_.erase(found_it); | ||
| RCUTILS_LOG_DEBUG_NAMED( | ||
| "resource_manager", "'%s' command interface removed from available list", | ||
| interface.c_str()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void ResourceManager::remove_controller_reference_interfaces(const std::string & controller_name) | ||
| { | ||
| auto interface_names = | ||
| resource_storage_->controllers_reference_interfaces_map_.at(controller_name); | ||
| resource_storage_->controllers_reference_interfaces_map_.erase(controller_name); | ||
|
|
||
| std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_); | ||
bmagyar marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in other cases you put the guards into the function that is called. Is this different for any reason? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
| std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_); | ||
| resource_storage_->remove_command_interfaces(interface_names); | ||
| } | ||
|
|
||
| // CM API: Called in "update"-thread | ||
| bool ResourceManager::command_interface_is_claimed(const std::string & key) const | ||
| { | ||
| if (!command_interface_is_available(key)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.