javax.bluetooth.L2CAPConnection Java Examples

The following examples show how to use javax.bluetooth.L2CAPConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BTL2CapListener.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void run() {
	try {
		L2CAPConnection clientConnection;
		CommChannel channel;
		while( (clientConnection = connectionNotifier.acceptAndOpen()) != null ) {
			channel = new BTL2CapCommChannel(
				clientConnection,
				inputPort().location(),
				createProtocol() );
			channel.setParentInputPort( inputPort() );
			interpreter().commCore().scheduleReceive( channel, inputPort() );
			channel = null; // Dispose for garbage collection
		}
	} catch( ClosedByInterruptException ce ) {
		try {
			connectionNotifier.close();
		} catch( IOException ioe ) {
			ioe.printStackTrace();
		}
	} catch( IOException e ) {
		e.printStackTrace();
	}
}
 
Example #2
Source File: MicroeditionConnector.java    From blucat with GNU General Public License v2.0 6 votes vote down vote up
private static int paramL2CAPMTU(Hashtable values, String name) {
	String v = (String) values.get(name);
	if (v == null) {
		if (name.equals(TRANSMIT_MTU)) {
			// This will select RemoteMtu
			return -1;
		} else {
			return L2CAPConnection.DEFAULT_MTU;
		}
	}
	try {
		int mtu = Integer.parseInt(v);
		if (mtu >= L2CAPConnection.MINIMUM_MTU) {
			return mtu;
		}
		if ((mtu > 0) && (mtu < L2CAPConnection.MINIMUM_MTU) && (name.equals(TRANSMIT_MTU))) {
			return L2CAPConnection.MINIMUM_MTU;
		}
	} catch (NumberFormatException e) {
		throw new IllegalArgumentException("invalid MTU value " + v);
	}
	throw new IllegalArgumentException("invalid MTU param value " + name + "=" + v);
}
 
Example #3
Source File: Connection.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
@Override
public L2CAPConnection acceptAndOpen() throws IOException {
	if (serverSocket == null) {
		throw new IOException();
	}
	socket = serverSocket.accept();
	return new L2CAPConnectionImpl(socket);
}
 
Example #4
Source File: BTL2CapCommChannel.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public BTL2CapCommChannel( L2CAPConnection connection, URI location, CommProtocol protocol )
	throws IOException {
	super( location, protocol );
	this.connection = connection;
	sendMTU = connection.getTransmitMTU();
	recvMTU = connection.getReceiveMTU();
	setToBeClosed( false ); // Bluetooth connections are kept open by default.
}
 
Example #5
Source File: L2CAPConnectionImpl.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public int getTransmitMTU() throws IOException {
	return L2CAPConnection.DEFAULT_MTU;
}
 
Example #6
Source File: L2CAPConnectionImpl.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public int getReceiveMTU() throws IOException {
	return L2CAPConnection.DEFAULT_MTU;
}
 
Example #7
Source File: Protocol.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
protected void checkUrl(BluetoothUrl url)
        throws IllegalArgumentException, BluetoothConnectionException {

    if (url.receiveMTU == -1) {
        url.receiveMTU = L2CAPConnection.DEFAULT_MTU;
    }

    if (url.isSystem()) {
        return;
    }

    super.checkUrl(url);

    if (!url.isServer && (url.port <= 0x1000 || url.port >= 0xffff ||
                ((url.port & 1) != 1) || ((url.port & 0x100) != 0))) {
        throw new IllegalArgumentException("Invalid PSM: " + url.port);
    }

    // IMPL_NOTE BluetoothConnectionException should be thrown here
    // It is temporary substituted by IllegalArgumentException
    // to pass TCK succesfully. To be changed back when fixed
    // TCK arrives. The erroneous TCK test is
    // javasoft.sqe.tests.api.javax.bluetooth.Connector.L2Cap.
    //                             openClientTests.L2Cap1014()
    //
    // Correct code here is
    // throw new BluetoothConnectionException(
    //    BluetoothConnectionException.UNACCEPTABLE_PARAMS,
    //    <message>);
    if (url.receiveMTU < L2CAPConnection.MINIMUM_MTU) {
        throw new IllegalArgumentException(
            "Receive MTU is too small");
    }

    if (url.receiveMTU > MAX_STACK_MTU) {
        throw new IllegalArgumentException("Receive MTU is too large");
    }

    if (url.transmitMTU != -1 && url.transmitMTU > MAX_STACK_MTU) {
        throw new BluetoothConnectionException(
            BluetoothConnectionException.UNACCEPTABLE_PARAMS,
            "Transmit MTU is too large");
    }
}
 
Example #8
Source File: SDPClientConnection.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
protected SDPClientConnection(String bluetoothAddress) throws IOException {
    address = bluetoothAddress;
    connection = (L2CAPConnection)SDP.getL2CAPConnection(
        SDP_L2CAP_URL_BEGIN + bluetoothAddress + SDP_L2CAP_URL_END);
    rw = new DataL2CAPReaderWriter(connection);
}
 
Example #9
Source File: SDPClientConnection.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
public L2CAPConnection getL2CAPConnection() {
	return connection;
}
 
Example #10
Source File: DataL2CAPReaderWriter.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
public DataL2CAPReaderWriter(L2CAPConnection con) throws IOException {
    this.con = con;
    writeBuffer = new byte[con.getTransmitMTU()];
    readBuffer = new byte[con.getReceiveMTU()];
}