resource_manager.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2018, University of Luxembourg
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of University of Luxembourg nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Maciej Zurad
36  *********************************************************************/
44 #ifndef ROBOT_ACTIVITY_RESOURCE_RESOURCE_MANAGER_H
45 #define ROBOT_ACTIVITY_RESOURCE_RESOURCE_MANAGER_H
46 
47 #include <ros/ros.h>
48 #include <ros/console.h>
49 
52 
53 #include <vector>
54 
55 namespace robot_activity
56 {
57 namespace resource
58 {
59 
69 template <class Resource>
71 {
72 public:
77 
82 
94  template<typename... Args>
95  typename Resource::SharedPtr add(Args&& ...args)
96  {
97  auto resource = std::make_shared<Resource>(std::forward<Args>(args)...);
98  resources_.push_back(resource);
99  return resource;
100  }
101 
107  void acquireAll(const ros::NodeHandlePtr& node_handle);
108 
112  void releaseAll();
113 
117  void pauseAll();
118 
122  void resumeAll();
123 
124 private:
125  std::vector<typename Resource::SharedPtr> resources_;
126 };
127 
133 template <class T>
134 class RMWrapper : public ResourceManager<T> {};
135 
140 template<>
141 class RMWrapper<ManagedSubscriber> : public ResourceManager<ManagedSubscriber>
142 {
143 public:
145 
158  template<typename... Args>
160  {
161  return add(std::forward<Args>(args)...);
162  }
163 };
164 
169 template<>
170 class RMWrapper<ManagedServiceServer> : public ResourceManager<ManagedServiceServer>
171 {
172 public:
174 
187  template<typename... Args>
189  {
190  return add(std::forward<Args>(args)...);
191  }
192 };
193 
196 
197 } // namespace resource
198 } // namespace robot_activity
199 
200 #endif // ROBOT_ACTIVITY_RESOURCE_RESOURCE_MANAGER_H
Resource::SharedPtr add(Args &&...args)
Adds a managed resource.
Specialization of the RMWrapper, where the managed resource is ManagedSubscriber. ...
void pauseAll()
Pauses all managed resources.
void resumeAll()
Resumes all managed resources.
Implementation of Managed class for ros::ServiceServer.
void acquireAll(const ros::NodeHandlePtr &node_handle)
Acquires all managed resources.
RMWrapper< ManagedSubscriber > SubscriberManager
ManagedServiceServer::SharedPtr advertiseService(Args &&...args)
Adds a service to the list of managed services.
ManagedSubscriber class implements a wrapper around ros::Subscriber with same functionality as ros::S...
Specialization of the RMWrapper, where the managed resource is ManagedServiceServer.
ManagedServiceServer class implements a wrapper around ros::ServiceServer with same functionality as ...
void releaseAll()
Releases all managed resources.
RMWrapper< ManagedServiceServer > ServiceServerManager
std::shared_ptr< Managed< ManagedSubscriber, ros::Subscriber > > SharedPtr
Implementation of Managed class for ros::Subscriber.
ManagedSubscriber::SharedPtr subscribe(Args &&...args)
Adds a subscriber to the list of managed subscribers.
Wrapper around the ResourceManager.
std::vector< typename Resource::SharedPtr > resources_


robot_activity
Author(s): Maciej ZURAD
autogenerated on Mon Jun 10 2019 14:33:22