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 31 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.
bdaddr_t local_addr ()
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.
bdaddr_t remote_addr ()
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
bool reuse_addr ()
void reuse_addr (bool b)
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

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 init_sa (int zero=(int) ZERO)
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 ()
bdaddr_t * sa_baddr ()
u_int8_t sa_channel ()

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_
sockaddr * sa_
int slen_
sockaddr_rc * rc_
bool reuse_addr_
bool silent_connect_

Static Protected Attributes

static int abort_on_error_

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 45 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 88 of file BluetoothSocket.h.

enum oasys::BluetoothSocket::sockaddr_t

Enumerator:
ZERO 
LOCAL 
REMOTE 

Definition at line 99 of file BluetoothSocket.h.


Constructor & Destructor Documentation

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

Definition at line 22 of file BluetoothSocket.cc.

References channel_, fd_, INIT, local_addr_, logfd_, proto_, remote_addr_, reuse_addr_, sa_, silent_connect_, slen_, 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 41 of file BluetoothSocket.cc.

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

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

Definition at line 60 of file BluetoothSocket.cc.

References close(), and sa_.


Member Function Documentation

void oasys::BluetoothSocket::configure (  ) 

Set the socket parameters.

Definition at line 200 of file BluetoothSocket.cc.

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

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 94 of file BluetoothSocket.cc.

References oasys::Bluetooth::batostr(), bind(), channel_, close(), errno, fd_, init_sa(), init_socket(), LOCAL, local_addr_, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), sa_, set_local_addr(), silent_connect_, and slen_.

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

System call wrappers.

Definition at line 123 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 129 of file BluetoothSocket.cc.

References oasys::Bluetooth::batostr(), channel_, close(), connect(), CONNECTING, errno, ESTABLISHED, fd_, init_sa(), init_socket(), log_debug, log_err, rc_, REMOTE, remote_addr_, sa_, set_remote_addr(), set_state(), silent_connect_, and slen_.

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

System call wrappers.

Definition at line 194 of file BluetoothSocket.cc.

References channel_, and remote_addr_.

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

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

System call wrappers.

Definition at line 241 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 dtn::BluetoothConvergenceLayer::Listener::accepted(), bind(), dtn::BluetoothConvergenceLayer::Connection::break_contact(), connect(), dtn::BluetoothConvergenceLayer::Connection::connect(), init_socket(), dtn::BluetoothConvergenceLayer::interface_down(), 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 262 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 358 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 364 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 174 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 574 of file BluetoothSocket.cc.

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

Referenced by oasys::BluetoothServer::accept(), dtn::BluetoothConvergenceLayer::Connection::send_bundle(), and oasys::BluetoothServer::timeout_accept().

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

Definition at line 106 of file BluetoothSocket.h.

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

Return the current state.

Definition at line 121 of file BluetoothSocket.h.

References state_.

Referenced by dtn::BluetoothConvergenceLayer::Connection::break_contact(), dtn::BluetoothConvergenceLayer::Connection::connect(), dtn::BluetoothConvergenceLayer::Connection::send_announce(), and dtn::BluetoothConvergenceLayer::Connection::send_loop().

int oasys::BluetoothSocket::fd (  ) 

The socket file descriptor.

Definition at line 370 of file BluetoothSocket.cc.

References fd_.

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

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

The local address that the socket is bound to.

Definition at line 383 of file BluetoothSocket.cc.

References get_local(), and local_addr_.

bdaddr_t oasys::BluetoothSocket::local_addr (  ) 

Definition at line 376 of file BluetoothSocket.cc.

References BDADDR_ANY, get_local(), and local_addr_.

u_int8_t oasys::BluetoothSocket::channel (  ) 

The channel that the socket is bound to.

Definition at line 390 of file BluetoothSocket.cc.

References channel_, and get_local().

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

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

The remote address that the socket is bound to.

Definition at line 404 of file BluetoothSocket.cc.

References get_remote(), and remote_addr_.

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

bdaddr_t oasys::BluetoothSocket::remote_addr (  ) 

Definition at line 397 of file BluetoothSocket.cc.

References BDADDR_ANY, get_remote(), and remote_addr_.

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

Set the local address that the socket is bound to.

Definition at line 411 of file BluetoothSocket.cc.

References local_addr_.

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

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

Set the remote address that the socket is bound to.

Definition at line 425 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 417 of file BluetoothSocket.cc.

References ASSERT, and channel_.

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

socket file descriptor

