~ubuntu-branches/ubuntu/quantal/psi/quantal

« 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: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
io_connect_t  root_port;
40
40
 
41
 
void sleepCallBack(void *, io_service_t, natural_t messageType, void * messageArgument)
 
41
void sleepCallBack(void* systemWatch, io_service_t, natural_t messageType, void * messageArgument)
42
42
{
43
43
        //printf("messageType %08lx, arg %08lx\n",
44
44
        //  (long unsigned int)messageType, (long unsigned int)messageArgument);
45
45
        
 
46
        MacSystemWatch* macSystemWatch = static_cast<MacSystemWatch*>(systemWatch);
46
47
        switch (messageType) {
47
48
                case kIOMessageSystemWillSleep:
48
49
                        // Sleep
49
 
                        MacSystemWatch::instance()->emitSleep();
 
50
                        macSystemWatch->emitSleep();
50
51
                        IOAllowPowerChange(root_port, (long)messageArgument);
51
52
                        break;
52
53
                        
57
58
                        // if there are.
58
59
                        //IOCancelPowerChange(root_port, (long)messageArgument);
59
60
 
60
 
                        MacSystemWatch::instance()->emitIdleSleep();
 
61
                        macSystemWatch->emitIdleSleep();
61
62
                        IOAllowPowerChange(root_port, (long)messageArgument);
62
63
                        break;
63
64
                        
64
65
                case kIOMessageSystemHasPoweredOn:
65
66
                        // Wakeup
66
 
                        MacSystemWatch::instance()->emitWakeup();
 
67
                        macSystemWatch->emitWakeup();
67
68
                        break;
68
69
        }
69
70
}
76
77
MacSystemWatch::MacSystemWatch()
77
78
{
78
79
        // Initialize sleep callback
79
 
        IONotificationPortRef  notify;
80
 
        io_object_t                        anIterator;
81
 
        root_port = IORegisterForSystemPower(0, &notify, sleepCallBack, &anIterator);
82
 
        if (root_port == NULL)
83
 
                        printf("IORegisterForSystemPower failed\n");
84
 
        else
 
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 {
85
87
                CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), kCFRunLoopCommonModes);
86
 
}
87
 
 
88
 
 
89
 
MacSystemWatch* MacSystemWatch::instance()
90
 
{
91
 
        if (!instance_) 
92
 
                instance_ = new MacSystemWatch();
93
 
 
94
 
        return instance_;
95
 
}
96
 
 
97
 
MacSystemWatch* MacSystemWatch::instance_ = 0;
 
88
        }
 
89
}