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 | #include "ariba/config.h"
|
---|
41 |
|
---|
42 | #ifdef HAVE_LOG4CXX_LOGGER_H
|
---|
43 | #include <log4cxx/logger.h>
|
---|
44 | #include <log4cxx/basicconfigurator.h>
|
---|
45 | #endif // HAVE_LOG4CXX_LOGGER_H
|
---|
46 |
|
---|
47 | namespace ariba {
|
---|
48 | namespace utility {
|
---|
49 |
|
---|
50 | StartupWrapper::ConfigurationList StartupWrapper::configurations;
|
---|
51 | #ifdef UNDERLAY_OMNET
|
---|
52 | StartupWrapper::ModuleList StartupWrapper::modules;
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
|
---|
56 |
|
---|
57 | StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
|
---|
58 | }
|
---|
59 |
|
---|
60 | StartupWrapper::~StartupWrapper(){
|
---|
61 | }
|
---|
62 |
|
---|
63 | #ifdef UNDERLAY_OMNET
|
---|
64 | void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
|
---|
65 | modules.push( mod );
|
---|
66 | }
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #ifdef UNDERLAY_OMNET
|
---|
70 | AribaOmnetModule* StartupWrapper::getCurrentModule(){
|
---|
71 | assert( modules.size() > 0 );
|
---|
72 |
|
---|
73 | AribaOmnetModule* ret = modules.front();
|
---|
74 | modules.pop();
|
---|
75 |
|
---|
76 | return ret;
|
---|
77 | }
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | void StartupWrapper::startSystem(){
|
---|
81 |
|
---|
82 | //
|
---|
83 | // having seeded the pseudo rng is always good
|
---|
84 | //
|
---|
85 |
|
---|
86 | srand( time(NULL) );
|
---|
87 |
|
---|
88 | //
|
---|
89 | // init the system queue
|
---|
90 | //
|
---|
91 |
|
---|
92 | if( ! SystemQueue::instance().isRunning() )
|
---|
93 | SystemQueue::instance().run();
|
---|
94 |
|
---|
95 | //
|
---|
96 | // init the logging system
|
---|
97 | //
|
---|
98 | // configure the logging
|
---|
99 | //
|
---|
100 |
|
---|
101 | #ifdef HAVE_LOG4CXX_LOGGER_H
|
---|
102 | log4cxx::BasicConfigurator::configure();
|
---|
103 |
|
---|
104 | // set the global log level to warning
|
---|
105 | {
|
---|
106 | log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
|
---|
107 | logger->setLevel(log4cxx::Level::getInfo());
|
---|
108 | }
|
---|
109 |
|
---|
110 | // set up again an individual level if you like
|
---|
111 | #ifndef HAVE_MAEMO
|
---|
112 | {
|
---|
113 | //log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("MCPO"));
|
---|
114 | //logger->setLevel(log4cxx::Level::getDebug());
|
---|
115 | }
|
---|
116 | #endif //HAVE_MAEMO
|
---|
117 | #endif //HAVE_LOG4CXX_LOGGER_H
|
---|
118 | }
|
---|
119 |
|
---|
120 | void StartupWrapper::stopSystem(){
|
---|
121 | SystemQueue::instance().cancel();
|
---|
122 | }
|
---|
123 |
|
---|
124 | void StartupWrapper::initConfig(string filename){
|
---|
125 | configurations.push( filename );
|
---|
126 | Configuration::setConfigFilename( filename );
|
---|
127 | }
|
---|
128 |
|
---|
129 | void StartupWrapper::handleSystemEvent(const SystemEvent& event){
|
---|
130 |
|
---|
131 | if( event.getType() == StartupWrapperEventStartup ){
|
---|
132 |
|
---|
133 | string config = configurations.front();
|
---|
134 | configurations.pop();
|
---|
135 | Configuration::setConfigFilename( config );
|
---|
136 |
|
---|
137 | //
|
---|
138 | // start the actual application
|
---|
139 | //
|
---|
140 |
|
---|
141 | // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
|
---|
142 | // wie wird im Falle von omnet die anwendung erstellt?
|
---|
143 |
|
---|
144 | service->startup();
|
---|
145 |
|
---|
146 | }
|
---|
147 |
|
---|
148 | }
|
---|
149 |
|
---|
150 | void StartupWrapper::startup(StartupInterface* service, bool block){
|
---|
151 |
|
---|
152 | StartupWrapper* startup = new StartupWrapper(service);
|
---|
153 | service->wrapper = startup;
|
---|
154 |
|
---|
155 | SystemQueue::instance().scheduleEvent(
|
---|
156 | SystemEvent( startup, StartupWrapperEventStartup, NULL), 0 );
|
---|
157 |
|
---|
158 | #ifndef UNDERLAY_OMNET
|
---|
159 | if( block ) getchar();
|
---|
160 | #endif
|
---|
161 | }
|
---|
162 |
|
---|
163 | void StartupWrapper::shutdown(StartupInterface* service, bool block){
|
---|
164 |
|
---|
165 | if( service == NULL || service->wrapper == NULL ) return;
|
---|
166 |
|
---|
167 | #ifdef UNDERLAY_OMNET
|
---|
168 | //TODO: service->shutdown();
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | if(block){
|
---|
172 | // call directly
|
---|
173 | service->shutdown();
|
---|
174 | }else{
|
---|
175 | // call async, but not using systemqueue! // TODO: mem leak
|
---|
176 | AsyncShutdown* async = new AsyncShutdown(service);
|
---|
177 | async->runBlockingMethod();
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
|
---|
182 | : service(_service){
|
---|
183 | }
|
---|
184 |
|
---|
185 | void StartupWrapper::AsyncShutdown::blockingFunction(){
|
---|
186 | service->shutdown();
|
---|
187 | }
|
---|
188 |
|
---|
189 | void StartupWrapper::AsyncShutdown::dispatchFunction(){
|
---|
190 | //unused
|
---|
191 | }
|
---|
192 |
|
---|
193 | }} // namespace ariba, utility
|
---|