GrabBag/VrNets/TCPClient/Inc/IVrTCPClient.h
2025-09-18 23:49:32 +08:00

66 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <string>
#include <functional>
// 前向声明
class CVrTCPClient;
class IVrTCPClient;
// 回调函数类型定义
using TCPRecvFunc = std::function<void(IVrTCPClient* pClient, const char* pData, const int nLen, void* pParam)>;
using LinkEventFunc = std::function<void(IVrTCPClient* pClient, bool connected, void* pParam)>;
/**
* @brief TCP客户端接口类
* 定义了TCP客户端的基本接口用于网络通信
*/
class IVrTCPClient
{
public:
virtual ~IVrTCPClient() = default;
/**
* @brief 连接设备
* @param sDevIP 设备IP地址
* @param nPort 端口号
* @param bReLink 是否自动重连
* @param linkFunc 连接状态回调函数
* @return 0表示成功其他值表示失败
*/
virtual int LinkDevice(const std::string sDevIP, int nPort, bool bReLink, LinkEventFunc linkFunc, void* pParam) = 0;
/**
* @brief 关闭设备连接
* @return 0表示成功其他值表示失败
*/
virtual int CloseDevice() = 0;
/**
* @brief 启动工作线程
* @param fRecvFunc 接收数据回调函数
* @return 0表示成功其他值表示失败
*/
virtual int StartWork(TCPRecvFunc fRecvFunc, void* pParam) = 0;
/**
* @brief 发送数据
* @param pdata 数据指针
* @param nLen 数据长度
* @return true表示成功false表示失败
*/
virtual bool SendData(const char* pdata, const int nLen) = 0;
/**
* @brief 创建TCP客户端实例
* @return TCP客户端实例指针
*/
static IVrTCPClient* CreateInstance();
/**
* @brief 销毁TCP客户端实例
* @param pInstance 待销毁的实例指针
*/
static void DestroyInstance(IVrTCPClient* pInstance);
};