~ubuntu-branches/ubuntu/wily/psi/wily

« back to all changes in this revision

Viewing changes to src/tools/systemwatch/systemwatch_mac.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2010-02-19 09:37:12 UTC
  • mfrom: (6.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100219093712-e225xvm1wjcf1cgi
Tags: 0.14-2
* comment out only function which uses va_list to work around build
  problems on armel
* Set Standards-Version to 3.8.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * systemwatch_mac.cpp - Detect changes in the system state (Mac OS X).
3
 
 * Copyright (C) 2005  Remko Troncon
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU General Public License
7
 
 * as published by the Free Software Foundation; either version 2
8
 
 * of the License, or (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 *
19
 
 */
20
 
 
21
 
#include <ctype.h>
22
 
#include <stdlib.h>
23
 
#include <stdio.h>
24
 
 
25
 
#include <mach/mach_port.h>
26
 
#include <mach/mach_interface.h>
27
 
#include <mach/mach_init.h>
28
 
 
29
 
#include <IOKit/pwr_mgt/IOPMLib.h>
30
 
#include <IOKit/IOMessage.h>
31
 
 
32
 
#include "systemwatch_mac.h"
33
 
 
34
 
 
35
 
// -----------------------------------------------------------------------------
36
 
// Callbacks
37
 
// -----------------------------------------------------------------------------
38
 
 
39
 
io_connect_t  root_port;
40
 
 
41
 
void sleepCallBack(void* systemWatch, io_service_t, natural_t messageType, void * messageArgument)
42
 
{
43
 
        //printf("messageType %08lx, arg %08lx\n",
44
 
        //  (long unsigned int)messageType, (long unsigned int)messageArgument);
45
 
        
46
 
        MacSystemWatch* macSystemWatch = static_cast<MacSystemWatch*>(systemWatch);
47
 
        switch (messageType) {
48
 
                case kIOMessageSystemWillSleep:
49
 
                        // Sleep
50
 
                        macSystemWatch->emitSleep();
51
 
                        IOAllowPowerChange(root_port, (long)messageArgument);
52
 
                        break;
53
 
                        
54
 
                case kIOMessageCanSystemSleep:
55
 
                        // Idle time sleep
56
 
 
57
 
                        // TODO: Check if file transfers are running, and don't go to sleep
58
 
                        // if there are.
59
 
                        //IOCancelPowerChange(root_port, (long)messageArgument);
60
 
 
61
 
                        macSystemWatch->emitIdleSleep();
62
 
                        IOAllowPowerChange(root_port, (long)messageArgument);
63
 
                        break;
64
 
                        
65
 
                case kIOMessageSystemHasPoweredOn:
66
 
                        // Wakeup
67
 
                        macSystemWatch->emitWakeup();
68
 
                        break;
69
 
        }
70
 
}
71
 
 
72
 
 
73
 
// -----------------------------------------------------------------------------
74
 
// MacSystemWatch
75
 
// -----------------------------------------------------------------------------
76
 
 
77
 
MacSystemWatch::MacSystemWatch()
78
 
{
79
 
        // Initialize sleep callback
80
 
        IONotificationPortRef notify;
81
 
        io_object_t           anIterator;
82
 
        root_port = IORegisterForSystemPower(this, &notify, sleepCallBack, &anIterator);
83
 
        if (!root_port) {
84
 
                printf("IORegisterForSystemPower failed\n");
85
 
        }
86
 
        else {
87
 
                CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), kCFRunLoopCommonModes);
88
 
        }
89
 
}