RSB  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PushInRouteConfigurator.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project
4  *
5  * Copyright (C) 2011 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 
28 
29 #include <boost/bind.hpp>
30 
32 
33 using namespace std;
34 
35 using namespace boost;
36 
37 using namespace rsc::runtime;
38 using namespace rsc::logging;
39 
40 using namespace rsb::transport;
41 
42 namespace rsb {
43 namespace eventprocessing {
44 
45 PushInRouteConfigurator::PushInRouteConfigurator(const Scope& scope,
46  const ParticipantConfig& config) :
47  InRouteConfigurator(scope, config),
48  logger(Logger::getLogger("rsb.eventprocessing.PushInRouteConfigurator")),
49  errorStrategy(ParticipantConfig::ERROR_STRATEGY_LOG) {
50 }
51 
53 }
54 
56  return "PushInRouteConfigurator";
57 }
58 
59 void PushInRouteConfigurator::printContents(ostream& stream) const {
61  stream << ", errorStrategy = " << this->errorStrategy;
62 }
63 
66 
67  // The base class has instantiated an
68  // EventReceivingStrategy. Retrieve it and install our error
69  // handling strategy.
71  = dynamic_pointer_cast<PushEventReceivingStrategy>(getEventReceivingStrategy());
72  this->eventReceivingStrategy->setHandlerErrorStrategy(this->errorStrategy);
73 
74  // Retrieve the set of connectors and ourselves to the list of
75  // handlers of each connector.
77  for (InRouteConfigurator::ConnectorSet::const_iterator it =
78  connectors.begin(); it != connectors.end(); ++it) {
79  InPushConnectorPtr connector = dynamic_pointer_cast<InPushConnector>(
80  *it);
81  assert(connector);
82  connector->addHandler(
83  HandlerPtr(
86  this->eventReceivingStrategy, _1))));
87  }
88 }
89 
90 void PushInRouteConfigurator::handlerAdded(rsb::HandlerPtr handler, const bool& wait) {
91  this->eventReceivingStrategy->addHandler(handler, wait);
92 }
93 
95  this->eventReceivingStrategy->removeHandler(handler, wait);
96 }
97 
99  if (this->eventReceivingStrategy) {
100  this->eventReceivingStrategy->setHandlerErrorStrategy(strategy);
101  }
102  this->errorStrategy = strategy;
103 }
104 
106  string impl = getReceivingStrategyConfig().getName();
107  Properties options = getReceivingStrategyConfig().getOptions();
108  RSCDEBUG(logger, "Instantiating event receiving strategy with config "
110  return EventReceivingStrategyPtr(getEventReceivingStrategyFactory().createInst(impl, options));
111 }
112 
113 }
114 }
void printContents(std::ostream &stream) const
A class responsible of configuring the route that processes incoming events from one or more InConnec...
void setErrorStrategy(const ParticipantConfig::ErrorStrategy &strategy)
Sets the desired error strategy to use.
const ParticipantConfig::EventProcessingStrategy & getReceivingStrategyConfig() const
void handlerAdded(rsb::HandlerPtr handler, const bool &wait)
Adds a new handler that will be notified about received events.
EventReceivingStrategyFactory & getEventReceivingStrategyFactory()
std::string getName() const
Returns the name of the implementation to be selected.
virtual void handle(EventPtr event)=0
Dispatches the event to the listener.
rsc::runtime::Properties getOptions() const
Returns the options for the strategy.
boost::shared_ptr< Handler > HandlerPtr
Definition: Handler.h:60
std::set< transport::InConnectorPtr > ConnectorSet
void handlerRemoved(rsb::HandlerPtr handler, const bool &wait)
Removes a previously registered handle.
boost::shared_ptr< EventReceivingStrategy > EventReceivingStrategyPtr
A utility class to simplify event handling in ordinary functions or member functions.
Definition: Handler.h:101
boost::shared_ptr< Handler > HandlerPtr
Definition: Handler.h:92
ErrorStrategy
Possible error handling strategies in user-provided code like event handlers.
boost::shared_ptr< InPushConnector > InPushConnectorPtr
Definition: Listener.h:58
EventReceivingStrategyPtr getEventReceivingStrategy() const
A class describing the configuration of Participant instances.
Objects of classes which implement this specialized InConnector interface provide the ability to rece...
Scope is a descriptor for a hierarchical channel of the unified bus.
Definition: Scope.h:46
This class serves as a base class for event receiving strategy classes that deliver rsb::Event s to r...