RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Assembly.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project
4  *
5  * Copyright (C) 2011 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <string>
30 #include <vector>
31 
32 #include <boost/cstdint.hpp>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/thread/recursive_mutex.hpp>
35 #include <boost/date_time/posix_time/ptime.hpp>
36 
37 #include <rsc/logging/Logger.h>
38 #include <rsc/threading/PeriodicTask.h>
39 #include <rsc/threading/ThreadedTaskExecutor.h>
40 
41 #include "../../protocol/Notification.h"
42 #include "../../protocol/FragmentedNotification.h"
43 #include "rsb/rsbexports.h"
44 
45 namespace rsb {
46 namespace spread {
47 
54 class RSB_EXPORT Assembly {
55 public:
56 
58  ~Assembly();
59 
65  rsb::protocol::NotificationPtr getCompleteNotification() const;
66 
77 
78  bool isComplete() const;
79 
86  unsigned int age() const;
87 
88 private:
89  rsc::logging::LoggerPtr logger;
90  unsigned int receivedParts;
91  std::vector<rsb::protocol::FragmentedNotificationPtr> store;
92  boost::posix_time::ptime birthTime;
93 
94 };
95 
96 typedef boost::shared_ptr<Assembly> AssemblyPtr;
97 
105 class RSB_EXPORT AssemblyPool {
106 public:
107 
118  explicit AssemblyPool(const unsigned int& ageS = 20,
119  const unsigned int& pruningIntervalMs = 4000);
120 
121  ~AssemblyPool();
122 
129  bool isPruning() const;
130 
138  void setPruning(const bool& prune);
139 
154 
155 private:
156  typedef std::map<std::string, boost::shared_ptr<Assembly> > Pool;
157 
158  class PruningTask: public rsc::threading::PeriodicTask {
159  public:
160 
161  PruningTask(Pool& pool, boost::recursive_mutex& poolMutex,
162  const unsigned int& ageS,
163  const unsigned int& pruningIntervalMs);
164 
165  void execute();
166 
167  private:
168  rsc::logging::LoggerPtr logger;
170  boost::recursive_mutex& poolMutex;
171  unsigned int maxAge;
172  };
173 
174  rsc::logging::LoggerPtr logger;
176  boost::recursive_mutex poolMutex;
177 
178  const unsigned int pruningAgeS;
179  const unsigned int pruningIntervalMs;
180 
181  rsc::threading::ThreadedTaskExecutor executor;
182  mutable boost::recursive_mutex pruningMutex;
183  rsc::threading::TaskPtr pruningTask;
184 };
185 
186 typedef boost::shared_ptr<AssemblyPool> AssemblyPoolPtr;
187 
188 }
189 }