#ifndef __TCPPLUGIN_HPP_ #define __TCPPLUGIN_HPP_ #include #include "UtilBase.hpp" #include "TCPClient.hpp" #include "requests.hpp" #include "config.hpp" #include "md5.h" #include "uuid.hpp" #include "ExpelDevice.h" #include "ExpelPlugin.hpp" #include "uuid.hpp" #include "PluginSubscriber.hpp" using namespace std; using namespace utility; namespace gsd { class TcpPlugin: public PluginSubscriber, public PluginBase { private: TcpPlugin(): PluginBase(){ } public: using Ptr = std::shared_ptr; /** * @description: getPtr * @return {*} */ static std::shared_ptr getPtr(); /** * @description: CreateNew * @return {*} */ static std::shared_ptr CreateNew(); ~TcpPlugin(){} /** * @description: 初始化 * @return {*} */ virtual bool Init(); /** * @description: * @return {*} */ virtual bool StartTask(); /** * @description: 释放 * @return {*} */ virtual void Destroy(); /** * @description: * @return {*} */ virtual bool Alive(); /** * @description: 发送心跳数据 * @return {*} */ void SendHeartbeatData(); /** * @description: 登录Netty * @return {*} */ void TCPLoginNetty(); /** * @description: 获取登录结果 * @return {*} */ bool getLoginNetty(); /** * @description: 监听Netty的数据 * @param {Ptr} &buf * @return {*} */ void ListenNettyData(const Buffer::Ptr &buf); /** * @description: 发送请求 * @param {string} RequestId UUID * @param {string} CommandEnum 命令枚举 * @param {string&} data 数据 * @param {function} t 回调函数(请求结果, 返回的数据) * @return {*} */ void sendRequest(std::string RequestId,std::string CommandEnum, std::string& data,function t); /** * @description: RestPlugin * @return {*} */ virtual bool RestPlugin(){ return true; } private: // TCP对象 TCPClient::Ptr tcpClient = nullptr; Timer::Ptr HeartbeatTimer = nullptr; Timer::Ptr NettyLoginTimer = nullptr; bool TcpNettyLogin = false; // 线程池 std::shared_ptr pool = nullptr; }; } // namespace gsd #endif