RunLoop and callback function
RunLoop and callback function
- Subject: RunLoop and callback function
- From: Thierry Bucco <email@hidden>
- Date: Tue, 27 Jan 2004 20:04:44 +0100
Hi,
I have a callback function which is executed when the power source
changes (this is a cocoa application).
Here is my litte source code :
******
void PowerSourcesHaveChanged()
{
NSLog(@"ca a changi...");
[self doThisPlease]; // <- self undeclared
}
/* initializePowerSourceChanges
*
* Registers a handler that gets called on power source (battery or UPS)
changes
*/
-(void)initializePowerSourceChanges
{
CFRunLoopSourceRef CFrls;
// Create and add RunLoopSource
CFrls =
IOPSNotificationCreateRunLoopSource(PowerSourcesHaveChanged, NULL);
if(CFrls) {
CFRunLoopAddSource(CFRunLoopGetCurrent(), CFrls,
kCFRunLoopDefaultMode);
CFRelease(CFrls);
}
}
******
It's works but in the function PowerSourcesHaveChanged, I get an error
because self is undeclared.
I tried to change :
IOPSNotificationCreateRunLoopSource(PowerSourcesHaveChanged, NULL);
by
IOPSNotificationCreateRunLoopSource(@selector(PowerSourcesHaveChanged),
NULL);
and void PowerSourcesHaveChanged()
by -(void)PowerSourcesHaveChanged
but my function is never called.
Have you an idea ?
Thanks you very much.
Thierry
iconless.com
_______________________________________________
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.