diff options
author | MaestroDD <MaestroDD@svn> | 2010-01-21 19:54:17 +0000 |
---|---|---|
committer | MaestroDD <MaestroDD@svn> | 2010-01-21 19:54:17 +0000 |
commit | db040febc3583a730b34c2c0260b277a337855ec (patch) | |
tree | ca2837a27bdfcc5fc4b665d91c3b2c430f890daf | |
parent | e6160dd0f0f32eea5492a7be1b68f237efb04014 (diff) |
[OSX] changed: replaced custom CocoaPowerSyscall implementation with sample code from Apple
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@27056 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | xbmc/osx/CocoaInterface.h | 5 | ||||
-rw-r--r-- | xbmc/osx/CocoaInterface.mm | 40 | ||||
-rw-r--r-- | xbmc/osx/CocoaPowerSyscall.cpp | 45 |
3 files changed, 64 insertions, 26 deletions
diff --git a/xbmc/osx/CocoaInterface.h b/xbmc/osx/CocoaInterface.h index eff2939ff2..63b8ff720c 100644 --- a/xbmc/osx/CocoaInterface.h +++ b/xbmc/osx/CocoaInterface.h @@ -23,7 +23,7 @@ #include <string> #include "StdString.h" - +#include <Carbon/Carbon.h> #ifdef __cplusplus extern "C" { @@ -75,6 +75,9 @@ extern "C" const char *Cocoa_Paste() ; + // helper from QA 1134 + // http://developer.apple.com/mac/library/qa/qa2001/qa1134.html + OSStatus SendAppleEventToSystemProcess(AEEventID EventToSend); #ifdef __cplusplus } #endif diff --git a/xbmc/osx/CocoaInterface.mm b/xbmc/osx/CocoaInterface.mm index 96f1872958..71b45ba098 100644 --- a/xbmc/osx/CocoaInterface.mm +++ b/xbmc/osx/CocoaInterface.mm @@ -537,3 +537,43 @@ const char *Cocoa_Paste() return NULL; } + +OSStatus SendAppleEventToSystemProcess(AEEventID EventToSend) +{ + AEAddressDesc targetDesc; + static const ProcessSerialNumber kPSNOfSystemProcess = { 0, kSystemProcess }; + AppleEvent eventReply = {typeNull, NULL}; + AppleEvent appleEventToSend = {typeNull, NULL}; + + OSStatus error = noErr; + + error = AECreateDesc(typeProcessSerialNumber, &kPSNOfSystemProcess, + sizeof(kPSNOfSystemProcess), &targetDesc); + + if (error != noErr) + { + return(error); + } + + error = AECreateAppleEvent(kCoreEventClass, EventToSend, &targetDesc, + kAutoGenerateReturnID, kAnyTransactionID, &appleEventToSend); + + AEDisposeDesc(&targetDesc); + if (error != noErr) + { + return(error); + } + + error = AESend(&appleEventToSend, &eventReply, kAENoReply, + kAENormalPriority, kAEDefaultTimeout, NULL, NULL); + + AEDisposeDesc(&appleEventToSend); + if (error != noErr) + { + return(error); + } + + AEDisposeDesc(&eventReply); + + return(error); +}
\ No newline at end of file diff --git a/xbmc/osx/CocoaPowerSyscall.cpp b/xbmc/osx/CocoaPowerSyscall.cpp index 7798796d56..9512541da3 100644 --- a/xbmc/osx/CocoaPowerSyscall.cpp +++ b/xbmc/osx/CocoaPowerSyscall.cpp @@ -19,13 +19,13 @@ * */ +#ifdef __APPLE__ // defined in PlatformDefs.h but I don't want to include that here typedef unsigned char BYTE; #include "Log.h" #include "SystemInfo.h" #include "CocoaPowerSyscall.h" -#ifdef __APPLE__ #include <IOKit/pwr_mgt/IOPMLib.h> #include "CocoaInterface.h" @@ -37,26 +37,26 @@ CCocoaPowerSyscall::CCocoaPowerSyscall() bool CCocoaPowerSyscall::Powerdown() { CLog::Log(LOGDEBUG, "CCocoaPowerSyscall::Powerdown"); - if (g_sysinfo.IsAppleTV()) - { - // The ATV prefered method is via command-line - system("echo frontrow | sudo -S shutdown -h now"); - } + //sending shutdown event to system + OSErr error = SendAppleEventToSystemProcess(kAEShutDown); + if (error == noErr) + CLog::Log(LOGINFO, "Computer is going to shutdown!"); else - { - // The OSX prefered method is via AppleScript - Cocoa_DoAppleScript("tell application \"System Events\" to shut down"); - } - return true; + CLog::Log(LOGINFO, "Computer wouldn't shutdown!"); + return (error == noErr); } bool CCocoaPowerSyscall::Suspend() { CLog::Log(LOGDEBUG, "CCocoaPowerSyscall::Suspend"); - // The OSX prefered method is via AppleScript - Cocoa_DoAppleScript("tell application \"System Events\" to sleep"); - - return true; + + //sending sleep event to system + OSErr error = SendAppleEventToSystemProcess(kAESleep); + if (error == noErr) + CLog::Log(LOGINFO, "Computer is going to sleep!"); + else + CLog::Log(LOGINFO, "Computer wouldn't sleep!"); + return (error == noErr); } bool CCocoaPowerSyscall::Hibernate() @@ -69,17 +69,12 @@ bool CCocoaPowerSyscall::Hibernate() bool CCocoaPowerSyscall::Reboot() { CLog::Log(LOGDEBUG, "CCocoaPowerSyscall::Reboot"); - if (g_sysinfo.IsAppleTV()) - { - // The ATV prefered method is via command-line - system("echo frontrow | sudo -S reboot"); - } + OSErr error = SendAppleEventToSystemProcess(kAERestart); + if (error == noErr) + CLog::Log(LOGINFO, "Computer is going to restart!"); else - { - // The OSX prefered method is via AppleScript - Cocoa_DoAppleScript("tell application \"System Events\" to reboot"); - } - return true; + CLog::Log(LOGINFO, "Computer wouldn't restart!"); + return (error == noErr); } bool CCocoaPowerSyscall::CanPowerdown() |