RSB  0.7.0
 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 
33 #include "../transport/OutConnector.h"
34 #include "../QualityOfServiceSpec.h"
35 #include "../transport/Connector.h"
36 #include "EventSendingStrategy.h"
37 
38 using namespace std;
39 
40 using namespace rsc::logging;
41 
42 using namespace rsb;
43 using namespace rsb::transport;
44 
45 namespace rsb {
46 namespace eventprocessing {
47 
48 typedef std::list<transport::OutConnectorPtr> ConnectorList;
49 
51 public:
52 
53  rsc::logging::LoggerPtr logger;
54 
57  volatile bool shutdown;
58 
59 };
60 
61 OutRouteConfigurator::OutRouteConfigurator() :
62  d(new Impl) {
63  d->logger = Logger::getLogger("rsb.eventprocessing.OutRouteConfigurator");
64  d->shutdown = false;
65 }
66 
68  if (!d->shutdown) {
69  deactivate();
70  }
71 }
72 
74  return "OutRouteConfigurator";
75 }
76 
77 void OutRouteConfigurator::printContents(ostream& stream) const {
78  stream << "connectors = " << d->connectors << ", shutdown = "
79  << d->shutdown;
80 }
81 
83  RSCDEBUG(d->logger, "Activating");
84 
85  // Activate all connectors.
86  for (ConnectorList::iterator it = d->connectors.begin(); it
87  != d->connectors.end(); ++it) {
88  (*it)->activate();
89  }
90 
91  // Create a strategy object and add all connectors to it.
92  d->eventSendingStrategy.reset(new DirectEventSendingStrategy());
93  for (ConnectorList::iterator it = d->connectors.begin(); it
94  != d->connectors.end(); ++it) {
95  RSCDEBUG(d->logger, "Adding connector " << *it
96  << " to strategy " << d->eventSendingStrategy);
97  d->eventSendingStrategy->addConnector(*it);
98  }
99 }
100 
102  RSCDEBUG(d->logger, "Deactivating");
103 
104  // Remove all connectors from the strategy object, the release the
105  // strategy.
106  for (ConnectorList::iterator it = d->connectors.begin(); it
107  != d->connectors.end(); ++it) {
108  RSCDEBUG(d->logger, "Removing connector " << *it
109  << " from strategy " << d->eventSendingStrategy);
110  if (d->eventSendingStrategy) {
111  d->eventSendingStrategy->removeConnector(*it);
112  }
113  }
114  d->eventSendingStrategy.reset();
115 
116  // Deactivate all connectors.
117  for (ConnectorList::iterator it = d->connectors.begin(); it
118  != d->connectors.end(); ++it) {
119  (*it)->deactivate();
120  }
121 
122  d->shutdown = true;
123 }
124 
126  RSCDEBUG(d->logger, "Adding connector " << connector);
127  d->connectors.push_back(connector);
128 }
129 
131  RSCDEBUG(d->logger, "Removing connector " << connector);
132  d->connectors.remove(connector);
133 }
134 
136  RSCDEBUG(d->logger, "OutRouteConfigurator::publish(Event) publishing new event: " << e);
137  d->eventSendingStrategy->process(e);
138 }
139 
141  const QualityOfServiceSpec& specs) {
142  for (ConnectorList::iterator it = d->connectors.begin(); it
143  != d->connectors.end(); ++it) {
144  (*it)->setQualityOfServiceSpecs(specs);
145  }
146 }
147 
148 }
149 }