user_agent.h

00001 /*   
00002  *   (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net)
00003  *
00004  *   This file is part of FREESECS.
00005  *
00006  *   FREESECS is free software: you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation, either version 3 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   FREESECS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with FREESECS, see COPYING.
00018  *   If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 #ifndef _USER_AGENT_H
00021 #define _USER_AGENT_H
00022 
00023 #include <string>
00024 #include <pthread.h>
00025 #include "shared_ptr.h"
00026 #include "hsms_cnx.h"
00027 #include "async_reception.h"
00028 #include "hsmsd_interface.h"
00029 
00030 namespace freesecs
00031 {
00035     class ua_req_handler_t
00036     {
00037     public:
00038         ua_req_handler_t();
00039         virtual ~ua_req_handler_t(){};
00040         void process_ctl(hsmsd_client_req_t&, size_t);
00041         void process_data(hsmsd_client_req_t&, size_t);
00042 
00043     protected:
00044         virtual void rcv_from_ctl(void *buf, size_t count) = 0;
00045         virtual void rcv_from_data(void *buf, size_t count) = 0;
00046 
00047         virtual void send_msg(hsms_cnx_t::pdata_t) = 0;
00048         virtual void start_cnx() = 0;
00049         virtual void stop_cnx() = 0;
00050         virtual void get_cnx_state() = 0;
00051 
00052     private:
00053         hsms_cnx_t::pdata_t _pmsg;
00054         int _msg_len;
00055         int _nb_received;
00056         int _data_state;
00057     };
00058 
00059 
00066     class user_agent_t : public ua_req_handler_t
00067     {
00068     public:
00069         typedef shared_ptr_t<hsms_cnx_t> pcnx_t;
00070 
00071     public:
00072         user_agent_t(   const char *ctl_in_fifo_name, 
00073                         const char *ctl_out_fifo_name, 
00074                         const char *data_in_fifo_name, 
00075                         const char *data_out_fifo_name, 
00076                         pcnx_t pcnx);
00077         virtual ~user_agent_t();
00078 
00079     public:
00080         /*user data handlers*/
00081         int user_ctl_handler(const size_t&);
00082         int user_data_handler(const size_t&);
00083         int user_error_handler(const int&);
00084         /*cnx data handlers*/
00085         int cnx_ctl_handler(const hsms_socket_t::pdata_t&);
00086         int cnx_data_handler(const hsms_socket_t::pdata_t&);
00087         int cnx_state_handler(const hsms_state_et&);
00088 
00089     protected:
00090     /*ua_req_handler_t iface*/
00091         virtual void rcv_from_ctl(void *buf, size_t count);
00092         virtual void rcv_from_data(void *buf, size_t count);
00093         virtual void send_msg(hsms_cnx_t::pdata_t);
00094         virtual void start_cnx();
00095         virtual void stop_cnx();
00096         virtual void get_cnx_state();
00097 
00098     private:
00099         pcnx_t                          _pcnx;
00100     private:
00101         int                             _fd_ctl_in;
00102         int                             _fd_ctl_out;
00103         int                             _fd_data_in;
00104         int                             _fd_data_out;
00105         shared_ptr_t<async_reception_t> _ar_ctl;
00106         shared_ptr_t<async_reception_t> _ar_data;
00107 
00108     private:
00109         hsmsd_client_req_t     _client_ctl_req;
00110         hsmsd_client_req_t     _client_data_req;
00111     };
00112 }//namespace
00113 #endif /*_USER_AGENT_H*/

Generated on Fri Oct 3 15:30:01 2008 for FREESECS hsms by  doxygen 1.5.1