~ubuntu-branches/ubuntu/jaunty/pcsc-lite/jaunty-security

« back to all changes in this revision

Viewing changes to src/powermgt_macosx.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2005-11-27 18:04:59 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127180459-qrex2gzpq9d8jexd
Tags: 1.2.9-beta9-1
* New upstream version
* debian/compat: change from 3 to 4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
 
3
 *
 
4
 * @APPLE_LICENSE_HEADER_START@
 
5
 * 
 
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.
 
11
 * 
 
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
 
18
 * under the License.
 
19
 * 
 
20
 * @APPLE_LICENSE_HEADER_END@
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
#include <ctype.h>
 
25
 
 
26
#ifdef __APPLE__
 
27
#include <stdlib.h>
 
28
#include <stdio.h>
 
29
 
 
30
#include <mach/mach_port.h>
 
31
#include <mach/mach_interface.h>
 
32
#include <mach/mach_init.h>
 
33
 
 
34
#include <IOKit/pwr_mgt/IOPMLib.h>
 
35
#include <IOKit/IOMessage.h>
 
36
 
 
37
#include "pcsclite.h"
 
38
#include "debuglog.h"
 
39
#include "readerfactory.h"
 
40
#include "thread_generic.h"
 
41
#include "hotplug.h"
 
42
 
 
43
static io_connect_t             root_port;
 
44
static IONotificationPortRef    notify;
 
45
static io_object_t              anIterator;
 
46
 
 
47
PCSCLITE_THREAD_T       pmgmtThread;
 
48
extern PCSCLITE_MUTEX   usbNotifierMutex;
 
49
 
 
50
void PMPowerRegistrationThread();
 
51
 
 
52
void PMPowerEventCallback(void * x,io_service_t y,natural_t messageType,void * messageArgument)
 
53
{
 
54
 
 
55
    switch ( messageType ) {
 
56
    case kIOMessageCanSystemSleep:
 
57
          IOAllowPowerChange(root_port,(long)messageArgument);
 
58
          break;
 
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");
 
65
          break;
 
66
    case kIOMessageSystemHasPoweredOn: 
 
67
        Log1(PCSC_LOG_INFO, "system coming out of sleep");
 
68
        HPSearchHotPluggables();
 
69
        RFAwakeAllReaders();
 
70
        SYS_MutexUnLock(&usbNotifierMutex);
 
71
        break;
 
72
    }
 
73
    
 
74
}
 
75
 
 
76
void PMPowerRegistrationThread() {
 
77
 
 
78
    root_port = IORegisterForSystemPower (0,&notify,PMPowerEventCallback,&anIterator);
 
79
  
 
80
    if ( root_port == 0 ) {
 
81
            Log1(PCSC_LOG_ERROR, "IORegisterForSystemPower failed");
 
82
            return;
 
83
    }
 
84
    
 
85
    CFRunLoopAddSource(CFRunLoopGetCurrent(),
 
86
                        IONotificationPortGetRunLoopSource(notify),
 
87
                        kCFRunLoopDefaultMode);
 
88
                
 
89
    CFRunLoopRun();
 
90
}
 
91
 
 
92
ULONG PMRegisterForPowerEvents() {
 
93
 
 
94
  LONG rv; 
 
95
    
 
96
  rv = SYS_ThreadCreate(&pmgmtThread, THREAD_ATTR_DEFAULT,
 
97
                  (PCSCLITE_THREAD_FUNCTION( )) PMPowerRegistrationThread, NULL);
 
98
  return 0;
 
99
}
 
100
 
 
101
#endif  /* __APPLE__ */