summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-24 18:58:29 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-24 18:58:29 (GMT)
commit3e2e0d3785d4527799441540addeee228f7f8359 (patch)
treecb936b0771edbbd8926d6f966d257e46eadcda81 /SwifTools/Idle
parentc7fb528f0d80f9d96a2d84444352386d5d4288dc (diff)
downloadswift-contrib-3e2e0d3785d4527799441540addeee228f7f8359.zip
swift-contrib-3e2e0d3785d4527799441540addeee228f7f8359.tar.bz2
Added MacOSX Idle querier.
Diffstat (limited to 'SwifTools/Idle')
-rw-r--r--SwifTools/Idle/MacOSXIdleQuerier.cpp25
-rw-r--r--SwifTools/Idle/MacOSXIdleQuerier.h17
-rw-r--r--SwifTools/Idle/PlatformIdleQuerier.cpp9
-rw-r--r--SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp10
4 files changed, 54 insertions, 7 deletions
diff --git a/SwifTools/Idle/MacOSXIdleQuerier.cpp b/SwifTools/Idle/MacOSXIdleQuerier.cpp
new file mode 100644
index 0000000..ac6dff9
--- /dev/null
+++ b/SwifTools/Idle/MacOSXIdleQuerier.cpp
@@ -0,0 +1,25 @@
+#include "SwifTools/Idle/MacOSXIdleQuerier.h"
+
+#include <cassert>
+#include <iostream>
+#include <CoreFoundation/CoreFoundation.h>
+
+namespace Swift {
+
+MacOSXIdleQuerier::MacOSXIdleQuerier() : ioService(NULL) {
+ mach_port_t masterPort;
+ IOMasterPort(MACH_PORT_NULL, &masterPort);
+ ioService = IOServiceGetMatchingService(masterPort, IOServiceMatching("IOHIDSystem"));
+ assert(ioService);
+}
+
+int MacOSXIdleQuerier::getIdleTimeSeconds() {
+ CFTypeRef property = IORegistryEntryCreateCFProperty(ioService, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
+ uint64_t idle = 0;
+ bool result = CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle);
+ assert(result);
+ CFRelease(property);
+ return idle / 1000000000;
+}
+
+}
diff --git a/SwifTools/Idle/MacOSXIdleQuerier.h b/SwifTools/Idle/MacOSXIdleQuerier.h
new file mode 100644
index 0000000..f70432d
--- /dev/null
+++ b/SwifTools/Idle/MacOSXIdleQuerier.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <IOKit/IOKitLib.h>
+
+#include "SwifTools/Idle/IdleQuerier.h"
+
+namespace Swift {
+ class MacOSXIdleQuerier : public IdleQuerier {
+ public:
+ MacOSXIdleQuerier();
+
+ virtual int getIdleTimeSeconds();
+
+ private:
+ io_service_t ioService;
+ };
+}
diff --git a/SwifTools/Idle/PlatformIdleQuerier.cpp b/SwifTools/Idle/PlatformIdleQuerier.cpp
index 76a3f7d..80a5da3 100644
--- a/SwifTools/Idle/PlatformIdleQuerier.cpp
+++ b/SwifTools/Idle/PlatformIdleQuerier.cpp
@@ -1,6 +1,9 @@
#include "SwifTools/Idle/PlatformIdleQuerier.h"
+#include "Swiften/Base/Platform.h"
-#if defined(HAVE_XSS)
+#if defined(SWIFTEN_PLATFORM_MACOSX)
+#include "SwifTools/Idle/MacOSXIdleQuerier.h"
+#elif defined(HAVE_XSS)
#include "SwifTools/Idle/XSSIdleQuerier.h"
#else
#include "SwifTools/Idle/DummyIdleQuerier.h"
@@ -12,7 +15,9 @@
namespace Swift {
PlatformIdleQuerier::PlatformIdleQuerier() : querier(NULL) {
-#if defined(HAVE_XSS)
+#if defined(SWIFTEN_PLATFORM_MACOSX)
+ querier = new MacOSXIdleQuerier();
+#elif defined(HAVE_XSS)
querier = new XSSIdleQuerier();
#else
querier = new DummyIdleQuerier();
diff --git a/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp b/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp
index 99a7099..a191b21 100644
--- a/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp
+++ b/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp
@@ -39,7 +39,7 @@ class ActualIdleDetectorTest : public CppUnit::TestFixture {
querier->idleTime = 15;
timerFactory->updateTime(15000);
- CPPUNIT_ASSERT_EQUAL(0U, idleEvents.size());
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(idleEvents.size()));
}
void testHandleTick_Idle() {
@@ -49,7 +49,7 @@ class ActualIdleDetectorTest : public CppUnit::TestFixture {
timerFactory->updateTime(15000);
- CPPUNIT_ASSERT_EQUAL(1U, idleEvents.size());
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(idleEvents.size()));
CPPUNIT_ASSERT(idleEvents[0]);
}
@@ -62,7 +62,7 @@ class ActualIdleDetectorTest : public CppUnit::TestFixture {
querier->idleTime = 30;
timerFactory->updateTime(30000);
- CPPUNIT_ASSERT_EQUAL(1U, idleEvents.size());
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(idleEvents.size()));
CPPUNIT_ASSERT(idleEvents[0]);
}
@@ -75,7 +75,7 @@ class ActualIdleDetectorTest : public CppUnit::TestFixture {
querier->idleTime = 5;
timerFactory->updateTime(30000);
- CPPUNIT_ASSERT_EQUAL(2U, idleEvents.size());
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(idleEvents.size()));
CPPUNIT_ASSERT(idleEvents[0]);
CPPUNIT_ASSERT(!idleEvents[1]);
}
@@ -87,7 +87,7 @@ class ActualIdleDetectorTest : public CppUnit::TestFixture {
timerFactory->updateTime(15000);
- CPPUNIT_ASSERT_EQUAL(0U, idleEvents.size());
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(idleEvents.size()));
}
private: