Re: Cocoa Selector As CF Callback Addr?
Re: Cocoa Selector As CF Callback Addr?
- Subject: Re: Cocoa Selector As CF Callback Addr?
- From: Sherm Pendley <email@hidden>
- Date: Fri, 19 Nov 2004 06:04:41 -0500
On Nov 19, 2004, at 5:42 AM, Lance Drake wrote:
There's a great new API demonstrated in the demo 'SimpleReach' project.
In it, there's a local routine that gets notified when net connectivity
changes. The routine in the sample code looks like this in the code:
Boolean ok = SCNetworkReachabilitySetCallback( thisTarget,
MyReachabilityCallback,
&thisContext );
The callback function you need to give here must be exactly that - a
*function*, not a method or a selector. As is typical with many C
callbacks however, the context parameter is simply passed to your
callback function as-is. It's there solely for your own use. So what
you do is pass an object as the context argument, and then within your
callback function reflect the call to that object.
When you set the callback:
Boolean ok = SCNetworkReachabilitySetCallback(
thisTarget,
MyReachabilityCallback,
(void *)self
);
Your callback function:
static void MyReachabilityCallback(
SCNetworkreachabilityRef target,
SCNetworkConnectionFlags flags,
void *info)
{
[(MyClass *)info reachabilityCallbackTarget:target
withFlags:flags];
}
sherm--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden