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) 2010 by Sebastian Wrede <swrede at techfak dot uni-bielefeld dot de>
6  * Copyright (C) 2012 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
7  *
8  * This file may be licensed under the terms of the
9  * GNU Lesser General Public License Version 3 (the ``LGPL''),
10  * or (at your option) any later version.
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the LGPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the LGPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * The development of this software was supported by:
23  * CoR-Lab, Research Institute for Cognition and Robotics
24  * Bielefeld University
25  *
26  * ============================================================ */
27 
28 #include "InPullConnector.h"
29 
30 #include "../../Scope.h"
31 
32 using namespace std;
33 
34 using namespace rsc::logging;
35 using namespace rsc::runtime;
36 
37 using namespace rsb::converter;
38 
39 namespace rsb {
40 namespace spread {
41 
42 transport::InPullConnector* InPullConnector::create(const Properties& args) {
43  static LoggerPtr logger = Logger::getLogger("rsb.spread.InPullConnector");
44  RSCDEBUG(logger, "creating InPullConnector with properties " << args);
45 
46  return new InPullConnector(args.get<ConverterSelectionStrategyPtr> ("converters"),
47  args.get<string> ("host", defaultHost()),
48  args.getAs<unsigned int> ("port", defaultPort()));
49 }
50 
51 InPullConnector::InPullConnector(ConverterSelectionStrategyPtr converters,
52  const string& host,
53  unsigned int port) :
54  logger(Logger::getLogger("rsb.spread.InPullConnector")),
55  active(false),
56  connector(new SpreadConnector(host, port)),
57  processor(converters) {
58 }
59 
61  if (this->active) {
62  deactivate();
63  }
64 }
65 
67  return "InPullConnector";
68 }
69 
70 void InPullConnector::printContents(ostream& stream) const {
71  stream << "active = " << this->active
72  << ", connector = " << this->connector;
73 }
74 
76  this->connector->activate();
77  this->active = true;
78 
79  // check that scope is applied
80  if (activationScope) {
82  activationScope.reset();
83  }
84 
85 }
86 
88  this->connector->deactivate();
89 }
90 
92  this->connector->setQualityOfServiceSpecs(specs);
93 }
94 
95 void InPullConnector::setScope(const Scope& scope) {
96  if (!active) {
97  this->activationScope.reset(new Scope(scope));
98  } else {
99  this->connector->join(this->connector->makeGroupName(scope));
100  }
101 }
102 
104  assert(block);
105 
106  SpreadMessagePtr message(new SpreadMessage());
107  EventPtr event;
108  while (true) {
109  this->connector->receive(message);
110  assert(message);
111  if (message->getType() != SpreadMessage::REGULAR) {
112  continue;
113  }
114  event = this->processor.processMessage(message);
115  if (event) {
116  return event;
117  }
118  };
119  // This should never happen so far unless non-blocking (not implemented so far)
120  return EventPtr();
121 }
122 
123 }
124 }