• 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
Re: Cocoa Selector As CF Callback Addr?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Cocoa Selector As CF Callback Addr? (From: Lance Drake <email@hidden>)

  • Prev by Date: Re: NSPanel with just a close button & title on title bar?
  • Next by Date: RE[2]: Cocoa Selector As CF Callback Addr?
  • Previous by thread: Re: Cocoa Selector As CF Callback Addr?
  • Next by thread: RE[2]: Cocoa Selector As CF Callback Addr?
  • Index(es):
    • Date
    • Thread