RSB  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transports.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project
4  *
5  * Copyright (C) 2011, 2012, 2013 Jan Moringen <jmoringe@techfak.uni-bielefeld.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 #include "Factory.h"
28 
29 #include <stdexcept>
30 
31 #include <boost/thread.hpp>
32 
35 #include "inprocess/OutConnector.h"
36 
37 #ifdef RSB_WITH_SOCKET_TRANSPORT
38 #include "socket/InPushConnector.h"
39 #include "socket/InPullConnector.h"
40 #include "socket/OutConnector.h"
41 #endif
42 
43 #include "transports.h"
44 
45 using namespace std;
46 
47 namespace rsb {
48 namespace transport {
49 
50 static bool registered = false;
51 static boost::mutex registrationMutex;
52 
54  boost::mutex::scoped_lock lock(registrationMutex);
55 
56  if (registered) {
57  return;
58  }
59  registered = true;
60 
61  // In-direction, push-style connectors
62  {
63  InPushFactory& factory = getInPushFactory();
64  factory.registerConnector("inprocess",
65  &inprocess::InPushConnector::create,
66  "inprocess",
67  false);
68 
69 #ifdef RSB_WITH_SOCKET_TRANSPORT
70  {
71  set<string> options;
72  options.insert("host");
73  options.insert("port");
74  options.insert("server");
75  options.insert("tcpnodelay");
76 
77  factory.registerConnector("socket",
78  &socket::InPushConnector::create,
79  "socket",
80  true,
81  options);
82  }
83 #endif
84 
85  }
86 
87  // In-direction, pull-style connectors
88  {
89  InPullFactory& factory = getInPullFactory();
90 
91  factory.registerConnector("inprocess",
92  &inprocess::InPullConnector::create,
93  "inprocess",
94  false);
95 
96 #ifdef RSB_WITH_SOCKET_TRANSPORT
97  {
98  set<string> options;
99  options.insert("host");
100  options.insert("port");
101  options.insert("server");
102  options.insert("tcpnodelay");
103 
104  factory.registerConnector("socket",
105  &socket::InPullConnector::create,
106  "socket",
107  true,
108  options);
109  }
110 #endif
111 
112  }
113 
114  // Out-direction connectors
115  {
116  OutFactory& factory = getOutFactory();
117  factory.registerConnector("inprocess",
118  &inprocess::OutConnector::create,
119  "inprocess",
120  false);
121 
122 #ifdef RSB_WITH_SOCKET_TRANSPORT
123  {
124  set<string> options;
125  options.insert("host");
126  options.insert("port");
127  options.insert("server");
128  options.insert("tcpnodelay");
129 
130  factory.registerConnector("socket",
131  &socket::OutConnector::create,
132  "socket",
133  true,
134  options);
135  }
136 #endif
137 
138  }
139 
140 }
141 
142 bool isRemote(const string& transportName) {
143  bool remote = false;
144  bool validResult = false;
145  try {
146  InPullFactory& factory = getInPullFactory();
148  = factory.getConnectorInfo(transportName);
149  remote = info.isRemote();
150  validResult = true;
151  } catch (const rsc::runtime::NoSuchObject&) {
152  }
153  try {
154  InPushFactory& factory = getInPushFactory();
156  = factory.getConnectorInfo(transportName);
157  if (validResult && (remote != info.isRemote())) {
158  throw std::logic_error("connectors of one transport disagree about remoteness.");
159  }
160  remote = info.isRemote();
161  validResult = true;
162  } catch (const rsc::runtime::NoSuchObject&) {
163  }
164  try {
165  OutFactory& factory = getOutFactory();
167  = factory.getConnectorInfo(transportName);
168  if (validResult && (remote != info.isRemote())) {
169  throw std::logic_error("connectors of one transport disagree about remoteness.");
170  }
171  remote = info.isRemote();
172  validResult = true;
173  } catch (const rsc::runtime::NoSuchObject&) {
174  }
175  if (!validResult) {
176  throw rsc::runtime::NoSuchObject(transportName);
177  }
178  return remote;
179 }
180 
181 }
182 }
Instances of this class describe capabilities and properties of connector implementations.
Definition: Factory.h:91
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.
Definition: Factory.h:231
ConnectorInfo getConnectorInfo(const std::string &name) const
Return information regarding the connector implementation named name.
Definition: Factory.h:201
static boost::mutex registrationMutex
Definition: transports.cpp:51
void registerDefaultTransports()
Definition: transports.cpp:53
bool isRemote(const string &transportName)
Definition: transports.cpp:142
InPullFactory & getInPullFactory()
Definition: Factory.cpp:32
bool isRemote() const
Return "remoteness" of the implementation.
Definition: Factory.h:139
InPushFactory & getInPushFactory()
Definition: Factory.cpp:36
OutFactory & getOutFactory()
Definition: Factory.cpp:40
Objects of this class are specialized factories that construct Connector objects and provide introspe...
Definition: Factory.h:52
static bool registered
Definition: transports.cpp:50