oasys::BluetoothSocket Class Reference

#include <BluetoothSocket.h>

Inheritance diagram for oasys::BluetoothSocket:

oasys::Logger oasys::IOHandlerBase oasys::BluetoothClient oasys::BluetoothServer oasys::RFCOMMClient oasys::BluetoothServerThread oasys::RFCOMMServer oasys::RFCOMMServerThread dtn::BluetoothConvergenceLayer::Listener

List of all members.


Detailed Description

BluetoothSocket is a base class that wraps around a Bluetooth socket.

It is a base class for RFCOMMClient (possibly others to follow?).

Definition at line 47 of file BluetoothSocket.h.


Public Types

enum  proto_t {
  L2CAP = 0, HCI, SCO, RFCOMM,
  BNEP, CMTP, HIDP, AVDTP
}
 from <bluetooth/bluetooth.h>: define BTPROTO_L2CAP 0 define BTPROTO_HCI 1 define BTPROTO_SCO 2 define BTPROTO_RFCOMM 3 define BTPROTO_BNEP 4 define BTPROTO_CMTP 5 define BTPROTO_HIDP 6 define BTPROTO_AVDTP 7 More...
enum  state_t {
  INIT, LISTENING, CONNECTING, ESTABLISHED,
  RDCLOSED, WRCLOSED, CLOSED, FINI
}
 Socket State values. More...
enum  sockaddr_t { ZERO, LOCAL, REMOTE }

Public Member Functions

 BluetoothSocket (int socktype, proto_t proto, const char *logbase)
 BluetoothSocket (int socktype, proto_t proto, int fd, bdaddr_t remote_addr, u_int8_t channel, const char *logbase)
virtual ~BluetoothSocket ()
void configure ()
 Set the socket parameters.
int async_connect_result ()
 In case connect() was called on a nonblocking socket and returned EINPROGRESS, this fn returns the errno result of the connect attempt.
virtual int poll_sockfd (int events, int *revents, int timeout_ms)
 Wrapper around poll() for this socket's fd.
state_t state ()
 Return the current state.
int fd ()
 The socket file descriptor.
void local_addr (bdaddr_t &addr)
 The local address that the socket is bound to.
u_int8_t channel ()
 The channel that the socket is bound to.
void remote_addr (bdaddr_t &addr)
 The remote address that the socket is bound to.
void set_local_addr (bdaddr_t &addr)
 Set the local address that the socket is bound to.
void set_remote_addr (bdaddr_t &addr)
 Set the remote address that the socket is bound to.
void set_channel (u_int8_t channel)
 Set the channel that the socket is bound to.
void set_logfd (bool logfd)
 socket file descriptor
void init_socket ()
virtual int bind (bdaddr_t local_addr, u_int8_t channel)
 System call wrappers.
virtual int bind ()
 System call wrappers.
virtual int connect (bdaddr_t remote_addr, u_int8_t channel)
 System call wrappers.
virtual int connect ()
 System call wrappers.
virtual int close ()
 System call wrappers.
virtual int shutdown (int how)
 System call wrappers.
virtual int send (const char *bp, size_t len, int flags)
 System call wrappers.
virtual int recv (char *bp, size_t len, int flags)
 System call wrappers.

Static Public Member Functions

static const char * socktypetoa (int socktype)

Public Attributes

struct
oasys::BluetoothSocket::bluetooth_socket_params 
params_
 Socket parameters are public fields that should be set after creating the socket but before the socket is used.

Protected Member Functions

void set_state (state_t state)
const char * statetoa (state_t state)
void set_proto (proto_t proto)
const char * prototoa (proto_t proto)
void get_local ()
void get_remote ()

Protected Attributes

int fd_
int socktype_
state_t state_
int proto_
bool logfd_
bdaddr_t local_addr_
bdaddr_t remote_addr_
u_int8_t channel_
struct sockaddr_rc * rc_

Static Protected Attributes

static int abort_on_error_ = 0

Classes

struct  bluetooth_socket_params
 Socket parameters are public fields that should be set after creating the socket but before the socket is used. More...

