RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
88  RSCDEBUG(d->logger, "Activating");
89 
90  // Activate all connectors.
91  for (ConnectorSet::iterator it = d->connectors.begin(); it
92  != d->connectors.end(); ++it) {
93  (*it)->setScope(d->scope);
94  (*it)->activate();
95  }
96 
97  // Create the event processing strategy and attach it to all
98  // connectors.
99  d->eventReceivingStrategy = createEventReceivingStrategy();
100 }
101 
103  RSCDEBUG(d->logger, "Deactivating");
104 
105  // Deactivate all connectors.
106  for (ConnectorSet::iterator it = d->connectors.begin(); it
107  != d->connectors.end(); ++it) {
108  (*it)->deactivate();
109  }
110 
111  // Release event processing strategy.
112  d->eventReceivingStrategy.reset();
113  d->shutdown = true;
114 }
115 
117  return d->receivingStrategyConfig;
118 }
119 
121  return d->eventReceivingStrategy;
122 }
123 
125  return d->connectors;
126 }
127 
129  RSCDEBUG(d->logger, "Adding connector " << connector);
130  d->connectors.insert(connector);
131 }
132 
134  RSCDEBUG(d->logger, "Removing connector " << connector);
135  d->connectors.erase(connector);
136 }
137 
139  for (ConnectorSet::iterator it = d->connectors.begin(); it
140  != d->connectors.end(); ++it) {
141  filter->notifyObserver(*it, filter::FilterAction::ADD);
142  }
143  d->eventReceivingStrategy->addFilter(filter);
144 }
145 
147  for (ConnectorSet::iterator it = d->connectors.begin(); it
148  != d->connectors.end(); ++it) {
149  filter->notifyObserver(*it, filter::FilterAction::REMOVE);
150  }
151  d->eventReceivingStrategy->removeFilter(filter);
152 }
153 
155  const QualityOfServiceSpec& specs) {
156  for (ConnectorSet::iterator it = d->connectors.begin(); it
157  != d->connectors.end(); ++it) {
158  (*it)->setQualityOfServiceSpecs(specs);
159  }
160 }
161 
162 }
163 }