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 #ifndef CEYLAN_SYSTEM_H_
00028 #define CEYLAN_SYSTEM_H_
00029
00030
00031 #include "CeylanTypes.h"
00032 #include "CeylanException.h"
00033 #include "CeylanFeatures.h"
00034
00035
00036
00037 #include <ctime>
00038 #include <string>
00039 #include <iosfwd>
00040 #include <map>
00041
00042
00043
00044
00045 namespace Ceylan
00046 {
00047
00048
00049
00056 namespace System
00057 {
00058
00059
00064 typedef size_t Size ;
00065
00066
00067
00072 typedef long Position ;
00073
00074
00075
00082
00083
00084
00085
00086
00087 #ifdef CEYLAN_RUNS_ON_WINDOWS
00088
00089 typedef signed int SignedSize ;
00090
00091 #else // CEYLAN_RUNS_ON_WINDOWS
00092
00093 typedef ssize_t SignedSize ;
00094
00095 #endif // CEYLAN_RUNS_ON_WINDOWS
00096
00097
00098
00108 typedef Uint32 Second ;
00109
00110
00111
00116 typedef Uint32 Millisecond ;
00117
00118
00119
00124 typedef Uint32 Microsecond ;
00125
00126
00127
00132 typedef Uint32 Nanosecond ;
00133
00134
00135
00136
00138 class CEYLAN_DLL SystemException: public Ceylan::Exception
00139 {
00140 public:
00141 explicit SystemException( const std::string & message ) ;
00142 virtual ~SystemException() throw() ;
00143
00144 } ;
00145
00146
00147
00149 class CEYLAN_DLL IOException: public SystemException
00150 {
00151 public:
00152 IOException( const std::string & message ) ;
00153 virtual ~IOException() throw() ;
00154 } ;
00155
00156
00157
00158
00168
00169
00170
00171
00172
00173 #ifdef CEYLAN_RUNS_ON_WINDOWS
00174
00175 typedef unsigned int FileDescriptor ;
00176
00177 #else // CEYLAN_RUNS_ON_WINDOWS
00178
00179 typedef int FileDescriptor ;
00180
00181 #endif // CEYLAN_RUNS_ON_WINDOWS
00182
00183
00184
00186 typedef int ErrorCode ;
00187
00188
00189
00191 CEYLAN_DLL ErrorCode getError() ;
00192
00193
00194
00196 CEYLAN_DLL std::string explainError( ErrorCode errorID ) ;
00197
00198
00199
00205 CEYLAN_DLL std::string explainError() ;
00206
00207
00208
00219 CEYLAN_DLL std::string getShellName() ;
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00235 typedef int InterruptMask ;
00236
00237
00238
00240 extern CEYLAN_DLL const InterruptMask AllInterruptsDisabled ;
00241
00242
00243
00245 typedef void (* IRQHandler)( void ) ;
00246
00247
00248
00262 CEYLAN_DLL void InitializeInterrupts( bool force = false ) ;
00263
00264
00265
00280 CEYLAN_DLL InterruptMask SetEnabledInterrupts(
00281 InterruptMask newMask = AllInterruptsDisabled ) ;
00282
00283
00284
00299 CEYLAN_DLL void InitializeIPC() ;
00300
00301
00302
00315 template <typename T>
00316 T* ConvertToNonCacheable( T * sourceAddress )
00317 {
00318
00319 return reinterpret_cast<T*>(
00320 reinterpret_cast<Ceylan::Uint32>( sourceAddress )
00321 + 0x400000 ) ;
00322
00323 }
00324
00325
00326
00348 CEYLAN_DLL Ceylan::Byte * CacheProtectedNew( Size numberOfBytes ) ;
00349
00350
00351
00361 CEYLAN_DLL void CacheProtectedDelete(
00362 Ceylan::Byte * cacheProtectedBuffer ) ;
00363
00364
00365 #if defined(CEYLAN_ARCH_NINTENDO_DS) && CEYLAN_ARCH_NINTENDO_DS == 1
00366
00367
00369 CEYLAN_DLL extern const Size CacheLineSize ;
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 #pragma warning( push )
00380 #pragma warning( disable: 4251 )
00381
00391 CEYLAN_DLL extern std::map<Ceylan::Byte *,Ceylan::Byte *>
00392 CacheProtectedMap ;
00393
00394 #pragma warning( pop )
00395
00396 #endif // CEYLAN_ARCH_NINTENDO_DS
00397
00398
00399
00400
00401
00402
00403
00409 CEYLAN_DLL bool HasAvailableData( FileDescriptor fd ) ;
00410
00411
00412
00427 CEYLAN_DLL Size FDRead( FileDescriptor fd, Ceylan::Byte * dataBuffer,
00428 Size toReadBytesNumber ) ;
00429
00430
00431
00445 CEYLAN_DLL Size FDWrite( FileDescriptor fd,
00446 const Ceylan::Byte * dataBuffer, Size toWriteBytesNumber ) ;
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00469 CEYLAN_DLL Second getTime() ;
00470
00471
00472
00482 CEYLAN_DLL std::string timeToString( const time_t & t ) ;
00483
00484
00485
00513 CEYLAN_DLL std::string durationToString(
00514 Second startingSecond, Microsecond startingMicrosecond,
00515 Second stoppingSecond, Microsecond stoppingMicrosecond ) ;
00516
00517
00518
00524 extern CEYLAN_DLL const Second MaximumDurationWithMicrosecondAccuracy ;
00525
00526
00527
00542 CEYLAN_DLL Microsecond getDurationBetween(
00543 Second startingSecond, Microsecond startingMicrosecond,
00544 Second stoppingSecond, Microsecond stoppingMicrosecond ) ;
00545
00546
00547
00576 CEYLAN_DLL void getPreciseTime( Second & seconds,
00577 Microsecond & microsec ) ;
00578
00579
00580
00613 CEYLAN_DLL Microsecond getAccuracyOfPreciseTime(
00614 Microsecond * minGap = 0, Microsecond * maxGap = 0 ) ;
00615
00616
00617
00629 CEYLAN_DLL Microsecond getPreciseTimeCallDuration() ;
00630
00631
00632
00633
00645 CEYLAN_DLL void sleepForSeconds( Second secondCount ) ;
00646
00647
00648
00660 CEYLAN_DLL bool areSubSecondSleepsAvailable() ;
00661
00662
00663
00684 CEYLAN_DLL void atomicSleep() ;
00685
00686
00687
00715 CEYLAN_DLL void basicSleep( Second secondCount, Nanosecond nanoCount ) ;
00716
00717
00718
00725 CEYLAN_DLL void basicSleep( Microsecond micros ) ;
00726
00727
00728
00772 CEYLAN_DLL bool smartSleep( Second secondCount,
00773 Microsecond microCount ) ;
00774
00775
00776
00798 CEYLAN_DLL bool smartSleepUntil( Second secondCount,
00799 Microsecond microCount ) ;
00800
00801
00802
00818 CEYLAN_DLL Microsecond getActualDurationForSleep(
00819 Microsecond requestedMicroseconds,
00820 Second requestedSeconds = 0 ) ;
00821
00822
00823
00873 CEYLAN_DLL Microsecond getSchedulingGranularity() ;
00874
00875
00876
00899 CEYLAN_DLL bool setLegacyStreamSynchronization( bool synchronized ) ;
00900
00901
00902
00903 }
00904
00905
00906 }
00907
00908
00909
00910 #endif // CEYLAN_SYSTEM_H_
00911