Member Enumeration Documentation

enum oasys::BluetoothSocket::proto_t

from <bluetooth/bluetooth.h>: define BTPROTO_L2CAP 0 define BTPROTO_HCI 1 define BTPROTO_SCO 2 define BTPROTO_RFCOMM 3 define BTPROTO_BNEP 4 define BTPROTO_CMTP 5 define BTPROTO_HIDP 6 define BTPROTO_AVDTP 7

Enumerator:
L2CAP 
HCI 
SCO 
RFCOMM 
BNEP 
CMTP 
HIDP 
AVDTP 

Definition at line 61 of file BluetoothSocket.h.

enum oasys::BluetoothSocket::state_t

Socket State values.

Enumerator:
INIT  initial state
LISTENING  server socket, called listen()
CONNECTING  client socket, called connect()
ESTABLISHED  connected socket, data can flow
RDCLOSED  shutdown(SHUT_RD) called, writing still enabled
WRCLOSED  shutdown(SHUT_WR) called, reading still enabled
CLOSED  shutdown called for both read and write
FINI  close() called on the socket

Definition at line 104 of file BluetoothSocket.h.

enum oasys::BluetoothSocket::sockaddr_t

Enumerator:
ZERO 
LOCAL 
REMOTE 

Definition at line 115 of file BluetoothSocket.h.


Constructor & Destructor Documentation

oasys::BluetoothSocket::BluetoothSocket ( int  socktype,
proto_t  proto,
const char *  logbase 
)

Definition at line 27 of file BluetoothSocket.cc.

References channel_, fd_, INIT, local_addr_, logfd_, proto_, remote_addr_, socktype_, and state_.

oasys::BluetoothSocket::BluetoothSocket ( int  socktype,
proto_t  proto,
int  fd,
bdaddr_t  remote_addr,
u_int8_t  channel,
const char *  logbase 
)

Definition at line 42 of file BluetoothSocket.cc.

References BDADDR_ANY, configure(), ESTABLISHED, fd_, local_addr_, oasys::Logger::logpathf(), proto_, prototoa(), set_channel(), set_remote_addr(), socktype_, and state_.

oasys::BluetoothSocket::~BluetoothSocket (  )  [virtual]

Definition at line 59 of file BluetoothSocket.cc.

References close().


Member Function Documentation

void oasys::BluetoothSocket::configure (  ) 

Set the socket parameters.

Definition at line 273 of file BluetoothSocket.cc.

References ASSERT, errno, fd_, oasys::LOG_DEBUG, oasys::LOG_WARN, oasys::Logger::logf(), params_, oasys::BluetoothSocket::bluetooth_socket_params::recv_bufsize_, oasys::BluetoothSocket::bluetooth_socket_params::reuseaddr_, and oasys::BluetoothSocket::bluetooth_socket_params::send_bufsize_.

Referenced by BluetoothSocket(), and init_socket().

int oasys::BluetoothSocket::bind ( bdaddr_t  local_addr,
u_int8_t  channel 
) [virtual]

System call wrappers.

Definition at line 141 of file BluetoothSocket.cc.

References ASSERT, bd2str, bind(), channel_, close(), errno, fd_, init_socket(), local_addr_, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), params_, proto_, prototoa(), rc_, RFCOMM, set_channel(), set_local_addr(), and oasys::BluetoothSocket::bluetooth_socket_params::silent_connect_.

Referenced by dtn::BluetoothConvergenceLayer::interface_up().

int oasys::BluetoothSocket::bind (  )  [virtual]

System call wrappers.

Definition at line 182 of file BluetoothSocket.cc.

References channel_, and local_addr_.

Referenced by bind(), oasys::BluetoothServerThread::bind_listen_start(), oasys::RFCOMMServerThread::rc_bind(), and oasys::RFCOMMClient::rc_connect().

int oasys::BluetoothSocket::connect ( bdaddr_t  remote_addr,
u_int8_t  channel 
) [virtual]

System call wrappers.

