de.avetana.bluetooth.connection
Class ConnectionFactory

java.lang.Object
  extended byde.avetana.bluetooth.connection.ConnectionFactory

public class ConnectionFactory
extends java.lang.Object

The class used to manage connections at the application level.

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:
One of the request of the JSR82 specification is to be able to test if a device is connected or not. For example the method javax.bluetooth.RemoteDevice.authenticate() must throw an exception if it is called for a remote device which is not connected with any local device. There is two ways of handling such a request:

The second solution was choosed because it is operating system independant and moreover, because it allows to better manage the error cases.
The task of the ConnectionFactory class is therefore to store all existing client and server connections but also to be able to identify the DiscoveryListener associated with a specified device.


Constructor Summary
ConnectionFactory()
          Creates a new ConnectionFactory object.
 
Method Summary
 void addConnection(BTConnection desc)
          Adds a connection to the list of registered connections
 void addListener(int transactionID, DiscoveryListener list)
          Registers a new DiscoveryListener.
 void addNotifier(ConnectionNotifier desc)
          Registers a new connection notifier
 BTConnection getConnectionForFID(int fid)
          Returns the connection for a given fid
 java.util.Vector getConnections()
          Returns the list of all registered connections.
 DiscoveryListener getListener(int id)
          Returns the DiscoveryListener associated with a remote device
 java.util.Vector getNotifiers()
          Returns the list of all registered notifiers.
 BTConnection isConnected(RemoteDevice dev)
          Tells if a remote device is currently connected with a local device
 boolean isListener(int transID)
           
 boolean removeConnection(BTConnection desc)
          Unregisters a Connection
 boolean removeConnection(int fid)
          Unregisters the Connection identified by its connection ID
 void removeListener(int transID)
           
 boolean removeNotifier(ConnectionNotifier desc)
          Unregisters a Connection notifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionFactory

public ConnectionFactory()
Creates a new ConnectionFactory object. Initialize all encapsulated variables.

Method Detail

addConnection

public void addConnection(BTConnection desc)
Adds a connection to the list of registered connections

Parameters:
desc - The unregistered connection

getConnections

public java.util.Vector getConnections()
Returns the list of all registered connections.

Returns:
A vector storing all registered connections

getConnectionForFID

public BTConnection getConnectionForFID(int fid)
Returns the connection for a given fid

Parameters:
fid -
Returns:

getNotifiers

public java.util.Vector getNotifiers()
Returns the list of all registered notifiers.

Returns:
A vector storing all registered notifiers

removeConnection

public boolean removeConnection(BTConnection desc)
Unregisters a Connection

Parameters:
desc - The registered connection
Returns:
true - if the connection was successfully unregistered
false - Otherwise.

addNotifier

public void addNotifier(ConnectionNotifier desc)
Registers a new connection notifier

Parameters:
desc - A new and unregistered connection notifier

removeNotifier

public boolean removeNotifier(ConnectionNotifier desc)
Unregisters a Connection notifier

Parameters:
desc - The registered connection notifier
Returns:
true - if the connection notifier was successfully unregistered
false - Otherwise.

removeConnection

public boolean removeConnection(int fid)
Unregisters the Connection identified by its connection ID

Parameters:
fid - The ID of the registered connection
Returns:
true - if the connection was successfully unregistered
false - Otherwise.

addListener

public void addListener(int transactionID,
                        DiscoveryListener list)
Registers a new DiscoveryListener.

Parameters:
list - The Discoverylistener associated with this remote device

isListener

public boolean isListener(int transID)

removeListener

public void removeListener(int transID)

getListener

public DiscoveryListener getListener(int id)
Returns the DiscoveryListener associated with a remote device

Returns:
The DiscoveryListener associated with a remote device

isConnected

public BTConnection isConnected(RemoteDevice dev)
Tells if a remote device is currently connected with a local device

Parameters:
dev - The remote device
Returns:
The BTConnection object - If the remote device is currently connected null - If the remote device is not connected.