123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #ifndef __TCPPLUGIN_HPP_
- #define __TCPPLUGIN_HPP_
- #include <iostream>
- #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<TcpPlugin>, public PluginBase
- {
- private:
- TcpPlugin(): PluginBase(){
- }
- public:
- using Ptr = std::shared_ptr<TcpPlugin>;
-
- /**
- * @description: getPtr
- * @return {*}
- */
- static std::shared_ptr<TcpPlugin> getPtr();
- /**
- * @description: CreateNew
- * @return {*}
- */
- static std::shared_ptr<TcpPlugin> 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<void(std::string)>} t 回调函数(请求结果, 返回的数据)
- * @return {*}
- */
- void sendRequest(std::string RequestId,std::string CommandEnum, std::string& data,function<void(int, std::string)> 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<ThreadPool> pool = nullptr;
- };
-
- } // namespace gsd
- #endif
|