• 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: address of method in a class instance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: address of method in a class instance


  • Subject: Re: address of method in a class instance
  • From: Andreas Monitzer <email@hidden>
  • Date: Thu, 6 Sep 2001 12:56:48 +0200

On Thursday, September 6, 2001, at 12:03 , Robert S Goldsmith wrote:

RSG> What I need is a way to get hold of the address of an ObjC
RSG> class instance member method. This way I can pass the
RSG> address and when the callback happens, the correct instance
RSG> is notified ...
RSG>
RSG> any ideas?
Yeah, an excellent one: get rid of CF and use Foundation.

I wish I could, but the IOKit usb stuff uses CF callbacks and there is nothing I can do about that.

The solution, it seems, based on everyones great help was:

1)Have a c function as the callback
2)pass self in the refCon field of the callback setup
3)use this refCon field to message the correct instance of the class with the iterator the callback returns
4)In the class instance, do what is needed on that event (eg. someone unplugging the usb device) and send a notification.
5)In the main class instance, listen for this notification and do things like changing the icon showing whether the usb device is plugged in or not.

Can anyone see a problem with all this? It seems to work...

You could skip #2 and #3 and just send the notification from the C-function. Your class instance could be just another observer.

For instance, is there any way the instance of the class responding to the callbacks could be destroyed without me knowing about it?

Sure.

This could cause a problem with the callback trying to message an instance that no longer exists. Is there an equivilent to 'init' that is called before 'dealloc' so I could catch that posibility?

Just unregister the callback in -dealloc.

andy
--
"He was addicted to life. But we cured him"


  • Follow-Ups:
    • Re: address of method in a class instance
      • From: Robert S Goldsmith <email@hidden>
References: 
 >Re: address of method in a class instance (From: Robert S Goldsmith <email@hidden>)

  • Prev by Date: Re: Why is NSTableView scrolling in Cocoa apps so slow?
  • Next by Date: Re: Why is NSTableView scrolling in Cocoa apps so slow?
  • Previous by thread: Re: address of method in a class instance
  • Next by thread: Re: address of method in a class instance
  • Index(es):
    • Date
    • Thread