de.avetana.bluetooth.connection
Class ConnectionNotifier

java.lang.Object
  extended byde.avetana.bluetooth.connection.ConnectionNotifier
All Implemented Interfaces:
Connection
Direct Known Subclasses:
L2CAPConnectionNotifierImpl, RFCommConnectionNotifierImpl

public abstract class ConnectionNotifier
extends java.lang.Object
implements Connection

The top-level connection notifier 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 class for connection notifiers.
Depending on the protocol, connection notifiers can differently implement the method AcceptAndOpen() but if only some method implementations differ, the principles of a JSR82 connection notifier remain for each protocol: a service record, a connection ID, a connection URL and a remote device. This class encapsulates the common properties of JSR82 notifiers and is therefore the class used in the ConnectionFactory.


Field Summary
protected  java.io.IOException failEx
          When registering of a connection fails, the reason is given here
protected  boolean isClosed
          Is the connection with the remote device closed?
protected  int m_fid
          The connection ID
protected  RemoteDevice m_remote
          The remote device
protected  int m_serverFid
          When a connection listener is established, its ID is stored as m_serverFid.
protected  long m_serviceHandle
          The service record handle
protected  BTConnection myConnection
          The current connection of this notifier
protected  ServiceRecord myRecord
          The local service record
protected  JSR82URL parsedURL
          The connection URL used to create the local service
 
Constructor Summary
ConnectionNotifier()
           
 
Method Summary
protected  void acceptAndOpenI()
          Waits for a client to connect to this service.
 void close()
          Closes the connection NOTIFIER (and not the connection itself) .
 JSR82URL getConnectionURL()
          Returns the connection URL
 RemoteDevice getRemoteDevice()
          Return the remote connections end
 long getServiceHandle()
          Returns the service record handle
 ServiceRecord getServiceRecord()
          Returns the local service record
 boolean isNotifierClosed()
          Gets the state of the notifier
 boolean isServiceRegistered()
          Gets the registration state of the local service
 void removeNotifier()
          Remove the notifier and the SDP Record
 void setConnectionID(int fid)
          Sets the connection ID
 void setFailure(java.io.IOException e)
           
 void setRemoteDevice(java.lang.String addr)
          Sets the remote device
 void setServerFID(int fid)
          Sets the connection ID
 void setServiceRecord(ServiceRecord a_record)
          Sets the local service record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_fid

protected int m_fid
The connection ID


myConnection

protected BTConnection myConnection
The current connection of this notifier


m_serverFid

protected int m_serverFid
When a connection listener is established, its ID is stored as m_serverFid. When the Notifier is closed m_serverFid will be closed too.


failEx

protected java.io.IOException failEx
When registering of a connection fails, the reason is given here


m_serviceHandle

protected long m_serviceHandle
The service record handle


myRecord

protected ServiceRecord myRecord
The local service record


isClosed

protected boolean isClosed
Is the connection with the remote device closed?


parsedURL

protected JSR82URL parsedURL
The connection URL used to create the local service


m_remote

protected RemoteDevice m_remote
The remote device

Constructor Detail

ConnectionNotifier

public ConnectionNotifier()
Method Detail

setConnectionID

public void setConnectionID(int fid)
Sets the connection ID

Parameters:
fid - The connection ID

setServerFID

public void setServerFID(int fid)
Sets the connection ID

Parameters:
fid - The connection ID

setFailure

public void setFailure(java.io.IOException e)

setRemoteDevice

public void setRemoteDevice(java.lang.String addr)
Sets the remote device

Parameters:
addr - The BT address of the remote device

getServiceHandle

public long getServiceHandle()
Returns the service record handle

Returns:
The service record handle

getConnectionURL

public JSR82URL getConnectionURL()
Returns the connection URL

Returns:
The connection URL

getRemoteDevice

public RemoteDevice getRemoteDevice()
Return the remote connections end

Returns:

getServiceRecord

public ServiceRecord getServiceRecord()
Returns the local service record

Returns:
The local service record

isServiceRegistered

public boolean isServiceRegistered()
Gets the registration state of the local service

Returns:
true - If the service is registered
false - Otherwise

isNotifierClosed

public boolean isNotifierClosed()
Gets the state of the notifier

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

setServiceRecord

public void setServiceRecord(ServiceRecord a_record)
                      throws java.lang.Exception
Sets the local service record.
BEWARE: this method does not update the service reocrd in the BCC

Parameters:
a_record - The new loca lservice record
Throws:
java.lang.Exception - ClassCastException - If the new local service record is not an instance of LocalServiceRecord

removeNotifier

public void removeNotifier()
Remove the notifier and the SDP Record


close

public void close()
Closes the connection NOTIFIER (and not the connection itself) .

Specified by:
close in interface Connection

acceptAndOpenI

protected void acceptAndOpenI()
                       throws java.io.IOException,
                              ServiceRegistrationException
Waits for a client to connect to this service. This method is called from the subClasses acceptAndOpen method

Throws:
java.io.IOException
ServiceRegistrationException