33 #include <rsc/logging/Logger.h>
34 #include <rsc/logging/LoggerFactory.h>
35 #include <rsc/misc/langutils.h>
36 #include <rsc/runtime/NoSuchObject.h>
37 #include <rsc/runtime/TypeStringTools.h>
38 #include <rsc/runtime/Printable.h>
39 #include <rsc/patterns/Factory.h>
41 #include <boost/type_traits.hpp>
46 #include "rsb/rsbexports.h"
51 template <
typename Interface>
71 template <
typename Interface>
72 class ConnectorFactory:
public rsc::patterns::Factory<std::string, Interface>,
73 private rsc::patterns::Singleton< ConnectorFactory<Interface> >,
74 public rsc::runtime::Printable {
100 name(name), schemas(schemas), remote(remote), options(options) {
101 this->options.insert(
"enabled");
146 }
else if (this->
name == other.
name) {
167 <<
", schemas = " << this->
schemas
168 <<
", remote = " << this->
remote
169 <<
", options = " << this->
options;
177 return rsc::patterns::Singleton< ConnectorFactory<Interface> >::getInstance();
183 typedef rsc::patterns::Factory<std::string, Interface>
Factory;
186 typedef std::map<std::string, ConnectorInfo>
InfoMap;
189 logger(rsc::logging::Logger::getLogger(
"rsb.transport.ConnectorFactory<" + rsc::runtime::typeName<Interface>() +
">")) {
202 typename InfoMap::const_iterator it = this->
infos.find(name);
203 if (it == this->
infos.end()) {
204 throw rsc::runtime::NoSuchObject(name);
210 std::set<ConnectorInfo> result;
212 for (
typename InfoMap::const_iterator it = this->
infos.begin();
213 it != this->
infos.end(); ++it) {
214 result.insert(it->second);
233 const std::set<std::string>& schemas = std::set<std::string>(),
235 const std::set<std::string>& options = std::set<std::string>()) {
236 RSCINFO(this->
logger,
"Registering connector "
238 <<
" for schemas " << schemas);
240 Factory::impls().register_(name, constructor);
243 this->
infos.insert(std::make_pair(name, info));
249 const std::set<std::string>& options = std::set<std::string>()) {
250 std::set<std::string> schemas;
251 schemas.insert(schema);
260 for (
typename ImplMapProxy::const_iterator it = implementations.begin(); it
261 != implementations.end(); ++it) {
267 template <
typename Interface>
268 ConnectorFactory<Interface>& ConnectorFactory<Interface>::getInstance() {
281 if (boost::is_same<Interface, InPullConnector>::value) {
283 }
else if (boost::is_same<Interface, InPushConnector>::value) {
285 }
else if (boost::is_same<Interface, OutConnector>::value) {
289 return (*(ConnectorFactory<Interface>*) 0);
std::map< std::string, ConnectorInfo > InfoMap
Instances of this class describe capabilities and properties of connector implementations.
void printContents(std::ostream &stream) const
Factory::CreateFunction CreateFunction
friend InPushFactory & getInPushFactory()
bool operator<(const ConnectorInfo &other) const
void registerConnector(const std::string &name, const CreateFunction &constructor, const std::set< std::string > &schemas=std::set< std::string >(), bool remote=true, const std::set< std::string > &options=std::set< std::string >())
For the connector implementation named name, register the construct function constructor, supported schemas schemas and recognized configuration options options.
rsc::logging::LoggerPtr logger
ConnectorInfo getConnectorInfo(const std::string &name) const
Return information regarding the connector implementation named name.
std::set< ConnectorInfo > getConnectorInfos() const
std::set< std::string > OptionList
ConnectorFactory< InPullConnector > InPullFactory
ConnectorFactory< OutConnector > OutFactory
std::set< std::string > SchemaList
void registerConnector(const std::string &name, const CreateFunction &constructor, const std::string &schema, bool remote=true, const std::set< std::string > &options=std::set< std::string >())
DEPRECATED(static ConnectorFactory< Interface > &getInstance())
ConnectorInfo(const std::string &name, const SchemaList &schemas, bool remote, const OptionList &options)
void printContents(std::ostream &stream) const
static ConnectorFactory< Interface > & getInstanceBase()
std::string getName() const
Return the name of the implementation.
rsc::patterns::Factory< std::string, Interface > Factory
friend InPullFactory & getInPullFactory()
InPullFactory & getInPullFactory()
OptionList getOptions() const
Return a list of option names describing configurations options recognized by the implementation...
bool isRemote() const
Return "remoteness" of the implementation.
friend OutFactory & getOutFactory()
InPushFactory & getInPushFactory()
Factory::ImplMapProxy ImplMapProxy
OutFactory & getOutFactory()
ConnectorFactory< InPushConnector > InPushFactory
Objects of this class are specialized factories that construct Connector objects and provide introspe...
SchemaList getSchemas() const
Return the set of schemas supported by the connector implementation.