hyperionjv / bluecove

Automatically exported from code.google.com/p/bluecove
0 stars 0 forks source link

2 adapters #85

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

Hello there...
I'm trying to run the following code:

BlueCoveImpl.useThreadLocalBluetoothStack();
BlueCoveImpl.setConfigProperty("bluecove.deviceID", "0");

 final Object id1 = BlueCoveImpl.getThreadBluetoothStackID();
 ... do some work with stack 1

Thread t1 = new Thread() {
    public void run() {
        BlueCoveImpl.setThreadBluetoothStackID(id1);
        agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
        agent.startInquiry(...);
        .....
    }
 };
 t1.start();

 Thread t2 = new Thread() {
    public void run() { BlueCoveImpl.setConfigProperty("bluecove.deviceID",
"1");
        agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
        agent.startInquiry(...);
        .....
    }
 }
 t2.start();

The first time I run it, both adapters work in parallel using the threads. 

As soon a the inquiry is completed I use t1.start(); and t2.start(); The
first Thread works fine, but the second thread doesn't, the exception is : 
javax.bluetooth.BluetoothStateException: LocalDevice 1 alredy in use

The first adapter (using the t1 thread) continues working in a infinite loop.

Any ideas?

Regards.

Original issue reported on code.google.com by rmoren...@gmail.com on 23 Sep 2009 at 9:58

GoogleCodeExporter commented 9 years ago
If you want to share the same adapter in multiple threads you need to 
initialize it
once in one thread.
---
BlueCoveImpl.useThreadLocalBluetoothStack();
BlueCoveImpl.setConfigProperty("bluecove.deviceID", "1");

final Object id2 = BlueCoveImpl.getThreadBluetoothStackID();
---

And then use it in all other threads lie this:
---
BlueCoveImpl.setThreadBluetoothStackID(id2);
----

New thread with code 
BlueCoveImpl.setConfigProperty("bluecove.deviceID", "1");
Will try to initiate the adapter again and should fail...

Original comment by skarzhev...@gmail.com on 8 Jan 2010 at 5:07