Intra2net AG

libt2n::server Class Reference

server base class More...

#include <server.hxx>

Inheritance diagram for libt2n::server:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual ~server ()
void set_default_timeout (int _default_timeout)
 set the default timeout for new client connections
int get_default_timeout (void)
 get the current default timeout for client connections
void set_logging (std::ostream *_logstream, log_level_values _log_level)
 activate logging to the given stream. everything above the given level is logged.
server_connectionget_connection (unsigned int conn_id)
 Gets a connection by id.
void add_callback (callback_event_type event, const boost::function< void(unsigned int)> &func)
 add a callback
virtual bool fill_buffer (long long usec_timeout=-1, long long *usec_timeout_remaining=NULL)=0
 look for new data and store it in the local buffer
void close ()
void cleanup ()
 check for timeouts, remove closed connections. don't forget to call this from time to time.
bool get_packet (std::string &data)
 get a complete data packet from any client. The packet is removed from the connection buffer.
bool get_packet (std::string &data, unsigned int &conn_id)
 get a complete data packet from any client. The packet is removed from the connection buffer.
std::ostream * get_logstream (log_level_values level)
 get pointer to logging stream, returns NULL if no logging needed

Protected Member Functions

 server ()
virtual bool fill_connection_buffers (void)=0
unsigned int add_connection (server_connection *newconn)
 add a new connection to the server
void do_callbacks (callback_event_type event, unsigned int conn_id)
 an event occured, call all server-side callbacks

Protected Attributes

std::map< unsigned int,
server_connection * > 
connections

Private Attributes

int default_timeout
log_level_values log_level
std::ostream * logstream
std::vector< std::list
< boost::function< void(unsigned
int)> > > 
callbacks
 vector initialized for all callback-types, all elements in each list will be called
unsigned int next_id

Detailed Description

server base class

constitutes a server. is abstract, use derived classes like socket_server.


Constructor & Destructor Documentation

libt2n::server::server (  )  [protected]
libt2n::server::~server (  )  [virtual]

References connections.


Member Function Documentation

void libt2n::server::add_callback ( callback_event_type  event,
const boost::function< void(unsigned int)> &  func 
)

add a callback

Parameters:
event event the function will be called at
func functor (see boost::function) that will be called
Note:
use boost::bind to bind to member functions like this: s.add_callback(new_connection,boost::bind(&my_class::func_to_call_back, boost::ref(*this), _1));

References callbacks, connections, and libt2n::new_connection.

Referenced by libt2n::command_server::command_server().

unsigned int libt2n::server::add_connection ( server_connection newconn  )  [protected]
void libt2n::server::cleanup (  ) 

check for timeouts, remove closed connections. don't forget to call this from time to time.

References connections, libt2n::debug, and LOGSTREAM.

Referenced by libt2n::command_server::handle().

void libt2n::server::close (  ) 

Close all open connections

References connections.

Referenced by libt2n::socket_server::~socket_server().

void libt2n::server::do_callbacks ( callback_event_type  event,
unsigned int  conn_id 
) [protected]

an event occured, call all server-side callbacks

Parameters:
event event that occured
conn_id connection-id parameter that will be given to the callback-function

References callbacks.

Referenced by add_connection().

virtual bool libt2n::server::fill_buffer ( long long  usec_timeout = -1,
long long *  usec_timeout_remaining = NULL 
) [pure virtual]

look for new data and store it in the local buffer

Parameters:
usec_timeout wait until new data is found, max timeout usecs. -1: wait endless 0: return instantly
usec_timeout_remaining if non-NULL the function will write the not used time to the given target
Return values:
true if new data was found (does not mean that the received data is a complete packet though)

Implemented in libt2n::socket_server.

Referenced by libt2n::command_server::handle().

virtual bool libt2n::server::fill_connection_buffers ( void   )  [protected, pure virtual]

Implemented in libt2n::socket_server.

server_connection * libt2n::server::get_connection ( unsigned int  conn_id  ) 

Gets a connection by id.

Parameters:
conn_id Connection ID
Return values:
Pointer to connection object

References connections.

Referenced by libt2n::command_server::handle(), and libt2n::command_server::send_hello().

int libt2n::server::get_default_timeout ( void   )  [inline]

get the current default timeout for client connections

References default_timeout.

Referenced by libt2n::socket_server::new_connection().

std::ostream * libt2n::server::get_logstream ( log_level_values  level  ) 

get pointer to logging stream, returns NULL if no logging needed

Reimplemented in libt2n::socket_server.

References log_level, and logstream.

Referenced by libt2n::server_connection::get_logstream(), libt2n::command_server::get_logstream(), and libt2n::command_server::handle_packet().

bool libt2n::server::get_packet ( std::string &  data,
unsigned int &  conn_id 
)

get a complete data packet from any client. The packet is removed from the connection buffer.

Parameters:
[out] data the data package
[out] conn_id the connection id we got this packet from
Return values:
true if packet found

References connections, libt2n::debug, and LOGSTREAM.

bool libt2n::server::get_packet ( std::string &  data  )  [inline]

get a complete data packet from any client. The packet is removed from the connection buffer.

Parameters:
[out] data the data package
Return values:
true if packet found

References get_packet().

Referenced by get_packet(), and libt2n::command_server::handle().

void libt2n::server::set_default_timeout ( int  _default_timeout  )  [inline]

set the default timeout for new client connections

References default_timeout.

Referenced by server().

void libt2n::server::set_logging ( std::ostream *  _logstream,
log_level_values  _log_level 
)

activate logging to the given stream. everything above the given level is logged.

References log_level, and logstream.

Referenced by server().


Member Data Documentation

std::vector<std::list<boost::function<void (unsigned int)> > > libt2n::server::callbacks [private]

vector initialized for all callback-types, all elements in each list will be called

Referenced by add_callback(), add_connection(), and do_callbacks().

std::map<unsigned int, server_connection*> libt2n::server::connections [protected]

Referenced by get_logstream(), and set_logging().

std::ostream* libt2n::server::logstream [private]

Referenced by get_logstream(), and set_logging().

unsigned int libt2n::server::next_id [private]

Referenced by add_connection(), and server().


The documentation for this class was generated from the following files:

Generated on 13 May 2015 by  doxygen 1.6.1
© Intra2net AG 2024 | Legal | Contact