MoSync 3.0.1
MAUtil::BluetoothConnection Class Reference

Can connect to a Bluetooth service by UUID. Works mostly like a Connection, except the connect() method is different. More...

#include <MAUtil/BluetoothConnection.h>

Inheritance diagram for MAUtil::BluetoothConnection:
MAUtil::Connection MAUtil::BluetoothServiceDiscoveryListener MAUtil::ConnListener

List of all members.

Public Member Functions

 BluetoothConnection (ConnectionListener *listener)
virtual ~BluetoothConnection ()
int connect (const MABtAddr &address, const MAUUID &uuid)
int connect (const char *url)
void close ()
void write (const void *src, int len)
void writeFromData (MAHandle data, int offset, int len)
void recv (void *dst, int maxlen)
void recvToData (MAHandle data, int offset, int maxlen)
void read (void *dst, int len)
void readToData (MAHandle data, int offset, int len)
void setListener (ConnectionListener *listener)
bool isOpen () const
int getAddr (MAConnAddr *dst)

Protected Member Functions

void recvMem (int prevRes)
void recvData (int prevRes)
virtual void connEvent (const MAConnEventData &data)

Protected Attributes

MAHandle mConn
ConnectionListenermListener
int mRemain
bytemDst
MAHandle mData
int mOffset
void(Connection::* mRecv )(int prevRes)

Detailed Description

Can connect to a Bluetooth service by UUID. Works mostly like a Connection, except the connect() method is different.

This class wraps the special behaviour of the Android platform, which does not currently support Bluetooth service discovery.


Constructor & Destructor Documentation

Parameters:
listenerWill receive events from this Connection.

Closes the connection, if open.

See also:
close()

Member Function Documentation

int MAUtil::BluetoothConnection::connect ( const MABtAddr address,
const MAUUID uuid 
)

Asynchronously opens a connection using a Bluetooth address and UUID.

Service discovery is performed. If a service is found, a connection is opened.

This function returns immediately. If the connect operation could be started, the return value will be > 0, and connectFinished() of the ConnectionListener associated with this Connection will be called when the operation is finished.

If the connect operation could NOT be started, the return value will be a CONNERR code < 0, and connectFinished() will not be called.

connectFinished() may use CONNERR_NOTFOUND to indicate that the requested service could not be found.

Parameters:
addressAddress to the remote device.
uuidThe UUID of the service you wish to connect to.
Returns:
> 0 on success, < 0 on error.
int MAUtil::BluetoothConnection::connect ( const char *  url)

Asynchronously opens a connection using a URL that specifies a Bluetooth address and a service UUID.

Service discovery is performed. If a service is found, a connection is opened.

This function returns immediately. If the connect operation could be started, the return value will be > 0, and connectFinished() of the ConnectionListener associated with this Connection will be called when the operation is finished.

If the connect operation could NOT be started, the return value will be a CONNERR code < 0, and connectFinished() will not be called.

connectFinished() may use CONNERR_NOTFOUND to indicate that the requested service could not be found.

Parameters:
urlHas the format: "btspp://<6 byte hex Bluetooth address>:<16 byte hex UUID>" Example: "btspp://38E7D8C7605E:DCBDB690C17111DF851A0800200C9A66"
Returns:
> 0 on success, < 0 on error.
Note:
This function supports only its own form of URL. If you want to use another form with an object of this class, you can call the superclass function with this syntax: btConn.Connection::connect(url)

Reimplemented from MAUtil::Connection.

Closes the connection, if open. Frees all resources allocated by this object. Allows this Connection object to be reused for further connections.

See also:
maConnClose()

Reimplemented from MAUtil::Connection.

void MAUtil::Connection::write ( const void *  src,
int  len 
) [inherited]

Causes ConnectionListener::connWriteFinished() to be called when the operation is complete.

See also:
maConnWrite()
Warning:
The source data must remain available until the operation is complete, so don't use local variables as input.
void MAUtil::Connection::writeFromData ( MAHandle  data,
int  offset,
int  len 
) [inherited]

Causes ConnectionListener::connWriteFinished() to be called when the operation is complete.

See also:
maConnWriteFromData()
void MAUtil::Connection::recv ( void *  dst,
int  maxlen 
) [inherited]

Reads between 1 and maxlen bytes to dst. Causes ConnectionListener::connRecvFinished() to be called when the operation is complete. Use this function when you don't care how much data you get, as long as you get something.

void MAUtil::Connection::recvToData ( MAHandle  data,
int  offset,
int  maxlen 
) [inherited]

Reads between 1 and maxlen bytes to data, starting at offset. Causes ConnectionListener::connRecvFinished() to be called when the operation is complete.

void MAUtil::Connection::read ( void *  dst,
int  len 
) [inherited]

Reads exactly len bytes to dst. Causes ConnectionListener::connReadFinished() to be called when the operation is complete. Use this function when you know exactly how much data you want, and are not interested in anything less.

void MAUtil::Connection::readToData ( MAHandle  data,
int  offset,
int  len 
) [inherited]

Reads exactly len bytes to data, starting at offset. Causes ConnectionListener::connReadFinished() to be called when the operation is complete.

void MAUtil::Connection::setListener ( ConnectionListener listener) [inherited]

Replaces the listener for this object.

Warning:
If you do this while an operation is active, the new listener will recieve the callback, not the old one. This may break your program if it is not aware.
bool MAUtil::Connection::isOpen ( ) const [inherited]

Returns true if the connection is open, false otherwise. The connection is considered open even during the connect() operation.

int MAUtil::Connection::getAddr ( MAConnAddr dst) [inherited]

Retrieves the remote address of this connection.

Returns:
> 0 on success, < 0 on error.
void MAUtil::Connection::recvMem ( int  prevRes) [protected, inherited]
void MAUtil::Connection::recvData ( int  prevRes) [protected, inherited]
virtual void MAUtil::Connection::connEvent ( const MAConnEventData data) [protected, virtual, inherited]

Implements MAUtil::ConnListener.

Reimplemented in MAUtil::HttpConnection.


Member Data Documentation

MAHandle MAUtil::Connection::mConn [protected, inherited]
int MAUtil::Connection::mRemain [protected, inherited]
byte* MAUtil::Connection::mDst [protected, inherited]
MAHandle MAUtil::Connection::mData [protected, inherited]
int MAUtil::Connection::mOffset [protected, inherited]
void(Connection::* MAUtil::Connection::mRecv)(int prevRes) [protected, inherited]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines