30 #include <boost/filesystem/fstream.hpp>
32 #include <rsc/config/Configuration.h>
33 #include <rsc/config/Environment.h>
35 #include <rsc/logging/OptionBasedConfigurator.h>
37 #include <rsc/plugins/Manager.h>
38 #include <rsc/plugins/Configurator.h>
40 #include <rsb/Version.h>
52 using namespace rsc::config;
53 using namespace rsc::logging;
54 using namespace rsc::runtime;
56 using namespace rsb::converter;
57 using namespace rsb::transport;
67 std::map<
typename C::value_type::first_type,
68 typename C::value_type::second_type>
70 typedef typename C::value_type::first_type first_type;
71 typedef typename C::value_type::second_type second_type;
73 typedef typename C::const_iterator const_iterator;
75 std::map<first_type, second_type> result;
76 for (const_iterator it = container.begin(); it != container.end(); ++it) {
79 result[it->first] = it->second;
82 if (result.find(it->second) != result.end()) {
83 throw std::invalid_argument(
86 "Multiple wire-schemas (%1%, %2%) selected for data-type %3%.\n"
87 "Probably you wrote the lines transport.<name>.cpp.%1% = %3% "
88 "and transport.<name>.cpp.%2% = %3% in your rsb config. One of "
89 "these should be deleted.")
96 result[it->second] = it->first;
100 throw std::runtime_error(
"got unexpected serialization direction");
109 rsc::logging::LoggerPtr logger) {
111 RSCDEBUG(logger,
"Supplied connector options " << options);
124 RSCDEBUG(logger,
"Converter configuration for transport `"
131 = converterRepository<string>()
132 ->getConvertersForSerialization
133 (converterSelectionToMap(config.
getConverters(), direction));
135 case DESERIALIZATION:
137 = converterRepository<string>()
138 ->getConvertersForDeserialization
139 (converterSelectionToMap(config.
getConverters(), direction));
143 throw std::runtime_error(
"got unexpected serialization direction");
145 RSCDEBUG(logger,
"Selected converters for transport `"
146 << config.
getName() <<
"': " << converters);
147 options[
"converters"] = converters;
169 logger(Logger::getLogger(
"rsb.Factory")),
170 pluginManager(new rsc::plugins::Manager()),
176 rsc::logging::OptionBasedConfigurator configurator;
177 configure(configurator,
"rsb.conf",
"RSC_", 0, 0,
false, Version::installPrefix());
181 RSCINFO(this->logger,
"Registering default implementations");
192 RSCINFO(this->logger,
"Processing plugin configuration");
196 vector<boost::filesystem::path> defaultPath;
200 defaultPath.push_back(userHomeDirectory()
201 / (
"." + Version::buildPluginPathSuffix()));
202 }
catch (
const runtime_error& e) {
203 RSCWARN(this->logger,
204 "Failed to determine user-specific plugin directory: "
207 defaultPath.push_back(Version::libdir() / Version::buildPluginPathSuffix());
208 rsc::plugins::Configurator configurator(
pluginManager, defaultPath);
210 configurator.execute(
true);
225 for (set<string>::const_iterator it = availableTransports.begin();
226 it != availableTransports.end(); ++it) {
245 RSCWARN(logger,
"No transports are enabled. This is probably a configuration error or an internal RSB error.");
255 configure(handler,
"rsb.conf",
"RSB_", 0, 0,
true,
256 Version::installPrefix());
268 const string& dataType,
308 listenerConfig, informerConfig, callback));
309 method->setSignalParticipantDestroyed(this->signalParticipantDestroyed);
310 (*this->signalParticipantCreated)(method, parent);
333 listenerConfig, informerConfig));
334 method->setSignalParticipantDestroyed(this->signalParticipantDestroyed);
335 (*this->signalParticipantCreated)(method, parent);
351 boost::recursive_mutex::scoped_lock lock(
configMutex);
356 boost::recursive_mutex::scoped_lock lock(
configMutex);
360 vector<InPullConnectorPtr>
363 vector<InPullConnectorPtr> connectors;
364 set<ParticipantConfig::Transport> configuredTransports = config.
getTransports();
365 for (set<ParticipantConfig::Transport>::const_iterator transportIt =
366 configuredTransports.begin(); transportIt
367 != configuredTransports.end(); ++transportIt) {
368 RSCDEBUG(logger,
"Trying to add connector " << *transportIt);
371 .createInst(transportIt->getName(),
372 prepareConnectorOptions(*transportIt,
375 }
catch (
const exception& e) {
376 throw runtime_error(boost::str(boost::format(
"Error configuring connector `%1%', in-pull: %2%")
377 % transportIt->getName() % e.what()));
383 vector<InPushConnectorPtr>
386 vector<InPushConnectorPtr> connectors;
387 set<ParticipantConfig::Transport> configuredTransports = config.
getTransports();
388 for (set<ParticipantConfig::Transport>::const_iterator transportIt =
389 configuredTransports.begin(); transportIt
390 != configuredTransports.end(); ++transportIt) {
391 RSCDEBUG(logger,
"Trying to add connector " << *transportIt);
394 .createInst(transportIt->getName(),
395 prepareConnectorOptions(*transportIt,
398 }
catch (
const exception& e) {
399 throw runtime_error(boost::str(boost::format(
"Error configuring connector `%1%', in-push: %2%")
400 % transportIt->getName() % e.what()));
406 vector<OutConnectorPtr>
409 vector<OutConnectorPtr> connectors;
410 set<ParticipantConfig::Transport> configuredTransports = config.
getTransports();
411 for (set<ParticipantConfig::Transport>::const_iterator transportIt =
412 configuredTransports.begin(); transportIt
413 != configuredTransports.end(); ++transportIt) {
414 RSCDEBUG(logger,
"Trying to add connector " << *transportIt);
417 .createInst(transportIt->getName(),
418 prepareConnectorOptions(*transportIt,
421 }
catch (
const exception& e) {
422 throw runtime_error(boost::str(boost::format(
"Error configuring connector `%1%', out: %2%")
423 % transportIt->getName() % e.what()));
rsc::runtime::Properties getOptions() const
Returns the specified options for the transport.
void registerDefaultEventProcessingStrategies()
A derived Method class which can be used to invoke methods on a remote LocalServer object...
bool isRemote(const string &transportName)
Returns true if transportName names a remote transport.
std::vector< transport::OutConnectorPtr > createOutConnectors(const ParticipantConfig &config)
boost::shared_ptr< RemoteMethod > RemoteMethodPtr
boost::shared_ptr< LocalServer > LocalServerPtr
boost::shared_ptr< LocalMethod > LocalMethodPtr
std::string getName() const
Returns the name of this transport description.
boost::signals2::signal< void(Participant *)> SignalParticipantDestroyed
ParticipantConfig getDefaultParticipantConfig() const
Returns the default configuration for new participants.
SignalParticipantDestroyedPtr getSignalParticipantDestroyed()
void addTransport(const Transport &transport)
Adds a transport to the list of desired transport mechanisms.
ConverterNames getConverters() const
boost::shared_ptr< Reader > ReaderPtr
ListenerPtr createListener(const Scope &scope, const ParticipantConfig &config=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates a new listener for the specified scope.
Factory & getFactory()
Returns a factory for client-level RSB objects.
std::vector< transport::InPushConnectorPtr > createInPushConnectors(const ParticipantConfig &config)
patterns::LocalServerPtr createLocalServer(const Scope &scope, const ParticipantConfig &listenerConfig=getFactory().getDefaultParticipantConfig(), const ParticipantConfig &informerConfig=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates a Server object that exposes methods under the scope scope.
set< string > getAvailableTransports(unsigned int requiredDirections)
Returns the names of all available transports which support requiredDirections.
SignalParticipantDestroyedPtr signalParticipantDestroyed
boost::shared_ptr< Listener > ListenerPtr
boost::shared_ptr< OutConnector > OutConnectorPtr
const std::vector< std::string > & getComponents() const
Returns all components of the scope as an ordered list.
boost::shared_ptr< Participant > ParticipantPtr
std::vector< transport::InPullConnectorPtr > createInPullConnectors(const ParticipantConfig &config)
A derived Method class which can be called from the remote side and implements its behavior by invoki...
boost::shared_ptr< ConverterSelectionStrategy< WireType > > Ptr
boost::shared_ptr< IntlCallback > CallbackPtr
Description of a desired transport.
The server side of a request-reply-based communication channel.
void registerDefaultTransports()
boost::shared_ptr< SignalParticipantCreated > SignalParticipantCreatedPtr
Factory for RSB user-level domain objects for communication patterns.
A Listener receives events published by rsb::Informer objects by participating in a channel with a su...
A Reader receives events published by a informers by participating in a channel with a suitable scope...
Transport & mutableTransport(const std::string &name)
Returns a single configured transport which can be modified in place.
InformerBasePtr createInformerBase(const Scope &scope, const std::string &dataType="", const ParticipantConfig &config=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates and returns a new Informer that publishes Event s under the Scope scope.
boost::shared_ptr< InPushConnector > InPushConnectorPtr
patterns::RemoteServer::RemoteMethodPtr createRemoteMethod(const Scope &scope, const ParticipantConfig &listenerConfig=getFactory().getDefaultParticipantConfig(), const ParticipantConfig &informerConfig=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates a patterns::RemoteServer::RemoteMethod.
static void provideConfigOptions(rsc::config::OptionHandler &handler)
Provides the default configuration options for RSB to the specified handler.
ParticipantConfig defaultConfig
Always acquire configMutex before reading or writing the config.
A class describing the configuration of Participant instances.
InPullFactory & getInPullFactory()
SignalParticipantCreatedPtr getSignalParticipantCreated()
ReaderPtr createReader(const Scope &scope, const ParticipantConfig &config=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates a new Reader object for the specified scope.
void setDefaultParticipantConfig(const ParticipantConfig &config)
Sets the default config for participants that will be used for every new participant that is created ...
boost::shared_ptr< InformerBase > InformerBasePtr
SignalParticipantCreatedPtr signalParticipantCreated
InPushFactory & getInPushFactory()
boost::shared_ptr< RemoteServer > RemoteServerPtr
OutFactory & getOutFactory()
void registerDefaultConverters()
rsc::plugins::ManagerPtr pluginManager
boost::recursive_mutex configMutex
patterns::LocalServer::LocalMethodPtr createLocalMethod(const Scope &scope, patterns::LocalServer::CallbackPtr callback, const ParticipantConfig &listenerConfig=getFactory().getDefaultParticipantConfig(), const ParticipantConfig &informerConfig=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates a patterns::LocalServer::LocalMethod.
boost::shared_ptr< SignalParticipantDestroyed > SignalParticipantDestroyedPtr
boost::shared_ptr< InPullConnector > InPullConnectorPtr
Scope is a descriptor for a hierarchical channel of the unified bus.
std::set< Transport > getTransports(bool includeDisabled=false) const
Returns the set of desired transports for a participant.
rsc::plugins::ManagerPtr getPluginManager() const
Returns the plugin manager instance used by the RSB core.
patterns::RemoteServerPtr createRemoteServer(const Scope &scope, const ParticipantConfig &listenerConfig=getFactory().getDefaultParticipantConfig(), const ParticipantConfig &informerConfig=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates a RemoteServer object for the server at scope scope.
Factory * factoryWhileLoadingPlugins
boost::signals2::signal< void(ParticipantPtr, ParticipantPtr)> SignalParticipantCreated
void setEnabled(bool value)
The client side of a request-reply-based communication channel.