00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #include "OSDLBasic.h"
00028 
00029 #include "OSDLEvents.h"              
00030 #include "OSDLVideo.h"               
00031 #include "OSDLCDROMDriveHandler.h"   
00032 
00033 #include "OSDLAudio.h"               
00034 
00035 #include "OSDLUtils.h"               
00036 
00037 
00038 
00039 #include "Ceylan.h"                  
00040 
00041 
00042 #include <list>
00043 
00044 
00045 
00046 #ifdef OSDL_USES_CONFIG_H
00047 #include "OSDLConfig.h"              
00048 #endif // OSDL_USES_CONFIG_H
00049 
00050 
00051 #if OSDL_ARCH_NINTENDO_DS
00052 #include "OSDLConfigForNintendoDS.h" 
00053 #endif // OSDL_ARCH_NINTENDO_DS
00054 
00055 
00056 #if OSDL_USES_SDL
00057 #include "SDL.h"                     
00058 #endif // OSDL_USES_SDL
00059 
00060 
00061 #if OSDL_USES_AGAR
00062 #include <agar/core.h>               
00063 #endif // OSDL_USES_AGAR
00064 
00065 
00066 
00067 
00068 using std::string ;
00069 
00070 using namespace Ceylan ;
00071 using namespace Ceylan::Log ;
00072 
00073 using namespace OSDL ;
00074 
00075 
00076 
00077 
00078 #if OSDL_VERBOSE_BASIC_MODULE
00079 
00080 #define LOG_DEBUG_BASIC(message)   LogPlug::debug(message)
00081 #define LOG_TRACE_BASIC(message)   LogPlug::trace(message)
00082 #define LOG_WARNING_BASIC(message) LogPlug::warning(message)
00083 
00084 #else // OSDL_VERBOSE_BASIC_MODULE
00085 
00086 #define LOG_DEBUG_BASIC(message)
00087 #define LOG_TRACE_BASIC(message)
00088 #define LOG_WARNING_BASIC(message)
00089 
00090 #endif // OSDL_VERBOSE_BASIC_MODULE
00091 
00092 
00093 
00094 
00095 
00096 const CommonModule::BackendReturnCode CommonModule::BackendSuccess =  0 ;
00097 const CommonModule::BackendReturnCode CommonModule::BackendError   = -1 ;
00098 
00099 
00100 
00101 
00102 bool CommonModule::_BackendInitialized = false ;
00103 
00104 
00105 
00106 
00107 
00108 const Ceylan::Version::VersionNumber oldestAgarSupportedMajor = 1 ;
00109 const Ceylan::Version::VersionNumber oldestAgarSupportedMinor = 3 ;
00110 const Ceylan::Version::VersionNumber oldestAgarSupportedPatch = 4 ;
00111 
00112 
00113 
00114 #define OSDL_DEBUG_VERSION 0
00115 
00116 
00117 
00118 const Ceylan::LibtoolVersion & OSDL::GetVersion()
00119 {
00120 
00121 
00122 #if OSDL_DEBUG_VERSION
00123 
00124     
00125 
00126     Ceylan::LibtoolVersion * ceylanVersion ;
00127 
00128     try
00129     {
00130 
00131         osdlVersion = new Ceylan::LibtoolVersion( OSDL_LIBTOOL_VERSION ) ;
00132 
00133     }
00134     catch( const Ceylan::Exception & e )
00135     {
00136 
00137         throw OSDL::Exception( "OSDL::GetVersion failed: " + e.toString() ) ;
00138 
00139     }
00140 
00141     return *osdlVersion ;
00142 
00143 
00144 #else // OSDL_DEBUG_VERSION
00145 
00146     static Ceylan::LibtoolVersion osdlVersion( OSDL_LIBTOOL_VERSION ) ;
00147 
00148     return osdlVersion ;
00149 
00150 #endif // OSDL_DEBUG_VERSION
00151 
00152 }
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 #if OSDL_USES_SDL
00166 
00167 const Ceylan::Flags CommonModule::UseTimer       = SDL_INIT_TIMER       ;
00168 const Ceylan::Flags CommonModule::UseAudio       = SDL_INIT_AUDIO       ;
00169 const Ceylan::Flags CommonModule::UseVideo       = SDL_INIT_VIDEO       ;
00170 const Ceylan::Flags CommonModule::UseCDROM       = SDL_INIT_CDROM       ;
00171 const Ceylan::Flags CommonModule::UseJoystick    = SDL_INIT_JOYSTICK    ;
00172 const Ceylan::Flags CommonModule::UseKeyboard    = 0x4000               ;
00173 const Ceylan::Flags CommonModule::UseMouse       = 0x8000               ;
00174 const Ceylan::Flags CommonModule::UseGUI         = 0x10000              ;
00175 
00176 const Ceylan::Flags CommonModule::UseEverything  = 0x0001FFFF  ;
00177 const Ceylan::Flags CommonModule::NoParachute    = SDL_INIT_NOPARACHUTE ;
00178 const Ceylan::Flags CommonModule::UseEventThread = SDL_INIT_EVENTTHREAD ;
00179 
00180 #else // OSDL_USES_SDL
00181 
00182 
00183 const Ceylan::Flags CommonModule::UseTimer       = 0x00000001 ;
00184 const Ceylan::Flags CommonModule::UseAudio       = 0x00000010 ;
00185 const Ceylan::Flags CommonModule::UseVideo       = 0x00000020 ;
00186 const Ceylan::Flags CommonModule::UseCDROM       = 0x00000100 ;
00187 const Ceylan::Flags CommonModule::UseJoystick    = 0x00000200 ;
00188 const Ceylan::Flags CommonModule::UseKeyboard    = 0x4000     ;
00189 const Ceylan::Flags CommonModule::UseMouse       = 0x8000     ;
00190 const Ceylan::Flags CommonModule::UseGUI         = 0x10000    ;
00191 const Ceylan::Flags CommonModule::UseEverything  = 0x0001FFFF  ;
00192 const Ceylan::Flags CommonModule::NoParachute    = 0x00100000 ;
00193 const Ceylan::Flags CommonModule::UseEventThread = 0x01000000 ;
00194 
00195 #endif // OSDL_USES_SDL
00196 
00197 
00198 
00199 
00200 const Ceylan::Flags CommonModule::UseEvents =
00201     UseJoystick | UseKeyboard | UseMouse ;
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 CommonModule * CommonModule::_CurrentCommonModule = 0 ;
00225 
00226 
00227 #if OSDL_USES_SDL
00228 
00230 const string CommonModule::_SDLEnvironmentVariables[] =
00231 {
00232         "SDL_DEBUG",
00233         "SDL_CDROM"
00234 } ;
00235 
00236 #else // OSDL_USES_SDL
00237 
00238 const string CommonModule::_SDLEnvironmentVariables[] = {} ;
00239 
00240 #endif // OSDL_USES_SDL
00241 
00242 
00243 
00244 
00245 CommonModule::CommonModule( Flags flags ) :
00246     Ceylan::Module(
00247         "OSDL common module",
00248         "This is the root module of OSDL",
00249         "http://osdl.sourceforge.net",
00250         "Olivier Boudeville",
00251         "olivier.boudeville@online.fr",
00252         OSDL::GetVersion(),
00253         "disjunctive LGPL/GPL" ),
00254     _video(  0 ),
00255     _events( 0 ),
00256     _audio(  0 ),
00257     _useGUI( false ),
00258     _flags( flags ),
00259     _cdromHandler( 0 ),
00260     _startingSecond( 0 ),
00261     _startingMicrosecond( 0 )
00262 {
00263 
00264 
00265     LOG_TRACE_BASIC( "CommonModule constructor" ) ;
00266 
00267     
00268     System::getPreciseTime( _startingSecond, _startingMicrosecond ) ;
00269 
00270     
00271     flags = AutoCorrectFlags( flags ) ;
00272 
00273     send( "Starting OSDL version " + OSDL::GetVersion().toString() + ". "
00274         + InterpretFlags( flags ) ) ;
00275 
00276 #if OSDL_USES_SDL
00277 
00278     SDL_version compileTimeSDLVersion ;
00279     SDL_VERSION( & compileTimeSDLVersion ) ;
00280 
00281     SDL_version linkTimeSDLVersion = *SDL_Linked_Version() ;
00282 
00283     send( "Using SDL backend, compiled against the "
00284         + Ceylan::toNumericalString( compileTimeSDLVersion.major) + "."
00285         + Ceylan::toNumericalString( compileTimeSDLVersion.minor) + "."
00286         + Ceylan::toNumericalString( compileTimeSDLVersion.patch)
00287         + " version, linked against the "
00288         + Ceylan::toNumericalString( linkTimeSDLVersion.major) + "."
00289         + Ceylan::toNumericalString( linkTimeSDLVersion.minor) + "."
00290         + Ceylan::toNumericalString( linkTimeSDLVersion.patch) + " version." ) ;
00291 
00292 #endif // OSDL_USES_SDL
00293 
00294 
00295 #if OSDL_ARCH_NINTENDO_DS
00296 
00297 #ifdef OSDL_RUNS_ON_ARM7
00298 
00299     throw OSDL::Exception( "CommonModule constructor failed: "
00300         "not supported on the ARM7." ) ;
00301 
00302 #elif defined(OSDL_RUNS_ON_ARM9)
00303 
00304     try
00305     {
00306 
00307         
00308         CommandManager::GetCommandManager().activate() ;
00309 
00310     }
00311     catch( const Ceylan::System::FIFO::FIFOException & e )
00312     {
00313 
00314         throw OSDL::Exception( "CommonModule constructor failed: "
00315             + e.toString() ) ;
00316 
00317     }
00318 
00319 #endif // OSDL_RUNS_ON_ARM7
00320 
00321 #endif // OSDL_ARCH_NINTENDO_DS
00322 
00323 
00324 #if OSDL_USES_SDL
00325 
00326     
00327     if ( SDL_Init( 0 ) != BackendSuccess )
00328         throw OSDL::Exception( "CommonModule constructor failed: "
00329             "SDL first initialization failed: "
00330             + Utils::getBackendLastError() ) ;
00331 
00332 #endif // OSDL_USES_SDL
00333 
00334 
00335     
00336 
00337 
00338 
00339 
00340 
00341 
00342 
00343 
00344     if ( flags & UseTimer )
00345     {
00346 
00347         send( "Initializing timer subsystem" ) ;
00348 
00349 #if OSDL_USES_SDL
00350 
00351         if ( _useGUI )
00352         {
00353             send( "Agar being used, no additional timer initialization is "
00354                 " needed." ) ;
00355         }
00356         else
00357         {
00358 
00359             if ( SDL_InitSubSystem( UseTimer ) != BackendSuccess )
00360                 throw OSDL::Exception( "CommonModule constructor: "
00361                     "unable to initialize timer subsystem: "
00362                     + Utils::getBackendLastError() ) ;
00363         }
00364 
00365 
00366     
00367 
00368 #endif // OSDL_USES_SDL
00369 
00370         send( "Timer subsystem initialized" ) ;
00371 
00372     }
00373 
00374 
00375 #if ! OSDL_ARCH_NINTENDO_DS
00376 
00377     if ( flags & UseCDROM )
00378     {
00379 
00380         _cdromHandler = new OSDL::CDROMDriveHandler() ;
00381 
00382     }
00383 
00384 #if OSDL_USES_SDL
00385 
00386     if ( flags & NoParachute )
00387     {
00388 
00389         send( "Disabling SDL parachute" ) ;
00390 
00391         if ( _useGUI )
00392         {
00393             send( "Agar being used, no SDL parachute request is needed." ) ;
00394         }
00395         else
00396         {
00397 
00398             if ( SDL_InitSubSystem( NoParachute ) != BackendSuccess )
00399                 throw OSDL::Exception( "CommonModule constructor: "
00400                     "unable to disable SDL parachute: "
00401                     + Utils::getBackendLastError() ) ;
00402 
00403             send( "SDL parachute initialized" ) ;
00404 
00405         }
00406 
00407     }
00408 
00409 #endif // OSDL_USES_SDL
00410 
00411 #endif // OSDL_ARCH_NINTENDO_DS
00412 
00413     
00414 
00415 
00416 
00417 
00418 
00419 
00420 
00421 
00422 
00423 
00424     if ( flags & UseVideo )
00425     {
00426 
00427         _video = new Video::VideoModule() ;
00428 
00429         if ( _useGUI )
00430             _video->setGUIEnableStatus( true ) ;
00431 
00432     }
00433 
00434     
00435     if ( flags & UseEvents )
00436     {
00437 
00438         _events = new Events::EventsModule( flags ) ;
00439 
00440         if ( _useGUI )
00441             _events->setGUIEnableStatus( true ) ;
00442 
00443     }
00444 
00445 
00446     
00447 
00448 
00449 
00450 
00451     if ( flags & UseAudio )
00452     {
00453 
00454         _audio = new Audio::AudioModule() ;
00455 
00456         if ( _useGUI )
00457             _audio->setGUIEnableStatus( true ) ;
00458 
00459     }
00460 
00461 
00462     
00463     if ( flags & UseGUI )
00464         enableGUI() ;
00465 
00466     _BackendInitialized = true ;
00467 
00468     send( "OSDL successfully initialized" ) ;
00469 
00470     dropIdentifier() ;
00471 
00472 }
00473 
00474 
00475 
00476 CommonModule::~CommonModule() throw()
00477 {
00478 
00479     System::Second currentSecond ;
00480     System::Microsecond currentMicrosecond ;
00481 
00482     System::getPreciseTime( currentSecond, currentMicrosecond ) ;
00483 
00484     send( "Stopping OSDL, which has been running for "
00485         + Ceylan::System::durationToString(
00486             _startingSecond, _startingMicrosecond,
00487             currentSecond, currentMicrosecond ) + "." ) ;
00488 
00489 
00490     if ( _cdromHandler != 0 )
00491     {
00492         delete _cdromHandler ;
00493         _cdromHandler = 0 ;
00494     }
00495 
00496     send( "CD-ROM stopped, now audio." ) ;
00497 
00498     if ( _audio != 0 )
00499     {
00500         delete _audio ;
00501         _audio = 0 ;
00502     }
00503 
00504     send( "Audio stopped, now events." ) ;
00505 
00506     if ( _events != 0 )
00507     {
00508         delete _events ;
00509         _events = 0 ;
00510     }
00511 
00512     send( "Events stopped, now video." ) ;
00513 
00514     if ( _video != 0 )
00515     {
00516         delete _video ;
00517         _video = 0 ;
00518     }
00519 
00520     send( "Video stopped." ) ;
00521 
00522 
00523     if ( _useGUI )
00524     {
00525 
00526         disableGUI() ;
00527 
00528 #if OSDL_USES_SDL
00529 
00530         
00531 
00532 
00533 
00534 
00535         SDL_Quit() ;
00536 
00537         send( "GUI and main back-end successfully stopped." ) ;
00538 
00539 #endif // OSDL_USES_SDL
00540 
00541     }
00542     else
00543     {
00544 
00545 #if OSDL_USES_SDL
00546 
00547         SDL_Quit() ;
00548 
00549         send( "Main back-end successfully stopped." ) ;
00550 
00551 #endif // OSDL_USES_SDL
00552 
00553     }
00554 
00555     send( "OSDL successfully stopped." ) ;
00556 
00557 }
00558 
00559 
00560 
00561 string CommonModule::InterpretFlags( Flags flags )
00562 {
00563 
00564     std::list<string> res ;
00565 
00566     if ( flags & UseTimer )
00567         res.push_back( "Timer requested (UseTimer is set)." ) ;
00568     else
00569         res.push_back( "No timer requested (UseTimer is not set)." ) ;
00570 
00571     if ( flags & UseAudio)
00572         res.push_back( "Audio requested (UseAudio is set)." ) ;
00573     else
00574         res.push_back( "No audio requested (UseAudio is not set)." ) ;
00575 
00576     if ( flags & UseVideo )
00577         res.push_back( "Video requested (UseVideo is set)." ) ;
00578     else
00579         res.push_back( "No video requested (UseVideo is not set)." ) ;
00580 
00581     if ( flags & UseGUI )
00582         res.push_back( "GUI requested (UseGUI is set)." ) ;
00583     else
00584         res.push_back( "No GUI requested (UseGUI is not set)." ) ;
00585 
00586     if ( flags & UseCDROM )
00587         res.push_back( "CD-ROM support requested (UseCDROM is set)." ) ;
00588     else
00589         res.push_back( "No CD-ROM support requested "
00590             "(UseCDROM is not set)." ) ;
00591 
00592 
00593     if ( flags & UseJoystick )
00594         res.push_back( "Joystick support requested (UseJoystick is set)." ) ;
00595     else
00596         res.push_back( "No joystick support requested "
00597             "(UseJoystick is not set)." ) ;
00598 
00599     if ( flags & UseKeyboard )
00600         res.push_back( "Keyboard support requested (UseKeyboard is set)." ) ;
00601     else
00602         res.push_back( "No keyboard support requested "
00603             "(UseKeyboard is not set)." ) ;
00604 
00605     if ( flags & UseMouse )
00606         res.push_back( "Mouse support requested (UseMouse is set)." ) ;
00607     else
00608         res.push_back( "No mouse support requested (UseMouse is not set)." ) ;
00609 
00610 
00611     if ( ( flags & UseEverything ) == UseEverything )
00612         res.push_back( "Every subsystem is requested "
00613             "(UseEverything is set)." ) ;
00614     else
00615         res.push_back( "Not all subsystems are requested "
00616             "(UseEverything is not set)." ) ;
00617 
00618     if ( flags & NoParachute )
00619         res.push_back( "No catching of fatal signals requested "
00620             "(NoParachute is set)." ) ;
00621     else
00622         res.push_back( "Fatal signal will be caught "
00623             "(NoParachute is not set)." ) ;
00624 
00625     if ( flags & UseEventThread )
00626         res.push_back( "Event thread requested (UseEventThread is set)." ) ;
00627     else
00628         res.push_back( "No event thread requested "
00629             "(UseEventThread is not set)." ) ;
00630 
00631 
00632     return "The specified flags for Common module, whose value is "
00633         + Ceylan::toString( flags,  true )
00634         + ", mean: " + Ceylan::formatStringList( res ) ;
00635 
00636 }
00637 
00638 
00639 
00640 Ceylan::System::Microsecond CommonModule::getRuntimeDuration() const
00641 {
00642 
00643     System::Second currentSecond ;
00644     System::Microsecond currentMicrosecond ;
00645 
00646     System::getPreciseTime( currentSecond, currentMicrosecond ) ;
00647 
00648     return System::getDurationBetween( _startingSecond, _startingMicrosecond,
00649         currentSecond, currentMicrosecond ) ;
00650 
00651 }
00652 
00653 
00654 
00655 bool CommonModule::hasVideoModule() const
00656 {
00657 
00658     return ( _video != 0 ) ;
00659 
00660 }
00661 
00662 
00663 
00664 Video::VideoModule & CommonModule::getVideoModule() const
00665 {
00666 
00667     if ( _video == 0 )
00668         throw OSDL::Exception(
00669             "CommonModule::getVideoModule: no video module available." ) ;
00670 
00671     return * _video ;
00672 
00673 }
00674 
00675 
00676 
00677 bool CommonModule::hasEventsModule() const
00678 {
00679 
00680     return ( _events != 0 ) ;
00681 
00682 }
00683 
00684 
00685 
00686 Events::EventsModule & CommonModule::getEventsModule() const
00687 {
00688 
00689     if ( _events == 0 )
00690         throw OSDL::Exception(
00691             "CommonModule::getEventsModule: no events module available." ) ;
00692 
00693     return * _events ;
00694 
00695 }
00696 
00697 
00698 
00699 bool CommonModule::hasAudioModule() const
00700 {
00701 
00702     return ( _audio != 0 ) ;
00703 
00704 }
00705 
00706 
00707 
00708 Audio::AudioModule & CommonModule::getAudioModule() const
00709 {
00710 
00711     if ( _audio == 0 )
00712         throw OSDL::Exception(
00713             "CommonModule::getAudioModule: no audio module available." ) ;
00714 
00715     return * _audio ;
00716 
00717 }
00718 
00719 
00720 
00721 void CommonModule::removeAudioModule()
00722 {
00723 
00724     if ( _audio == 0 )
00725         throw OSDL::Exception(
00726             "CommonModule::removeAudioModule: no audio module available." ) ;
00727 
00728     delete _audio ;
00729 
00730     _audio = 0 ;
00731 
00732 }
00733 
00734 
00735 
00736 Flags CommonModule::getFlags() const
00737 {
00738 
00739     return _flags ;
00740 
00741 }
00742 
00743 
00744 
00745 bool CommonModule::isGUIEnabled() const
00746 {
00747 
00748     return _useGUI ;
00749 
00750 }
00751 
00752 
00753 
00754 void CommonModule::enableGUI()
00755 {
00756 
00757     if ( _useGUI )
00758         throw OSDL::Exception( "CommonModule::enableGUI failed: "
00759             "GUI was already enabled." ) ;
00760 
00761     
00762 
00763 
00764 
00765     if ( _video == 0 )
00766         throw OSDL::Exception( "CommonModule::enableGUI failed: "
00767             "the video module must have already be created." ) ;
00768 
00769     _video->setGUIEnableStatus( true ) ;
00770 
00771 
00772     if ( _audio == 0 )
00773         throw OSDL::Exception( "CommonModule::enableGUI failed: "
00774             "the audio module must have already be created." ) ;
00775 
00776     _audio->setGUIEnableStatus( true ) ;
00777 
00778 
00779     if ( _events == 0 )
00780         throw OSDL::Exception( "CommonModule::enableGUI failed: "
00781             "the events module must have already be created." ) ;
00782 
00783     _events->setGUIEnableStatus( true ) ;
00784 
00785 
00786 #if OSDL_USES_SDL
00787 
00788 #if OSDL_USES_AGAR
00789 
00790     AG_AgarVersion linkTimeAgarVersion ;
00791 
00792     AG_GetVersion( &linkTimeAgarVersion ) ;
00793 
00794     send( "Using Agar backend for the GUI, linked against the "
00795         + Ceylan::toNumericalString( linkTimeAgarVersion.major ) + "."
00796         + Ceylan::toNumericalString( linkTimeAgarVersion.minor ) + "."
00797         + Ceylan::toNumericalString( linkTimeAgarVersion.patch )
00798         + ", release codenamed '"
00799         + Ceylan::toString( *linkTimeAgarVersion.release ) + "'." ) ;
00800 
00801     const string applicationName = "OSDL-application" ;
00802 
00803     
00804 
00805 
00806 
00807 
00808 #if OSDL_DEBUG_GUI
00809 
00810     int res = AG_InitCore( applicationName.c_str(),
00811       AG_VERBOSE | AG_NO_CFG_AUTOLOAD ) ;
00812 
00813 #else // OSDL_DEBUG_GUI
00814 
00815     int res = AG_InitCore( applicationName.c_str(), AG_NO_CFG_AUTOLOAD ) ;
00816 
00817 #endif // OSDL_DEBUG_GUI
00818 
00819     if ( res == -1 )
00820         throw OSDL::Exception( "CommonModule::enableGUI failed: "
00821             "initialization of the Agar core library failed: "
00822             + std::string( AG_GetError() ) ) ;
00823 
00824     if ( ! AG_VERSION_ATLEAST( oldestAgarSupportedMajor,
00825             oldestAgarSupportedMinor, oldestAgarSupportedPatch ) )
00826         throw OSDL::Exception( "The version of this Agar library in use "
00827             "is too old to be supported, needing at least "
00828             + Ceylan::toNumericalString( oldestAgarSupportedMajor ) + "."
00829             + Ceylan::toNumericalString( oldestAgarSupportedMinor ) + "."
00830             + Ceylan::toNumericalString( oldestAgarSupportedPatch ) + "." );
00831 
00832 #else // OSDL_USES_AGAR
00833 
00834     throw OSDL::Exception( "CommonModule::enableGUI failed: "
00835         "using a GUI was requested, "
00836         "but no Agar library support is available." ) ;
00837 
00838 #endif //OSDL_USES_AGAR
00839 
00840 #endif // OSDL_USES_SDL
00841 
00842     _useGUI = true ;
00843 
00844 }
00845 
00846 
00847 
00848 void CommonModule::CommonModule::disableGUI()
00849 {
00850 
00851     if ( ! _useGUI )
00852         throw OSDL::Exception( "CommonModule::disableGUI failed: "
00853             "GUI was not enabled." ) ;
00854 
00855 #if OSDL_USES_AGAR
00856 
00857     
00858 
00859 
00860 
00861     AG_Destroy() ;
00862 
00863 #endif //OSDL_USES_AGAR
00864 
00865     _useGUI = false ;
00866 
00867 }
00868 
00869 
00870 
00871 bool CommonModule::hasCDROMDriveHandler() const
00872 {
00873 
00874     return ( _cdromHandler != 0 ) ;
00875 
00876 }
00877 
00878 
00879 CDROMDriveHandler & CommonModule::getCDROMDriveHandler() const
00880 {
00881 
00882     if ( _cdromHandler == 0 )
00883         throw OSDL::Exception( "CommonModule::getCDROMDriveHandler: "
00884             "no CD-ROM handler available." ) ;
00885 
00886     return * _cdromHandler ;
00887 
00888 }
00889 
00890 
00891 
00892 const string CommonModule::toString( Ceylan::VerbosityLevels level ) const
00893 {
00894 
00895     string res = "Common root module, with currently video module " ;
00896 
00897     if ( _video != 0 )
00898         res += "enabled" ;
00899     else
00900         res += "disabled" ;
00901 
00902     res += ", with event module " ;
00903 
00904     if ( _events != 0 )
00905         res += "enabled" ;
00906     else
00907         res += "disabled" ;
00908 
00909     res += ", with audio module " ;
00910 
00911     if ( _audio != 0 )
00912         res += "enabled" ;
00913     else
00914         res += "disabled" ;
00915 
00916     res += ", using " ;
00917 
00918     if ( _cdromHandler != 0 )
00919         res += "a" ;
00920     else
00921         res += "no" ;
00922 
00923     res += " CD-ROM handler" ;
00924 
00925     if ( _useGUI )
00926         res += ", with GUI support enabled" ;
00927     else
00928         res += ", with GUI support disabled" ;
00929 
00930     if ( level == Ceylan::low )
00931         return res ;
00932 
00933 
00934     res += ". " + InterpretFlags( _flags ) ;
00935 
00936     if ( level == Ceylan::medium )
00937         return res ;
00938 
00939     std::list<string> completeMessage ;
00940 
00941     completeMessage.push_back( res ) ;
00942 
00943     completeMessage.push_back( Ceylan::Module::toString()  ) ;
00944 
00945     completeMessage.push_back(
00946         "The version of the Ceylan library currently linked to is "
00947         + Ceylan::GetVersion().toString() + "." ) ;
00948 
00949     completeMessage.push_back(
00950         "The version of the OSDL library currently linked to is "
00951         + OSDL::GetVersion().toString() + "." ) ;
00952 
00953     return Ceylan::formatStringList( completeMessage ) ;
00954 
00955 }
00956 
00957 
00958 
00959 string CommonModule::DescribeEnvironmentVariables()
00960 {
00961 
00962 #if OSDL_USES_SDL
00963 
00964     Ceylan::Uint16 varCount = sizeof( _SDLEnvironmentVariables )
00965         / sizeof (string) ;
00966 
00967     string result = "Examining the " + Ceylan::toString( varCount )
00968         + " general-purpose environment variables for SDL backend:" ;
00969 
00970     std::list<string> variables ;
00971 
00972     string var, value ;
00973 
00974     TextOutputFormat htmlFormat = Ceylan::TextDisplayable::GetOutputFormat() ;
00975 
00976     for ( Ceylan::Uint16 i = 0; i < varCount; i++ )
00977     {
00978 
00979         var = _SDLEnvironmentVariables[ i ] ;
00980         value = Ceylan::System::getEnvironmentVariable( var ) ;
00981 
00982         if ( value.empty() )
00983         {
00984             if ( htmlFormat == Ceylan::TextDisplayable::html )
00985             {
00986                 variables.push_back( "<em>" + var + "</em> is not set." ) ;
00987             }
00988             else
00989             {
00990                 variables.push_back( var + " is not set." ) ;
00991             }
00992         }
00993         else
00994         {
00995             if ( htmlFormat == Ceylan::TextDisplayable::html )
00996             {
00997                 variables.push_back( "<b>" + var + "</b> set to ["
00998                     + value + "]." ) ;
00999             }
01000             else
01001             {
01002                 variables.push_back( var + " set to [" + value + "]." ) ;
01003             }
01004         }
01005 
01006     }
01007 
01008     return result + Ceylan::formatStringList( variables ) ;
01009 
01010 #else // OSDL_USES_SDL
01011 
01012     return "(not using SDL)" ;
01013 
01014 #endif // OSDL_USES_SDL
01015 
01016 }
01017 
01018 
01019 
01020 bool CommonModule::IsBackendInitialized()
01021 {
01022 
01023     return _BackendInitialized ;
01024 
01025 }
01026 
01027 
01028 
01029 Flags CommonModule::AutoCorrectFlags( Flags inputFlags )
01030 {
01031 
01032 #if OSDL_USES_SDL
01033 
01034     
01035 
01036 
01037 
01038 
01039 
01040 
01041 
01042 
01043     if ( inputFlags & UseGUI )
01044     {
01045 
01046         if ( ! ( inputFlags & UseEvents ) )
01047         {
01048 
01049             
01050 
01051 
01052 
01053 
01054 
01055             LOG_WARNING_BASIC( "CommonModule::AutoCorrectFlags: "
01056                 "the use of a GUI (graphical user interface) was requested, "
01057                 "whereas managing events was not specifically set. "
01058                 "The events subsystem has been automatically enabled." ) ;
01059 
01060             inputFlags |= UseEvents ;
01061 
01062         }
01063 
01064 
01065         if ( ! ( inputFlags & UseAudio ) )
01066         {
01067 
01068             
01069 
01070 
01071 
01072 
01073 
01074             LOG_WARNING_BASIC( "CommonModule::AutoCorrectFlags: "
01075                 "the use of a GUI (graphical user interface) was requested, "
01076                 "whereas managing audio was not specifically set. "
01077                 "The audio subsystem has been automatically enabled." ) ;
01078 
01079             inputFlags |= UseAudio ;
01080 
01081         }
01082 
01083     }
01084 
01085 
01086     
01087 
01088 
01089 
01090 
01091 
01092     if ( ! ( inputFlags & UseVideo ) )
01093     {
01094 
01095         
01096 
01097         if ( inputFlags & UseEvents )
01098         {
01099 
01100             
01101 
01102 
01103 
01104 
01105 
01106             LOG_WARNING_BASIC( "CommonModule::AutoCorrectFlags: "
01107                 "at least one input device was selected, "
01108                 "hence event support was requested, "
01109                 "whereas video was not specifically set. "
01110                 "Since the event loop needs video, "
01111                 "the video subsystem has been automatically enabled." ) ;
01112 
01113             inputFlags |= UseVideo ;
01114 
01115         }
01116 
01117     }
01118 
01119 
01120 
01121 #endif // OSDL_USES_SDL
01122 
01123     return inputFlags ;
01124 
01125 }
01126 
01127 
01128 
01129 
01130 
01131 
01132 
01133 CommonModule & OSDL::getCommonModule( Flags flags )
01134 {
01135 
01136     
01137     flags = CommonModule::AutoCorrectFlags( flags ) ;
01138 
01139     LogPlug::info( "Retrieving basic common module for OSDL" ) ;
01140 
01141     if ( CommonModule::_CurrentCommonModule == 0 )
01142     {
01143 
01144         
01145         LogPlug::info(
01146             "OSDL was not running yet, launching basic OSDL with flags "
01147             + Ceylan::toString( flags,  true ) ) ;
01148 
01149         CommonModule::_CurrentCommonModule = new CommonModule( flags ) ;
01150 
01151         return * CommonModule::_CurrentCommonModule ;
01152 
01153     }
01154     else
01155     {
01156 
01157         
01158         LogPlug::info( "OSDL is already running, comparing demanded flags "
01159             "with flags of the running version." ) ;
01160 
01161         if ( flags == CommonModule::_CurrentCommonModule->getFlags() )
01162         {
01163 
01164             
01165 
01166 
01167 
01168 
01169 
01170             LogPlug::info( "Flags are matching, "
01171                 "returning already launched basic OSDL module" ) ;
01172 
01173             return * CommonModule::_CurrentCommonModule ;
01174 
01175         }
01176         else
01177         {
01178 
01179             
01180 
01181 
01182 
01183 
01184             LogPlug::info( "Flags do not match, "
01185                 "stopping already launched OSDL root module, "
01186                 "restarting with new flags, returning this new instance" ) ;
01187 
01188             delete CommonModule::_CurrentCommonModule ;
01189 
01190             CommonModule::_CurrentCommonModule = new CommonModule( flags ) ;
01191 
01192             return * CommonModule::_CurrentCommonModule ;
01193 
01194         }
01195     }
01196 
01197 }
01198 
01199 
01200 
01201 bool OSDL::hasExistingCommonModule()
01202 {
01203 
01204     return ( CommonModule::_CurrentCommonModule != 0 ) ;
01205 
01206 }
01207 
01208 
01209 
01210 CommonModule & OSDL::getExistingCommonModule()
01211 {
01212 
01213     if ( CommonModule::_CurrentCommonModule == 0 )
01214         throw OSDL::Exception( "OSDL::getExistingCommonModule failed: "
01215             "no common module available." ) ;
01216 
01217     return * CommonModule::_CurrentCommonModule ;
01218 
01219 }
01220 
01221 
01222 
01223 void OSDL::stop()
01224 {
01225 
01226     if ( CommonModule::_CurrentCommonModule == 0 )
01227     {
01228 
01229         LogPlug::error(
01230             "OSDL::stop has been called whereas OSDL was not running." ) ;
01231 
01232     }
01233     else
01234     {
01235 
01236         LogPlug::info( "Stopping launched OSDL module." ) ;
01237 
01238         
01239         delete CommonModule::_CurrentCommonModule ;
01240         CommonModule::_CurrentCommonModule = 0 ;
01241 
01242     }
01243 
01244 }