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

Last change on this file since 4738 was 4483, checked in by Christoph Mayer, 15 years ago

-StartupWrapper bisschen umgeschrieben, erste Schritte für sauberes runterfahren

File size: 5.1 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
41namespace ariba {
42namespace utility {
43
44StartupWrapper::ConfigurationList StartupWrapper::configurations;
45#ifdef UNDERLAY_OMNET
46StartupWrapper::ModuleList StartupWrapper::modules;
47#endif
48
49SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
50
51StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
52}
53
54StartupWrapper::~StartupWrapper(){
55}
56
57#ifdef UNDERLAY_OMNET
58void StartupWrapper::insertCurrentModule(AribaOmnetModule* mod){
59 modules.push( mod );
60}
61#endif
62
63#ifdef UNDERLAY_OMNET
64AribaOmnetModule* StartupWrapper::getCurrentModule(){
65 assert( modules.size() > 0 );
66
67 AribaOmnetModule* ret = modules.front();
68 modules.pop();
69
70 return ret;
71}
72#endif
73
74void 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::getDebug());
101 }
102
103 // set up again an individual level if you like
104 {
105// log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseOverlay"));
106// logger->setLevel(log4cxx::Level::getDebug());
107 }
108 {
109// log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("BaseCommunication"));
110// logger->setLevel(log4cxx::Level::getDebug());
111 }
112
113 //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
114 // DON'T SVN COMMIT YOUR CHANTED LOGGING! THE ABOVE CODE MUST REMAIN AS IS!
115 //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
116}
117
118void StartupWrapper::stopSystem(){
119 SystemQueue::instance().cancel();
120}
121
122void StartupWrapper::initConfig(string filename){
123 configurations.push( filename );
124 Configuration::setConfigFilename( filename );
125}
126
127void StartupWrapper::handleSystemEvent(const SystemEvent& event){
128
129 if( event.getType() == StartupWrapperEventStartup ){
130
131 string config = configurations.front();
132 configurations.pop();
133 Configuration::setConfigFilename( config );
134
135 //
136 // start the actual application
137 //
138
139 // TODO: im falle von omnet ist service = null, da von SpoVNetOmnetModule so ÃŒbergeben
140 // wie wird im Falle von omnet die anwendung erstellt?
141
142 service->startup();
143
144 }
145
146}
147
148void StartupWrapper::startup(StartupInterface* service, bool block){
149
150 StartupWrapper* startup = new StartupWrapper(service);
151 service->wrapper = startup;
152
153 SystemQueue::instance().scheduleEvent(
154 SystemEvent( startup, StartupWrapperEventStartup, NULL), 0 );
155
156#ifndef UNDERLAY_OMNET
157 if( block ) getchar();
158#endif
159}
160
161void StartupWrapper::shutdown(StartupInterface* service, bool block){
162
163 if( service == NULL || service->wrapper == NULL ) return;
164
165#ifdef UNDERLAY_OMNET
166 //TODO: service->shutdown();
167#endif
168
169 if(block){
170 // call directly
171 service->shutdown();
172 }else{
173 // call async, but not using systemqueue! // TODO: mem leak
174 AsyncShutdown* async = new AsyncShutdown(service);
175 async->runBlockingMethod();
176 }
177}
178
179StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
180 : service(_service){
181}
182
183void StartupWrapper::AsyncShutdown::blockingFunction(){
184 service->shutdown();
185}
186
187void StartupWrapper::AsyncShutdown::dispatchFunction(){
188 //unused
189}
190
191}} // namespace ariba, utility
Note: See TracBrowser for help on using the repository browser.