00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include <ctype.h>
00025
00026 #ifdef __APPLE__
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029
00030 #include <mach/mach_port.h>
00031 #include <mach/mach_interface.h>
00032 #include <mach/mach_init.h>
00033
00034 #include <IOKit/pwr_mgt/IOPMLib.h>
00035 #include <IOKit/IOMessage.h>
00036
00037 #include "misc.h"
00038 #include "pcsclite.h"
00039 #include "debuglog.h"
00040 #include "readerfactory.h"
00041 #include "thread_generic.h"
00042 #include "hotplug.h"
00043
00044 static io_connect_t root_port;
00045 static IONotificationPortRef notify;
00046 static io_object_t anIterator;
00047
00048 PCSCLITE_THREAD_T pmgmtThread;
00049 extern PCSCLITE_MUTEX usbNotifierMutex;
00050
00051 void PMPowerRegistrationThread();
00052
00053 void PMPowerEventCallback(void * x,io_service_t y,natural_t messageType,void * messageArgument)
00054 {
00055
00056 switch ( messageType ) {
00057 case kIOMessageCanSystemSleep:
00058 IOAllowPowerChange(root_port,(long)messageArgument);
00059 break;
00060 case kIOMessageSystemWillSleep:
00061 Log1(PCSC_LOG_INFO, "system going into sleep");
00062 SYS_MutexLock(&usbNotifierMutex);
00063 RFSuspendAllReaders();
00064 IOAllowPowerChange(root_port,(long)messageArgument);
00065 Log1(PCSC_LOG_INFO, "system allowed to sleep");
00066 break;
00067 case kIOMessageSystemHasPoweredOn:
00068 Log1(PCSC_LOG_INFO, "system coming out of sleep");
00069 HPSearchHotPluggables();
00070 RFAwakeAllReaders();
00071 SYS_MutexUnLock(&usbNotifierMutex);
00072 break;
00073 }
00074
00075 }
00076
00077 void PMPowerRegistrationThread() {
00078
00079 root_port = IORegisterForSystemPower (0,¬ify,PMPowerEventCallback,&anIterator);
00080
00081 if ( root_port == 0 ) {
00082 Log1(PCSC_LOG_ERROR, "IORegisterForSystemPower failed");
00083 return;
00084 }
00085
00086 CFRunLoopAddSource(CFRunLoopGetCurrent(),
00087 IONotificationPortGetRunLoopSource(notify),
00088 kCFRunLoopDefaultMode);
00089
00090 CFRunLoopRun();
00091 }
00092
00093 ULONG PMRegisterForPowerEvents() {
00094
00095 LONG rv;
00096
00097 rv = SYS_ThreadCreate(&pmgmtThread, THREAD_ATTR_DEFAULT,
00098 (PCSCLITE_THREAD_FUNCTION( )) PMPowerRegistrationThread, NULL);
00099 return 0;
00100 }
00101
00102 #endif