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 <VirtualRobot/Robot.h>
27 
28 #include <mutex>
29 
30 namespace armarx
31 {
32 
33  /** This class holds a pool of local VirtualRobots for multi threaded applications
34  * that can be requested by the user.
35  * When calling getRobot() it is guaranteed that that robot is not requested by any other user/thread.
36  * When the return shared ptr goes out of the, the robot is available again.
37  *
38  */
39  class RobotPool
40  {
41  public:
42  RobotPool(VirtualRobot::RobotPtr robot, size_t defaultSize = 1);
43  /**
44  * @brief getRobot
45  * @param inflation inflation of collision model in mm
46  * @return
47  */
48  VirtualRobot::RobotPtr getRobot(int inflation = 0);
49  size_t getPoolSize() const;
50  size_t getRobotsInUseCount() const;
51  /**
52  * @brief Removes unused robots from the pool.
53  * @return number of cleaned up robots
54  */
55  size_t clean();
56  private:
57  std::map<int, std::vector<VirtualRobot::RobotPtr>> robots;
58  VirtualRobot::RobotPtr baseRobot;
59  mutable std::mutex mutex;
60  };
61  using RobotPoolPtr = std::shared_ptr<RobotPool>;
62 }
63 
64 
armarx::RobotPool::RobotPool
RobotPool(VirtualRobot::RobotPtr robot, size_t defaultSize=1)
Definition: RobotPool.cpp:34
armarx::RobotPoolPtr
std::shared_ptr< class RobotPool > RobotPoolPtr
Definition: RobotUnitModuleRobotData.h:35
armarx::RobotPool::getPoolSize
size_t getPoolSize() const
Definition: RobotPool.cpp:64
armarx::RobotPool::clean
size_t clean()
Removes unused robots from the pool.
Definition: RobotPool.cpp:92
armarx::RobotPool
This class holds a pool of local VirtualRobots for multi threaded applications that can be requested ...
Definition: RobotPool.h:39
armarx::RobotPool::getRobot
VirtualRobot::RobotPtr getRobot(int inflation=0)
getRobot
Definition: RobotPool.cpp:44
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotPool::getRobotsInUseCount
size_t getRobotsInUseCount() const
Definition: RobotPool.cpp:75
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18