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 "OSDLCDROMDriveHandler.h"
00028
00029 #include "OSDLCDROMDrive.h"
00030
00031 #include "OSDLBasic.h"
00032 #include "OSDLUtils.h"
00033
00034
00035
00036 #ifdef OSDL_USES_CONFIG_H
00037 #include "OSDLConfig.h"
00038 #endif // OSDL_USES_CONFIG_H
00039
00040 #if OSDL_ARCH_NINTENDO_DS
00041 #include "OSDLConfigForNintendoDS.h"
00042 #endif // OSDL_ARCH_NINTENDO_DS
00043
00044
00045 #if OSDL_USES_SDL
00046 #include "SDL.h"
00047 #endif // OSDL_USES_SDL
00048
00049
00050 #include <list>
00051
00052
00053
00054 using std::list ;
00055 using std::string ;
00056 using std::map ;
00057
00058
00059 using namespace OSDL ;
00060
00061
00062
00063 CDROMDriveException::CDROMDriveException( const std::string & message ) :
00064 OSDL::Exception( message )
00065 {
00066
00067 }
00068
00069
00070
00071 CDROMDriveException::~CDROMDriveException() throw()
00072 {
00073
00074 }
00075
00076
00077
00078
00079 CDROMDriveHandler::CDROMDriveHandler() :
00080 Object(),
00081 _drives()
00082 {
00083
00084 #if OSDL_USES_SDL
00085
00086 send( "Initializing CD-ROM subsystem" ) ;
00087
00088 if ( SDL_InitSubSystem( CommonModule::UseCDROM )
00089 != CommonModule::BackendSuccess )
00090 throw CDROMDriveException( "CDROMDriveHandler constructor: "
00091 "unable to initialize CD-ROM subsystem: "
00092 + Utils::getBackendLastError() ) ;
00093
00094 send( "CD-ROM subsystem initialized" ) ;
00095
00096 #else // OSDL_USES_SDL
00097
00098 throw CDROMDriveException( "CDROMDriveHandler constructor: "
00099 "no SDL support available" ) ;
00100
00101 #endif // OSDL_USES_SDL
00102
00103 }
00104
00105
00106
00107 CDROMDriveHandler::~CDROMDriveHandler() throw()
00108 {
00109
00110 #if OSDL_USES_SDL
00111
00112 send( "Stopping CD-ROM subsystem." ) ;
00113
00114 for ( map<CDROMDriveNumber, CDROMDrive *>::const_iterator it
00115 = _drives.begin() ; it != _drives.end(); it++ )
00116 {
00117 delete (*it).second ;
00118 }
00119
00120
00121 _drives.clear() ;
00122
00123 SDL_QuitSubSystem( CommonModule::UseCDROM ) ;
00124
00125 send( "CD-ROM subsystem stopped." ) ;
00126 #endif // OSDL_USES_SDL
00127
00128 }
00129
00130
00131
00132 CDROMDriveNumber CDROMDriveHandler::GetAvailableCDROMDrivesCount()
00133 {
00134
00135 #if OSDL_USES_SDL
00136
00137 return SDL_CDNumDrives() ;
00138
00139 #else // OSDL_USES_SDL
00140
00141 return 0 ;
00142
00143 #endif // OSDL_USES_SDL
00144
00145 }
00146
00147
00148
00149 CDROMDrive & CDROMDriveHandler::getCDROMDrive( CDROMDriveNumber number )
00150 {
00151
00152 #if OSDL_USES_SDL
00153
00154 map<CDROMDriveNumber, CDROMDrive *>::const_iterator it
00155 = _drives.find( number ) ;
00156
00157 if ( it != _drives.end() )
00158 {
00159
00160
00161 return * (*it).second ;
00162
00163 }
00164
00165
00166 CDROMDrive * newDrive = new CDROMDrive( number ) ;
00167
00168
00169
00170
00171
00172
00173 _drives[ number ] = newDrive ;
00174
00175 return *newDrive ;
00176
00177 #else // OSDL_USES_SDL
00178
00179 throw CDROMDriveException( " CDROMDriveHandler::getCDROMDrive: "
00180 "no SDL support available" ) ;
00181
00182 #endif // OSDL_USES_SDL
00183
00184 }
00185
00186
00187
00188 const std::string CDROMDriveHandler::toString( Ceylan::VerbosityLevels level )
00189 const
00190 {
00191
00192 #if OSDL_USES_SDL
00193
00194 CDROMDriveNumber driveNumber = GetAvailableCDROMDrivesCount() ;
00195
00196 if ( driveNumber == 0 )
00197 return "No available CD-ROM drive found" ;
00198
00199 if ( _drives.empty() )
00200 return "None of the " + Ceylan::toString( driveNumber )
00201 + " available drive(s) is currently opened." ;
00202
00203
00204
00205 list<string> descriptions ;
00206
00207 for ( map<CDROMDriveNumber, CDROMDrive *>::const_iterator it
00208 = _drives.begin() ; it != _drives.end(); it++ )
00209 {
00210 descriptions.push_back( (*it).second->toString() ) ;
00211 }
00212
00213 return "Out of " + Ceylan::toString( driveNumber )
00214 + " available CD-ROM drive(s), "
00215 + Ceylan::toString( static_cast<Ceylan::Uint32>( _drives.size() ) )
00216 + " is/are opened: " + Ceylan::formatStringList( descriptions ) ;
00217
00218 #else // OSDL_USES_SDL
00219
00220 return "" ;
00221
00222 #endif // OSDL_USES_SDL
00223
00224 }
00225