Re: Cocoa Selector As CF Callback Addr?
Re: Cocoa Selector As CF Callback Addr?
- Subject: Re: Cocoa Selector As CF Callback Addr?
- From: Nicko van Someren <email@hidden>
- Date: Fri, 19 Nov 2004 11:14:52 +0000
On 19 Nov 2004, at 10:42, Lance Drake wrote:
...
My attempt to convert the source into a Cocoa object went perfectly
until
I got to setting the callback address which was implemented as:
Boolean ok = SCNetworkReachabilitySetCallback(thisTarget,
(SCNetworkReachabilityCallBack)@selector(MyReachabilityCallback:flags:
info:),
&thisContext );
The compiler is quite happy with the construct. Unfortunately, the app
cannot accommodate this call and an exception is immediately generated.
A selector is an address used by the linker which happens to point to a
string representation of a message name. You can't actually call a
selector; it has to be resolved through the message sending system.
You can resolve a selector to a function pointer called and IMP. The
IMP (implementation) is a function pointer to a C function of with a
type defined as:
typedef id (*IMP)(id, SEL, ...);
Unfortunately this isn't going to do what you want either, since the
callback function prototype does not fit this form.
After poking around in the (very often very helpful) ADCRefLib, I could
find see any reason why the runtime situation would be such a disaster.
Can anyone please point me to the particulars that would allow for this
callback to succeed?
I suggest that you define a C function somewhere which goes something
along the line of:
void mySCCallBack(SCNetworkReachabilityRef target,
SCNetworkConnectionFlags flags, void *info ) {
MyObjectType *obj = (MyObjectType *) info;
[obj handleCallBackWithTarget: target flags: flags];
}
You can pass a pointer to this function as your callback handler and a
pointer to the object you want notified as the context in the set
callback function.
Nicko
_______________________________________________
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