RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InPullConnector.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project
4  *
5  * Copyright (C) 2012 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 "InPullConnector.h"
28 
29 #include "../../MetaData.h"
30 
31 #include "Factory.h"
32 
33 using namespace std;
34 
35 using namespace boost;
36 
37 using namespace rsc::logging;
38 using namespace rsc::runtime;
39 using namespace rsc::threading;
40 
41 namespace rsb {
42 namespace transport {
43 namespace socket {
44 
45 transport::InPullConnector* InPullConnector::create(const Properties& args) {
46  LoggerPtr logger = Logger::getLogger("rsb.transport.socket.InPullConnector");
47  RSCDEBUG(logger, "Creating InPullConnector with properties " << args);
48 
49  return new InPullConnector(args.get<ConverterSelectionStrategyPtr>("converters"),
50  args.get<string> ("host", DEFAULT_HOST),
51  args.getAs<unsigned int> ("port", DEFAULT_PORT),
52  args.getAs<Server> ("server", SERVER_AUTO),
53  args.getAs<bool> ("tcpnodelay", false));
54 }
55 
56 InPullConnector::InPullConnector(ConverterSelectionStrategyPtr converters,
57  const string& host,
58  unsigned int port,
59  Server server,
60  bool tcpnodelay) :
61  ConnectorBase(converters, host, port, server, tcpnodelay),
62  InConnector(converters, host, port, server, tcpnodelay),
63  logger(Logger::getLogger("rsb.transport.socket.InPullConnector")) {
64 }
65 
67 }
68 
70  if (!this->active) {
71  throw std::runtime_error("Cannot handle events when not active");
72  }
73 
74  // busEvent is an intermediate object. The deserialization of the
75  // payload still has to be performed.
76  EventPtr event(new Event(*busEvent));
77 
78  event->mutableMetaData().setReceiveTime();
79 
80  // Extract the serialized data and wire-schema from the
81  // intermediate event.
82  boost::shared_ptr<string> wireData = static_pointer_cast<string>(event->getData());
83  string wireSchema = event->getMetaData().getUserInfo("rsb.wire-schema");
84 
85  // Apply the configured converter.
87  = getConverter(wireSchema)->deserialize(wireSchema, *wireData);
88  event->setData(d.second);
89  event->setType(d.first);
90 
91  this->queue.push(event);
92 }
93 
95  if (block) {
96  return this->queue.pop();
97  } else {
98  try {
99  return this->queue.tryPop();
100  } catch (const QueueEmptyException&) {
101  return EventPtr();
102  }
103  }
104 }
105 
106 
107 }
108 }
109 }