RSB  0.17.0
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 
58  ConnectorList connectors;
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 
85 const std::set<std::string> OutRouteConfigurator::getTransportURLs() const {
86  std::set<std::string> result;
87  for (ConnectorList::iterator it = d->connectors.begin();
88  it != d->connectors.end(); ++it) {
89  result.insert((*it)->getTransportURL());
90  }
91  return result;
92 }
93 
95  RSCDEBUG(d->logger, "Activating");
96 
97  // Activate all connectors.
98  for (ConnectorList::iterator it = d->connectors.begin(); it
99  != d->connectors.end(); ++it) {
100  (*it)->setScope(d->scope);
101  (*it)->activate();
102  }
103 
104  // Create a strategy object and add all connectors to it.
105  d->eventSendingStrategy.reset(new DirectEventSendingStrategy());
106  for (ConnectorList::iterator it = d->connectors.begin(); it
107  != d->connectors.end(); ++it) {
108  RSCDEBUG(d->logger, "Adding connector " << *it
109  << " to strategy " << d->eventSendingStrategy);
110  d->eventSendingStrategy->addConnector(*it);
111  }
112 }
113 
115  RSCDEBUG(d->logger, "Deactivating");
116 
117  // Remove all connectors from the strategy object, the release the
118  // strategy.
119  for (ConnectorList::iterator it = d->connectors.begin(); it
120  != d->connectors.end(); ++it) {
121  RSCDEBUG(d->logger, "Removing connector " << *it
122  << " from strategy " << d->eventSendingStrategy);
123  if (d->eventSendingStrategy) {
124  d->eventSendingStrategy->removeConnector(*it);
125  }
126  }
127  d->eventSendingStrategy.reset();
128 
129  // Deactivate all connectors.
130  for (ConnectorList::iterator it = d->connectors.begin(); it
131  != d->connectors.end(); ++it) {
132  (*it)->deactivate();
133  }
134 
135  d->shutdown = true;
136 }
137 
139  RSCDEBUG(d->logger, "Adding connector " << connector);
140  d->connectors.push_back(connector);
141 }
142 
144  RSCDEBUG(d->logger, "Removing connector " << connector);
145  d->connectors.remove(connector);
146 }
147 
149  RSCDEBUG(d->logger, "OutRouteConfigurator::publish(Event) publishing new event: " << e);
150  d->eventSendingStrategy->process(e);
151 }
152 
154  const QualityOfServiceSpec& specs) {
155  for (ConnectorList::iterator it = d->connectors.begin(); it
156  != d->connectors.end(); ++it) {
157  (*it)->setQualityOfServiceSpecs(specs);
158  }
159 }
160 
161 }
162 }
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.
STL namespace.
boost::shared_ptr< OutConnector > OutConnectorPtr
void removeConnector(transport::OutConnectorPtr connector)
const std::set< std::string > getTransportURLs() const
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:264
Scope is a descriptor for a hierarchical channel of the unified bus.
Definition: Scope.h:46