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 #ifndef HARDWARE_INTERFACE_HARDWARE_RESOURCE_MANAGER_H
31 #define HARDWARE_INTERFACE_HARDWARE_RESOURCE_MANAGER_H
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 }
129 
130 #endif // HARDWARE_INTERFACE_HARDWARE_RESOURCE_MANAGER_H
Abstract Hardware Interface.
An exception related to a HardwareInterface.
virtual void claim(std::string resource)
Claim a resource by name.
Class for handling named resources.
ResourceHandle getHandle(const std::string &name)
Get a resource handle by name.
ResourceHandle getHandle(const std::string &name)
Get a resource handle by name.
Base class for handling hardware resources.


hardware_interface
Author(s): Wim Meeussen, Adolfo Rodriguez Tsouroukdissian
autogenerated on Mon Apr 20 2020 03:52:05