oasys::BluetoothServerThread Class Reference

#include <BluetoothServer.h>

Inheritance diagram for oasys::BluetoothServerThread:

oasys::BluetoothServer oasys::Thread oasys::BluetoothSocket oasys::Logger oasys::IOHandlerBase oasys::RFCOMMServerThread dtn::BluetoothConvergenceLayer::Listener

List of all members.


Detailed Description

Simple class that implements a thread of control that loops, blocking on accept(), and issuing the accepted() callback when new connections arrive.

Definition at line 61 of file BluetoothServer.h.


Public Member Functions

 BluetoothServerThread (int socktype, BluetoothSocket::proto_t proto, const char *name, char *logbase="/btserver", int flags=0, int accept_timeout=-1)
virtual void accepted (int fd, bdaddr_t addr, u_int8_t channel)=0
 Virtual callback hook that gets called when new connections arrive.
void run ()
 Loop forever, issuing blocking calls to BluetoothServer::accept(), then calling the accepted() function when new connections arrive.
int bind_listen_start (bdaddr_t local_addr, u_int8_t local_channel)

Protected Attributes

int accept_timeout_
 If not -1, then call timeout_accept in the main loop.

Constructor & Destructor Documentation

oasys::BluetoothServerThread::BluetoothServerThread ( int  socktype,
BluetoothSocket::proto_t  proto,
const char *  name,
char *  logbase = "/btserver",
int  flags = 0,
int  accept_timeout = -1 
) [inline]

Definition at line 63 of file BluetoothServer.h.


Member Function Documentation

virtual void oasys::BluetoothServerThread::accepted ( int  fd,
bdaddr_t  addr,
u_int8_t  channel 
) [pure virtual]

Virtual callback hook that gets called when new connections arrive.

Implemented in dtn::BluetoothConvergenceLayer::Listener.

Referenced by run().

void oasys::BluetoothServerThread::run (  )  [virtual]

Loop forever, issuing blocking calls to BluetoothServer::accept(), then calling the accepted() function when new connections arrive.

Note that unlike in the Thread base class, this run() method is public in case we don't want to actually create a new thread for this guy, but instead just want to run the main loop.

Implements oasys::Thread.

Definition at line 112 of file BluetoothServer.cc.

References oasys::BluetoothServer::accept(), accept_timeout_, accepted(), ASSERT, bd2str, oasys::BluetoothSocket::channel(), oasys::BluetoothSocket::close(), errno, oasys::BluetoothSocket::fd(), oasys::IOINTR, oasys::IOTIMEOUT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), oasys::BluetoothSocket::set_remote_addr(), oasys::Thread::should_stop(), and oasys::BluetoothServer::timeout_accept().

int oasys::BluetoothServerThread::bind_listen_start ( bdaddr_t  local_addr,
u_int8_t  local_channel 
)

Bind to an address, open the channel for listening and start the thread.

Most uses of BluetoothServerThread will simply call these functions in sequence, so this helper function is to merge such redundancy.

Returns:
-1 on error, 0 otherwise.

Definition at line 158 of file BluetoothServer.cc.

References oasys::BluetoothSocket::bind(), oasys::BluetoothServer::listen(), and oasys::Thread::start().


Member Data Documentation

int oasys::BluetoothServerThread::accept_timeout_ [protected]

If not -1, then call timeout_accept in the main loop.

This gives a caller a (rough) way to stop the thread by calling set_should_stop() and then waiting for the accept call to timeout, at which point the bit will be checked.

Definition at line 105 of file BluetoothServer.h.

Referenced by run(), and oasys::RFCOMMServerThread::set_accept_timeout().


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 08:43:50 2007 for DTN Reference Implementation by  doxygen 1.5.3