RSB  0.17.0
InRouteConfigurator.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 "InRouteConfigurator.h"
28 
29 #include "../Factory.h"
30 #include "../ParticipantConfig.h"
31 #include "../QualityOfServiceSpec.h"
32 #include "../filter/Filter.h"
33 #include "EventReceivingStrategy.h"
34 
35 using namespace std;
36 using namespace rsc::logging;
37 using namespace rsb;
38 using namespace rsb::filter;
39 using namespace rsb::transport;
40 
41 namespace rsb {
42 namespace eventprocessing {
43 
45 public:
46 
48  const ParticipantConfig::EventProcessingStrategy& receivingStrategyConfig) :
49  receivingStrategyConfig(receivingStrategyConfig) {
50 
51  }
52 
53  rsc::logging::LoggerPtr logger;
54 
56 
60  volatile bool shutdown;
61 };
62 
63 InRouteConfigurator::InRouteConfigurator(const Scope& scope,
64  const ParticipantConfig& config) :
65  d(new Impl(config.getEventReceivingStrategy())) {
66  d->logger = Logger::getLogger("rsb.eventprocessing.InRouteConfigurator");
67  d->scope = scope;
68  d->shutdown = false;
69 }
70 
72  if (!d->shutdown) {
73  deactivate();
74  }
75 }
76 
78  return "InRouteConfigurator";
79 }
80 
81 void InRouteConfigurator::printContents(ostream& stream) const {
82  stream << "scope = " << d->scope << ", connectors = " << d->connectors
83  << ", eventReceivingStrategy = " << d->eventReceivingStrategy
84  << ", shutdown = " << d->shutdown;
85 }
86 
87 const std::set<std::string> InRouteConfigurator::getTransportURLs() const {
88  std::set<std::string> result;
89  for (ConnectorSet::iterator it = d->connectors.begin();
90  it != d->connectors.end(); ++it) {
91  result.insert((*it)->getTransportURL());
92  }
93  return result;
94 }
95 
97  RSCDEBUG(d->logger, "Activating");
98 
99  // Activate all connectors.
100  for (ConnectorSet::iterator it = d->connectors.begin(); it
101  != d->connectors.end(); ++it) {
102  (*it)->setScope(d->scope);
103  (*it)->activate();
104  }
105 
106  // Create the event processing strategy and attach it to all
107  // connectors.
108  d->eventReceivingStrategy = createEventReceivingStrategy();
109 }
110 
112  RSCDEBUG(d->logger, "Deactivating");
113 
114  // Deactivate all connectors.
115  for (ConnectorSet::iterator it = d->connectors.begin(); it
116  != d->connectors.end(); ++it) {
117  (*it)->deactivate();
118  }
119 
120  // Release event processing strategy.
121  d->eventReceivingStrategy.reset();
122  d->shutdown = true;
123 }
124 
126  return d->receivingStrategyConfig;
127 }
128 
130  return d->eventReceivingStrategy;
131 }
132 
134  return d->connectors;
135 }
136 
138  RSCDEBUG(d->logger, "Adding connector " << connector);
139  d->connectors.insert(connector);
140 }
141 
143  RSCDEBUG(d->logger, "Removing connector " << connector);
144  d->connectors.erase(connector);
145 }
146 
148  for (ConnectorSet::iterator it = d->connectors.begin(); it
149  != d->connectors.end(); ++it) {
150  filter->notifyObserver(*it, filter::FilterAction::ADD);
151  }
152  d->eventReceivingStrategy->addFilter(filter);
153 }
154 
156  for (ConnectorSet::iterator it = d->connectors.begin(); it
157  != d->connectors.end(); ++it) {
158  filter->notifyObserver(*it, filter::FilterAction::REMOVE);
159  }
160  d->eventReceivingStrategy->removeFilter(filter);
161 }
162 
164  const QualityOfServiceSpec& specs) {
165  for (ConnectorSet::iterator it = d->connectors.begin(); it
166  != d->connectors.end(); ++it) {
167  (*it)->setQualityOfServiceSpecs(specs);
168  }
169 }
170 
171 }
172 }
Specification of desired quality of service settings for sending and receiving events.
void filterRemoved(filter::FilterPtr filter)
void printContents(std::ostream &stream) const
const ParticipantConfig::EventProcessingStrategy & getReceivingStrategyConfig() const
A filter shall be added to the FilterObserver.
virtual EventReceivingStrategyPtr createEventReceivingStrategy()=0
void filterAdded(filter::FilterPtr filter)
STL namespace.
A filter shall be remove from the observer.
const std::set< std::string > getTransportURLs() const
void setQualityOfServiceSpecs(const QualityOfServiceSpec &specs)
Define the desired quality of service specifications for published events.
Impl(const ParticipantConfig::EventProcessingStrategy &receivingStrategyConfig)
boost::shared_ptr< Filter > FilterPtr
void addConnector(transport::InConnectorPtr connector)
std::set< transport::InConnectorPtr > ConnectorSet
ParticipantConfig::EventProcessingStrategy receivingStrategyConfig
boost::shared_ptr< EventReceivingStrategy > EventReceivingStrategyPtr
void removeConnector(transport::InConnectorPtr connector)
Instances of this class describe the selection and configuration of an event processing strategy...
EventReceivingStrategyPtr getEventReceivingStrategy() const
A class describing the configuration of Participant instances.
boost::shared_ptr< InConnector > InConnectorPtr
Scope is a descriptor for a hierarchical channel of the unified bus.
Definition: Scope.h:46