RSB  0.9.6
 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 #include <rsc/config/OptionHandler.h>
39 #include <rsc/plugins/Manager.h>
40 
41 #include "rsb/rsbexports.h"
42 
43 #include "ParticipantConfig.h"
44 #include "Reader.h"
45 #include "Listener.h"
46 #include "Informer.h"
47 #include "Service.h"
48 
49 #include "transport/Connector.h"
50 #include "transport/Factory.h"
51 
52 #include "patterns/Server.h"
53 #include "patterns/RemoteServer.h"
54 
55 namespace rsb {
56 
57 class Factory;
58 
64 RSB_EXPORT Factory& getFactory();
65 
71 class RSB_EXPORT Factory: private rsc::patterns::Singleton<Factory> {
72 public:
73 
79  DEPRECATED(static Factory& getInstance());
80 
81  virtual ~Factory();
82 
97  template<class DataType>
99  createInformer(const Scope& scope,
100  const ParticipantConfig& config
101  = getFactory().getDefaultParticipantConfig(),
102  const std::string& dataType
104  return typename Informer<DataType>::Ptr(new Informer<DataType> (
105  createOutConnectors(config), scope, config, dataType));
106  }
107 
121  InformerBasePtr createInformerBase(const Scope& scope,
122  const std::string& dataType
123  = "",
124  const ParticipantConfig& config
125  = getFactory().getDefaultParticipantConfig());
126 
135  ListenerPtr createListener(const Scope& scope,
136  const ParticipantConfig& config =
137  getFactory().getDefaultParticipantConfig());
138 
150  ReaderPtr createReader(const Scope& scope,
151  const ParticipantConfig& config =
152  getFactory().getDefaultParticipantConfig());
153 
160  ServicePtr createService(const Scope& scope);
161 
173  const Scope& scope,
174  const ParticipantConfig &listenerConfig =
175  getFactory().getDefaultParticipantConfig(),
176  const ParticipantConfig &informerConfig =
177  getFactory().getDefaultParticipantConfig());
178 
190  const Scope& scope,
191  const ParticipantConfig &listenerConfig =
192  getFactory().getDefaultParticipantConfig(),
193  const ParticipantConfig &informerConfig =
194  getFactory().getDefaultParticipantConfig());
195 
201  ParticipantConfig getDefaultParticipantConfig() const;
202 
209  void setDefaultParticipantConfig(const ParticipantConfig& config);
210 
216  rsc::plugins::ManagerPtr getPluginManager() const;
217 
218  friend class rsc::patterns::Singleton<Factory>;
219 
220 private:
224  Factory();
225 
226  static Factory& getInstanceBase();
227  friend Factory& getFactory();
228 
229  rsc::logging::LoggerPtr logger;
230 
231  rsc::plugins::ManagerPtr pluginManager;
232 
237  mutable boost::recursive_mutex configMutex;
238 
239  std::vector<transport::OutConnectorPtr>
240  createOutConnectors(const ParticipantConfig& config);
241 
242  std::vector<transport::InPullConnectorPtr>
243  createInPullConnectors(const ParticipantConfig& config);
244 
245  std::vector<transport::InPushConnectorPtr>
246  createInPushConnectors(const ParticipantConfig& config);
247 
248  void configureSubsystem(rsc::config::OptionHandler& handler,
249  const std::string& environmentVariablePrefix = "RSB_");
250 
251 };
252 
253 }
patterns::RemoteServerPtr createRemoteServer(const Scope &scope)
Creates and returns a RemoteServer object for the server at Scope scope.
ServicePtr createService(const Scope &scope)
Creates and returns a Service instance operating on Scope scope.
A informer to publish data of a specified type expressed through the template parameter.
Definition: Informer.h:230
boost::shared_ptr< Reader > ReaderPtr
Definition: Reader.h:101
Factory & getFactory()
Returns a factory for client-level RSB objects.
Definition: Factory.cpp:89
Informer< DataType >::Ptr createInformer(const Scope &scope, const ParticipantConfig &config=getFactory().getDefaultParticipantConfig(), const std::string &dataType=detail::TypeName< DataType >()())
Creates and returns a new Informer that publishes Event s under the Scope scope.
Definition: Factory.h:99
boost::shared_ptr< Server > ServerPtr
Definition: Server.h:293
boost::shared_ptr< Listener > ListenerPtr
Definition: Listener.h:150
ReaderPtr createReader(const Scope &scope, const ParticipantConfig &config)
Creates and returns a new Reader object for Scope scope.
ListenerPtr createListener(const Scope &scope, const ParticipantConfig &config)
Creates and returns a new Listener for the Scope scope.
DEPRECATED(RSB_EXPORT Repository< std::string >::Ptr stringConverterRepository())
boost::shared_ptr< Informer< T > > Ptr
Shared pointer type for this informer.
Definition: Informer.h:236
Factory for RSB user-level domain objects for communication patterns.
Definition: Factory.h:71
boost::shared_ptr< Service > ServicePtr
Definition: Service.h:42
ParticipantConfig defaultConfig
Always acquire configMutex before reading or writing the config.
Definition: Factory.h:236
patterns::ServerPtr createServer(const Scope &scope)
Creates and returns a Server object that exposes methods under the Scope scope.
A class describing the configuration of Participant instances.
boost::shared_ptr< InformerBase > InformerBasePtr
Definition: Informer.h:211
boost::shared_ptr< RemoteServer > RemoteServerPtr
Definition: RemoteServer.h:282
rsc::logging::LoggerPtr logger
Definition: Factory.h:229
rsc::plugins::ManagerPtr pluginManager
Definition: Factory.h:231
boost::recursive_mutex configMutex
Definition: Factory.h:237
Scope is a descriptor for a hierarchical channel of the unified bus.
Definition: Scope.h:46