bluegammon.io
Class BluetoothFacade

java.lang.Object
  extended bybluegammon.io.BluetoothFacade
All Implemented Interfaces:
javax.bluetooth.DiscoveryListener

public class BluetoothFacade
extends java.lang.Object
implements javax.bluetooth.DiscoveryListener

Facade for JSR82, connecting via the btspp protocol.

Author:
Peter Andersson

Field Summary
static java.lang.String BT_PROTOCOL
          Protocol
 
Fields inherited from interface javax.bluetooth.DiscoveryListener
INQUIRY_COMPLETED, INQUIRY_ERROR, INQUIRY_TERMINATED, SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_DEVICE_NOT_REACHABLE, SERVICE_SEARCH_ERROR, SERVICE_SEARCH_NO_RECORDS, SERVICE_SEARCH_TERMINATED
 
Constructor Summary
BluetoothFacade()
           
 
Method Summary
 void closeServer(java.lang.String serviceNumber)
          Closes the server setup for specified service ID.
 javax.microedition.io.StreamConnection connect(javax.bluetooth.ServiceRecord record)
          Returns a client StreamConnection for specified service record.
 javax.microedition.io.StreamConnection connect(java.lang.String serviceNumber, javax.bluetooth.RemoteDevice device)
          Returns a client StreamConnection for specified device and service number.
 void deviceDiscovered(javax.bluetooth.RemoteDevice btDevice, javax.bluetooth.DeviceClass cod)
           
 java.util.Vector findDevices()
          Returns all devices nearby.
 void inquiryCompleted(int discType)
           
 void servicesDiscovered(int transID, javax.bluetooth.ServiceRecord[] records)
           
 void serviceSearchCompleted(int transID, int respCode)
           
 javax.microedition.io.StreamConnection waitForClient(java.lang.String serviceNumber)
          Setups a server if needed and returns a client.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BT_PROTOCOL

public static final java.lang.String BT_PROTOCOL
Protocol

See Also:
Constant Field Values
Constructor Detail

BluetoothFacade

public BluetoothFacade()
Method Detail

findDevices

public java.util.Vector findDevices()
                             throws java.io.IOException
Returns all devices nearby. This method blocks until discovery is finished.

Returns:
a Vector of RemoteDevices.
Throws:
java.io.IOException

connect

public javax.microedition.io.StreamConnection connect(java.lang.String serviceNumber,
                                                      javax.bluetooth.RemoteDevice device)
                                               throws java.io.IOException
Returns a client StreamConnection for specified device and service number. This method searches for bluetooth services on specified device. If no service with specified service number is found, null is returned.

Parameters:
serviceNumber - The ID for the provided service
device - The device to connect to
Returns:
A streamconnection or null if service not provided by device
Throws:
java.io.IOException

connect

public javax.microedition.io.StreamConnection connect(javax.bluetooth.ServiceRecord record)
                                               throws java.io.IOException
Returns a client StreamConnection for specified service record.

Parameters:
record - The service record
Returns:
A streamconnection
Throws:
java.io.IOException

waitForClient

public javax.microedition.io.StreamConnection waitForClient(java.lang.String serviceNumber)
                                                     throws java.io.IOException
Setups a server if needed and returns a client. This method blocks until a client is connected. If multiple clients are allowed to be connected, simply call this method multiple times.

Parameters:
serviceNumber - The ID for the provided service
Returns:
A streamconnection
Throws:
java.io.IOException

closeServer

public void closeServer(java.lang.String serviceNumber)
                 throws java.io.IOException
Closes the server setup for specified service ID.

Parameters:
serviceNumber - The ID for the provided service
Throws:
java.io.IOException

servicesDiscovered

public void servicesDiscovered(int transID,
                               javax.bluetooth.ServiceRecord[] records)
Specified by:
servicesDiscovered in interface javax.bluetooth.DiscoveryListener

serviceSearchCompleted

public void serviceSearchCompleted(int transID,
                                   int respCode)
Specified by:
serviceSearchCompleted in interface javax.bluetooth.DiscoveryListener

deviceDiscovered

public void deviceDiscovered(javax.bluetooth.RemoteDevice btDevice,
                             javax.bluetooth.DeviceClass cod)
Specified by:
deviceDiscovered in interface javax.bluetooth.DiscoveryListener

inquiryCompleted

public void inquiryCompleted(int discType)
Specified by:
inquiryCompleted in interface javax.bluetooth.DiscoveryListener