RobotPool.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2018
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <map>
27 #include <mutex>
28 
29 #include <VirtualRobot/VirtualRobot.h>
30 
31 namespace armarx
32 {
33 
34  /** This class holds a pool of local VirtualRobots for multi threaded applications
35  * that can be requested by the user.
36  * When calling getRobot() it is guaranteed that that robot is not requested by any other user/thread.
37  * When the return shared ptr goes out of the, the robot is available again.
38  *
39  */
40  class RobotPool
41  {
42  public:
43  RobotPool(VirtualRobot::RobotPtr robot, size_t defaultSize = 1);
44  /**
45  * @brief getRobot
46  * @param inflation inflation of collision model in mm
47  * @return
48  */
49  VirtualRobot::RobotPtr getRobot(int inflation = 0);
50  size_t getPoolSize() const;
51  size_t getRobotsInUseCount() const;
52  /**
53  * @brief Removes unused robots from the pool.
54  * @return number of cleaned up robots
55  */
56  size_t clean();
57 
58  private:
59  std::map<int, std::vector<VirtualRobot::RobotPtr>> robots;
60  VirtualRobot::RobotPtr baseRobot;
61  mutable std::mutex mutex;
62  };
63 
64  using RobotPoolPtr = std::shared_ptr<RobotPool>;
65 } // namespace armarx
armarx::RobotPool::RobotPool
RobotPool(VirtualRobot::RobotPtr robot, size_t defaultSize=1)
Definition: RobotPool.cpp:35
armarx::RobotPoolPtr
std::shared_ptr< class RobotPool > RobotPoolPtr
Definition: RobotUnitModuleRobotData.h:35
armarx::RobotPool::getPoolSize
size_t getPoolSize() const
Definition: RobotPool.cpp:68
armarx::RobotPool::clean
size_t clean()
Removes unused robots from the pool.
Definition: RobotPool.cpp:98
armarx::RobotPool
This class holds a pool of local VirtualRobots for multi threaded applications that can be requested ...
Definition: RobotPool.h:40
armarx::RobotPool::getRobot
VirtualRobot::RobotPtr getRobot(int inflation=0)
getRobot
Definition: RobotPool.cpp:45
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::RobotPool::getRobotsInUseCount
size_t getRobotsInUseCount() const
Definition: RobotPool.cpp:80
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19