site_archiver@lists.apple.com Delivered-To: bluetooth-dev@lists.apple.com Joe On Oct 23, 2006, at 11:30 AM, Christian Martin wrote: Hi Joe, Anyway... I will try to dig in a bit more... Thx Christian Christian, Joe On Oct 20, 2006, at 7:53 AM, Christian Martin wrote: Hi Joseph, Thx for your rapid answer. Thx. Christian Martin B.Sc. Math/Computer From: Joseph Kelly <joeman@mac.com> To: Christian Martin <cmartin64x@hotmail.com> Subject: Re: IOBluetoothDeviceRegisterForDisconnectNotification Date: Thu, 19 Oct 2006 13:57:21 -0700 Joe K. On Oct 19, 2006, at 12:57 PM, Christian Martin wrote: _______________________________________________ Do not post admin requests to the list. They will be ignored. Bluetooth-dev mailing list (Bluetooth-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/bluetooth-dev/site_archiver%40lists.a... To quote the Apple engineer who answered this same question for me last year: "IOBluetoothUI is not thread safe. It uses both IOBluetooth and AppKit of which neither are thread safe. Your best bet is to use the main thread as your Bluetooth thread and enqueue any Bluetooth operations to be performed on it. Not ideal, but it should work for you." I found that I could do some operations on a non-main thread, but I would get intermittent failures -- async writes wouldn't complete etc. I implemented a fancy command queue with all kinds of neat locking mechanisms to allow the main thread to perform all my bluetooth, and it worked perfectly. If you're not writing a well behaved Cocoa application, you've got a bit of work to do. Check on the Java lists to see if anyone has implemented a Bluetooth solution... Is there any way you can send messages to the main thread of your Java app? If you can, that's a place to start. I appreciate you took some time to answer my question(s). I am not an experienced programmer on OS X so I tend to go ahead with the best of my knowledge. I am currently able to start a java application, load a JNI which contains the appropriate calls to triger a device search. The only way I can get a list of all the devices is to set a separate thread (inside the JNI in C) which has the series of calls for a device search and, at the end, I make a call to the runloop. By doing so, the callback fctns are called and I can get the list of devices available. Obviously, the thread never dies since it is caught in the runloop. I can say it works !... but can I claim it is thread safe ??? This is where I am lost. You state : "...thread restriction I claim is indeed true for the C apis ..." . I do not know where I can get a clear answer on this... I guess I am pushing it a bit too much in doing something that stands out of realm of reasonable path to follow ! It's not impossible. First I would verify that the thread restriction I claim is indeed true for the C apis (I've been using the ObjectiveC api). This would probably involve getting the bluetooth working first by calling your C functions (that you're wrapping in JNI) in a purely C environment using main and non-main threads -- query, connect, open channel, send/receive, close channel, disconnect. Second, if you find that it doesn't work except on the main thread, you might investigate whether you can set up the main thread before you run the jvm. I would be fairly certain (your mileage may vary ;-) that once you enter the jvm that it sits in a runloop and fields window manager events. You could add a bunch of sources to the main thread's runloop, and your jni functions could post requests to the main thread by triggering those sources, which would then carry out the bluetooth operation on the main thread. Etc. If you plan on talking to one device at a time, this should be fairly straightforward. For simultaneous devices, you might have to implement a command queue of some kind. I'm CC'ing this back to the list in hopes that someone more knowledgeable about Bluetooth, Java, threading, etc. than I will chime in... I am currently working on a Java Application which would need some call into the api of bluetooth. So, I did a JNI to wrap it up. Now, according to what you are saying JAVA/JNI/Bluetooth is not possible ! Please let me know if there is an avenue that I am missing... I am seriously stuck here. The Apple Bluetooth implementation is not thread safe. In order for it to work correctly, you must make all calls from the main thread. IOBluetoothDeviceRegisterForDisconnectNotification _________________________________________________________________ Say hello to the next generation of Search. Live Search – try it now. http://www.live.com/?mkt=en-ca _________________________________________________________________ Ready for the world's first international mobile film festival celebrating the creative potential of today's youth? Check out Mobile Jam Fest for your a chance to WIN $10,000! www.mobilejamfest.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Joseph Kelly