de.avetana.bluetooth.connection
Class BTConnection

java.lang.Object
  extended byde.avetana.bluetooth.connection.BTConnection
Direct Known Subclasses:
L2CAPConnectionImpl, RFCommConnectionImpl

public class BTConnection
extends java.lang.Object

The top-level connection class.

COPYRIGHT:
(c) Copyright 2004 Avetana GmbH ALL RIGHTS RESERVED.

This file is part of the Avetana bluetooth API for Linux.

The Avetana bluetooth API for Linux is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

The Avetana bluetooth API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

The development of the Avetana bluetooth API is based on the work of Christian Lorenz (see the Javabluetooth Stack at http://www.javabluetooth.org) for some classes, on the work of the jbluez team (see http://jbluez.sourceforge.net/) and on the work of the bluez team (see the BlueZ linux Stack at http://www.bluez.org) for the C code. Classes, part of classes, C functions or part of C functions programmed by these teams and/or persons are explicitly mentioned.



Description:
The top-level connection class. Each connection (whatever the protocol) can be described with at least three variables:

The advantage of such a top-level class is classical: a connection factory can work only with BTConnection instances without special handling and casting for each protocol.
That's why the L2CAPConnectionImpl as well as the RFCommConnection class extends BTConnection. If someone wants to add a new protocol to this JSR82 implementation (like OBEX or SCO), I would suggest that every class dealing with connection (or at least every Object returned by a call to the static method Connector.Open(...)) extends this BTConnection class


Field Summary
protected  boolean closed
          If true, the connection was closed by the client or the server.
protected  java.util.Vector dataBuffer
          This is where incoming data is buffered
protected  int fid
          The connection ID
protected  RemoteDevice m_remote
          The remote device the local BT device is connected to.
 
Constructor Summary
protected BTConnection(int a_fid)
          Creates a new instance of BTConnection and set the value of the connection ID
protected BTConnection(int fid, java.lang.String addr)
          Creates a new instance of BTConnection.
 
Method Summary
protected  int available()
           
 void close()
          Closes the current connection
 int getConnectionID()
          Returns the connection ID
 RemoteDevice getRemoteDevice()
          Returns the remote device
 boolean isClosed()
          Returns the state of the connection
 void newData(byte[] data)
          Called from BlueZ when new data has arrived for that connection
protected  byte[] read(int len)
          Read the most recent packet of data (L2CAP) or all data available < len for RFComm
 void setRemoteDevice(RemoteDevice a_device)
          Sets the remote device
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closed

protected boolean closed
If true, the connection was closed by the client or the server. Default value is false


fid

protected int fid
The connection ID


m_remote

protected RemoteDevice m_remote
The remote device the local BT device is connected to.


dataBuffer

protected java.util.Vector dataBuffer
This is where incoming data is buffered

Constructor Detail

BTConnection

protected BTConnection(int a_fid)
Creates a new instance of BTConnection and set the value of the connection ID

Parameters:
a_fid - The connection ID

BTConnection

protected BTConnection(int fid,
                       java.lang.String addr)
Creates a new instance of BTConnection. Set the value of the connection ID and the address of the remote device

Parameters:
fid - The connection ID
addr - The address of the remote device
Method Detail

setRemoteDevice

public void setRemoteDevice(RemoteDevice a_device)
Sets the remote device

Parameters:
a_device - The new remote device

getRemoteDevice

public RemoteDevice getRemoteDevice()
Returns the remote device

Returns:
The remote device

isClosed

public boolean isClosed()
Returns the state of the connection

Returns:
true - If the connection is closed.
false - Otherwise

getConnectionID

public int getConnectionID()
Returns the connection ID

Returns:
The connection ID

close

public void close()
Closes the current connection


newData

public void newData(byte[] data)
Called from BlueZ when new data has arrived for that connection

Parameters:
data -

read

protected byte[] read(int len)
               throws java.io.IOException
Read the most recent packet of data (L2CAP) or all data available < len for RFComm

Parameters:
len - 0 for L2CAP reading of one packet or > 0 for RFComm to specify the maximum number of bytes requested
Returns:
array with data.
Throws:
java.io.IOException - if the connection is closed.

available

protected int available()
                 throws java.io.IOException
Throws:
java.io.IOException