@@ -460,6 +460,33 @@ class ResourceStorage
460460 hardware_info_map_[hardware.get_name ()].command_interfaces = add_command_interfaces (interfaces);
461461 }
462462
463+ void add_command_interface (std::shared_ptr<ReadWriteHandle> command_interface)
464+ {
465+ const auto [it, success] = command_interface_map_.insert (
466+ std::make_pair (command_interface->get_name (), command_interface));
467+ if (!success)
468+ {
469+ std::string msg (
470+ " ResourceStorage: Tried to insert CommandInterface with already existing key. Insert[" +
471+ command_interface->get_name () + " ]" );
472+ throw std::runtime_error (msg);
473+ }
474+ }
475+
476+ void add_command_interface (CommandInterface && command_interface)
477+ {
478+ const auto [it, success] = command_interface_map_.emplace (std::make_pair (
479+ command_interface.get_name (),
480+ std::make_shared<CommandInterface>(std::move (command_interface))));
481+ if (!success)
482+ {
483+ std::string msg (
484+ " ResourceStorage: Tried to insert CommandInterface with already existing key. Insert[" +
485+ command_interface.get_name () + " ]" );
486+ throw std::runtime_error (msg);
487+ }
488+ }
489+
463490 // / Adds exported command interfaces into internal storage.
464491 /* *
465492 * Add command interfaces to the internal storage. Command interfaces exported from hardware or
@@ -478,7 +505,7 @@ class ResourceStorage
478505 for (auto & interface : interfaces)
479506 {
480507 auto key = interface.get_name ();
481- command_interface_map_. emplace (std::make_pair (key, std:: move (interface) ));
508+ add_command_interface (std::move (interface));
482509 claimed_command_interface_map_.emplace (std::make_pair (key, false ));
483510 interface_names.push_back (key);
484511 }
@@ -563,13 +590,13 @@ class ResourceStorage
563590 std::pair<bool , std::shared_ptr<distributed_control::CommandForwarder>> find_command_forwarder (
564591 const std::string & key)
565592 {
566- // auto command_forwarder = state_interface_state_publisher_map_ .find(key);
567- // // we could not find a command forwarder for the provided key
568- // if (command_forwarder == state_interface_state_publisher_map_ .end())
569- // {
570- // return std::make_pair(false, nullptr);
571- // }
572- // return std::make_pair(true, command_forwarder->second);
593+ auto command_forwarder = command_interface_command_forwarder_map_ .find (key);
594+ // we could not find a command forwarder for the provided key
595+ if (command_forwarder == command_interface_command_forwarder_map_ .end ())
596+ {
597+ return std::make_pair (false , nullptr );
598+ }
599+ return std::make_pair (true , command_forwarder->second );
573600 }
574601
575602 void check_for_duplicates (const HardwareInfo & hardware_info)
@@ -708,7 +735,7 @@ class ResourceStorage
708735 // / Storage of all available state interfaces
709736 std::map<std::string, std::shared_ptr<ReadOnlyHandle>> state_interface_map_;
710737 // / Storage of all available command interfaces
711- std::map<std::string, CommandInterface > command_interface_map_;
738+ std::map<std::string, std::shared_ptr<ReadWriteHandle> > command_interface_map_;
712739
713740 // / Vectors with interfaces available to controllers (depending on hardware component state)
714741 std::vector<std::string> available_state_interfaces_;
@@ -919,7 +946,7 @@ ResourceManager::get_command_forwarders() const
919946std::pair<bool , std::shared_ptr<distributed_control::CommandForwarder>>
920947ResourceManager::find_command_forwarder (const std::string & key)
921948{
922- // return resource_storage_->find_command_forwarder(key);
949+ return resource_storage_->find_command_forwarder (key);
923950}
924951
925952// CM API: Called in "callback/slow"-thread
0 commit comments