ros2_control - galactic
loaned_command_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_COMMAND_INTERFACE_HPP_
16 #define HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_
17 
18 #include <functional>
19 #include <string>
20 #include <utility>
21 
22 #include "hardware_interface/handle.hpp"
23 
24 namespace hardware_interface
25 {
27 {
28 public:
29  using Deleter = std::function<void(void)>;
30 
31  explicit LoanedCommandInterface(CommandInterface & command_interface)
32  : LoanedCommandInterface(command_interface, nullptr)
33  {
34  }
35 
36  LoanedCommandInterface(CommandInterface & command_interface, Deleter && deleter)
37  : command_interface_(command_interface), deleter_(std::forward<Deleter>(deleter))
38  {
39  }
40 
41  LoanedCommandInterface(const LoanedCommandInterface & other) = delete;
42 
44 
45  virtual ~LoanedCommandInterface()
46  {
47  if (deleter_)
48  {
49  deleter_();
50  }
51  }
52 
53  const std::string & get_name() const { return command_interface_.get_name(); }
54 
55  const std::string & get_interface_name() const { return command_interface_.get_interface_name(); }
56 
57  const std::string get_full_name() const { return command_interface_.get_full_name(); }
58 
59  void set_value(double val) { command_interface_.set_value(val); }
60 
61  double get_value() const { return command_interface_.get_value(); }
62 
63 protected:
64  CommandInterface & command_interface_;
65  Deleter deleter_;
66 };
67 
68 } // namespace hardware_interface
69 #endif // HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_
Definition: handle.hpp:118
Definition: loaned_command_interface.hpp:27
Definition: actuator.hpp:29