Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mamueluth committed Dec 20, 2023
1 parent 6144b74 commit 626412b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
15 changes: 11 additions & 4 deletions hardware_interface/include/hardware_interface/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef std::variant<double> HANDLE_DATATYPE;
class Handle
{
public:
[[deprecated("Use InterfaceDescription for initializing the Command-/StateIntefaces.")]]
[[deprecated("Use InterfaceDescription for initializing the Interface")]]

Handle(
const std::string & prefix_name, const std::string & interface_name,
Expand All @@ -52,14 +52,14 @@ class Handle
value_ptr_ = std::get_if<double>(&value_);
}

[[deprecated("Use InterfaceDescription for initializing the Command-/StateIntefaces.")]]
[[deprecated("Use InterfaceDescription for initializing the Interface")]]

explicit Handle(const std::string & interface_name)
: interface_name_(interface_name), value_ptr_(nullptr)
{
}

[[deprecated("Use InterfaceDescription for initializing the Command-/StateIntefaces.")]]
[[deprecated("Use InterfaceDescription for initializing the Interface")]]

explicit Handle(const char * interface_name)
: interface_name_(interface_name), value_ptr_(nullptr)
Expand Down Expand Up @@ -93,23 +93,30 @@ class Handle
const std::string & get_prefix_name() const { return prefix_name_; }

double get_value() const
{
{ // BEGIN (Handle export change): for backward compatibility
// TODO(Manuel) return value_ if old functionality is removed
THROW_ON_NULLPTR(value_ptr_);
return *value_ptr_;
// END
}

void set_value(double value)
{
// BEGIN (Handle export change): for backward compatibility
// TODO(Manuel) set value_ directly if old functionality is removed
THROW_ON_NULLPTR(this->value_ptr_);
*this->value_ptr_ = value;
// END
}

protected:
std::string prefix_name_;
std::string interface_name_;
HANDLE_DATATYPE value_;
// BEGIN (Handle export change): for backward compatibility
// TODO(Manuel) redeclare as HANDLE_DATATYPE * value_ptr_ if old functionality is removed
double * value_ptr_;
// END
};

class StateInterface : public Handle
Expand Down
34 changes: 17 additions & 17 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ class ResourceStorage
}
}

// TODO(Manuel) BEGIN: for backward compatibility, can be removed if export_state_interfaces()
// method is removed
// BEGIN (Handle export change): for backward compatibility, can be removed if
// export_state_interfaces() method is removed
void insert_state_interface(const StateInterface & state_interface)
{
const auto [it, success] = state_interface_map_.emplace(std::make_pair(
Expand All @@ -456,7 +456,7 @@ class ResourceStorage
throw std::runtime_error(msg);
}
}
// TODO(Manuel) END: for backward compatibility
// END: for backward compatibility

template <class HardwareT>
void import_state_interfaces(HardwareT & hardware)
Expand All @@ -467,7 +467,7 @@ class ResourceStorage
// a) there is nothing to export -> on_export_state_interfaces() does return nothing as well
// b) default implementation for export_state_interfaces() is used -> new functionality ->
// Framework exports and creates everything
if (interfaces.size() == 0)
if (interfaces.empty())
{
std::vector<std::shared_ptr<StateInterface>> interface_ptrs =
hardware.on_export_state_interfaces();
Expand All @@ -478,8 +478,8 @@ class ResourceStorage
interface_names.push_back(interface->get_name());
}
}
// TODO(Manuel) BEGIN: for backward compatibility, can be removed if export_state_interfaces()
// method is removed
// BEGIN (Handle export change): for backward compatibility, can be removed if
// export_state_interfaces() method is removed
else
{
interface_names.reserve(interfaces.size());
Expand All @@ -489,7 +489,7 @@ class ResourceStorage
interface_names.push_back(interface.get_name());
}
}
// TODO(Manuel) END: for backward compatibility
// END: for backward compatibility

hardware_info_map_[hardware.get_name()].state_interfaces = interface_names;
available_state_interfaces_.reserve(
Expand All @@ -509,8 +509,8 @@ class ResourceStorage
}
}

// TODO(Manuel) BEGIN: for backward compatibility, can be removed if export_command_interfaces()
// method is removed
// BEGIN (Handle export change): for backward compatibility, can be removed if
// export_command_interfaces() method is removed
void insert_command_interface(CommandInterface && command_interface)
{
std::string key = command_interface.get_name();
Expand All @@ -524,7 +524,7 @@ class ResourceStorage
throw std::runtime_error(msg);
}
}
// TODO(Manuel) END: for backward compatibility
// END: for backward compatibility

template <class HardwareT>
void import_command_interfaces(HardwareT & hardware)
Expand All @@ -534,21 +534,21 @@ class ResourceStorage
// a) there is nothing to export -> on_export_command_interfaces() does return nothing as well
// b) default implementation for export_command_interfaces() is used -> new functionality ->
// Framework exports and creates everything
if (interfaces.size() == 0)
if (interfaces.empty())
{
std::vector<std::shared_ptr<CommandInterface>> interface_ptrs =
hardware.on_export_command_interfaces();
hardware_info_map_[hardware.get_name()].command_interfaces =
add_command_interfaces(interface_ptrs);
}
// TODO(Manuel) BEGIN: for backward compatibility, can be removed if export_command_interfaces()
// method is removed
// BEGIN (Handle export change): for backward compatibility, can be removed if
// export_command_interfaces() method is removed
else
{
hardware_info_map_[hardware.get_name()].command_interfaces =
add_command_interfaces(interfaces);
}
// TODO(Manuel) END: for backward compatibility
// END: for backward compatibility
}

/// Adds exported command interfaces into internal storage.
Expand All @@ -562,8 +562,8 @@ class ResourceStorage
* \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.
*/
// TODO(Manuel) BEGIN: for backward compatibility, can be removed if export_command_interfaces()
// method is removed
// BEGIN (Handle export change): for backward compatibility, can be removed if
// export_command_interfaces() method is removed
std::vector<std::string> add_command_interfaces(std::vector<CommandInterface> & interfaces)
{
std::vector<std::string> interface_names;
Expand All @@ -580,7 +580,7 @@ class ResourceStorage

return interface_names;
}
// TODO(Manuel) END: for backward compatibility
// END: for backward compatibility

std::vector<std::string> add_command_interfaces(
std::vector<std::shared_ptr<CommandInterface>> & interfaces)
Expand Down

0 comments on commit 626412b

Please sign in to comment.