00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _HSMS_SM_H
00021 #define _HSMS_SM_H
00022
00023 #include <string>
00024 #include "shared_ptr.h"
00025 #include "hsms_socket.h"
00026 #include "event_pump.h"
00027 #include "timer.h"
00028
00029 namespace freesecs
00030 {
00034 typedef struct
00035 {
00036 std::string name;
00037 uint32_t port;
00038 uint16_t t6;
00039 uint16_t t7;
00040 uint16_t t8;
00041 uint16_t linktest;
00042 uint16_t session_id;
00043 }hsms_passive_params_t;
00044
00048 typedef struct
00049 {
00050 std::string name;
00051 std::string ip;
00052 uint32_t port;
00053 uint16_t t5;
00054 uint16_t t6;
00055 uint16_t t8;
00056 uint16_t linktest;
00057 uint16_t session_id;
00058 }hsms_active_params_t;
00059
00063 typedef enum
00064 {
00065 e_tcpip_established = 0,
00066 e_hsms_msg_rcvd,
00067 e_tcpip_error,
00068 e_cnx_term_req,
00069 e_cnx_start_req,
00070 e_datamsg_send_req,
00071 e_linktest_timeout,
00072 e_t5_timeout,
00073 e_t6_timeout,
00074 e_t7_timeout,
00075 e_t8_timeout,
00076 e_data_received,
00077 e_tcpip_broken,
00078 e_tcpip_cnx_failure
00079 }
00080 hsms_ev_et;
00081
00085 typedef enum
00086 {
00087 e_hsms_not_connected,
00088 e_hsms_not_selected,
00089 e_hsms_selected,
00090 e_hsms_not_connected_t5
00091 }
00092 hsms_state_et;
00093
00097 typedef struct
00098 {
00099 hsms_ev_et type;
00100 hsms_socket_t::pdata_t pdata;
00101 }
00102 hsms_event_t;
00103
00114 class hsms_sm_t : public simple_event_pump_t<hsms_event_t>
00115 {
00116 public:
00117 typedef hsms_socket_t::data_t data_t;
00118 typedef hsms_socket_t::pdata_t pdata_t;
00119
00120 public:
00121 hsms_sm_t();
00122 virtual ~hsms_sm_t();
00123
00127 signal_one_arg_t<hsms_state_et> state_signal;
00128 #if 0
00129
00132 signal_one_arg_t<pdata_t> rx_signal;
00133 #endif
00134
00137 hsms_state_et get_state() const;
00138
00139 protected:
00144 virtual int open_tcp() = 0;
00149 virtual int close_tcp() = 0;
00154 virtual int send_over_tcp(pdata_t) = 0;
00159 virtual int recv_from_tcp(pdata_t) = 0;
00164 virtual void hsms_msg_received(pdata_t) = 0;
00165
00166 protected:
00170 void close_cnx();
00174 virtual int process(const hsms_event_t&) = 0;
00175
00176 protected:
00177 hsms_state_et _state;
00178
00179
00180 protected:
00181 ms_timer_t t5;
00182 ms_timer_t t6;
00183 ms_timer_t t7;
00184 ms_timer_t t8;
00185 ms_timer_t linktest_timer;
00186
00187 int t5_handler();
00188 int t6_handler();
00189 int t7_handler();
00190 int t8_handler();
00191 int linktest_handler();
00192
00193 protected:
00200 unsigned short _tid;
00201 };
00202
00206 class passive_hsms_sm_t : public virtual hsms_sm_t
00207 {
00208 public:
00209 passive_hsms_sm_t(hsms_passive_params_t);
00210 virtual ~passive_hsms_sm_t();
00211
00212 protected:
00216 virtual int process(const hsms_event_t&);
00217
00218 protected:
00222 bool x0(pdata_t);
00226 bool x1(pdata_t);
00230 bool x2(pdata_t);
00234 bool x3(pdata_t);
00238 bool x4(pdata_t);
00242 bool x5(pdata_t);
00246 bool x6(pdata_t);
00247
00248
00252 int z1(pdata_t);
00256 int z2(pdata_t);
00260 int z3(pdata_t);
00264 int z4(pdata_t);
00268 int z5(pdata_t);
00272 int z6(pdata_t);
00276 int z7(pdata_t);
00280 int z9(pdata_t);
00284 int z10(pdata_t);
00288 int z11(pdata_t);
00292 int z12(pdata_t);
00296 int z0_0(hsms_event_t);
00300 int z1_0(pdata_t);
00304 int z2_0(pdata_t);
00305
00306 private:
00307 hsms_passive_params_t _params;
00308 };
00309
00313 class active_hsms_sm_t : public virtual hsms_sm_t
00314 {
00315 public:
00316 active_hsms_sm_t(hsms_active_params_t);
00317 virtual ~active_hsms_sm_t();
00318
00319 protected:
00323 virtual int process(const hsms_event_t &);
00324
00325 protected:
00329 bool x0(pdata_t);
00333 bool x1(pdata_t);
00337 bool x2(pdata_t);
00341 bool x3(pdata_t);
00345 bool x4(pdata_t);
00349 bool x5(pdata_t);
00353 bool x6(pdata_t);
00357 int z1(pdata_t);
00361 int z3(pdata_t);
00365 int z4(pdata_t);
00369 int z5(pdata_t);
00373 int z6(pdata_t);
00377 int z7(pdata_t);
00381 int z8(pdata_t);
00385 int z9(pdata_t);
00389 int z10(pdata_t);
00393 int z11(pdata_t);
00397 int z12(pdata_t);
00401 int z13(pdata_t);
00405 int z14(pdata_t);
00409 int z0_0(pdata_t);
00413 int z1_0(pdata_t);
00417 int z2_0(pdata_t);
00418
00419 private:
00420 hsms_active_params_t _params;
00421 };
00422 }
00423 #endif //_HSMS_SM_H