Re: Cocoa callback handling
Re: Cocoa callback handling
- Subject: Re: Cocoa callback handling
- From: John Stiles <email@hidden>
- Date: Tue, 7 Aug 2007 15:09:19 -0700
If you can require Leopard, and have access to seeds, you should
check out some of the stuff that's coming. I can't say more due to
NDA concerns but it seems like it would be of interest to the OP.
On Aug 7, 2007, at 2:54 PM, Scott Ribe wrote:
Well, when the callback is set up and working properly, it is invoked
at a very high frequency. Spawning a new thread each time would be
overkill.
Then you might consider using a queue. Spawn the thread, which blocks
waiting on a queue. Then the callback happens on the main thread,
and pushes
data onto the queue.
Sorry, my queue-handling code is old and doesn't need updating, so
I still
use Carbon stuff: MPQueue. I don't know if there's a Cocoa
equivalent, but
if not the Carbon stuff is pretty easy since you can just pass
pointers to
Objective-C instances through the queue. Of course you have to cast
types
correctly, and set up and manage an autorelease pool in the secondary
thread, and balance retain/release as always. Assuming that the
data that
you're processing is an NSObject of some kind; if not, well, apply
other
memory management techniques as appropriate ;-)
The thing is, your SDK probably can only call back onto the main
thread, and
you probably have no control over that. It *might* note what thread
it is
"started" in--if there's some kind of start-up call to get it
going, you
might try calling that from the thread on which you want to receive
callbacks.
Either way, from your description it sounds like the SDK is running
in the
background on its own thread. In which case it is either getting
the thread
id of the main thread and calling back on that, or getting the id
of the
thread in which it is "start" and calling back on that. I would
guess it's
just calling into the main thread, and expecting you to deal with
it from
there however you wish. But it's worth poking around a little, and
it might
be worth a suggestion to the developer to add a call to let you
specify the
thread you want called.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden