Fields Summary |
---|
private int | handleIdentidies this connection at native layer,
-1 if connection is not open. |
int | peerHandleTemporary stores peer's native handle for accepted connection.
Used by doAccept method. |
byte[] | peerAddressTemporary stores remote device address for accepted connection. |
private boolean | isListenModeIndicates whether notifier is listening for incoming connections. |
private int | cidChannel Id. |
private DataElement | CHANNEL_IDKeeps channel id for service record validation. |
static final DataElement | L2CAP_UUIDKeeps L2CAP UUID for service record validation. |
static final DataElement | RFCOMM_UUIDKeeps RFCOMM UUID for service record validation. |
static final DataElement | SPP_UUIDKeeps SPP UUID for service record validation. |
private int | pushHandleBluetooth PushRegistry handle, used in native methods only. |
Methods Summary |
---|
private native int | accept0()Accepts incoming client connection request.
Note: the method gets native connection handle directly from
handle field of BTSPPNotifierImpl object.
Note: new native connection handle to work with accepted incoming
client connection is setted directly to handle field of
appropriate BTSPPConnectionImpl object.
|
public javax.microedition.io.StreamConnection | acceptAndOpen()Accepts client connection to the service this notifier is assigned to.
Adds corresponding service record to the SDDB, blocks until a successfull
connection to a client is established, retrieves the connection.
ensureConnectable();
// switch on listen mode if it has not been done yet
doListen();
// adds the record only if is not yet in SDDB
SDDB.getInstance().updateServiceRecord(serviceRec);
StreamConnection client;
do {
ensureConnectable();
// accept incoming connections if any
client = doAccept();
} while (client == null);
return client;
|
protected void | checkServiceRecord()Ensures that the service record is valid.
synchronized (serviceRec) {
// check if the ServiceClassIDList is not missing
if (serviceRec.getAttributeValue(
ServiceRecordImpl.SERVICE_CLASS_ATTR_ID) == null) {
throw new ServiceRegistrationException(
"ServiceClassIDList is missing.");
}
// check the ProtocolList is not missed
DataElement protocolList = serviceRec.getAttributeValue(
ServiceRecordImpl.PROTOCOL_DESCRIPTOR_LIST);
if (protocolList == null) {
throw new ServiceRegistrationException(
"ProtocolDescriptorList is missing.");
}
Enumeration protocolListEnum =
(Enumeration)protocolList.getValue();
boolean l2cap = false;
boolean rfcomm = false;
while (protocolListEnum.hasMoreElements()) {
Enumeration protocolEnum = (Enumeration)((DataElement)
protocolListEnum.nextElement()).getValue();
// check that L2CAP/RFCOMM UUIDs are not missing, check the CN
// is not missing and the value has not changed
while (protocolEnum.hasMoreElements()) {
DataElement element = (DataElement)protocolEnum.
nextElement();
if (compareDataElements(element, L2CAP_UUID)) {
l2cap = true;
}
if (compareDataElements(element, RFCOMM_UUID)) {
rfcomm = true;
if (!protocolEnum.hasMoreElements() ||
!compareDataElements((DataElement)protocolEnum.
nextElement(), CHANNEL_ID)) {
throw new ServiceRegistrationException(
"Channel value has changed.");
}
}
if (l2cap && rfcomm) {
return;
}
}
}
}
throw new ServiceRegistrationException("L2CAP UUID is missing.");
|
public void | close()Closes this notifier making corresponding service record inaccessible.
updates the information on the communication server.
if (isClosed) {
return;
}
isClosed = true;
SDDB.getInstance().removeServiceRecord(serviceRec);
doClose();
|
private native void | close0()Closes this server connection.
Releases all native resources (such as sockets) owned by this notifier.
Note: the method gets native connection handle directly from
handle field of BTSPPNotifierImpl object.
|
private native int | create0(boolean auth, boolean authz, boolean enc, boolean master)Creates a server connection.
Note: the method sets native connection handle directly to
handle field of BTSPPNotifierImpl object.
|
public static com.sun.kvem.jsr082.bluetooth.ServiceRecordImpl | createServiceRecord(com.sun.midp.io.j2me.btspp.BTSPPNotifierImpl notifier, com.sun.midp.io.BluetoothUrl url, int cn)Creates an empty service record for the given URL and channel value.
DataElement serviceList = new DataElement(DataElement.DATSEQ);
serviceList.addElement(new DataElement(DataElement.UUID,
new UUID(url.uuid, false)));
serviceList.addElement(SPP_UUID);
DataElement protocolList = new DataElement(DataElement.DATSEQ);
DataElement protocol = new DataElement(DataElement.DATSEQ);
protocol.addElement(L2CAP_UUID);
protocolList.addElement(protocol);
protocol = new DataElement(DataElement.DATSEQ);
protocol.addElement(RFCOMM_UUID);
if (notifier != null) {
notifier.CHANNEL_ID = new DataElement(DataElement.U_INT_1, cn);
protocol.addElement(notifier.CHANNEL_ID);
} else {
protocol.addElement(new DataElement(DataElement.U_INT_1, cn));
}
protocolList.addElement(protocol);
int[] attrIDs;
DataElement[] attrVals;
if (url.name != null) {
DataElement name = new DataElement(DataElement.STRING, url.name);
attrIDs = new int[] {
ServiceRecordImpl.SERVICE_CLASS_ATTR_ID,
ServiceRecordImpl.PROTOCOL_DESCRIPTOR_LIST,
ServiceRecordImpl.NAME_ATTR_ID
};
attrVals = new DataElement[] { serviceList, protocolList, name };
} else {
attrIDs = new int[] {
ServiceRecordImpl.SERVICE_CLASS_ATTR_ID,
ServiceRecordImpl.PROTOCOL_DESCRIPTOR_LIST
};
attrVals = new DataElement[] { serviceList, protocolList };
}
return new ServiceRecordImpl(notifier, attrIDs, attrVals);
|
public static com.sun.kvem.jsr082.bluetooth.ServiceRecordImpl | createServiceRecord(java.lang.String url)Creates an empty service record for the given URL
return createServiceRecord(null, new BluetoothUrl(url), 0);
|
private javax.microedition.io.StreamConnection | doAccept()Advertises acception by calling underlying stack methods.
if (!isListenMode) {
throw new BluetoothStateException("Device is not in listen mode");
}
/*
* Note: native handle is set to peerHandleID field directly
* by accept0 method and retrieved by L2CAPConnectionImpl constructor.
*/
accept0();
return new BTSPPConnectionImpl(url, mode, this);
|
private void | doClose()Closes this notifier at native layer.
close0();
|
private int | doCreate(com.sun.midp.io.BluetoothUrl url)Creates an instanse of server connection at native layer.
return create0(url.authenticate, url.authorize,
url.encrypt, url.master);
|
private void | doListen()Force listen mode by calling underlying stack methods.
// force listening if it had not been done yet
if (!isListenMode) {
listen0();
isListenMode = true;
}
|
private void | ensureConnectable()Ensures that this notifier can accept connections.
if (isClosed) {
throw new BluetoothConnectionException(
BluetoothConnectionException.FAILED_NOINFO,
"Notifier is closed.");
}
if (!BCC.getInstance().isConnectable()) {
throw new BluetoothStateException("The device is not connectable.");
}
checkServiceRecord();
|
private native void | finalize()Native finalizer.
Releases all native resources used by this connection.
|
private static native void | initialize()Native static class initializer.
|
private native void | listen0()Force Bluetooth stack to listen for incoming client connections.
Note: the method gets native connection handle directly from
handle field of BTSPPNotifierImpl object.
|
private native boolean | pushCheckout(java.lang.String url, int suiteId)Checks out (takes ownership of) an active server connection maintained
by push subsystem.
|