Intra2net AG

libt2n::command_client Class Reference

a client sending out commands to a server More...

#include <command_client.hxx>

List of all members.

Public Member Functions

 command_client (client_connection *_c, long long _command_timeout_usec=command_timeout_usec_default, long long _hello_timeout_usec=hello_timeout_usec_default)
virtual ~command_client ()
void replace_connection (client_connection *_c)
 replace the connection currently in use with a new one
void send_command (command *cmd, result_container &res)
 send a command to the server and store the result
void set_command_timeout_usec (long long _command_timeout_usec=command_timeout_usec_default)
void set_hello_timeout_usec (long long _hello_timeout_usec=hello_timeout_usec_default)
long long get_command_timeout_usec (void)
long long get_hello_timeout_usec (void)
bool is_connection_closed (void)
t2n_exceptionget_constuctor_exception (void)

Static Public Attributes

static const long long command_timeout_usec_default = 90000000
static const long long hello_timeout_usec_default = 30000000

Private Member Functions

void read_hello ()
 read and check the hello message at the beginning of a connection
std::string read_packet (const long long &usec_timeout)
 return a complete packet
bool check_hello (const std::string &hellostr)
 check if a hello message is valid

Private Attributes

client_connectionc
long long hello_timeout_usec
long long command_timeout_usec
t2n_exceptionconstructorException

Detailed Description

a client sending out commands to a server


Constructor & Destructor Documentation

libt2n::command_client::command_client ( client_connection _c,
long long  _command_timeout_usec = command_timeout_usec_default,
long long  _hello_timeout_usec = hello_timeout_usec_default 
)

Constructor

Parameters:
_c connection for this command. Ownership of the pointer is outside.
_command_timeout_usec timeout until the command has to be completed
_hello_timeout_usec timeout until hello has to be received

References libt2n::connection::add_callback(), c, libt2n::t2n_communication_error::clone(), libt2n::connection::close(), command_timeout_usec, constructorException, hello_timeout_usec, is_connection_closed(), libt2n::new_connection, and read_hello().

libt2n::command_client::~command_client (  )  [virtual]

Destructor

References constructorException.


Member Function Documentation

bool libt2n::command_client::check_hello ( const std::string &  hellostr  )  [private]

check if a hello message is valid

Parameters:
hellostr std::string with the message to check
Return values:
true if the hello is good and complete
Note:
you can check incomplete hellos. you will get a false return value but no exception. throws exceptions as soon as something is wrong.

Referenced by read_hello().

long long libt2n::command_client::get_command_timeout_usec ( void   )  [inline]

References command_timeout_usec.

t2n_exception* libt2n::command_client::get_constuctor_exception ( void   )  [inline]

References constructorException.

long long libt2n::command_client::get_hello_timeout_usec ( void   )  [inline]

References hello_timeout_usec.

bool libt2n::command_client::is_connection_closed ( void   )  [inline]

References c, and libt2n::connection::is_closed().

Referenced by command_client(), and send_command().

void libt2n::command_client::read_hello (  )  [private]

read and check the hello message at the beginning of a connection

Note:
throws exceptions if something went wrong

References c, check_hello(), libt2n::connection::fill_buffer(), libt2n::connection::get_packet(), hello_timeout_usec, libt2n::connection::is_closed(), and libt2n::connection::peek_packet().

Referenced by command_client(), and replace_connection().

std::string libt2n::command_client::read_packet ( const long long &  usec_timeout  )  [private]

return a complete packet

Parameters:
usec_timeout maximum microseconds to wait until the packet is complete
Return values:
packet data as std::string
Note:
throws a t2n_transfer_error if the timeout is exceeded

References c, libt2n::connection::fill_buffer(), libt2n::connection::get_packet(), and libt2n::connection::is_closed().

Referenced by send_command().

void libt2n::command_client::replace_connection ( client_connection _c  ) 

replace the connection currently in use with a new one

Parameters:
_c pointer to the new connection
Note:
the old connection must still be valid when this method is called, it can safely be deleted after this method returned
all callbacks registered on the old connection will be copied over to the new one

References libt2n::__events_end, libt2n::connection::add_callback(), c, libt2n::connection::get_callback_list(), and read_hello().

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

void libt2n::command_client::send_command ( command cmd,
result_container res 
)

send a command to the server and store the result

Parameters:
cmd pointer to a command-object
[out] res result container to store the result in
Note:
you can check incomplete hellos. you will get a false return value but no exception. throws exceptions as soon as something is wrong.

References c, command_timeout_usec, libt2n::fulldebug, libt2n::client_connection::get_logstream(), is_connection_closed(), read_packet(), and libt2n::connection::write().

void libt2n::command_client::set_command_timeout_usec ( long long  _command_timeout_usec = command_timeout_usec_default  )  [inline]

References command_timeout_usec.

void libt2n::command_client::set_hello_timeout_usec ( long long  _hello_timeout_usec = hello_timeout_usec_default  )  [inline]

References hello_timeout_usec.


Member Data Documentation

const long long libt2n::command_client::command_timeout_usec_default = 90000000 [static]
const long long libt2n::command_client::hello_timeout_usec_default = 30000000 [static]

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