hardware_resource_manager.h
Go to the documentation of this file.
1 // Copyright (C) 2013, PAL Robotics S.L.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of hiDOF, Inc. nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
29 
30 #pragma once
31 
32 
33 #include <string>
34 
37 
38 namespace hardware_interface
39 {
40 
41 struct ClaimResources;
42 struct DontClaimResources;
43 
78 template <class ResourceHandle, class ClaimPolicy = DontClaimResources>
79 class HardwareResourceManager : public HardwareInterface, public ResourceManager<ResourceHandle>
80 {
81 public:
82  typedef ResourceHandle ResourceHandleType;
83 
96  ResourceHandle getHandle(const std::string& name)
97  {
98  try
99  {
100  ResourceHandle out = this->ResourceManager<ResourceHandle>::getHandle(name);
101 
102  // If ClaimPolicy type is ClaimResources, the below method claims resources, for DontClaimResources it's a no-op
103  ClaimPolicy::claim(this, name);
104 
105  return out;
106  }
107  catch(const std::logic_error& e)
108  {
109  throw HardwareInterfaceException(e.what());
110  }
111  }
112 
113  /*\}*/
114 };
115 
117 struct ClaimResources
118 {
119  static void claim(HardwareInterface* hw, const std::string& name) {hw->claim(name);}
120 };
121 
122 struct DontClaimResources
123 {
124  static void claim(HardwareInterface* /*hw*/, const std::string& /*name*/) {}
125 };
128 }
hardware_interface::HardwareResourceManager::ResourceHandleType
ResourceHandle ResourceHandleType
Definition: hardware_resource_manager.h:82
hardware_interface::HardwareResourceManager::getHandle
ResourceHandle getHandle(const std::string &name)
Get a resource handle by name.
Definition: hardware_resource_manager.h:96
hardware_interface::HardwareInterface
Abstract Hardware Interface.
Definition: hardware_interface.h:46
hardware_interface
Definition: actuator_command_interface.h:36
hardware_interface::ResourceManager
Class for handling named resources.
Definition: resource_manager.h:69
hardware_interface::ResourceManager::getHandle
ResourceHandle getHandle(const std::string &name)
Get a resource handle by name.
Definition: resource_manager.h:113
hardware_interface::HardwareInterfaceException
An exception related to a HardwareInterface.
Definition: hardware_interface.h:71
hardware_interface.h
resource_manager.h
hardware_interface::HardwareResourceManager
Base class for handling hardware resources.
Definition: hardware_resource_manager.h:79


hardware_interface
Author(s): Wim Meeussen, Adolfo Rodriguez Tsouroukdissian
autogenerated on Tue Oct 15 2024 02:08:19