RSB  0.17.0
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 
34 #include <boost/signals2.hpp>
35 
36 #include <boost/thread/recursive_mutex.hpp>
37 
38 #include <rsc/misc/langutils.h>
39 #include <rsc/logging/Logger.h>
40 #include <rsc/runtime/TypeStringTools.h>
41 #include <rsc/config/OptionHandler.h>
42 #include <rsc/plugins/Manager.h>
43 
44 #include "rsb/rsbexports.h"
45 
46 #include "ParticipantConfig.h"
47 #include "Reader.h"
48 #include "Listener.h"
49 #include "Informer.h"
50 
51 #include "transport/Connector.h"
52 #include "transport/Factory.h"
53 
54 #include "patterns/LocalServer.h"
55 #include "patterns/RemoteServer.h"
56 
57 namespace rsb {
58 
59 typedef boost::signals2::signal<void(ParticipantPtr, ParticipantPtr)> SignalParticipantCreated;
60 typedef boost::shared_ptr<SignalParticipantCreated> SignalParticipantCreatedPtr;
61 
62 class Factory;
63 
69 RSB_EXPORT Factory& getFactory();
70 
77 class RSB_EXPORT Factory {
78 public:
79 
80  virtual ~Factory();
81 
82  SignalParticipantCreatedPtr getSignalParticipantCreated();
83 
84  SignalParticipantDestroyedPtr getSignalParticipantDestroyed();
85 
105  template<class DataType>
106  typename Informer<DataType>::Ptr
107  createInformer(const Scope& scope,
108  const ParticipantConfig& config
109  = getFactory().getDefaultParticipantConfig(),
110  const std::string& dataType
112  ParticipantPtr parent
113  = ParticipantPtr()) {
114  typename Informer<DataType>::Ptr informer(
115  new Informer<DataType>(createOutConnectors(config), scope,
116  config, dataType));
117  informer->setSignalParticipantDestroyed(this->signalParticipantDestroyed);
118  (*this->signalParticipantCreated)(informer, parent);
119  return informer;
120  }
121 
139  InformerBasePtr createInformerBase(const Scope& scope,
140  const std::string& dataType
141  = "",
142  const ParticipantConfig& config
143  = getFactory().getDefaultParticipantConfig(),
144  ParticipantPtr parent
145  = ParticipantPtr());
146 
158  ListenerPtr createListener(const Scope& scope,
159  const ParticipantConfig& config
160  = getFactory().getDefaultParticipantConfig(),
161  ParticipantPtr parent
162  = ParticipantPtr());
163 
182  ReaderPtr createReader(const Scope& scope,
183  const ParticipantConfig& config
184  = getFactory().getDefaultParticipantConfig(),
185  ParticipantPtr parent
186  = ParticipantPtr());
187 
206  patterns::LocalServer::LocalMethodPtr createLocalMethod(
207  const Scope& scope,
209  const ParticipantConfig& listenerConfig
210  = getFactory().getDefaultParticipantConfig(),
211  const ParticipantConfig& informerConfig
212  = getFactory().getDefaultParticipantConfig(),
213  ParticipantPtr parent
214  = ParticipantPtr());
215 
230  const Scope& scope,
231  const ParticipantConfig& listenerConfig
232  = getFactory().getDefaultParticipantConfig(),
233  const ParticipantConfig& informerConfig
234  = getFactory().getDefaultParticipantConfig(),
235  ParticipantPtr parent
236  = ParticipantPtr());
237 
251  patterns::RemoteServer::RemoteMethodPtr createRemoteMethod(
252  const Scope& scope,
253  const ParticipantConfig& listenerConfig
254  = getFactory().getDefaultParticipantConfig(),
255  const ParticipantConfig& informerConfig
256  = getFactory().getDefaultParticipantConfig(),
257  ParticipantPtr parent
258  = ParticipantPtr());
259 
274  const Scope& scope,
275  const ParticipantConfig& listenerConfig
276  = getFactory().getDefaultParticipantConfig(),
277  const ParticipantConfig& informerConfig
278  = getFactory().getDefaultParticipantConfig(),
279  ParticipantPtr parent
280  = ParticipantPtr());
281 
287  ParticipantConfig getDefaultParticipantConfig() const;
288 
295  void setDefaultParticipantConfig(const ParticipantConfig& config);
296 
302  rsc::plugins::ManagerPtr getPluginManager() const;
303 
316  static void provideConfigOptions(const std::string& environmentVariablePrefix,
317  rsc::config::OptionHandler& handler,
318  bool stripPrefix = true);
319 
320 private:
324  Factory();
325 
326  friend Factory& getFactory();
327 
328  rsc::logging::LoggerPtr logger;
329 
330  rsc::plugins::ManagerPtr pluginManager;
331 
336  mutable boost::recursive_mutex configMutex;
337 
338  SignalParticipantCreatedPtr signalParticipantCreated;
340 
341  std::vector<transport::OutConnectorPtr>
342  createOutConnectors(const ParticipantConfig& config);
343 
344  std::vector<transport::InPullConnectorPtr>
345  createInPullConnectors(const ParticipantConfig& config);
346 
347  std::vector<transport::InPushConnectorPtr>
348  createInPushConnectors(const ParticipantConfig& config);
349 
350  void configureSubsystem(rsc::config::OptionHandler& handler,
351  const std::string& environmentVariablePrefix = "RSB_");
352 
353 };
354 
355 }
patterns::LocalServerPtr createLocalServer(const Scope &scope)
Creates and returns a Server object that exposes methods under the Scope scope.
patterns::RemoteServerPtr createRemoteServer(const Scope &scope)
Creates and returns a RemoteServer object for the server at Scope scope.
Informer< DataType >::Ptr createInformer(const Scope &scope, const ParticipantConfig &config=getFactory().getDefaultParticipantConfig(), const std::string &dataType=detail::TypeName< DataType >()(), ParticipantPtr parent=ParticipantPtr())
Creates and returns a new Informer that publishes Event s under the Scope scope.
Definition: Factory.h:107
boost::shared_ptr< RemoteMethod > RemoteMethodPtr
Definition: RemoteServer.h:115
boost::shared_ptr< LocalServer > LocalServerPtr
Definition: LocalServer.h:489
boost::shared_ptr< LocalMethod > LocalMethodPtr
Definition: LocalServer.h:387
A informer to publish data of a specified type expressed through the template parameter.
Definition: Informer.h:236
boost::shared_ptr< Reader > ReaderPtr
Definition: Reader.h:106
Factory & getFactory()
Returns a factory for client-level RSB objects.
Definition: Factory.cpp:163
SignalParticipantDestroyedPtr signalParticipantDestroyed
Definition: Factory.h:339
boost::shared_ptr< Listener > ListenerPtr
Definition: Listener.h:155
boost::shared_ptr< Participant > ParticipantPtr
Definition: Participant.h:122
ReaderPtr createReader(const Scope &scope, const ParticipantConfig &config)
Creates and returns a new Reader object for Scope scope.
boost::shared_ptr< IntlCallback > CallbackPtr
Definition: LocalServer.h:71
ListenerPtr createListener(const Scope &scope, const ParticipantConfig &config)
Creates and returns a new Listener for the Scope scope.
boost::shared_ptr< SignalParticipantCreated > SignalParticipantCreatedPtr
Definition: Factory.h:60
boost::shared_ptr< Informer< T > > Ptr
Shared pointer type for this informer.
Definition: Informer.h:242
Factory for RSB user-level domain objects for communication patterns.
Definition: Factory.h:77
ParticipantConfig defaultConfig
Always acquire configMutex before reading or writing the config.
Definition: Factory.h:335
A class describing the configuration of Participant instances.
boost::shared_ptr< InformerBase > InformerBasePtr
Definition: Informer.h:217
SignalParticipantCreatedPtr signalParticipantCreated
Definition: Factory.h:338
boost::shared_ptr< RemoteServer > RemoteServerPtr
Definition: RemoteServer.h:311
rsc::logging::LoggerPtr logger
Definition: Factory.h:328
rsc::plugins::ManagerPtr pluginManager
Definition: Factory.h:330
boost::recursive_mutex configMutex
Definition: Factory.h:336
boost::shared_ptr< SignalParticipantDestroyed > SignalParticipantDestroyedPtr
Definition: Participant.h:48
Scope is a descriptor for a hierarchical channel of the unified bus.
Definition: Scope.h:46
boost::signals2::signal< void(ParticipantPtr, ParticipantPtr)> SignalParticipantCreated
Definition: Factory.h:59