Java Code Examples for javax.bluetooth.L2CAPConnection

The following examples show how to use javax.bluetooth.L2CAPConnection. These examples are extracted from open source projects. 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 Project: jolie   Source File: BTL2CapListener.java    License: 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 Project: blucat   Source File: MicroeditionConnector.java    License: 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 Project: J2ME-Loader   Source File: Connection.java    License: 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
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 Project: J2ME-Loader   Source File: L2CAPConnectionImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int getTransmitMTU() throws IOException {
	return L2CAPConnection.DEFAULT_MTU;
}
 
Example 6
Source Project: J2ME-Loader   Source File: L2CAPConnectionImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int getReceiveMTU() throws IOException {
	return L2CAPConnection.DEFAULT_MTU;
}
 
Example 7
Source Project: pluotsorbet   Source File: Protocol.java    License: 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
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
public L2CAPConnection getL2CAPConnection() {
	return connection;
}
 
Example 10
public DataL2CAPReaderWriter(L2CAPConnection con) throws IOException {
    this.con = con;
    writeBuffer = new byte[con.getTransmitMTU()];
    readBuffer = new byte[con.getReceiveMTU()];
}