• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Alternative reference to self?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Alternative reference to self?


  • Subject: Alternative reference to self?
  • From: Dale Gillard <email@hidden>
  • Date: Sun, 12 Jan 2003 21:59:45 +1100

Hi all

I need to check when a user's Mac sleeps and wakes so I can start and stop a timer. I've used the code in Fire as a guide based on a message from Eric in the archives. It works fine except that it won't accept a reference to [self ...] (my app's controller):

// Start of snippet
void sleepNotification( void * refcon, io_service_t service, natural_t messageType, void * messageArgument )
{
switch( messageType )
{
case kIOMessageSystemWillSleep:
[self stopRecentItemsTimer]; // Compiler warning - `self' undeclared (first use in this function).
IOAllowPowerChange( powerConnection, (long) messageArgument );
break;
...
// End of snippet

This IOKit C function handle the notifications but doesn't like a reference to [self ..] in the above switch statement. The compiler warns : `self' undeclared (first use in this function). So how can I get a reference to self so I can send it the stopRecentItemsTimer message?

Fire *appears* to handle this issue by making the controller class the NSApp's delegate, creating a message that returns a reference to the delegate instance and substituting this instead of [self ..].

In Fire, the equivalent message to my [self stopRecentItemsTimer] would be [[Controller controller] stopRecentItemsTimer]. (My controller class is Controller.h.)

So my long winded question is: is there a more elegant way to get a reference to an instance of self using NSObject or the Objective-C runtime? I can't seem to find anything in the documentation that suggests so.

As an aside, we really need NSWorkspace notifications like NSWorkspaceWillSleepNotification and NSWorkspaceDidWakeNotification in the AppKit. Applications that use NSTimers, etc can't ignore a Mac sleeping as the events are 'saved', accumulate and fire one after the other when the Mac is reawakened. At least that's my experience so far.

Many thanks for any help

Dale
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Alternative reference to self?
      • From: email@hidden
  • Prev by Date: Re: Aqua Human Interface and Safari
  • Next by Date: Re: Notes about WebCore
  • Previous by thread: Re: NSDistributedNotification in a Foundation tool
  • Next by thread: Re: Alternative reference to self?
  • Index(es):
    • Date
    • Thread