Just use CFRunLoopAddSource(CFRunLoopGetCurrent(), ...).
The CFRunLoop and the Appkit run loop are the exact same thing and
Appkit sets up the main run loop for you when you call
NSApplicationMain() in main.c . Your callbacks will be called
automatically. I do this sort of thing all the time without having to
resort to threads.
-raleigh
On Apr 27, 2005, at 5:26 PM, Dave Camp wrote:
On Apr 27, 2005, at 3:36 PM, Juan Pablo Pertierra wrote:
Right now my cocoa application can read from the USB port and do
exactly what i need it to do, except for the fact that while it is
reading from the USB port everything else freezes, waiting to return
from the RunLoop. I have based my USB code on the USB SImpleExample.
In the end I want it to read from the USB port and write what is
read to a file, while the user can still perform some simple
functions on the UI of the application.
So, first of all, is there any way to add the ReadAsync notifications
to the cocoa application's RunLoop without explicitly having to call
CFRunLoop and wait for it to return? It seems that the cocoa
application must already have it's own runloop?
If not, i'm thinking I need to just fire up another thread to do all
the USB reading/writing to disk. I know the basics of NSThread, but
I am unsure how to mix the USB code with a new thread. Should all
the USB initialization be done on the separate thread, or can I
initialize the USB(open ports, configure device, etc) on the main
program and then just spawn the thread when I need to read?
The latter should work fine. Be sure to put an NSAutoreleasePool in
the thread so you don't leak Cocoa objects, and use whatever
synchronization primitives you need (e.g. NSLock) to safely marshal
data from one thread to the other.
Dave
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden
This email sent to email@hidden
-----------------------------------------------
Raleigh Ledet, <email@hidden>
Wacom Technology Corp.
Mac Software Engineer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden