Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RunLoop and callback function



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.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.