959 /*! |
960 /*! |
960 \macro QT_VERSION_CHECK |
961 \macro QT_VERSION_CHECK |
961 \relates <QtGlobal> |
962 \relates <QtGlobal> |
962 |
963 |
963 Turns the major, minor and patch numbers of a version into an |
964 Turns the major, minor and patch numbers of a version into an |
964 integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can |
965 integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can |
965 be compared with another similarly processed version id. |
966 be compared with another similarly processed version id. |
966 |
967 |
967 \sa QT_VERSION |
968 \sa QT_VERSION |
968 */ |
969 */ |
969 |
970 |
1190 system on which the application is run. |
1191 system on which the application is run. |
1191 |
1192 |
1192 \value SV_9_2 Symbian OS v9.2 |
1193 \value SV_9_2 Symbian OS v9.2 |
1193 \value SV_9_3 Symbian OS v9.3 |
1194 \value SV_9_3 Symbian OS v9.3 |
1194 \value SV_9_4 Symbian OS v9.4 |
1195 \value SV_9_4 Symbian OS v9.4 |
|
1196 \value SV_SF_1 Symbian^1 |
|
1197 \value SV_SF_2 Symbian^2 |
|
1198 \value SV_SF_3 Symbian^3 |
|
1199 \value SV_SF_4 Symbian^4 |
1195 \value SV_Unknown An unknown and currently unsupported platform |
1200 \value SV_Unknown An unknown and currently unsupported platform |
1196 |
1201 |
1197 \sa S60Version, WinVersion, MacVersion |
1202 \sa S60Version, WinVersion, MacVersion |
1198 */ |
1203 */ |
1199 |
1204 |
1206 SDK on which the application is run. |
1211 SDK on which the application is run. |
1207 |
1212 |
1208 \value SV_S60_3_1 S60 3rd Edition Feature Pack 1 |
1213 \value SV_S60_3_1 S60 3rd Edition Feature Pack 1 |
1209 \value SV_S60_3_2 S60 3rd Edition Feature Pack 2 |
1214 \value SV_S60_3_2 S60 3rd Edition Feature Pack 2 |
1210 \value SV_S60_5_0 S60 5th Edition |
1215 \value SV_S60_5_0 S60 5th Edition |
|
1216 \value SV_S60_5_1 S60 5th Edition Feature Pack 1 |
|
1217 \value SV_S60_5_2 S60 5th Edition Feature Pack 2 |
1211 \value SV_S60_Unknown An unknown and currently unsupported platform |
1218 \value SV_S60_Unknown An unknown and currently unsupported platform |
1212 \omitvalue SV_S60_None |
1219 \omitvalue SV_S60_None |
1213 |
1220 |
1214 \sa SymbianVersion, WinVersion, MacVersion |
1221 \sa SymbianVersion, WinVersion, MacVersion |
1215 */ |
1222 */ |
1794 TFindFile fileFinder(rfs); |
1801 TFindFile fileFinder(rfs); |
1795 CDir* contents; |
1802 CDir* contents; |
1796 TInt err = fileFinder.FindWildByDir(qt_S60Filter, qt_S60SystemInstallDir, contents); |
1803 TInt err = fileFinder.FindWildByDir(qt_S60Filter, qt_S60SystemInstallDir, contents); |
1797 if (err == KErrNone) { |
1804 if (err == KErrNone) { |
1798 err = contents->Sort(EDescending|ESortByName); |
1805 err = contents->Sort(EDescending|ESortByName); |
1799 if (err == KErrNone) { |
1806 if (err == KErrNone && contents->Count() > 0 && (*contents)[0].iName.Length() >= 12) { |
1800 TInt major = (*contents)[0].iName[9] - '0'; |
1807 TInt major = (*contents)[0].iName[9] - '0'; |
1801 TInt minor = (*contents)[0].iName[11] - '0'; |
1808 TInt minor = (*contents)[0].iName[11] - '0'; |
1802 if (major == 3) { |
1809 if (major == 3) { |
1803 if (minor == 1) { |
1810 if (minor == 1) { |
1804 return cachedS60Version = SV_S60_3_1; |
1811 return cachedS60Version = SV_S60_3_1; |
1821 return cachedS60Version = SV_S60_3_1; |
1834 return cachedS60Version = SV_S60_3_1; |
1822 # elif defined(__S60_32__) |
1835 # elif defined(__S60_32__) |
1823 return cachedS60Version = SV_S60_3_2; |
1836 return cachedS60Version = SV_S60_3_2; |
1824 # elif defined(__S60_50__) |
1837 # elif defined(__S60_50__) |
1825 return cachedS60Version = SV_S60_5_0; |
1838 return cachedS60Version = SV_S60_5_0; |
1826 # else |
1839 # endif |
|
1840 # endif |
|
1841 //If reaching here, it was not possible to determine the version |
1827 return cachedS60Version = SV_S60_Unknown; |
1842 return cachedS60Version = SV_S60_Unknown; |
1828 # endif |
|
1829 # else |
|
1830 return cachedS60Version = SV_S60_Unknown; |
|
1831 # endif |
|
1832 } |
1843 } |
1833 QSysInfo::SymbianVersion QSysInfo::symbianVersion() |
1844 QSysInfo::SymbianVersion QSysInfo::symbianVersion() |
1834 { |
1845 { |
1835 switch (s60Version()) { |
1846 switch (s60Version()) { |
1836 case SV_S60_3_1: |
1847 case SV_S60_3_1: |
1837 return SV_9_2; |
1848 return SV_9_2; |
1838 case SV_S60_3_2: |
1849 case SV_S60_3_2: |
1839 return SV_9_3; |
1850 return SV_9_3; |
1840 case SV_S60_5_0: |
1851 case SV_S60_5_0: |
|
1852 return SV_9_4; |
|
1853 case SV_S60_5_1: |
|
1854 return SV_9_4; |
|
1855 case SV_S60_5_2: |
1841 return SV_9_4; |
1856 return SV_9_4; |
1842 default: |
1857 default: |
1843 return SV_Unknown; |
1858 return SV_Unknown; |
1844 } |
1859 } |
1845 } |
1860 } |
2163 #elif defined(Q_OS_WINCE) |
2178 #elif defined(Q_OS_WINCE) |
2164 QString fstr = QString::fromLatin1(buf); |
2179 QString fstr = QString::fromLatin1(buf); |
2165 fstr += QLatin1Char('\n'); |
2180 fstr += QLatin1Char('\n'); |
2166 OutputDebugString(reinterpret_cast<const wchar_t *> (fstr.utf16())); |
2181 OutputDebugString(reinterpret_cast<const wchar_t *> (fstr.utf16())); |
2167 #elif defined(Q_OS_SYMBIAN) |
2182 #elif defined(Q_OS_SYMBIAN) |
|
2183 // RDebug::Print has a cap of 256 characters so break it up |
2168 _LIT(format, "[Qt Message] %S"); |
2184 _LIT(format, "[Qt Message] %S"); |
|
2185 const int maxBlockSize = 256 - ((const TDesC &)format).Length(); |
2169 const TPtrC8 ptr(reinterpret_cast<const TUint8*>(buf)); |
2186 const TPtrC8 ptr(reinterpret_cast<const TUint8*>(buf)); |
2170 #if !defined(QT_WARNING_FILE_OUTPUT) |
|
2171 // RDebug::Print has a cap of 256 characters so break it up |
|
2172 const int maxBlockSize = 256 - ((const TDesC &)format).Length(); |
|
2173 HBufC* hbuffer = q_check_ptr(HBufC::New(qMin(maxBlockSize, ptr.Length()))); |
2187 HBufC* hbuffer = q_check_ptr(HBufC::New(qMin(maxBlockSize, ptr.Length()))); |
2174 for (int i = 0; i < ptr.Length(); i += hbuffer->Length()) { |
2188 for (int i = 0; i < ptr.Length(); i += hbuffer->Length()) { |
2175 hbuffer->Des().Copy(ptr.Mid(i, qMin(maxBlockSize, ptr.Length()-i))); |
2189 hbuffer->Des().Copy(ptr.Mid(i, qMin(maxBlockSize, ptr.Length()-i))); |
2176 RDebug::Print(format, hbuffer); |
2190 RDebug::Print(format, hbuffer); |
2177 } |
2191 } |
2178 delete hbuffer; |
2192 delete hbuffer; |
2179 #else |
2193 //QTP:Prod add logging to the file |
|
2194 #if defined(QT_WARNING_FILE_OUTPUT) |
2180 _LIT( KLogDir, "QT" ); |
2195 _LIT( KLogDir, "QT" ); |
2181 _LIT( KLogFile, "QT.log" ); |
2196 _LIT( KLogFile, "QT.log" ); |
2182 _LIT( KLogStarting, "*** Starting new Qt application ***"); |
2197 _LIT( KLogStarting, "Starting: %S"); |
2183 static bool logStarted; |
2198 static bool logStarted; |
2184 if ( !logStarted ){ |
2199 if ( !logStarted ){ |
2185 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, KLogStarting ); |
2200 RProcess curProc; |
|
2201 TBuf<KMaxFullName + 20> procName; |
|
2202 TFullName fullName = curProc.FullName(); |
|
2203 procName.Format(KLogStarting, &fullName); |
|
2204 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, procName); |
2186 logStarted = true; |
2205 logStarted = true; |
2187 } |
2206 } |
2188 |
2207 |
2189 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, ptr ); |
2208 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, ptr ); |
2190 #endif |
2209 #endif |
2514 Thread-safe version of the standard C++ \c srand() function. |
2533 Thread-safe version of the standard C++ \c srand() function. |
2515 |
2534 |
2516 Sets the argument \a seed to be used to generate a new random number sequence of |
2535 Sets the argument \a seed to be used to generate a new random number sequence of |
2517 pseudo random integers to be returned by qrand(). |
2536 pseudo random integers to be returned by qrand(). |
2518 |
2537 |
2519 If no seed value is provided, qrand() is automatically seeded with a value of 1. |
|
2520 |
|
2521 The sequence of random numbers generated is deterministic per thread. For example, |
2538 The sequence of random numbers generated is deterministic per thread. For example, |
2522 if two threads call qsrand(1) and subsequently calls qrand(), the threads will get |
2539 if two threads call qsrand(1) and subsequently calls qrand(), the threads will get |
2523 the same random number sequence. |
2540 the same random number sequence. |
2524 |
2541 |
2525 \sa qrand() |
2542 \sa qrand() |
2526 */ |
2543 */ |
2527 void qsrand(uint seed) |
2544 void qsrand(uint seed) |
2528 { |
2545 { |
2529 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) |
2546 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) |
2530 SeedStorageType *pseed = randTLS()->localData(); |
2547 SeedStorage *seedStorage = randTLS(); |
2531 if (!pseed) |
2548 if (seedStorage) { |
2532 randTLS()->setLocalData(pseed = new SeedStorageType); |
2549 SeedStorageType *pseed = seedStorage->localData(); |
2533 *pseed = seed; |
2550 if (!pseed) |
|
2551 seedStorage->setLocalData(pseed = new SeedStorageType); |
|
2552 *pseed = seed; |
|
2553 } else { |
|
2554 //golbal static seed storage should always exist, |
|
2555 //except after being deleted by QGlobalStaticDeleter. |
|
2556 //But since it still can be called from destructor of another |
|
2557 //global static object, fallback to sqrand(seed) |
|
2558 srand(seed); |
|
2559 } |
2534 #else |
2560 #else |
2535 // On Windows srand() and rand() already use Thread-Local-Storage |
2561 // On Windows and Symbian srand() and rand() already use Thread-Local-Storage |
2536 // to store the seed between calls |
2562 // to store the seed between calls |
|
2563 // this is also valid for QT_NO_THREAD |
2537 srand(seed); |
2564 srand(seed); |
2538 #endif |
2565 #endif |
2539 } |
2566 } |
2540 |
2567 |
2541 /*! \internal |
2568 /*! \internal |
2547 The default seed is a combination of current time, a stack address and a |
2574 The default seed is a combination of current time, a stack address and a |
2548 serial counter (since thread stack addresses are re-used). |
2575 serial counter (since thread stack addresses are re-used). |
2549 */ |
2576 */ |
2550 void qsrand() |
2577 void qsrand() |
2551 { |
2578 { |
2552 #if (defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) |
2579 #if (defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD) |
2553 SeedStorageType *pseed = randTLS()->localData(); |
2580 SeedStorage *seedStorage = randTLS(); |
2554 if (pseed) { |
2581 if (seedStorage) { |
2555 // already seeded |
2582 SeedStorageType *pseed = seedStorage->localData(); |
2556 return; |
2583 if (pseed) { |
|
2584 // already seeded |
|
2585 return; |
|
2586 } |
|
2587 seedStorage->setLocalData(pseed = new SeedStorageType); |
|
2588 // start beyond 1 to avoid the sequence reset |
|
2589 static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2); |
|
2590 *pseed = QDateTime::currentDateTime().toTime_t() |
|
2591 + quintptr(&pseed) |
|
2592 + serial.fetchAndAddRelaxed(1); |
|
2593 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
2594 // for Windows and Symbian the srand function must still be called. |
|
2595 srand(*pseed); |
|
2596 #endif |
2557 } |
2597 } |
2558 randTLS()->setLocalData(pseed = new SeedStorageType); |
2598 |
2559 // start beyond 1 to avoid the sequence reset |
2599 //QT_NO_THREAD implementations |
2560 static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2); |
2600 #else |
2561 *pseed = QDateTime::currentDateTime().toTime_t() |
|
2562 + quintptr(&pseed) |
|
2563 + serial.fetchAndAddRelaxed(1); |
|
2564 #if defined(Q_OS_WIN) |
|
2565 // for Windows the srand function must still be called. |
|
2566 srand(*pseed); |
|
2567 #endif |
|
2568 |
|
2569 #elif defined(Q_OS_WIN) |
|
2570 static unsigned int seed = 0; |
2601 static unsigned int seed = 0; |
2571 |
2602 |
2572 if (seed) |
2603 if (seed) |
2573 return; |
2604 return; |
2574 |
2605 |
|
2606 #if defined(Q_OS_SYMBIAN) |
|
2607 seed = Math::Random(); |
|
2608 #elif defined(Q_OS_WIN) |
2575 seed = GetTickCount(); |
2609 seed = GetTickCount(); |
|
2610 #else |
|
2611 seed = quintptr(&seed) + QDateTime::currentDateTime().toTime_t(); |
|
2612 #endif |
2576 srand(seed); |
2613 srand(seed); |
2577 #else |
2614 #endif // defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD) |
2578 // Symbian? |
|
2579 |
|
2580 #endif // defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) |
|
2581 } |
2615 } |
2582 |
2616 |
2583 /*! |
2617 /*! |
2584 \relates <QtGlobal> |
2618 \relates <QtGlobal> |
2585 \since 4.2 |
2619 \since 4.2 |
2596 \sa qsrand() |
2630 \sa qsrand() |
2597 */ |
2631 */ |
2598 int qrand() |
2632 int qrand() |
2599 { |
2633 { |
2600 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) |
2634 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) |
2601 SeedStorageType *pseed = randTLS()->localData(); |
2635 SeedStorage *seedStorage = randTLS(); |
2602 if (!pseed) { |
2636 if (seedStorage) { |
2603 randTLS()->setLocalData(pseed = new SeedStorageType); |
2637 SeedStorageType *pseed = seedStorage->localData(); |
2604 *pseed = 1; |
2638 if (!pseed) { |
|
2639 seedStorage->setLocalData(pseed = new SeedStorageType); |
|
2640 *pseed = 1; |
|
2641 } |
|
2642 return rand_r(pseed); |
|
2643 } else { |
|
2644 //golbal static seed storage should always exist, |
|
2645 //except after being deleted by QGlobalStaticDeleter. |
|
2646 //But since it still can be called from destructor of another |
|
2647 //global static object, fallback to qrand() |
|
2648 return rand(); |
2605 } |
2649 } |
2606 return rand_r(pseed); |
|
2607 #else |
2650 #else |
2608 // On Windows srand() and rand() already use Thread-Local-Storage |
2651 // On Windows and Symbian srand() and rand() already use Thread-Local-Storage |
2609 // to store the seed between calls |
2652 // to store the seed between calls |
|
2653 // this is also valid for QT_NO_THREAD |
2610 return rand(); |
2654 return rand(); |
2611 #endif |
2655 #endif |
2612 } |
2656 } |
2613 |
2657 |
2614 /*! |
2658 /*! |