Definition at line 264 of file BluetoothSocket.cc.

References connect(), set_channel(), and set_remote_addr().

Referenced by dtn::BluetoothConvergenceLayer::Connection::connect().

int oasys::BluetoothSocket::connect (  )  [virtual]

System call wrappers.

Definition at line 188 of file BluetoothSocket.cc.

References ASSERT, bd2str, channel_, close(), CONNECTING, errno, ESTABLISHED, fd_, init_socket(), log_debug, log_err, params_, proto_, prototoa(), rc_, remote_addr_, RFCOMM, set_state(), oasys::BluetoothSocket::bluetooth_socket_params::silent_connect_, and state_.

Referenced by connect(), and oasys::RFCOMMClient::rc_connect().

int oasys::BluetoothSocket::close (  )  [virtual]

System call wrappers.

Definition at line 313 of file BluetoothSocket.cc.

References ASSERT, errno, fd_, FINI, INIT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), set_state(), state_, and statetoa().

Referenced by bind(), connect(), dtn::BluetoothConvergenceLayer::Connection::disconnect(), init_socket(), oasys::RFCOMMServerThread::rc_bind(), oasys::RFCOMMClient::rc_connect(), oasys::BluetoothServerThread::run(), and ~BluetoothSocket().

int oasys::BluetoothSocket::shutdown ( int  how  )  [virtual]

System call wrappers.

Definition at line 334 of file BluetoothSocket.cc.

References ASSERT, CLOSED, errno, ESTABLISHED, fd_, FINI, INIT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), RDCLOSED, set_state(), state_, statetoa(), and WRCLOSED.

int oasys::BluetoothSocket::send ( const char *  bp,
size_t  len,
int  flags 
) [virtual]

System call wrappers.

Definition at line 380 of file BluetoothSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::send().

int oasys::BluetoothSocket::recv ( char *  bp,
size_t  len,
int  flags 
) [virtual]

System call wrappers.

Definition at line 386 of file BluetoothSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::recv().

int oasys::BluetoothSocket::async_connect_result (  ) 

In case connect() was called on a nonblocking socket and returned EINPROGRESS, this fn returns the errno result of the connect attempt.

It also sets the socket state appropriately

Definition at line 244 of file BluetoothSocket.cc.

References ASSERT, CONNECTING, errno, ESTABLISHED, fd_, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), and state_.

int oasys::BluetoothSocket::poll_sockfd ( int  events,
int *  revents,
int  timeout_ms 
) [virtual]

Wrapper around poll() for this socket's fd.

Definition at line 487 of file BluetoothSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::poll_single().

Referenced by oasys::BluetoothServer::timeout_accept().

static const char* oasys::BluetoothSocket::socktypetoa ( int  socktype  )  [inline, static]

Definition at line 122 of file BluetoothSocket.h.

state_t oasys::BluetoothSocket::state (  )  [inline]

Return the current state.

Definition at line 137 of file BluetoothSocket.h.

References state_.

Referenced by dtn::BluetoothConvergenceLayer::Connection::accept(), dtn::BluetoothConvergenceLayer::Connection::connect(), and dtn::BluetoothConvergenceLayer::Connection::disconnect().

int oasys::BluetoothSocket::fd (  ) 

The socket file descriptor.

Definition at line 392 of file BluetoothSocket.cc.

References fd_.

Referenced by dtn::BluetoothConvergenceLayer::Connection::initialize_pollfds(), and oasys::BluetoothServerThread::run().

void oasys::BluetoothSocket::local_addr ( bdaddr_t &  addr  ) 

The local address that the socket is bound to.

Definition at line 398 of file BluetoothSocket.cc.

References get_local(), and local_addr_.

Referenced by dtn::BluetoothConvergenceLayer::dump_interface().

u_int8_t oasys::BluetoothSocket::channel (  ) 

The channel that the socket is bound to.

Definition at line 405 of file BluetoothSocket.cc.

References channel_, and get_local().

Referenced by dtn::BluetoothConvergenceLayer::Connection::connect(), dtn::BluetoothConvergenceLayer::dump_interface(), and oasys::BluetoothServerThread::run().

void oasys::BluetoothSocket::remote_addr ( bdaddr_t &  addr  ) 

The remote address that the socket is bound to.

Definition at line 412 of file BluetoothSocket.cc.

References get_remote(), and remote_addr_.

Referenced by dtn::BluetoothConvergenceLayer::Connection::accept(), and dtn::BluetoothConvergenceLayer::Connection::connect().

void oasys::BluetoothSocket::set_local_addr ( bdaddr_t &  addr  ) 

Set the local address that the socket is bound to.

Definition at line 419 of file BluetoothSocket.cc.

References local_addr_.

Referenced by bind(), and dtn::BluetoothConvergenceLayer::Connection::Connection().

void oasys::BluetoothSocket::set_remote_addr ( bdaddr_t &  addr  ) 

Set the remote address that the socket is bound to.

Definition at line 433 of file BluetoothSocket.cc.

References remote_addr_.

Referenced by BluetoothSocket(), connect(), dtn::BluetoothConvergenceLayer::Connection::Connection(), oasys::RFCOMMClient::rc_connect(), and oasys::BluetoothServerThread::run().

void oasys::BluetoothSocket::set_channel ( u_int8_t  channel  ) 

Set the channel that the socket is bound to.

Definition at line 425 of file BluetoothSocket.cc.

References ASSERT, and channel_.

Referenced by bind(), BluetoothSocket(), connect(), and dtn::BluetoothConvergenceLayer::Connection::Connection().

void oasys::BluetoothSocket::set_logfd ( bool  logfd  )  [inline]

socket file descriptor

Definition at line 178 of file BluetoothSocket.h.

References logfd_.

Referenced by dtn::BluetoothConvergenceLayer::Connection::Connection().

void oasys::BluetoothSocket::init_socket (  ) 

Definition at line 65 of file BluetoothSocket.cc.

References ASSERT, close(), configure(), errno, fd_, FINI, INIT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), logfd_, oasys::Logger::logpath_appendf(), proto_, prototoa(), socktype_, and state_.

Referenced by bind(), connect(), and dtn::BluetoothConvergenceLayer::Connection::Connection().

void oasys::BluetoothSocket::set_state ( state_t  state  )  [protected]

Definition at line 108 of file BluetoothSocket.cc.

References oasys::LOG_DEBUG, oasys::Logger::logf(), state_, and statetoa().

Referenced by close(), connect(), oasys::BluetoothServer::listen(), and shutdown().

const char * oasys::BluetoothSocket::statetoa ( state_t  state  )  [protected]

Definition at line 91 of file BluetoothSocket.cc.

References ASSERT, CLOSED, CONNECTING, ESTABLISHED, FINI, INIT, LISTENING, RDCLOSED, and WRCLOSED.

Referenced by oasys::BluetoothServer::accept(), close(), set_state(), and shutdown().

void oasys::BluetoothSocket::set_proto ( proto_t  proto  )  [protected]

Definition at line 133 of file BluetoothSocket.cc.

References oasys::LOG_DEBUG, oasys::Logger::logf(), proto_, and prototoa().

const char * oasys::BluetoothSocket::prototoa ( proto_t  proto  )  [protected]

Definition at line 116 of file BluetoothSocket.cc.

References ASSERT, AVDTP, BNEP, CMTP, HCI, HIDP, L2CAP, RFCOMM, and SCO.

Referenced by oasys::BluetoothServer::accept(), bind(), BluetoothSocket(), connect(), get_local(), get_remote(), init_socket(), and set_proto().

void oasys::BluetoothSocket::get_local (  )  [protected]

Definition at line 439 of file BluetoothSocket.cc.

References channel_, fd_, local_addr_, proto_, prototoa(), rc_, and RFCOMM.

Referenced by channel(), and local_addr().

void oasys::BluetoothSocket::get_remote (  )  [protected]

Definition at line 463 of file BluetoothSocket.cc.