Definition at line 162 of file BluetoothSocket.h.

References logfd_.

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

bool oasys::BluetoothSocket::reuse_addr (  )  [inline]

Definition at line 164 of file BluetoothSocket.h.

References reuse_addr_.

void oasys::BluetoothSocket::reuse_addr ( bool  b  )  [inline]

Definition at line 165 of file BluetoothSocket.h.

References reuse_addr_.

void oasys::BluetoothSocket::init_socket (  ) 

Definition at line 68 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(), and connect().

void oasys::BluetoothSocket::init_sa ( int  zero = (int) ZERO  )  [protected]

Definition at line 536 of file BluetoothSocket.cc.

References ASSERT, AVDTP, BNEP, channel_, CMTP, HCI, HIDP, L2CAP, LOCAL, local_addr_, proto_, rc_, remote_addr_, RFCOMM, sa_, SCO, slen_, and ZERO.

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

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

Definition at line 325 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 308 of file BluetoothSocket.cc.

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

Referenced by close(), set_state(), and shutdown().

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

Definition at line 350 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 333 of file BluetoothSocket.cc.

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

Referenced by BluetoothSocket(), init_socket(), and set_proto().

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

Definition at line 431 of file BluetoothSocket.cc.

References AVDTP, BNEP, channel_, CMTP, fd_, HCI, HIDP, init_sa(), L2CAP, local_addr_, proto_, rc_, RFCOMM, sa_, SCO, and ZERO.

Referenced by channel(), and local_addr().

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

Definition at line 507 of file BluetoothSocket.cc.

References AVDTP, BNEP, channel_, CMTP, fd_, HCI, HIDP, init_sa(), L2CAP, proto_, rc_, remote_addr_, RFCOMM, sa_, SCO, and ZERO.

Referenced by remote_addr().

bdaddr_t * oasys::BluetoothSocket::sa_baddr (  )  [protected]

Definition at line 461 of file BluetoothSocket.cc.

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

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

u_int8_t oasys::BluetoothSocket::sa_channel (  )  [protected]

Definition at line 484 of file BluetoothSocket.cc.

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

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


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.

Reimplemented in dtn::BluetoothConvergenceLayer::Listener.

Referenced by configure().

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

Definition at line 178 of file BluetoothSocket.h.

int oasys::BluetoothSocket::fd_ [protected]

Definition at line 179 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 180 of file BluetoothSocket.h.

Referenced by BluetoothSocket(), and init_socket().

state_t oasys::BluetoothSocket::state_ [protected]

Definition at line 181 of file BluetoothSocket.h.

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

int oasys::BluetoothSocket::proto_ [protected]

Definition at line 182 of file BluetoothSocket.h.

Referenced by BluetoothSocket(), get_local(), get_remote(), init_sa(), init_socket(), sa_baddr(), sa_channel(), and set_proto().

bool oasys::BluetoothSocket::logfd_ [protected]

Definition at line 183 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 184 of file BluetoothSocket.h.

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

bdaddr_t oasys::BluetoothSocket::remote_addr_ [protected]

Definition at line 185 of file BluetoothSocket.h.

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

u_int8_t oasys::BluetoothSocket::channel_ [protected]

Definition at line 186 of file BluetoothSocket.h.

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

struct sockaddr* oasys::BluetoothSocket::sa_ [protected]

Definition at line 187 of file BluetoothSocket.h.

Referenced by oasys::BluetoothServer::accept(), bind(), BluetoothSocket(), connect(), get_local(), get_remote(), init_sa(), sa_baddr(), sa_channel(), and ~BluetoothSocket().

int oasys::BluetoothSocket::slen_ [protected]

Definition at line 188 of file BluetoothSocket.h.

Referenced by oasys::BluetoothServer::accept(), bind(), BluetoothSocket(), connect(), and init_sa().

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

Definition at line 189 of file BluetoothSocket.h.

Referenced by connect(), get_local(), get_remote(), init_sa(), sa_baddr(), and sa_channel().

bool oasys::BluetoothSocket::reuse_addr_ [protected]

Definition at line 190 of file BluetoothSocket.h.

Referenced by BluetoothSocket(), and reuse_addr().

bool oasys::BluetoothSocket::silent_connect_ [protected]

Definition at line 191 of file BluetoothSocket.h.

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


The documentation for this class was generated from the following files:
Generated on Fri Dec 22 14:48:05 2006 for DTN Reference Implementation by  doxygen 1.5.1