SelectServiceHandlerpublic final class SelectServiceHandler extends Object implements javax.bluetooth.DiscoveryListenerThis class represents the module which is used by
DiscoveryAgent#selectService method implementation. |
Fields Summary |
---|
private static final boolean | DEBUGSet to false in RR version - then the javac skip the code. | private Vector | btDevs | private Hashtable | btDevsHash | private Object | btDevsLock | private boolean | selectDevDisStarted | private boolean | selectDevDisStopped | private DiscoveryAgentImpl | agent |
Constructors Summary |
---|
SelectServiceHandler(DiscoveryAgentImpl agent)Constructs SelectServiceHandler for
DiscoveryAgentImpl given.
this.agent = agent;
|
Methods Summary |
---|
public void | deviceDiscovered(javax.bluetooth.RemoteDevice btDevice, javax.bluetooth.DeviceClass cod)
// if this bloototh device was found in preknown or
// cached devices skips it now.
if (btDevsHash.put(btDevice, btDevice) == null) {
btDevs.addElement(btDevice);
}
| public void | inquiryCompleted(int discType)
synchronized (btDevsLock) {
selectDevDisStopped = true;
btDevsLock.notify();
}
| private java.lang.String | selectFromDevicesList(javax.bluetooth.RemoteDevice[] devs, javax.bluetooth.UUID uuid, int security, boolean master, java.util.Hashtable disDevsHash)
if (devs == null) {
return null;
}
for (int i = 0; i < devs.length; i++) {
if (disDevsHash.put(devs[i], devs[i]) != null) {
continue;
}
String url = selectService(devs[i], uuid, security, master);
if (url != null) {
if (DEBUG) {
System.out.println("\turl=" + url);
}
return url;
}
}
return null;
| java.lang.String | selectService(javax.bluetooth.UUID uuid, int security, boolean master)
if (DEBUG) {
System.out.println("selectService:");
System.out.println("\tuuid=" + uuid);
}
Vector disDevsVector = null;
Hashtable disDevsHash = new Hashtable();
if (uuid == null) {
throw new NullPointerException("uuid is null");
}
// check in CACHED and PREKNOWN devices
String url = selectFromDevicesList(agent.retrieveDevices(
DiscoveryAgent.PREKNOWN), uuid, security, master, disDevsHash);
if (url != null) {
return url;
}
url = selectFromDevicesList(agent.retrieveDevices(
DiscoveryAgent.CACHED), uuid, security, master, disDevsHash);
if (url != null) {
return url;
}
// start own device discovery now
synchronized (btDevsLock) {
if (selectDevDisStarted) {
throw new BluetoothStateException(
"The previous device discovery is running...");
}
selectDevDisStarted = true;
btDevs = new Vector();
btDevsHash = disDevsHash;
}
try {
agent.startInquiry(DiscoveryAgent.GIAC, this);
} catch (BluetoothStateException btse) {
synchronized (btDevsLock) {
selectDevDisStarted = false;
btDevs = null;
btDevsHash = null;
}
throw btse;
}
synchronized (btDevsLock) {
if (!selectDevDisStopped) {
try {
btDevsLock.wait();
} catch (InterruptedException ie) {
// ignore (breake waiting)
}
disDevsVector = btDevs;
btDevs = null;
btDevsHash = null;
selectDevDisStarted = false;
selectDevDisStopped = false;
}
}
for (int i = 0; i < disDevsVector.size(); i++) {
RemoteDevice btDev = (RemoteDevice) disDevsVector.elementAt(i);
url = selectService(btDev, uuid, security, master);
if (url != null) {
if (DEBUG) {
System.out.println("\turl=" + url);
}
return url;
}
}
if (DEBUG) {
System.out.println("\turl=null");
}
return null;
| private java.lang.String | selectService(javax.bluetooth.RemoteDevice btDev, javax.bluetooth.UUID uuid, int security, boolean master)
UUID[] uuidSet = new UUID[] {uuid};
ServiceSelector selector = new ServiceSelector(null, uuidSet, btDev);
ServiceRecord serRec = selector.getServiceRecord();
if (serRec == null) {
return null;
} else {
return serRec.getConnectionURL(security, master);
}
| public void | serviceSearchCompleted(int transID, int respCode)
throw new RuntimeException("unexpected call");
| public void | servicesDiscovered(int transID, javax.bluetooth.ServiceRecord[] servRecord)
throw new RuntimeException("unexpected call");
|
|