Skip to content

Commit

Permalink
Add constructor using sharedptr, deprecated reference-based ones
Browse files Browse the repository at this point in the history
  • Loading branch information
bmagyar committed Oct 7, 2024
1 parent f4ec3d6 commit 9c16a79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ class LoanedCommandInterface
public:
using Deleter = std::function<void(void)>;

explicit LoanedCommandInterface(CommandInterface & command_interface)
[[deprecated("Replaced by the new version using shared_ptr")]] explicit LoanedCommandInterface(
CommandInterface & command_interface)
: LoanedCommandInterface(command_interface, nullptr)
{
}

LoanedCommandInterface(CommandInterface & command_interface, Deleter && deleter)
[[deprecated("Replaced by the new version using shared_ptr")]] LoanedCommandInterface(
CommandInterface & command_interface, Deleter && deleter)
: command_interface_(command_interface), deleter_(std::forward<Deleter>(deleter))
{
}

LoanedCommandInterface(CommandInterface::SharedPtr command_interface, Deleter && deleter)
: command_interface_(*command_interface), deleter_(std::forward<Deleter>(deleter))
{
}

LoanedCommandInterface(const LoanedCommandInterface & other) = delete;

LoanedCommandInterface(LoanedCommandInterface && other) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ class LoanedStateInterface
public:
using Deleter = std::function<void(void)>;

explicit LoanedStateInterface(StateInterface & state_interface)
[[deprecated("Replaced by the new version using shared_ptr")]] explicit LoanedStateInterface(
StateInterface & state_interface)
: LoanedStateInterface(state_interface, nullptr)
{
}

LoanedStateInterface(StateInterface & state_interface, Deleter && deleter)
[[deprecated("Replaced by the new version using shared_ptr")]] LoanedStateInterface(
StateInterface & state_interface, Deleter && deleter)
: state_interface_(state_interface), deleter_(std::forward<Deleter>(deleter))
{
}

LoanedStateInterface(StateInterface::SharedPtr state_interface, Deleter && deleter)
: state_interface_(*state_interface), deleter_(std::forward<Deleter>(deleter))
{
}

LoanedStateInterface(const LoanedStateInterface & other) = delete;

LoanedStateInterface(LoanedStateInterface && other) = default;
Expand Down
4 changes: 2 additions & 2 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ LoanedStateInterface ResourceManager::claim_state_interface(const std::string &
}

std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
return LoanedStateInterface(*(resource_storage_->state_interface_map_.at(key)));
return LoanedStateInterface(resource_storage_->state_interface_map_.at(key));
}

// CM API: Called in "callback/slow"-thread
Expand Down Expand Up @@ -1440,7 +1440,7 @@ LoanedCommandInterface ResourceManager::claim_command_interface(const std::strin
resource_storage_->claimed_command_interface_map_[key] = true;
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
return LoanedCommandInterface(
*(resource_storage_->command_interface_map_.at(key)),
resource_storage_->command_interface_map_.at(key),
std::bind(&ResourceManager::release_command_interface, this, key));
}

Expand Down

0 comments on commit 9c16a79

Please sign in to comment.