Fields Summary |
---|
private static final boolean | DEBUG |
private static DiscoveryAgentImpl | instanceKeeps an instance to the object of this class to be
accessible from the implementation. |
private Hashtable | knownDevicesKeeps the RemoteDeviceImpl references of known devices. |
private Hashtable | cachedDevicesKeeps the RemoteDeviceImpl references of cached devices. |
private javax.bluetooth.DiscoveryListener | d_listenerKeeps the listener of the device discovery inquire.
Also, it is used as flag that a device is in inquire mode. |
private Object | d_lockKeeps the lock object for device discovery synchronization. |
private SelectServiceHandler | selectServiceHandlerKeeps the reference to module responsible for selecting services. |
Methods Summary |
---|
public void | addCachedDevice(java.lang.String addr)Adds address of remote device found during inquiry request to internal
inquiry cache.
The method does nothing if the RemoteDevice is already in the cache.
RemoteDevice rd = getRemoteDevice(addr);
synchronized (cachedDevices) {
cachedDevices.put(addr, rd);
}
|
public boolean | cancelInquiry(javax.bluetooth.DiscoveryListener listener)
if (listener == null) {
throw new NullPointerException("null listener");
}
synchronized (d_lock) {
// no inquiry was started
if (d_listener == null) {
return false;
}
// not valid listener
if (d_listener != listener) {
return false;
}
// process the inquiry in the device specific way
cancelInquiry();
}
inquiryCompleted(DiscoveryListener.INQUIRY_TERMINATED);
return true;
|
private void | cancelInquiry()Cancels inquiry in device specific way.
BluetoothStack.getInstance().cancelInquiry(d_listener);
|
public boolean | cancelServiceSearch(int transID)
if (DEBUG) {
System.out.println("cancelServiceSearch: transID=" + transID);
}
return ServiceSearcher.cancel(transID);
|
private javax.bluetooth.RemoteDevice[] | getCachedDevices()
synchronized (cachedDevices) {
int len = cachedDevices.size();
if (len == 0) {
return null;
}
RemoteDevice[] res = new RemoteDevice[len];
Enumeration e = cachedDevices.elements();
for (int i = 0; e.hasMoreElements(); i++) {
res[i] = (RemoteDevice)e.nextElement();
}
return res;
}
|
public static synchronized com.sun.kvem.jsr082.bluetooth.DiscoveryAgentImpl | getInstance()Returns the instance of this singleton constructing it if needed.
if (instance == null) {
instance = new DiscoveryAgentImpl();
}
return instance;
|
public RemoteDeviceImpl | getRemoteDevice(java.lang.String addr)Porting interface: this method is used by the device specific
implementation to create the RemoteDevice object by address.
Also, this method puts the new remote devices into cache of
known devices.
synchronized (knownDevices) {
addr = addr.toUpperCase();
RemoteDeviceImpl rd = (RemoteDeviceImpl) knownDevices.get(addr);
if (rd == null) {
rd = new RemoteDeviceImpl(addr);
knownDevices.put(addr, rd);
}
return rd;
}
|
public void | inquiryCompleted(int discType)Porting interface: this method is used by the device specific
implementation to notify this class, that the current inquire
has been completed.
DiscoveryListener listener;
synchronized (d_lock) {
listener = d_listener;
d_listener = null;
}
new Completed(listener, discType);
|
public javax.bluetooth.RemoteDevice[] | retrieveDevices(int option)
switch (option) {
case DiscoveryAgent.CACHED:
// IMPL_NOTE: use native cache keeping addresses of found devices
// to share the cache between multiple isolates
return getCachedDevices();
case DiscoveryAgent.PREKNOWN:
Vector pk = BCC.getInstance().getPreknownDevices();
if (pk == null || pk.size() == 0) {
return null;
}
RemoteDevice[] res = new RemoteDevice[pk.size()];
for (int i = 0; i < pk.size(); i++) {
String addr = (String)pk.elementAt(i);
res[i] = getRemoteDevice(addr);
}
return res;
default:
throw new IllegalArgumentException("Invalid option value: "
+ option);
}
|
public int | searchServices(int[] attrSet, javax.bluetooth.UUID[] uuidSet, javax.bluetooth.RemoteDevice btDev, javax.bluetooth.DiscoveryListener discListener)
if (DEBUG) {
System.out.println("searchServices: ");
System.out.println("\tattrSet=" + attrSet);
if (attrSet != null) {
for (int i = 0; i < attrSet.length; i++) {
System.out.println("\tattrSet[" + i + "]=0x" + attrSet[i]);
}
}
System.out.println("\tuuidSet=" + uuidSet);
if (uuidSet != null) {
for (int i = 0; i < uuidSet.length; i++) {
System.out.println("\tuuidSet[" + i + "]=" + uuidSet[i]);
}
}
System.out.println("\tadderess=" + btDev.getBluetoothAddress());
}
ServiceSearcher searcher = new ServiceSearcher(attrSet, uuidSet,
btDev, discListener);
// the 'transID' is assigned by service discoverer (searcher)
int transID = searcher.start();
if (DEBUG) {
System.out.println("\ttransID=" + transID);
}
return transID;
|
public java.lang.String | selectService(javax.bluetooth.UUID uuid, int security, boolean master)
// use the separated class to light this one
return selectServiceHandler.selectService(uuid, security, master);
|
public boolean | startInquiry(int accessCode, javax.bluetooth.DiscoveryListener listener)
if (accessCode != DiscoveryAgent.GIAC &&
accessCode != DiscoveryAgent.LIAC &&
(accessCode < 0x9E8B00 || accessCode > 0x9E8B3F)) {
throw new IllegalArgumentException("Access code is out of range: "
+ accessCode);
}
if (listener == null) {
throw new NullPointerException("null listener");
}
// IMPL_NOTE see
// kvem/classes/com/sun/kvem/jsr082/impl/bluetooth/
// BTDeviceDiscoverer.java
// heck what access codes should be supported.
// Return false if access code is not supported.
synchronized (d_lock) {
if (d_listener != null) {
throw new BluetoothStateException(
"The previous device discovery is running...");
}
d_listener = listener;
// process the inquiry in the device specific way
return startInquiry(accessCode);
}
|
private boolean | startInquiry(int accessCode)
return BluetoothStack.getEnabledInstance().startInquiry(
accessCode, d_listener);
|