#ifndef __EVIO_HPP_ #define __EVIO_HPP_ #include #include #include struct client:std::enable_shared_from_this { virtual std::string name()=0; virtual int type()=0; //分站:1,模拟客户端:2 virtual int handle()=0; virtual void set_conn_type(int type)=0; //设置分站类型1:site,2:虚拟推送客户端 virtual void close()=0; virtual void send(std::vector&&b)=0; // virtual bool check_timestamp(const char*)=0; virtual ~client(){} }; struct service_callback; struct service_handle { virtual int run(int port)=0; virtual void stop()=0; virtual void boardcast(const std::vector&msg)=0; virtual ~service_handle(){} static service_handle*instance(service_callback*sc); }; struct service_callback:service_handle { service_handle*m_handle{nullptr}; void set_handle(service_handle*handle) { m_handle=handle; } int run(int port) { return m_handle->run(port); } void stop() { m_handle->stop(); } void boardcast(const std::vector&msg) { m_handle->boardcast(msg); } virtual void on_connect(const std::shared_ptr& clt) { log_info("client(%s) connected",clt->name().c_str()); } virtual void on_close(const std::shared_ptr &clt) { log_info("client(%s) closed",clt->name().c_str()); } virtual void on_error(const std::shared_ptr &clt,const char*error) { log_info("client(%s) error with:%s",clt->name().c_str(),error); } virtual void on_send_timeout(const std::shared_ptr &clt) { log_info("client(%s) send time out",clt->name().c_str()); } virtual void on_recv_timeout(const std::shared_ptr &clt) { log_info("client(%s) recv time out",clt->name().c_str()); } virtual void on_message(const std::shared_ptr& clt,const char*data,size_t len)=0; virtual void on_timer()=0; virtual ~service_callback(){} }; #endif