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 "CeylanSystemInformation.h"
00028
00029 #include "CeylanLogPlug.h"
00030 #include "CeylanOperators.h"
00031
00032
00033 #include <string>
00034
00035
00036 using std::string ;
00037
00038
00039 using namespace Ceylan ;
00040 using namespace Ceylan::Log ;
00041 using namespace Ceylan::System ;
00042
00043
00044 #ifdef CEYLAN_USES_CONFIG_H
00045 #include "CeylanConfig.h"
00046 #endif // CEYLAN_USES_CONFIG_H
00047
00048
00049
00050
00051 #if CEYLAN_ARCH_NINTENDO_DS
00052
00053 #include "CeylanConfigForNintendoDS.h"
00054 #include "CeylanFIFO.h"
00055
00056
00057
00058 extern "C"
00059 {
00060
00061 #include <unistd.h>
00062 #include <malloc.h>
00063
00064 }
00065
00066
00068 extern u8 __end__[] ;
00069
00071 extern u8 __eheap_end[] ;
00072
00073 #endif // CEYLAN_ARCH_NINTENDO_DS
00074
00075
00076
00077
00078 extern "C"
00079 {
00080
00081
00082 #ifdef CEYLAN_USES_SYS_SYSINFO_H
00083
00084
00085 #if CEYLAN_ARCH_SOLARIS == 0
00086 #include <sys/sysinfo.h>
00087 #endif // CEYLAN_ARCH_SOLARIS
00088
00089 #endif // CEYLAN_USES_SYS_SYSINFO_H
00090
00091
00092
00093 }
00094
00095
00096
00097 UnsignedLongInteger Ceylan::System::getSecondsSinceSystemBoot()
00098 {
00099
00100 #ifdef CEYLAN_USES_SYSINFO
00101
00102 #if CEYLAN_ARCH_SOLARIS
00103
00104 throw SystemException(
00105 "Ceylan::System::getSecondsSinceSystemBoot: "
00106 "not available on Solaris platform." ) ;
00107
00108 #else // CEYLAN_ARCH_SOLARIS
00109
00110 struct sysinfo sysinfoStruct ;
00111
00112 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00113 throw SystemException(
00114 "Ceylan::System::getSecondsSinceSystemBoot: "
00115 "unable to query system: " + explainError() ) ;
00116
00117 return static_cast<UnsignedLongInteger>( sysinfoStruct.uptime ) ;
00118
00119 #endif // CEYLAN_ARCH_SOLARIS
00120
00121 #else // CEYLAN_USES_SYSINFO
00122
00123 throw SystemException(
00124 "Ceylan::System::getSecondsSinceSystemBoot: "
00125 "not available on this platform." ) ;
00126
00127 #endif // CEYLAN_USES_SYSINFO
00128
00129 }
00130
00131
00132
00133 Ceylan::Uint32 Ceylan::System::getTotalProcessCount()
00134 {
00135
00136 #if CEYLAN_ARCH_NINTENDO_DS
00137
00138 return 1 ;
00139
00140 #else // CEYLAN_ARCH_NINTENDO_DS
00141
00142 #ifdef CEYLAN_USES_SYSINFO
00143
00144 #if CEYLAN_ARCH_SOLARIS
00145
00146 throw SystemException(
00147 "Ceylan::System::getTotalProcessCount: "
00148 "not available on Solaris platform." ) ;
00149
00150 #else // CEYLAN_ARCH_SOLARIS
00151
00152 struct sysinfo sysinfoStruct ;
00153
00154 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00155 throw SystemException(
00156 "Ceylan::System::getTotalProcessCount: "
00157 "unable to query system: " + explainError() ) ;
00158
00159 return static_cast<Ceylan::Uint32>( sysinfoStruct.procs ) ;
00160
00161 #endif // CEYLAN_ARCH_SOLARIS
00162
00163 #else // CEYLAN_USES_SYSINFO
00164
00165 throw SystemException(
00166 "Ceylan::System::getTotalProcessCount: "
00167 "not available on this platform." ) ;
00168
00169 #endif // CEYLAN_USES_SYSINFO
00170
00171 #endif // CEYLAN_ARCH_NINTENDO_DS
00172
00173 }
00174
00175
00176
00177
00178 UnsignedLongInteger Ceylan::System::getTotalSystemMemorySize()
00179 {
00180
00181 #if CEYLAN_ARCH_NINTENDO_DS
00182
00183
00184 return (4*1024 - 4) * 1024 ;
00185
00186 #else // CEYLAN_ARCH_NINTENDO_DS
00187
00188 #ifdef CEYLAN_USES_SYSINFO
00189
00190 #if CEYLAN_ARCH_SOLARIS
00191
00192 throw SystemException(
00193 "Ceylan::System::getTotalSystemMemorySize: "
00194 "not available on Solaris platform." ) ;
00195
00196 #else // CEYLAN_ARCH_SOLARIS
00197
00198 struct sysinfo sysinfoStruct ;
00199
00200 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00201 throw SystemException(
00202 "Ceylan::System::getTotalSystemMemorySize: "
00203 "unable to query system: " + explainError() ) ;
00204
00205 return static_cast<UnsignedLongInteger>(
00206 sysinfoStruct.mem_unit * sysinfoStruct.totalram ) ;
00207
00208 #endif // CEYLAN_ARCH_SOLARIS
00209
00210 #else // CEYLAN_USES_SYSINFO
00211
00212 throw SystemException(
00213 "Ceylan::System::getTotalSystemMemorySize: "
00214 "not available on this platform." ) ;
00215
00216 #endif // CEYLAN_USES_SYSINFO
00217
00218 #endif // CEYLAN_ARCH_NINTENDO_DS
00219
00220 }
00221
00222
00223
00224 UnsignedLongInteger Ceylan::System::getFreeSystemMemorySize()
00225 {
00226
00227 #if CEYLAN_ARCH_NINTENDO_DS
00228
00229
00230
00231
00232
00233
00234
00235 struct mallinfo mi = mallinfo() ;
00236
00237 return mi.fordblks + __eheap_end - (u8*) sbrk(0) ;
00238
00239 #else // CEYLAN_ARCH_NINTENDO_DS
00240
00241 #ifdef CEYLAN_USES_SYSINFO
00242
00243 #if CEYLAN_ARCH_SOLARIS
00244
00245 throw SystemException(
00246 "Ceylan::System::getFreeSystemMemorySize: "
00247 "not available on Solaris platform." ) ;
00248
00249 #else // CEYLAN_ARCH_SOLARIS
00250
00251 struct sysinfo sysinfoStruct ;
00252
00253 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00254 throw SystemException(
00255 "Ceylan::System::getFreeSystemMemorySize: "
00256 "unable to query system: " + explainError() ) ;
00257
00258 return static_cast<UnsignedLongInteger>(
00259 sysinfoStruct.mem_unit * sysinfoStruct.freeram ) ;
00260
00261 #endif // CEYLAN_ARCH_SOLARIS
00262
00263 #else // CEYLAN_USES_SYSINFO
00264
00265 throw SystemException(
00266 "Ceylan::System::getFreeSystemMemorySize: "
00267 "not available on this platform." ) ;
00268
00269 #endif // CEYLAN_USES_SYSINFO
00270
00271 #endif // CEYLAN_ARCH_NINTENDO_DS
00272
00273 }
00274
00275
00276
00277 UnsignedLongInteger Ceylan::System::getUsedSystemMemorySize()
00278 {
00279
00280 #if CEYLAN_ARCH_NINTENDO_DS
00281
00282
00283
00284
00285
00286
00287
00288 struct mallinfo mi = mallinfo() ;
00289
00290 return mi.uordblks ;
00291
00292 #else // CEYLAN_ARCH_NINTENDO_DS
00293
00294 throw SystemException(
00295 "Ceylan::System::getUsedSystemMemorySize: "
00296 "not available on this platform." ) ;
00297
00298 #endif // CEYLAN_ARCH_NINTENDO_DS
00299
00300 }
00301
00302
00303
00304 UnsignedLongInteger Ceylan::System::getTotalSwapMemorySize()
00305 {
00306
00307 #if CEYLAN_ARCH_NINTENDO_DS
00308
00309 return 0 ;
00310
00311 #else // CEYLAN_ARCH_NINTENDO_DS
00312
00313 #ifdef CEYLAN_USES_SYSINFO
00314
00315 #if CEYLAN_ARCH_SOLARIS
00316
00317 throw SystemException(
00318 "Ceylan::System::getTotalSwapMemorySize: "
00319 "not available on Solaris platform." ) ;
00320
00321 #else // CEYLAN_ARCH_SOLARIS
00322
00323 struct sysinfo sysinfoStruct ;
00324
00325 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00326 throw SystemException(
00327 "Ceylan::System::getTotalSwapMemorySize: "
00328 "unable to query system: " + explainError() ) ;
00329
00330 return static_cast<UnsignedLongInteger>(
00331 sysinfoStruct.mem_unit * sysinfoStruct.totalswap ) ;
00332
00333 #endif // CEYLAN_ARCH_SOLARIS
00334
00335 #else // CEYLAN_USES_SYSINFO
00336
00337 throw SystemException(
00338 "Ceylan::System::getTotalSwapMemorySize: "
00339 "not available on this platform." ) ;
00340
00341 #endif // CEYLAN_USES_SYSINFO
00342
00343 #endif // CEYLAN_ARCH_NINTENDO_DS
00344
00345 }
00346
00347
00348
00349 UnsignedLongInteger Ceylan::System::getFreeSwapMemorySize()
00350 {
00351
00352 #if CEYLAN_ARCH_NINTENDO_DS
00353
00354 return 0 ;
00355
00356 #else // CEYLAN_ARCH_NINTENDO_DS
00357
00358 #ifdef CEYLAN_USES_SYSINFO
00359
00360 #if CEYLAN_ARCH_SOLARIS
00361
00362 throw SystemException(
00363 "Ceylan::System::getFreeSwapMemorySize: "
00364 "not available on Solaris platform." ) ;
00365
00366 #else // CEYLAN_ARCH_SOLARIS
00367
00368 struct sysinfo sysinfoStruct ;
00369
00370 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00371 throw SystemException(
00372 "Ceylan::System::getFreeSwapMemorySize: "
00373 "unable to query system: " + explainError() ) ;
00374
00375 return static_cast<UnsignedLongInteger>(
00376 sysinfoStruct.mem_unit * sysinfoStruct.freeswap ) ;
00377
00378 #endif // CEYLAN_ARCH_SOLARIS
00379
00380 #else // CEYLAN_USES_SYSINFO
00381
00382 throw SystemException(
00383 "Ceylan::System::getFreeSwapMemorySize: "
00384 "not available on this platform." ) ;
00385
00386 #endif // CEYLAN_USES_SYSINFO
00387
00388 #endif // CEYLAN_ARCH_NINTENDO_DS
00389
00390 }
00391
00392
00393
00394 UnsignedLongInteger Ceylan::System::getTotalHighMemorySize()
00395 {
00396
00397 #if CEYLAN_ARCH_NINTENDO_DS
00398
00399 return 0 ;
00400
00401 #else // CEYLAN_ARCH_NINTENDO_DS
00402
00403 #ifdef CEYLAN_USES_SYSINFO
00404
00405 #if CEYLAN_ARCH_SOLARIS
00406
00407 throw SystemException(
00408 "Ceylan::System::getTotalHighMemorySize: "
00409 "not available on Solaris platform." ) ;
00410
00411 #else // CEYLAN_ARCH_SOLARIS
00412
00413 struct sysinfo sysinfoStruct ;
00414
00415 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00416 throw SystemException(
00417 "Ceylan::System::getTotalHighMemorySize: "
00418 "unable to query system: " + explainError() ) ;
00419
00420 return static_cast<UnsignedLongInteger>(
00421 sysinfoStruct.mem_unit * sysinfoStruct.totalhigh ) ;
00422
00423 #endif // CEYLAN_ARCH_SOLARIS
00424
00425 #else // CEYLAN_USES_SYSINFO
00426
00427 throw SystemException(
00428 "Ceylan::System::getTotalHighMemorySize: "
00429 "not available on this platform." ) ;
00430
00431 #endif // CEYLAN_USES_SYSINFO
00432
00433 #endif // CEYLAN_ARCH_NINTENDO_DS
00434
00435 }
00436
00437
00438
00439 UnsignedLongInteger Ceylan::System::getFreeHighMemorySize()
00440 {
00441
00442 #if CEYLAN_ARCH_NINTENDO_DS
00443
00444 return 0 ;
00445
00446 #else // CEYLAN_ARCH_NINTENDO_DS
00447
00448 #ifdef CEYLAN_USES_SYSINFO
00449
00450 #if CEYLAN_ARCH_SOLARIS
00451
00452 throw SystemException(
00453 "Ceylan::System::getFreeHighMemorySize: "
00454 "not available on Solaris platform." ) ;
00455
00456 #else // CEYLAN_ARCH_SOLARIS
00457
00458 struct sysinfo sysinfoStruct ;
00459
00460 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00461 throw SystemException(
00462 "Ceylan::System::getFreeHighMemorySize: "
00463 "unable to query system: " + explainError() ) ;
00464
00465 return static_cast<UnsignedLongInteger>(
00466 sysinfoStruct.mem_unit * sysinfoStruct.freehigh ) ;
00467
00468 #endif // CEYLAN_ARCH_SOLARIS
00469
00470 #else // CEYLAN_USES_SYSINFO
00471
00472 throw SystemException(
00473 "Ceylan::System::getFreeHighMemorySize: "
00474 "not available on this platform." ) ;
00475
00476 #endif // CEYLAN_USES_SYSINFO
00477
00478 #endif // CEYLAN_ARCH_NINTENDO_DS
00479
00480 }
00481
00482
00483
00484 UnsignedLongInteger Ceylan::System::getSharedMemorySize()
00485 {
00486
00487 #if CEYLAN_ARCH_NINTENDO_DS
00488
00489
00490 return getTotalSystemMemorySize() ;
00491
00492 #else // CEYLAN_ARCH_NINTENDO_DS
00493
00494 #ifdef CEYLAN_USES_SYSINFO
00495
00496 #if CEYLAN_ARCH_SOLARIS
00497
00498 throw SystemException(
00499 "Ceylan::System::getSharedMemorySize: "
00500 "not available on Solaris platform." ) ;
00501
00502 #else // CEYLAN_ARCH_SOLARIS
00503
00504 struct sysinfo sysinfoStruct ;
00505
00506 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00507 throw SystemException(
00508 "Ceylan::System::getSharedMemorySize: "
00509 "unable to query system: " + explainError() ) ;
00510
00511 return static_cast<UnsignedLongInteger>(
00512 sysinfoStruct.mem_unit * sysinfoStruct.sharedram ) ;
00513
00514 #endif // CEYLAN_ARCH_SOLARIS
00515
00516 #else // CEYLAN_USES_SYSINFO
00517
00518 throw SystemException(
00519 "Ceylan::System::getSharedMemorySize: "
00520 "not available on this platform." ) ;
00521
00522 #endif // CEYLAN_USES_SYSINFO
00523
00524 #endif // CEYLAN_ARCH_NINTENDO_DS
00525
00526 }
00527
00528
00529
00530 UnsignedLongInteger Ceylan::System::getBuffersMemorySize()
00531 {
00532
00533 #if CEYLAN_ARCH_NINTENDO_DS
00534
00535 return 0 ;
00536
00537 #else // CEYLAN_ARCH_NINTENDO_DS
00538
00539 #ifdef CEYLAN_USES_SYSINFO
00540
00541 #if CEYLAN_ARCH_SOLARIS
00542
00543 throw SystemException(
00544 "Ceylan::System::getBuffersMemorySize: "
00545 "not available on Solaris platform." ) ;
00546
00547 #else // CEYLAN_ARCH_SOLARIS
00548
00549 struct sysinfo sysinfoStruct ;
00550
00551 if ( ::sysinfo( & sysinfoStruct ) != 0 )
00552 throw SystemException(
00553 "Ceylan::System::getBuffersMemorySize: "
00554 "unable to query system: " + explainError() ) ;
00555
00556 return static_cast<UnsignedLongInteger>(
00557 sysinfoStruct.mem_unit * sysinfoStruct.bufferram ) ;
00558
00559 #endif // CEYLAN_ARCH_SOLARIS
00560
00561 #else // CEYLAN_USES_SYSINFO
00562
00563 throw SystemException(
00564 "Ceylan::System::getBuffersMemorySize: "
00565 "not available on this platform." ) ;
00566
00567 #endif // CEYLAN_USES_SYSINFO
00568
00569 #endif // CEYLAN_ARCH_NINTENDO_DS
00570
00571 }
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581 string Ceylan::System::GetUserName()
00582 {
00583
00584 #if CEYLAN_ARCH_NINTENDO_DS
00585
00586 #ifdef CEYLAN_RUNS_ON_ARM9
00587
00588
00589
00590
00591
00592
00593 char name[11] ;
00594
00595
00596
00597 for ( Ceylan::Uint32 i = 0; i < PersonalData->nameLen; i++ )
00598 name[i] = static_cast<char>( PersonalData->name[i] & 0xff ) ;
00599
00600 name[PersonalData->nameLen] = 0 ;
00601
00602 return string( name ) ;
00603
00604 #else // CEYLAN_RUNS_ON_ARM9
00605
00606 throw SystemException( "Ceylan::System::getUserName: "
00607 "not available on the ARM7." ) ;
00608
00609 #endif // CEYLAN_RUNS_ON_ARM9
00610
00611 #else // CEYLAN_ARCH_NINTENDO_DS
00612
00613 throw SystemException( "Ceylan::System::getUserName: "
00614 "not available on this platform." ) ;
00615
00616 #endif // CEYLAN_ARCH_NINTENDO_DS
00617
00618 }
00619
00620
00621
00622 BatteryStatus Ceylan::System::GetBatteryStatus()
00623 {
00624
00625 #if CEYLAN_ARCH_NINTENDO_DS
00626
00627 #ifdef CEYLAN_RUNS_ON_ARM9
00628
00629
00630
00631 FIFO & fifo = FIFO::GetActivatedFIFO() ;
00632
00633 fifo.sendBatteryStatusRequest() ;
00634
00635
00636 return fifo.getBatteryStatus() ;
00637
00638
00639 #else // CEYLAN_RUNS_ON_ARM9
00640
00641 throw SystemException( "GetBatteryStatus failed: "
00642 "not available on the ARM7." ) ;
00643
00644 #endif // CEYLAN_RUNS_ON_ARM9
00645
00646 #else // CEYLAN_ARCH_NINTENDO_DS
00647
00648 throw SystemException( "GetBatteryStatus failed: "
00649 "not available on this platform." ) ;
00650
00651 #endif // CEYLAN_ARCH_NINTENDO_DS
00652
00653 }
00654
00655
00656
00657 DSType Ceylan::System::GetDSType()
00658 {
00659
00660 #if CEYLAN_ARCH_NINTENDO_DS
00661
00662 #ifdef CEYLAN_RUNS_ON_ARM9
00663
00664
00665
00666 FIFO & fifo = FIFO::GetActivatedFIFO() ;
00667
00668 fifo.sendDSTypeRequest() ;
00669
00670
00671 return fifo.getDSType() ;
00672
00673
00674 #else // CEYLAN_RUNS_ON_ARM9
00675
00676 throw SystemException( "GetDSType failed: "
00677 "not available on the ARM7." ) ;
00678
00679 #endif // CEYLAN_RUNS_ON_ARM9
00680
00681 #else // CEYLAN_ARCH_NINTENDO_DS
00682
00683 throw SystemException( "GetDSType failed: "
00684 "not available on this platform." ) ;
00685
00686 #endif // CEYLAN_ARCH_NINTENDO_DS
00687
00688 }
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716 bool Ceylan::System::openGLContextsCanBeLost()
00717 {
00718
00719 return openGLContextsLostOnResize()
00720 || openGLContextsLostOnApplicationSwitch()
00721 || openGLContextsLostOnColorDepthChange() ;
00722
00723 }
00724
00725
00726
00727 bool Ceylan::System::openGLContextsLostOnResize()
00728 {
00729
00730 #if CEYLAN_ARCH_WINDOWS
00731
00732 return true ;
00733
00734 #else // CEYLAN_ARCH_WINDOWS
00735
00736
00737
00738 #if CEYLAN_ARCH_MACOSX
00739
00740 return true ;
00741
00742 #else // CEYLAN_ARCH_MACOSX
00743
00744 return false ;
00745
00746 #endif // CEYLAN_ARCH_MACOSX
00747
00748
00749 #endif // CEYLAN_ARCH_WINDOWS
00750
00751 }
00752
00753
00754
00755 bool Ceylan::System::openGLContextsLostOnApplicationSwitch()
00756 {
00757
00758 #if CEYLAN_ARCH_WINDOWS
00759
00760 return true ;
00761
00762 #else // CEYLAN_ARCH_WINDOWS
00763
00764
00765
00766 #if CEYLAN_ARCH_MACOSX
00767
00768 return true ;
00769
00770 #else // CEYLAN_ARCH_MACOSX
00771
00772 return false ;
00773
00774 #endif // CEYLAN_ARCH_MACOSX
00775
00776
00777 #endif // CEYLAN_ARCH_WINDOWS
00778
00779 }
00780
00781
00782
00783 bool Ceylan::System::openGLContextsLostOnColorDepthChange()
00784 {
00785
00786 #if CEYLAN_ARCH_WINDOWS
00787
00788 return true ;
00789
00790 #else // CEYLAN_ARCH_WINDOWS
00791
00792
00793
00794 #if CEYLAN_ARCH_MACOSX
00795
00796 return true ;
00797
00798 #else // CEYLAN_ARCH_MACOSX
00799
00800 return false ;
00801
00802 #endif // CEYLAN_ARCH_MACOSX
00803
00804
00805 #endif // CEYLAN_ARCH_WINDOWS
00806
00807 }
00808