2
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4
* @APPLE_LICENSE_HEADER_START@
6
* The contents of this file constitute Original Code as defined in and
7
* are subject to the Apple Public Source License Version 1.1 (the
8
* "License"). You may not use this file except in compliance with the
9
* License. Please obtain a copy of the License at
10
* http://www.apple.com/publicsource and read it before using this file.
12
* This Original Code and all software distributed under the License are
13
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17
* License for the specific language governing rights and limitations
20
* @APPLE_LICENSE_HEADER_END@
30
#include <mach/mach_port.h>
31
#include <mach/mach_interface.h>
32
#include <mach/mach_init.h>
34
#include <IOKit/pwr_mgt/IOPMLib.h>
35
#include <IOKit/IOMessage.h>
39
#include "readerfactory.h"
40
#include "thread_generic.h"
43
static io_connect_t root_port;
44
static IONotificationPortRef notify;
45
static io_object_t anIterator;
47
PCSCLITE_THREAD_T pmgmtThread;
48
extern PCSCLITE_MUTEX usbNotifierMutex;
50
void PMPowerRegistrationThread();
52
void PMPowerEventCallback(void * x,io_service_t y,natural_t messageType,void * messageArgument)
55
switch ( messageType ) {
56
case kIOMessageCanSystemSleep:
57
IOAllowPowerChange(root_port,(long)messageArgument);
59
case kIOMessageSystemWillSleep:
60
Log1(PCSC_LOG_INFO, "system going into sleep");
61
SYS_MutexLock(&usbNotifierMutex);
62
RFSuspendAllReaders();
63
IOAllowPowerChange(root_port,(long)messageArgument);
64
Log1(PCSC_LOG_INFO, "system allowed to sleep");
66
case kIOMessageSystemHasPoweredOn:
67
Log1(PCSC_LOG_INFO, "system coming out of sleep");
68
HPSearchHotPluggables();
70
SYS_MutexUnLock(&usbNotifierMutex);
76
void PMPowerRegistrationThread() {
78
root_port = IORegisterForSystemPower (0,¬ify,PMPowerEventCallback,&anIterator);
80
if ( root_port == 0 ) {
81
Log1(PCSC_LOG_ERROR, "IORegisterForSystemPower failed");
85
CFRunLoopAddSource(CFRunLoopGetCurrent(),
86
IONotificationPortGetRunLoopSource(notify),
87
kCFRunLoopDefaultMode);
92
ULONG PMRegisterForPowerEvents() {
96
rv = SYS_ThreadCreate(&pmgmtThread, THREAD_ATTR_DEFAULT,
97
(PCSCLITE_THREAD_FUNCTION( )) PMPowerRegistrationThread, NULL);
101
#endif /* __APPLE__ */