References channel_, fd_, proto_, prototoa(), rc_, remote_addr_, and RFCOMM.

Referenced by remote_addr().


Member Data Documentation

struct oasys::BluetoothSocket::bluetooth_socket_params oasys::BluetoothSocket::params_

Socket parameters are public fields that should be set after creating the socket but before the socket is used.

Referenced by bind(), configure(), connect(), and oasys::RFCOMMClient::rc_connect().

int oasys::BluetoothSocket::abort_on_error_ = 0 [static, protected]

Definition at line 189 of file BluetoothSocket.h.

int oasys::BluetoothSocket::fd_ [protected]

Definition at line 190 of file BluetoothSocket.h.

Referenced by oasys::BluetoothServer::accept(), async_connect_result(), bind(), BluetoothSocket(), close(), configure(), connect(), fd(), get_local(), oasys::BluetoothClient::get_nonblocking(), get_remote(), init_socket(), oasys::BluetoothServer::listen(), poll_sockfd(), oasys::BluetoothClient::read(), oasys::BluetoothClient::readall(), oasys::BluetoothClient::readv(), oasys::BluetoothClient::readvall(), recv(), send(), oasys::BluetoothClient::set_nonblocking(), shutdown(), oasys::BluetoothClient::timeout_read(), oasys::BluetoothClient::timeout_readall(), oasys::BluetoothClient::timeout_readv(), oasys::BluetoothClient::timeout_readvall(), oasys::BluetoothClient::timeout_write(), oasys::BluetoothClient::timeout_writeall(), oasys::BluetoothClient::timeout_writev(), oasys::BluetoothClient::timeout_writevall(), oasys::BluetoothClient::write(), oasys::BluetoothClient::writeall(), oasys::BluetoothClient::writev(), and oasys::BluetoothClient::writevall().

int oasys::BluetoothSocket::socktype_ [protected]

Definition at line 191 of file BluetoothSocket.h.

Referenced by BluetoothSocket(), and init_socket().

state_t oasys::BluetoothSocket::state_ [protected]

Definition at line 192 of file BluetoothSocket.h.

Referenced by oasys::BluetoothServer::accept(), async_connect_result(), BluetoothSocket(), close(), connect(), init_socket(), set_state(), shutdown(), and state().

int oasys::BluetoothSocket::proto_ [protected]

Definition at line 193 of file BluetoothSocket.h.

Referenced by oasys::BluetoothServer::accept(), bind(), BluetoothSocket(), connect(), get_local(), get_remote(), init_socket(), and set_proto().

bool oasys::BluetoothSocket::logfd_ [protected]

Definition at line 194 of file BluetoothSocket.h.

Referenced by BluetoothSocket(), init_socket(), dtn::BluetoothConvergenceLayer::Listener::Listener(), and set_logfd().

bdaddr_t oasys::BluetoothSocket::local_addr_ [protected]

Definition at line 195 of file BluetoothSocket.h.

Referenced by bind(), BluetoothSocket(), get_local(), local_addr(), oasys::RFCOMMServerThread::rc_bind(), oasys::RFCOMMClient::rc_connect(), and set_local_addr().

bdaddr_t oasys::BluetoothSocket::remote_addr_ [protected]

Definition at line 196 of file BluetoothSocket.h.

Referenced by BluetoothSocket(), connect(), get_remote(), oasys::RFCOMMClient::rc_connect(), remote_addr(), and set_remote_addr().

u_int8_t oasys::BluetoothSocket::channel_ [protected]

Definition at line 197 of file BluetoothSocket.h.

Referenced by bind(), BluetoothSocket(), channel(), connect(), get_local(), get_remote(), oasys::RFCOMMServerThread::rc_bind(), oasys::RFCOMMClient::rc_connect(), and set_channel().

struct sockaddr_rc* oasys::BluetoothSocket::rc_ [read, protected]

Definition at line 198 of file BluetoothSocket.h.

Referenced by oasys::BluetoothServer::accept(), bind(), connect(), get_local(), and get_remote().


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