Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

powermgt_macosx.c

00001 /*
00002  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
00003  *
00004  * @APPLE_LICENSE_HEADER_START@
00005  *
00006  * The contents of this file constitute Original Code as defined in and
00007  * are subject to the Apple Public Source License Version 1.1 (the
00008  * "License").  You may not use this file except in compliance with the
00009  * License.  Please obtain a copy of the License at
00010  * http://www.apple.com/publicsource and read it before using this file.
00011  *
00012  * This Original Code and all software distributed under the License are
00013  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
00014  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
00015  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
00017  * License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * @APPLE_LICENSE_HEADER_END@
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,&notify,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  /* __APPLE__ */

Generated on Fri Jan 26 22:54:53 2007 for pcsc-lite by  doxygen 1.3.9.1