RSB  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OutRouteConfigurator.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project
4  *
5  * Copyright (C) 2010 by Sebastian Wrede <swrede at techfak dot uni-bielefeld dot 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 "OutRouteConfigurator.h"
28 
29 #include <rsc/runtime/ContainerIO.h>
30 #include <rsc/logging/Logger.h>
31 
32 #include "../Scope.h"
33 #include "../QualityOfServiceSpec.h"
34 
35 #include "../transport/OutConnector.h"
36 #include "../transport/Connector.h"
37 
39 #include "EventSendingStrategy.h"
40 
41 using namespace std;
42 
43 using namespace rsc::logging;
44 
45 using namespace rsb;
46 using namespace rsb::transport;
47 
48 namespace rsb {
49 namespace eventprocessing {
50 
51 typedef std::list<transport::OutConnectorPtr> ConnectorList;
52 
54 public:
55  rsc::logging::LoggerPtr logger;
56 
60  volatile bool shutdown;
61 };
62 
63 OutRouteConfigurator::OutRouteConfigurator(const Scope& scope) :
64  d(new Impl) {
65  d->logger = Logger::getLogger("rsb.eventprocessing.OutRouteConfigurator");
66  d->scope = scope;
67  d->shutdown = false;
68 }
69 
71  if (!d->shutdown) {
72  deactivate();
73  }
74 }
75 
77  return "OutRouteConfigurator";
78 }
79 
80 void OutRouteConfigurator::printContents(ostream& stream) const {
81  stream << "connectors = " << d->connectors << ", shutdown = "
82  << d->shutdown;
83 }
84 
86  RSCDEBUG(d->logger, "Activating");
87 
88  // Activate all connectors.
89  for (ConnectorList::iterator it = d->connectors.begin(); it
90  != d->connectors.end(); ++it) {
91  (*it)->setScope(d->scope);
92  (*it)->activate();
93  }
94 
95  // Create a strategy object and add all connectors to it.
96  d->eventSendingStrategy.reset(new DirectEventSendingStrategy());
97  for (ConnectorList::iterator it = d->connectors.begin(); it
98  != d->connectors.end(); ++it) {
99  RSCDEBUG(d->logger, "Adding connector " << *it
100  << " to strategy " << d->eventSendingStrategy);
101  d->eventSendingStrategy->addConnector(*it);
102  }
103 }
104 
106  RSCDEBUG(d->logger, "Deactivating");
107 
108  // Remove all connectors from the strategy object, the release the
109  // strategy.
110  for (ConnectorList::iterator it = d->connectors.begin(); it
111  != d->connectors.end(); ++it) {
112  RSCDEBUG(d->logger, "Removing connector " << *it
113  << " from strategy " << d->eventSendingStrategy);
114  if (d->eventSendingStrategy) {
115  d->eventSendingStrategy->removeConnector(*it);
116  }
117  }
118  d->eventSendingStrategy.reset();
119 
120  // Deactivate all connectors.
121  for (ConnectorList::iterator it = d->connectors.begin(); it
122  != d->connectors.end(); ++it) {
123  (*it)->deactivate();
124  }
125 
126  d->shutdown = true;
127 }
128 
130  RSCDEBUG(d->logger, "Adding connector " << connector);
131  d->connectors.push_back(connector);
132 }
133 
135  RSCDEBUG(d->logger, "Removing connector " << connector);
136  d->connectors.remove(connector);
137 }
138 
140  RSCDEBUG(d->logger, "OutRouteConfigurator::publish(Event) publishing new event: " << e);
141  d->eventSendingStrategy->process(e);
142 }
143 
145  const QualityOfServiceSpec& specs) {
146  for (ConnectorList::iterator it = d->connectors.begin(); it
147  != d->connectors.end(); ++it) {
148  (*it)->setQualityOfServiceSpecs(specs);
149  }
150 }
151 
152 }
153 }
Specification of desired quality of service settings for sending and receiving events.
void addConnector(transport::OutConnectorPtr connector)
std::list< transport::OutConnectorPtr > ConnectorList
This event sending strategy just passes incoming events to its associated rsb::transport::OutConnecto...
void setQualityOfServiceSpecs(const QualityOfServiceSpec &specs)
Define the desired quality of service specifications for published events.
boost::shared_ptr< OutConnector > OutConnectorPtr
void removeConnector(transport::OutConnectorPtr connector)
void publish(EventPtr e)
Publish event to out ports of this router.
void printContents(std::ostream &stream) const
boost::shared_ptr< EventSendingStrategy > EventSendingStrategyPtr
boost::shared_ptr< Event > EventPtr
Definition: Event.h:251
Scope is a descriptor for a hierarchical channel of the unified bus.
Definition: Scope.h:46