1 | // [License]
|
---|
2 | // The Ariba-Underlay Copyright
|
---|
3 | //
|
---|
4 | // Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
|
---|
5 | //
|
---|
6 | // Institute of Telematics
|
---|
7 | // UniversitÀt Karlsruhe (TH)
|
---|
8 | // Zirkel 2, 76128 Karlsruhe
|
---|
9 | // Germany
|
---|
10 | //
|
---|
11 | // Redistribution and use in source and binary forms, with or without
|
---|
12 | // modification, are permitted provided that the following conditions are
|
---|
13 | // met:
|
---|
14 | //
|
---|
15 | // 1. Redistributions of source code must retain the above copyright
|
---|
16 | // notice, this list of conditions and the following disclaimer.
|
---|
17 | // 2. Redistributions in binary form must reproduce the above copyright
|
---|
18 | // notice, this list of conditions and the following disclaimer in the
|
---|
19 | // documentation and/or other materials provided with the distribution.
|
---|
20 | //
|
---|
21 | // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
|
---|
22 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
23 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
|
---|
25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
32 | //
|
---|
33 | // The views and conclusions contained in the software and documentation
|
---|
34 | // are those of the authors and should not be interpreted as representing
|
---|
35 | // official policies, either expressed or implied, of the Institute of
|
---|
36 | // Telematics.
|
---|
37 | // [License]
|
---|
38 |
|
---|
39 | #include "StartupWrapper.h"
|
---|
40 |
|
---|
41 | namespace ariba {
|
---|
42 | namespace utility {
|
---|
43 |
|
---|
44 | StartupWrapper::ConfigurationList StartupWrapper::configurations;
|
---|
45 | #ifdef UNDERLAY_OMNET
|
---|
46 | StartupWrapper::ModuleList StartupWrapper::modules;
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
|
---|
50 |
|
---|
51 | StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
|
---|
52 | }
|
---|
53 |
|
---|
54 | StartupWrapper::~StartupWrapper(){
|
---|
55 | }
|
---|
56 |
|
---|
57 | #ifdef UNDERLAY_OMNET
|
---|
58 | void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
|
---|
59 | modules.push( mod );
|
---|
60 | }
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #ifdef UNDERLAY_OMNET
|
---|
64 | AribaOmnetModule* StartupWrapper::getCurrentModule(){
|
---|
65 | assert( modules.size() > 0 );
|
---|
66 |
|
---|
67 | AribaOmnetModule* ret = modules.front();
|
---|
68 | modules.pop();
|
---|
69 |
|
---|
70 | return ret;
|
---|
71 | }
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | void StartupWrapper::startSystem(){
|
---|
75 |
|
---|
76 | //
|
---|
77 | // having seeded the pseudo rng is always good
|
---|
78 | //
|
---|
79 |
|
---|
80 | srand( time(NULL) );
|
---|
81 |
|
---|
82 | //
|
---|
83 | // init the system queue
|
---|
84 | //
|
---|
85 |
|
---|
86 | if( ! SystemQueue::instance().isRunning() )
|
---|
87 | SystemQueue::instance().run();
|
---|
88 |
|
---|
89 | //
|
---|
90 | // init the logging system
|
---|
91 | //
|
---|
92 | // configure the logging
|
---|
93 | //
|
---|
94 |
|
---|
95 | log4cxx::BasicConfigurator::configure();
|
---|
96 |
|
---|
97 | // set the global log level
|
---|
98 | {
|
---|
99 | log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
|
---|
100 | logger->setLevel(log4cxx::Level::getInfo());
|
---|
101 | }
|
---|
102 |
|
---|
103 | // set up again an individual level if you like
|
---|
104 | /*
|
---|
105 | {
|
---|
106 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("PingPong"));
|
---|
107 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
108 | }
|
---|
109 | {
|
---|
110 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseCommunication"));
|
---|
111 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
112 | }
|
---|
113 | {
|
---|
114 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("OverlayBootstrap"));
|
---|
115 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
116 | }
|
---|
117 | {
|
---|
118 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BootstrapManager"));
|
---|
119 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
120 | }
|
---|
121 | {
|
---|
122 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BluetoothSdp"));
|
---|
123 | logger->setLevel(log4cxx::Level::getDebug());
|
---|
124 | }
|
---|
125 | {
|
---|
126 | log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("rfcomm"));
|
---|
127 | logger->setLevel(log4cxx::Level::getAll());
|
---|
128 | }*/
|
---|
129 |
|
---|
130 | //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
131 | // DON'T SVN COMMIT YOUR CHANGED LOGGING! THE ABOVE CODE MUST REMAIN AS IS!
|
---|
132 | //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
133 | }
|
---|
134 |
|
---|
135 | void StartupWrapper::stopSystem(){
|
---|
136 | SystemQueue::instance().cancel();
|
---|
137 | }
|
---|
138 |
|
---|
139 | void StartupWrapper::initConfig(string filename){
|
---|
140 | configurations.push( filename );
|
---|
141 | Configuration::setConfigFilename( filename );
|
---|
142 | }
|
---|
143 |
|
---|
144 | void StartupWrapper::handleSystemEvent(const SystemEvent& event){
|
---|
145 |
|
---|
146 | if( event.getType() == StartupWrapperEventStartup ){
|
---|
147 |
|
---|
148 | string config = configurations.front();
|
---|
149 | configurations.pop();
|
---|
150 | Configuration::setConfigFilename( config );
|
---|
151 |
|
---|
152 | //
|
---|
153 | // start the actual application
|
---|
154 | //
|
---|
155 |
|
---|
156 | // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
|
---|
157 | // wie wird im Falle von omnet die anwendung erstellt?
|
---|
158 |
|
---|
159 | service->startup();
|
---|
160 |
|
---|
161 | }
|
---|
162 |
|
---|
163 | }
|
---|
164 |
|
---|
165 | void StartupWrapper::startup(StartupInterface* service, bool block){
|
---|
166 |
|
---|
167 | StartupWrapper* startup = new StartupWrapper(service);
|
---|
168 | service->wrapper = startup;
|
---|
169 |
|
---|
170 | SystemQueue::instance().scheduleEvent(
|
---|
171 | SystemEvent( startup, StartupWrapperEventStartup, NULL), 0 );
|
---|
172 |
|
---|
173 | #ifndef UNDERLAY_OMNET
|
---|
174 | if( block ) getchar();
|
---|
175 | #endif
|
---|
176 | }
|
---|
177 |
|
---|
178 | void StartupWrapper::shutdown(StartupInterface* service, bool block){
|
---|
179 |
|
---|
180 | if( service == NULL || service->wrapper == NULL ) return;
|
---|
181 |
|
---|
182 | #ifdef UNDERLAY_OMNET
|
---|
183 | //TODO: service->shutdown();
|
---|
184 | #endif
|
---|
185 |
|
---|
186 | if(block){
|
---|
187 | // call directly
|
---|
188 | service->shutdown();
|
---|
189 | }else{
|
---|
190 | // call async, but not using systemqueue! // TODO: mem leak
|
---|
191 | AsyncShutdown* async = new AsyncShutdown(service);
|
---|
192 | async->runBlockingMethod();
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
|
---|
197 | : service(_service){
|
---|
198 | }
|
---|
199 |
|
---|
200 | void StartupWrapper::AsyncShutdown::blockingFunction(){
|
---|
201 | service->shutdown();
|
---|
202 | }
|
---|
203 |
|
---|
204 | void StartupWrapper::AsyncShutdown::dispatchFunction(){
|
---|
205 | //unused
|
---|
206 | }
|
---|
207 |
|
---|
208 | }} // namespace ariba, utility
|
---|