source: source/ariba/utility/system/StartupWrapper.cpp@ 9652

Last change on this file since 9652 was 7916, checked in by Christoph Mayer, 15 years ago
File size: 5.0 KB
Line 
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
47namespace ariba {
48namespace utility {
49
50StartupWrapper::ConfigurationList StartupWrapper::configurations;
51#ifdef UNDERLAY_OMNET
52StartupWrapper::ModuleList StartupWrapper::modules;
53#endif
54
55SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
56
57StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
58}
59
60StartupWrapper::~StartupWrapper(){
61}
62
63#ifdef UNDERLAY_OMNET
64void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
65 modules.push( mod );
66}
67#endif
68
69#ifdef UNDERLAY_OMNET
70AribaOmnetModule* StartupWrapper::getCurrentModule(){
71 assert( modules.size() > 0 );
72
73 AribaOmnetModule* ret = modules.front();
74 modules.pop();
75
76 return ret;
77}
78#endif
79
80void 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
120void StartupWrapper::stopSystem(){
121 SystemQueue::instance().cancel();
122}
123
124void StartupWrapper::initConfig(string filename){
125 configurations.push( filename );
126 Configuration::setConfigFilename( filename );
127}
128
129void StartupWrapper::handleSystemEvent(const SystemEvent& event){
130
131 if( event.getType() == StartupWrapperEventStartup ){
132
133 if(!configurations.empty()){
134 string config = configurations.front();
135 configurations.pop();
136 Configuration::setConfigFilename( config );
137 }
138
139 //
140 // start the actual application
141 //
142
143 // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
144 // wie wird im Falle von omnet die anwendung erstellt?
145
146 service->startup();
147
148 }
149
150}
151
152void StartupWrapper::startup(StartupInterface* service, bool block){
153
154 StartupWrapper* startup = new StartupWrapper(service);
155 service->wrapper = startup;
156
157 SystemQueue::instance().scheduleEvent(
158 SystemEvent( startup, StartupWrapperEventStartup, NULL), 0 );
159
160#ifndef UNDERLAY_OMNET
161 if( block ) getchar();
162#endif
163}
164
165void StartupWrapper::shutdown(StartupInterface* service, bool block){
166
167 if( service == NULL || service->wrapper == NULL ) return;
168
169#ifdef UNDERLAY_OMNET
170 //TODO: service->shutdown();
171#endif
172
173 if(block){
174 // call directly
175 service->shutdown();
176 }else{
177 // call async, but not using systemqueue! // TODO: mem leak
178 AsyncShutdown* async = new AsyncShutdown(service);
179 async->runBlockingMethod();
180 }
181}
182
183StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
184 : service(_service){
185}
186
187void StartupWrapper::AsyncShutdown::blockingFunction(){
188 service->shutdown();
189}
190
191void StartupWrapper::AsyncShutdown::dispatchFunction(){
192 //unused
193}
194
195}} // namespace ariba, utility
Note: See TracBrowser for help on using the repository browser.