123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #ifndef __EVIO_HPP_
- #define __EVIO_HPP_
- #include <string>
- #include <vector>
- #include <memory>
- struct client:std::enable_shared_from_this<client>
- {
- 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<char>&&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<char>&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<char>&msg)
- {
- m_handle->boardcast(msg);
- }
- virtual void on_connect(const std::shared_ptr<client>& clt)
- {
- log_info("client(%s) connected",clt->name().c_str());
- }
- virtual void on_close(const std::shared_ptr<client> &clt)
- {
- log_info("client(%s) closed",clt->name().c_str());
- }
- virtual void on_error(const std::shared_ptr<client> &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<client> &clt)
- {
- log_info("client(%s) send time out",clt->name().c_str());
- }
- virtual void on_recv_timeout(const std::shared_ptr<client> &clt)
- {
- log_info("client(%s) recv time out",clt->name().c_str());
- }
- virtual void on_message(const std::shared_ptr<client>& clt,const char*data,size_t len)=0;
- virtual void on_timer()=0;
- virtual ~service_callback(){}
- };
- #endif
|