Re: Machine sleep & wake notifications in a daemon
Re: Machine sleep & wake notifications in a daemon
- Subject: Re: Machine sleep & wake notifications in a daemon
- From: Ken Thomases <email@hidden>
- Date: Thu, 08 Jan 2015 17:19:47 -0600
On Jan 8, 2015, at 4:54 PM, Andrew Keller <email@hidden> wrote:
> On Jan 8, 2015, at 5:20 PM, Ken Thomases <email@hidden> wrote:
>
>> On Jan 8, 2015, at 4:03 PM, Andrew Keller <email@hidden> wrote:
>>
>>> <https://developer.apple.com/library/mac/qa/qa1340/_index.html>
>
> Yes. It looks very promising, but on the first try, I wasn't able to keep the run loop running (it exited immediately). I suspect that the problem has to do with the run loop not having any input sources.
It is true that a run loop without any input sources will exit immediately. However, the code in listing 3 has added an input source to the run loop:
// add the notification port to the application runloop
CFRunLoopAddSource( CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notifyPortRef), kCFRunLoopCommonModes );
> Also, I have a feeling that there may be something missing conceptually. Suppose I do manage to keep the run loop running using a new input source. How do the OS and the application frameworks know to route the notification there?
The code creates an IONotificationPort, creates a run loop source from that, and adds that source to the run loop. That's how the system knows to route the notification there. It sends the notification to all notification ports. The notification port is tied to the run loop source. Since the source was added to the run loop, the run loop is monitoring the notification port.
Did you modify the code? You might try separating out the call to IONotificationPortGetRunLoopSource() so that you can examine its result. Is it returning a non-NULL source reference?
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden