📄 hsmsd_cnx_proxy.h
字号:
/* * (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net) * * This file is part of FREESECS. * * FREESECS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * FREESECS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with FREESECS, see COPYING. * If not, see <http://www.gnu.org/licenses/>. */#ifndef _HSMSD_CNX_PROXY_H#define _HSMSD_CNX_PROXY_H#include <string>#include <vector>#include <semaphore.h>#include <pthread.h>#include "shared_ptr.h"#include "event_pump.h"#include "async_reception.h"#include "hsmsd_interface.h"#include "hsmsd_cli.h"namespace freesecs{ /** * \brief HSMS cnx thin client implementation class */ class hsmsd_proxy_t { public: hsmsd_proxy_t(const char *cnx_name); ~hsmsd_proxy_t(); int set_msg_handler(hsmsd_msg_handler_t); int set_cnx_state_handler(hsmsd_cnx_state_handler_t); int set_cnx_error_handler(hsmsd_cnx_error_handler_t); int start(); int stop(); int get_state(hsmsd_cnx_state_t*); int send_msg(hsmsd_msg_t*); public: int ctrl_rcvd_handler(const size_t&); int data_rcvd_handler(const size_t&); int rcv_error_handler(const int&); private: std::string _cnx_name; hsmsd_msg_t _rsp_msg_hdr; hsmsd_msg_t _data_msg_hdr; std::vector<unsigned char> _msg_data; private: hsmsd_server_rsp_t _srv_ctl_msg; hsmsd_server_rsp_t _srv_data_msg; hsmsd_server_rsp_t _srv_msg_pool[hsmsd_server_rsp_t::MAX_RSP_TYPE]; sem_t _rsp_sem_pool[hsmsd_server_rsp_t::MAX_RSP_TYPE]; private: int _fd_ctl_in; int _fd_ctl_out; int _fd_data_in; int _fd_data_out; shared_ptr_t<async_reception_t> _ctl_ar; shared_ptr_t<async_reception_t> _data_ar; int _rstate; private: hsmsd_msg_handler_t _msg_h; hsmsd_cnx_state_handler_t _cnx_state_h; hsmsd_cnx_error_handler_t _cnx_error_h; private: /** * this async pump enables calling hsmsd client APIs * from within API callbacks * */ class event_base_t { public: event_base_t(){}; virtual ~event_base_t(){}; virtual void operator()(void) const = 0; /*{ printf("event base :(\n"); };*/ }; template<typename cb_t, typename arg_t> class event_to_client_t : public event_base_t { public: event_to_client_t(cb_t cb, arg_t arg) :_cb(cb),_arg(arg){} event_to_client_t(const event_to_client_t& other){_cb = other._cb; _arg = other._arg;} event_to_client_t & operator = (const event_to_client_t & other) {_cb = other._cb; _arg = other._arg; return *this;} virtual void operator()(void) const { _cb(_arg); } private: cb_t _cb; arg_t _arg; }; typedef shared_ptr_t<event_base_t> pevent_base_t; class pump_events_to_client_t : public threaded_event_pump_t<pevent_base_t> { private: virtual int process(const pevent_base_t& e) { (*e.get())(); return 0; } }; static pump_events_to_client_t client_event_pump; typedef event_to_client_t<hsmsd_cnx_state_handler_t,hsmsd_cnx_state_t> state_event_t; typedef event_to_client_t<hsmsd_cnx_error_handler_t, int> error_event_t; typedef event_to_client_t<hsmsd_msg_handler_t, hsmsd_msg_t*> msg_event_t; };}//namespace#endif /*_HSMSD_CNX_PROXY_H*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -