summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SConstruct2
-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
-rw-r--r--SwifTools/SConscript2
6 files changed, 56 insertions, 9 deletions
diff --git a/SConstruct b/SConstruct
index 29be052..cfc34c5 100644
--- a/SConstruct
+++ b/SConstruct
@@ -95,7 +95,7 @@ if env["PLATFORM"] == "win32" :
env["SHLINKCOM"] = [env["SHLINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2']
if env["PLATFORM"] == "darwin" :
- env.Append(FRAMEWORKS = "AppKit")
+ env.Append(FRAMEWORKS = ["IOKit", "AppKit"])
# Testing
env["TEST_TYPE"] = env["test"]
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:
diff --git a/SwifTools/SConscript b/SwifTools/SConscript
index cff2c6b..a92e0dc 100644
--- a/SwifTools/SConscript
+++ b/SwifTools/SConscript
@@ -19,7 +19,7 @@ sources = [
if myenv["PLATFORM"] == "win32" :
pass
elif myenv["PLATFORM"] == "darwin" :
- pass
+ sources += ["Idle/MacOSXIdleQuerier.cpp"]
elif myenv["HAVE_XSS"] :
myenv.Append(CPPDEFINES = ["HAVE_XSS"])
sources += ["Idle/XSSIdleQuerier.cpp"]