RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Factory.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project.
4  *
5  * Copyright (C) 2011 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot 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/shared_ptr.hpp>
33 #include <boost/thread/recursive_mutex.hpp>
34 
35 #include <rsc/logging/Logger.h>
36 #include <rsc/runtime/TypeStringTools.h>
37 #include <rsc/patterns/Singleton.h>
38 
39 #include "rsb/rsbexports.h"
40 
41 #include "ParticipantConfig.h"
42 #include "Reader.h"
43 #include "Listener.h"
44 #include "Informer.h"
45 #include "Service.h"
46 
47 #include "transport/Connector.h"
48 #include "transport/Factory.h"
49 
50 #include "patterns/Server.h"
51 #include "patterns/RemoteServer.h"
52 
53 namespace rsb {
54 
60 class RSB_EXPORT Factory: public rsc::patterns::Singleton<Factory> {
61 public:
62 
63  virtual ~Factory();
64 
79  template<class DataType>
81  createInformer(const Scope& scope,
82  const ParticipantConfig& config
83  = Factory::getInstance().getDefaultParticipantConfig(),
84  const std::string& dataType
86  return typename Informer<DataType>::Ptr(new Informer<DataType> (
87  createOutConnectors(config), scope, config, dataType));
88  }
89 
103  InformerBasePtr createInformerBase(const Scope& scope,
104  const std::string& dataType
105  = "",
106  const ParticipantConfig& config
107  = Factory::getInstance().getDefaultParticipantConfig());
108 
117  ListenerPtr createListener(const Scope& scope,
118  const ParticipantConfig& config =
119  Factory::getInstance().getDefaultParticipantConfig());
120 
132  ReaderPtr createReader(const Scope& scope,
133  const ParticipantConfig& config =
134  Factory::getInstance().getDefaultParticipantConfig());
135 
142  ServicePtr createService(const Scope& scope);
143 
155  const Scope& scope,
156  const ParticipantConfig &listenerConfig =
157  Factory::getInstance().getDefaultParticipantConfig(),
158  const ParticipantConfig &informerConfig =
159  Factory::getInstance().getDefaultParticipantConfig());
160 
172  const Scope& scope,
173  const ParticipantConfig &listenerConfig =
174  Factory::getInstance().getDefaultParticipantConfig(),
175  const ParticipantConfig &informerConfig =
176  Factory::getInstance().getDefaultParticipantConfig());
177 
183  ParticipantConfig getDefaultParticipantConfig() const;
184 
191  void setDefaultParticipantConfig(const ParticipantConfig& config);
192 
193  friend class rsc::patterns::Singleton<Factory>;
194 
195 private:
196 
203  transport::OutFactory& getOutFactoryInstance();
204 
208  Factory();
209 
210  rsc::logging::LoggerPtr logger;
211 
216  mutable boost::recursive_mutex configMutex;
217 
218  std::vector<transport::OutConnectorPtr>
219  createOutConnectors(const ParticipantConfig& config);
220 
221  std::vector<transport::InPullConnectorPtr>
222  createInPullConnectors(const ParticipantConfig& config);
223 
224  std::vector<transport::InPushConnectorPtr>
225  createInPushConnectors(const ParticipantConfig& config);
226 
227  void configureLogging();
228 
229 };
230 
231 }