inlib  1.2.0
Public Member Functions | Protected Member Functions | Protected Attributes
inlib::wall::data_client Class Reference
Collaboration diagram for inlib::wall::data_client:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 data_client (std::ostream &a_out, bool a_verbose, bool a_warn)
virtual ~data_client ()
inlib::net::inet_socketsocket ()
std::ostream & out ()
bool initialize (const std::string &a_server, unsigned int a_port)
bool steer ()
bool poll ()
bool send_buffer_doc (inlib::uint64 a_length, const char *a_buffer, const std::string &a_options="")

Protected Member Functions

 data_client (const data_client &a_from)
virtual bool dispatch (const std::string &a_prot, bool &a_handled)

Protected Attributes

std::ostream & m_out
inlib::net::inet_socket m_socket

Detailed Description

Definition at line 14 of file data_client.


Constructor & Destructor Documentation

inlib::wall::data_client::data_client ( std::ostream &  a_out,
bool  a_verbose,
bool  a_warn 
) [inline]

Definition at line 16 of file data_client.

  :m_out(a_out)
  ,m_socket(a_out,a_verbose)
  ,m_warn(a_warn)
  {}
virtual inlib::wall::data_client::~data_client ( ) [inline, virtual]

Definition at line 23 of file data_client.

{}
inlib::wall::data_client::data_client ( const data_client a_from) [inline, protected]

Definition at line 25 of file data_client.

  :m_out(a_from.m_out)
  ,m_socket(a_from.m_out,false)
  ,m_warn(a_from.m_warn)
  {}

Member Function Documentation

virtual bool inlib::wall::data_client::dispatch ( const std::string &  a_prot,
bool &  a_handled 
) [inline, protected, virtual]

Definition at line 181 of file data_client.

                                                                 {
    if(a_prot==inlib::wall::protocol::disconnect()) {
      m_socket.disconnect();
      a_handled = true;

    } else if(a_prot==inlib::wall::protocol::start()) {
  
      a_handled = true;

    } else {
      if(m_warn) {
        m_out << "inlib::data_client::dispatch :"
              << " unknown prot " << inlib::sout(a_prot) << "."
              << std::endl;
      }
      a_handled = false;
    }

    return true;
  }
bool inlib::wall::data_client::initialize ( const std::string &  a_server,
unsigned int  a_port 
) [inline]

Definition at line 35 of file data_client.

                                                                 {
    if(!m_socket.connect(a_server,a_port,20,1)) return false;
    if(m_socket.verbose()) {
      m_out << "inlib::data_client::initialize :"
            << " connected."
            << std::endl;
    }
    return true;
  }
std::ostream& inlib::wall::data_client::out ( ) [inline]

Definition at line 34 of file data_client.

{return m_out;}
bool inlib::wall::data_client::poll ( ) [inline]

Definition at line 78 of file data_client.

              {
    while(true){
      bool have_input;
      if(!m_socket.is_there_input(have_input)) {
        m_out << "inlib::data_client::poll :"
              << " is_there_input failed"
              << std::endl;       
        m_socket.disconnect();
        return false;
      }
      if(!have_input) return true;

      std::string prot;
      if(!m_socket.fetch_string(prot)) {
        m_out << "inlib::data_client::poll :"
              << " fetch failed"
              << std::endl;       
        m_socket.disconnect();
        return false;
      }
  
      if(m_socket.verbose()) {
        m_out << "inlib::data_client::poll :"
              << " received prot " << prot
              << std::endl;       
      }  

      bool handled;
      if(!dispatch(prot,handled)) {
        m_out << "inlib::data_client::poll :"
              << " distpatch failed"
              << std::endl;       
        m_socket.disconnect();
        return false;
      }
      //could have received a inlib::wall::protocol::disconnect()
      if(!m_socket.is_connected()) return true;
  
    }  
  }
bool inlib::wall::data_client::send_buffer_doc ( inlib::uint64  a_length,
const char *  a_buffer,
const std::string &  a_options = "" 
) [inline]

Definition at line 147 of file data_client.

                                                               {
    if(!m_socket.send_string(inlib::wall::protocol::doc())) {
      m_out << "inlib::data_client::send_doc :"
            << " send_string() failed."
            << std::endl;
      return false;
    }

    if(!m_socket.send_string(a_options)) {
      m_out << "inlib::data_client::send_doc :"
            << " send_string() failed."
            << std::endl;
      return false;
    }

    if(!m_socket.send<inlib::uint64>(a_length)) {
      m_out << "inlib::data_client::send_doc :"
            << " send lengtj failed."
            << std::endl;
      return false;
    }
    if(!m_socket.send_buffer(a_buffer,a_length)) {
      m_out << "inlib::data_client::send_doc :"
            << " send_buffer() failed."
            << std::endl;
      return false;
    }

    return true;
  }
inlib::net::inet_socket& inlib::wall::data_client::socket ( ) [inline]

Definition at line 33 of file data_client.

{return m_socket;}
bool inlib::wall::data_client::steer ( ) [inline]

Definition at line 45 of file data_client.

               {
    while(true){
      std::string prot;
      if(!m_socket.fetch_string(prot)) {
        m_out << "inlib::data_client::steer :"
              << " fetch failed"
              << std::endl;       
        m_socket.disconnect();
        return false;
      }
  
      if(m_socket.verbose()) {
        m_out << "inlib::data_client::steer :"
              << " received prot " << inlib::sout(prot)
              << std::endl;       
      }
  
      bool handled;
      if(!dispatch(prot,handled)) {
        m_out << "inlib::data_client::steer :"
              << " distpatch failed"
              << std::endl;       
        m_socket.disconnect();
        return false;
      }
  
    }
  
    m_socket.disconnect();
  
    return true;
  }

Member Data Documentation

std::ostream& inlib::wall::data_client::m_out [protected]

Definition at line 202 of file data_client.

Definition at line 203 of file data_client.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines