From fe9a92ef71d5ab183672d0aeb94ca88e03854c7b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 5 Oct 2011 16:19:00 +0200 Subject: QtSensors: Compile on Windows. Add missing modules, re-introduce timestamp function. Change-Id: I0edbe8b012accfec5d619d53ebf136e75b99a456 Reviewed-on: http://codereview.qt-project.org/6072 Reviewed-by: Qt Sanity Bot Reviewed-by: Lincoln Ramsay --- src/plugins/sensors/dummy/dummycommon.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/plugins/sensors/dummy') diff --git a/src/plugins/sensors/dummy/dummycommon.cpp b/src/plugins/sensors/dummy/dummycommon.cpp index e3c7d044..264c4206 100644 --- a/src/plugins/sensors/dummy/dummycommon.cpp +++ b/src/plugins/sensors/dummy/dummycommon.cpp @@ -41,8 +41,8 @@ #include "dummycommon.h" -#ifdef Q_OS_WINCE -#include +#ifdef Q_OS_WIN +#include // WINCE has but using clock() gives a link error because // the function isn't actually implemented. #else @@ -101,12 +101,35 @@ static qint64 absoluteToNSecs(qint64 cpuTime) qint64 nsecs = cpuTime * info.numer / info.denom; return nsecs; } +#elif defined(Q_OS_WIN) +// Obtain a time stamp from the performance counter, +// default to tick count. +static quint64 windowsTimeStamp() +{ + static bool hasFrequency = false; + static quint64 frequency = 0; + if (!hasFrequency) { + LARGE_INTEGER frequencyLI; + hasFrequency = true; + QueryPerformanceFrequency(&frequencyLI); + frequency = frequencyLI.QuadPart; + } + + if (frequency) { // Microseconds. + LARGE_INTEGER counterLI; + if (QueryPerformanceCounter(&counterLI)) + return 1000000 * counterLI.QuadPart / frequency; + } + return GetTickCount(); +} #endif quint64 dummycommon::getTimestamp() { -#ifdef Q_OS_WINCE - // This implementation is based on code found here: +#if defined(Q_OS_WIN) + return windowsTimeStamp(); +#elif defined(Q_OS_WINCE) + //d This implementation is based on code found here: // http://social.msdn.microsoft.com/Forums/en/vssmartdevicesnative/thread/74870c6c-76c5-454c-8533-812cfca585f8 HANDLE currentThread = GetCurrentThread(); FILETIME creationTime, exitTime, kernalTime, userTime; -- cgit v1.2.3