Methods Summary |
---|
private native boolean | askFriendlyName(java.lang.String addr)Passes remote device's friendly name acquisition request to the native
porting layer.
|
public java.lang.String | askFriendlyNameSync(java.lang.String addr)Retrieves friendly name from a remote device synchronously.
if (!askFriendlyName(addr)) {
return null;
}
nameResults.remove(addr);
startPolling();
return (String)waitResult(nameResults, addr,
ASK_FRIENDLY_NAME_TIMEOUT);
|
private native boolean | authenticate(java.lang.String addr)Passes remote device authentication request to the native porting layer.
|
public boolean | authenticateSync(java.lang.String addr)Performs remote device authentication synchronously.
if (!authenticate(addr)) {
return false;
}
int handle = getHandle(addr);
authenticateResults.remove(new Integer(handle));
startPolling();
Boolean result = (Boolean)waitResult(authenticateResults,
new Integer(handle), AUTHENTICATE_TIMEOUT);
if (result == null) {
return false;
}
return result.booleanValue();
|
public boolean | cancelInquiry(javax.bluetooth.DiscoveryListener listener)Removes the device from inquiry mode.
if (discListener != listener) {
return false;
}
if (cancelInquiry()) {
stopPolling();
discListener = null;
return true;
}
return false;
|
private native boolean | cancelInquiry()Passes cancellation of device discovery request to the native porting
layer.
|
private native boolean | checkEvents()Checks if Bluetooth events are available on the native porting layer.
|
public native boolean | enable()Enables Bluetooth radio.
|
private native boolean | encrypt(java.lang.String addr, boolean enable)Passes connection encryption change request to the native porting layer.
|
public boolean | encryptSync(java.lang.String addr, boolean enable)Sets encryption mode synchronously.
if (!encrypt(addr, enable)) {
return false;
}
int handle = getHandle(addr);
encryptResults.remove(new Integer(handle));
startPolling();
Boolean result = (Boolean)waitResult(encryptResults,
new Integer(handle), ENCRYPT_TIMEOUT);
if (result == null) {
return false;
}
return result.booleanValue();
|
private native void | finalize()Releases native resources.
|
public native int | getAccessCode()Retrieves the inquiry access code that the local Bluetooth device is
scanning for during inquiry scans.
|
public native int | getDeviceClass()Returns class of device including service classes.
|
public static synchronized com.sun.midp.jsr082.bluetooth.BluetoothStack | getEnabledInstance()Returns a BluetoothStack object and guarantees that Bluetooth
radio is on.
getInstance();
if (!instance.isEnabled() && !instance.enable()) {
throw new BluetoothStateException("Failed turning Bluetooth on");
}
// intent here is launching EmulationPolling and SDPServer
// in emulation mode
com.sun.kvem.jsr082.bluetooth.SDDB.getInstance();
return instance;
|
private native int | getHandle(java.lang.String addr)Retrieves default ACL connection handle for the specified remote device.
|
public static synchronized com.sun.midp.jsr082.bluetooth.BluetoothStack | getInstance()Returns a BluetoothStack object.
if (instance == null) {
// Note to porting engineer: please replace the class name with
// the one you intend to use on the target platform.
instance = new GenericBluetoothStack();
}
return instance;
|
public native java.lang.String | getLocalAddress()Returns Bluetooth address of the local device.
|
public native java.lang.String | getLocalName()Returns user-friendly name for the local device.
|
private native void | initialize()Allocates native resources.
|
public native boolean | isEnabled()Checks if the Bluetooth radio is enabled.
|
void | onAuthenticationComplete(int handle, boolean result)Called when an authentication request is completed.
stopPolling();
putResult(authenticateResults, new Integer(handle),
new Boolean(result));
|
void | onEncryptionChange(int handle, boolean result)Called when a set encryption request is completed.
stopPolling();
putResult(encryptResults, new Integer(handle), new Boolean(result));
|
void | onInquiryComplete(boolean success)Called when an inquiry request is completed.
if (discListener == null) {
return;
}
stopPolling();
discListener = null;
inquiryHistory.removeAllElements();
int type = success ? DiscoveryListener.INQUIRY_COMPLETED :
DiscoveryListener.INQUIRY_ERROR;
DiscoveryAgentImpl.getInstance().inquiryCompleted(type);
|
void | onInquiryResult(InquiryResult result)Called when an inquiry result is obtained.
if (discListener == null) {
return;
}
String addr = result.getAddress();
Enumeration e = inquiryHistory.elements();
while (e.hasMoreElements()) {
InquiryResult oldResult = (InquiryResult)e.nextElement();
if (oldResult.getAddress().equals(addr)) {
// inquiry result is already in our possession
return;
}
}
inquiryHistory.addElement(result);
RemoteDevice dev
= DiscoveryAgentImpl.getInstance().getRemoteDevice(addr);
DiscoveryAgentImpl.getInstance().addCachedDevice(addr);
discListener.deviceDiscovered(dev, result.getDeviceClass());
|
void | onNameRetrieve(java.lang.String addr, java.lang.String name)Called when a name retrieval request is completed.
stopPolling();
putResult(nameResults, addr, name);
|
public void | pollEvents()Checks for Bluetooth events and processes them.
while (checkEvents()) {
BluetoothEvent event = retrieveEvent();
if (event != null) {
event.dispatch();
}
}
|
private void | putResult(java.util.Hashtable hashtable, java.lang.Object key, java.lang.Object value)Puts result value into hastable and notifies threads waiting for the
result to appear.
synchronized (hashtable) {
hashtable.put(key, value);
hashtable.notify();
}
|
protected native int | readData(byte[] data)Reads binary event data from the native porting layer. This data can
be interpreted differently by different subclasses of BluetoothStack.
|
protected abstract BluetoothEvent | retrieveEvent()Retrieves Bluetooth event.
|
public native boolean | setAccessCode(int accessCode)Sets the inquiry access code that the local Bluetooth device is
scanning for during inquiry scans.
|
public native boolean | setServiceClasses(int classes)Sets major service class bits of the device.
|
public boolean | startInquiry(int accessCode, javax.bluetooth.DiscoveryListener listener)Places the device into inquiry mode.
if (discListener != null || listener == null) {
return false;
}
discListener = listener;
if (startInquiry(accessCode)) {
inquiryHistory.removeAllElements();
startPolling();
return true;
}
return false;
|
private native boolean | startInquiry(int accessCode)Passes device discovery request to the native porting layer.
|
public synchronized void | startPolling()Starts a supplementary polling thread.
pollRequests++;
PollingThread.resume();
|
public synchronized void | stopPolling()Cancels event polling for one request. Polling thread will continue to
run unless there are no other pending requests.
pollRequests--;
if (pollRequests > 0) {
return;
}
PollingThread.suspend();
|
protected static native java.lang.String | stringUTF8(byte[] buffer, int offset, int length)Creates Java String object from UTF-8 encoded string.
|
private java.lang.Object | waitResult(java.util.Hashtable hashtable, java.lang.Object key, long timeout)Waits for the specified key to appear in the given hastable. If the key
does not appear within the timeout specified, null value is
returned.
synchronized (hashtable) {
if (timeout == 0) {
// infinite timeout
while (true) {
if (hashtable.containsKey(key)) {
return hashtable.remove(key);
}
try {
// wait for a new key-value pair to appear in hashtable
hashtable.wait();
} catch (InterruptedException e) {
return null;
}
}
}
// endTime indicates time up to which the method is allowed to run
long endTime = System.currentTimeMillis() + timeout;
while (true) {
if (hashtable.containsKey(key)) {
return hashtable.remove(key);
}
// update timeout value
timeout = endTime - System.currentTimeMillis();
if (timeout <= 0) {
return null;
}
try {
// wait for a new key-value pair to appear in hashtable
hashtable.wait(timeout);
} catch (InterruptedException e) {
return null;
}
}
}
|