On Jan 12, 2015, at 10:30 AM, Andrew Keller <and...@kellerfarm.com> wrote:
> On Jan 8, 2015, at 7:00 PM, Andrew Keller <and...@kellerfarm.com> wrote: > >> On Jan 8, 2015, at 6:11 PM, Greg Parker <gpar...@apple.com> wrote: >> >>> On Jan 8, 2015, at 2:54 PM, Andrew Keller <and...@kellerfarm.com> wrote: >>> >>>> On Jan 8, 2015, at 5:20 PM, Ken Thomases <k...@codeweavers.com> wrote: >>>> >>>>> On Jan 8, 2015, at 4:03 PM, Andrew Keller <and...@kellerfarm.com> wrote: >>>>> >>>>>> I would like to receive machine sleep and wake notifications in my >>>>>> daemon. In my Cocoa GUI application, I was able to easily follow the >>>>>> sample code under Listing 1 on the page >>>>>> <https://developer.apple.com/library/mac/qa/qa1340/_index.html>, but >>>>>> when I tried the same approach in my daemon, I received no errors or >>>>>> warnings from Xcode or in the system console, and yet the handlers also >>>>>> did not fire. After poking around for a while, I have a hunch that it >>>>>> may have something to do with the main event queue not being the same >>>>>> (or existing at all?) in a non-Cocoa GUI application. >>>>>> >>>>>> Is it possible to have a Cocoa-style event queue in a daemon, or is >>>>>> there another way to receive machine sleep and wake notifications from >>>>>> the OS in a daemon? >>>>> >>>>> Did you read further down that QA article you linked to listings 3 and 4? > > Thanks again; everything works as expected. > > One last question: Is there anything bad about using this code in a Cocoa > application, assuming you correctly guarantee that the new run loop is not > running on the main thread? Not terrible, but it's redundant and therefore slightly wasteful. First, Cocoa is already doing this for you and posting the NSWorkspace notifications. Second, even if you want to use the IOKit notifications rather than the NSWorkspace ones, you shouldn't need to create a separate thread just to be parked in a run loop waiting for these IOKit notifications. You could add the run loop source to the main run loop (the run loop of the main thread). NSApplication will service the main run loop as part of the main event loop. Regards, Ken _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com