ros2_control - humble
Loading...
Searching...
No Matches
loaned_state_interface.hpp
1// Copyright 2020 Open Source Robotics Foundation, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef HARDWARE_INTERFACE__LOANED_STATE_INTERFACE_HPP_
16#define HARDWARE_INTERFACE__LOANED_STATE_INTERFACE_HPP_
17
18#include <functional>
19#include <string>
20#include <utility>
21
22#include "hardware_interface/handle.hpp"
23
24namespace hardware_interface
25{
27{
28public:
29 using Deleter = std::function<void(void)>;
30
31 explicit LoanedStateInterface(StateInterface & state_interface)
32 : LoanedStateInterface(state_interface, nullptr)
33 {
34 }
35
36 LoanedStateInterface(StateInterface & state_interface, Deleter && deleter)
37 : state_interface_(state_interface), deleter_(std::forward<Deleter>(deleter))
38 {
39 }
40
41 LoanedStateInterface(const LoanedStateInterface & other) = delete;
42
44
45 virtual ~LoanedStateInterface()
46 {
47 if (deleter_)
48 {
49 deleter_();
50 }
51 }
52
53 const std::string get_name() const { return state_interface_.get_name(); }
54
55 const std::string & get_interface_name() const { return state_interface_.get_interface_name(); }
56
57 [[deprecated(
58 "Replaced by get_name method, which is semantically more correct")]] const std::string
59 get_full_name() const
60 {
61 return state_interface_.get_name();
62 }
63
64 const std::string & get_prefix_name() const { return state_interface_.get_prefix_name(); }
65
66 double get_value() const { return state_interface_.get_value(); }
67
68protected:
69 StateInterface & state_interface_;
70 Deleter deleter_;
71};
72
73} // namespace hardware_interface
74#endif // HARDWARE_INTERFACE__LOANED_STATE_INTERFACE_HPP_
Definition loaned_state_interface.hpp:27
Definition handle.hpp:117
Definition actuator.hpp:31