aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/my/Idle_mac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/my/Idle_mac.cpp')
-rw-r--r--src/modules/my/Idle_mac.cpp237
1 files changed, 127 insertions, 110 deletions
diff --git a/src/modules/my/Idle_mac.cpp b/src/modules/my/Idle_mac.cpp
index 543b1c326..02d7a42f5 100644
--- a/src/modules/my/Idle_mac.cpp
+++ b/src/modules/my/Idle_mac.cpp
@@ -20,143 +20,160 @@
#ifdef COMPILE_ON_MAC
- #include "Idle.h"
- #include <Carbon/Carbon.h>
+#include "Idle.h"
+#include <Carbon/Carbon.h>
- // Why does Apple have to make this so complicated?
- static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr) {
- OSStatus err;
- FSRef frameworksFolderRef;
- CFURLRef baseURL;
- CFURLRef bundleURL;
+// Why does Apple have to make this so complicated?
+static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef * bundlePtr)
+{
+ OSStatus err;
+ FSRef frameworksFolderRef;
+ CFURLRef baseURL;
+ CFURLRef bundleURL;
- if ( bundlePtr == nil ) return( -1 );
+ if(bundlePtr == nil)
+ return (-1);
- *bundlePtr = nil;
+ *bundlePtr = nil;
- baseURL = nil;
- bundleURL = nil;
+ baseURL = nil;
+ bundleURL = nil;
- err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
- if (err == noErr) {
- baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
- if (baseURL == nil) {
- err = coreFoundationUnknownErr;
- }
- }
- if (err == noErr) {
- bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false);
- if (bundleURL == nil) {
- err = coreFoundationUnknownErr;
- }
- }
- if (err == noErr) {
- *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
- if (*bundlePtr == nil) {
- err = coreFoundationUnknownErr;
- }
- }
- if (err == noErr) {
- if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
- err = coreFoundationUnknownErr;
- }
+ err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
+ if(err == noErr)
+ {
+ baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
+ if(baseURL == nil)
+ {
+ err = coreFoundationUnknownErr;
}
-
- // Clean up.
- if (err != noErr && *bundlePtr != nil) {
- CFRelease(*bundlePtr);
- *bundlePtr = nil;
+ }
+ if(err == noErr)
+ {
+ bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false);
+ if(bundleURL == nil)
+ {
+ err = coreFoundationUnknownErr;
}
- if (bundleURL != nil) {
- CFRelease(bundleURL);
+ }
+ if(err == noErr)
+ {
+ *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
+ if(*bundlePtr == nil)
+ {
+ err = coreFoundationUnknownErr;
}
- if (baseURL != nil) {
- CFRelease(baseURL);
+ }
+ if(err == noErr)
+ {
+ if(!CFBundleLoadExecutable(*bundlePtr))
+ {
+ err = coreFoundationUnknownErr;
}
-
- return err;
}
+ // Clean up.
+ if(err != noErr && *bundlePtr != nil)
+ {
+ CFRelease(*bundlePtr);
+ *bundlePtr = nil;
+ }
+ if(bundleURL != nil)
+ {
+ CFRelease(bundleURL);
+ }
+ if(baseURL != nil)
+ {
+ CFRelease(baseURL);
+ }
- class IdlePlatform::Private {
- public:
- EventLoopTimerRef mTimerRef;
- int mSecondsIdle;
-
- Private() : mTimerRef(0), mSecondsIdle(0) {}
+ return err;
+}
- static pascal void IdleTimerAction(EventLoopTimerRef, EventLoopIdleTimerMessage inState, void* inUserData);
+class IdlePlatform::Private
+{
+public:
+ EventLoopTimerRef mTimerRef;
+ int mSecondsIdle;
- };
+ Private() : mTimerRef(0), mSecondsIdle(0) {}
+ static pascal void IdleTimerAction(EventLoopTimerRef, EventLoopIdleTimerMessage inState, void * inUserData);
+};
- pascal void IdlePlatform::Private::IdleTimerAction(EventLoopTimerRef, EventLoopIdleTimerMessage inState, void* inUserData) {
- switch (inState) {
- case kEventLoopIdleTimerStarted:
- case kEventLoopIdleTimerStopped:
+pascal void IdlePlatform::Private::IdleTimerAction(EventLoopTimerRef, EventLoopIdleTimerMessage inState, void * inUserData)
+{
+ switch(inState)
+ {
+ case kEventLoopIdleTimerStarted:
+ case kEventLoopIdleTimerStopped:
// Get invoked with this constant at the start of the idle period,
- // or whenever user activity cancels the idle.
- ((IdlePlatform::Private*)inUserData)->mSecondsIdle = 0;
- break;
- case kEventLoopIdleTimerIdling:
- // Called every time the timer fires (i.e. every second).
- ((IdlePlatform::Private*)inUserData)->mSecondsIdle++;
- break;
- }
- }
-
-
- IdlePlatform::IdlePlatform() {
- d = new Private();
- }
-
- IdlePlatform::~IdlePlatform() {
- RemoveEventLoopTimer(d->mTimerRef);
- delete d;
+ // or whenever user activity cancels the idle.
+ ((IdlePlatform::Private *)inUserData)->mSecondsIdle = 0;
+ break;
+ case kEventLoopIdleTimerIdling:
+ // Called every time the timer fires (i.e. every second).
+ ((IdlePlatform::Private *)inUserData)->mSecondsIdle++;
+ break;
}
+}
+IdlePlatform::IdlePlatform()
+{
+ d = new Private();
+}
- // Typedef for the function we're getting back from CFBundleGetFunctionPointerForName.
- typedef OSStatus (*InstallEventLoopIdleTimerPtr)(EventLoopRef inEventLoop,
- EventTimerInterval inFireDelay,
- EventTimerInterval inInterval,
- EventLoopIdleTimerUPP inTimerProc,
- void * inTimerData,
- EventLoopTimerRef * outTimer);
-
-
- bool IdlePlatform::init() {
- // May already be init'ed.
- if (d->mTimerRef) {
- return true;
- }
-
- // According to the docs, InstallEventLoopIdleTimer is new in 10.2.
- // According to the headers, it has been around since 10.0.
- // One of them is lying. We'll play it safe and weak-link the function.
+IdlePlatform::~IdlePlatform()
+{
+ RemoveEventLoopTimer(d->mTimerRef);
+ delete d;
+}
- // Load the "Carbon.framework" bundle.
- CFBundleRef carbonBundle;
- if (LoadFrameworkBundle( CFSTR("Carbon.framework"), &carbonBundle ) != noErr) {
- return false;
- }
+// Typedef for the function we're getting back from CFBundleGetFunctionPointerForName.
+typedef OSStatus (*InstallEventLoopIdleTimerPtr)(EventLoopRef inEventLoop,
+ EventTimerInterval inFireDelay,
+ EventTimerInterval inInterval,
+ EventLoopIdleTimerUPP inTimerProc,
+ void * inTimerData,
+ EventLoopTimerRef * outTimer);
- // Load the Mach-O function pointers for the routine we will be using.
- InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName(carbonBundle, CFSTR("InstallEventLoopIdleTimer"));
- if (myInstallEventLoopIdleTimer == 0) {
- return false;
- }
+bool IdlePlatform::init()
+{
+ // May already be init'ed.
+ if(d->mTimerRef)
+ {
+ return true;
+ }
- EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP(Private::IdleTimerAction);
- if ((*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &d->mTimerRef)) {
- return true;
- }
+ // According to the docs, InstallEventLoopIdleTimer is new in 10.2.
+ // According to the headers, it has been around since 10.0.
+ // One of them is lying. We'll play it safe and weak-link the function.
+ // Load the "Carbon.framework" bundle.
+ CFBundleRef carbonBundle;
+ if(LoadFrameworkBundle(CFSTR("Carbon.framework"), &carbonBundle) != noErr)
+ {
return false;
}
+ // Load the Mach-O function pointers for the routine we will be using.
+ InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName(carbonBundle, CFSTR("InstallEventLoopIdleTimer"));
+ if(myInstallEventLoopIdleTimer == 0)
+ {
+ return false;
+ }
- int IdlePlatform::secondsIdle() const {
- return d->mSecondsIdle;
+ EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP(Private::IdleTimerAction);
+ if((*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &d->mTimerRef))
+ {
+ return true;
}
+
+ return false;
+}
+
+int IdlePlatform::secondsIdle() const
+{
+ return d->mSecondsIdle;
+}
#endif