Re: address of method in a class instance
Re: address of method in a class instance
- Subject: Re: address of method in a class instance
- From: Robert S Goldsmith <email@hidden>
- Date: Thu, 06 Sep 2001 11:03:56 +0100
Hi :)
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.
As was suggested, CF callbacks work fine combined with
NSApplication runloops (because they are based on the same
thing in reality).
:)
Can anyone see a problem with all this? It seems to work...
For instance, is there any way the instance of the class
responding to the callbacks could be destroyed without me
knowing about it? 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?
Robert