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 hsms_cnx_t_class 00021 #define hsms_cnx_t_class 00022 00023 #include <string.h> 00024 #include <stdint.h> 00025 #include "signals.h" 00026 #include "shared_ptr.h" 00027 #include "hsms_msg.h" 00028 #include "hsms_socket.h" 00029 #include "async_reception.h" 00030 #include "hsms_statemachine.h" 00031 00032 namespace freesecs 00033 { 00034 /* 00035 * \brief HSMS connection base class. 00036 * Implements HSMS state machine base class 00037 * virtual methods for managing tcp cnx 00038 * and sending/receiving data over tcp via 00039 * hsms async socket class object 00040 */ 00041 class hsms_cnx_t: public virtual hsms_sm_t 00042 { 00043 public: 00044 typedef hsms_socket_t::data_t data_t; 00045 typedef hsms_socket_t::pdata_t pdata_t; 00046 00047 public: 00048 virtual ~hsms_cnx_t(); 00049 00050 const char *name() const; 00051 00052 uint16_t session_id() const; 00053 00057 int start(); 00061 int stop(); 00065 int send(pdata_t); 00066 00070 signal_one_arg_t<pdata_t> rx_signal; 00071 00072 00073 protected: 00079 virtual int open_tcp(); 00085 virtual int close_tcp(); 00091 virtual int send_over_tcp(hsms_socket_t::pdata_t); 00098 virtual int recv_from_tcp(hsms_socket_t::pdata_t); 00103 virtual void hsms_msg_received(hsms_socket_t::pdata_t); 00104 00105 protected: 00109 hsms_cnx_t(const char *name, uint16_t session_id, const char *remote_ip, unsigned remote_port); 00113 hsms_cnx_t(const char *name, uint16_t session_id, unsigned local_port); 00114 00115 private: 00121 int sock_cnx_state_change_handler(const hsms_socket_t::cnx_state_et&); 00129 int sock_cnx_failed_handler(); 00133 int sock_msg_rcv_handler(const pdata_t&); 00138 int sock_data_partially_recvd_handler(); 00142 int sock_recv_error_handler(); 00143 00144 private: 00148 hsms_socket_async_t _socket; 00149 00150 private: 00151 std::string _name; 00152 uint16_t _session_id; 00153 00154 private: 00155 hsms_cnx_t(); 00156 00157 }; 00158 00162 class hsms_active_cnx_t : public hsms_cnx_t, public active_hsms_sm_t 00163 { 00164 public: 00165 hsms_active_cnx_t(const hsms_active_params_t&); 00166 virtual ~hsms_active_cnx_t(); 00167 }; 00168 00172 class hsms_passive_cnx_t : public hsms_cnx_t, public passive_hsms_sm_t 00173 { 00174 public: 00175 hsms_passive_cnx_t(const hsms_passive_params_t&); 00176 virtual ~hsms_passive_cnx_t(); 00177 }; 00178 }//namespace 00179 00180 #endif //hsms_cnx_t_class