This commit is contained in:
binbinnomoney 2024-07-26 22:52:34 +08:00
commit 94af1eaaea
8 changed files with 33 additions and 8 deletions

View File

@ -9,6 +9,7 @@
* I/O多路复用
* 套接字编程
* TCP协议
* 事件循环
# 各文件的作用
* **TcpModule.h**定义了TCP模块的公共接口和数据结构包括服务器和客户端参数结构体、回调函数类型等。

View File

@ -28,10 +28,13 @@ public:
virtual ssize_t Write(const void *buf, const size_t bufLenght);
virtual void Closed(void);
};
/**
* @brief Verify that the header of the client object is legal.
*/
typedef struct i_tcp_client_header
{
const char *mCheckName;
} ITcpClientHeader;
} ITcpClientHeader;
typedef struct tcp_client
{
ITcpClientHeader mHeader;

View File

@ -17,6 +17,9 @@
#include "StatusCode.h"
#include "TcpModule.h"
#include <memory>
/**
* @brief Handle data interaction and connection state changes on established TCP connections.
*/
class ITcpClientAccept
{
public:
@ -35,6 +38,9 @@ public:
virtual void Init(void);
virtual void UnInit(void);
};
/**
* @brief Verify that the header of the server object is legal.
*/
typedef struct i_tcp_server_header
{
const char *mCheckName;

View File

@ -28,7 +28,7 @@
*
* @param io Socket handle
* @param buf The transmitted data content
* @param len
* @param len Byte length of transmitted data
*/
static void on_message(hio_t *io, void *buf, int len)
{
@ -61,7 +61,6 @@ TcpClientImpl::TcpClientImpl(const TcpClientParam &param, const void *object) :
}
/**
* @brief Initialize TCP clients, create event loops, I/O objects, and set callback functions for connection and closure.
*
*/
void TcpClientImpl::Init(void)
{
@ -89,7 +88,6 @@ void TcpClientImpl::Init(void)
}
/**
* @brief De-initialize the TCP client, close the I/O object and wait for the receiving thread to end.
*
*/
void TcpClientImpl::UnInit(void)
{

View File

@ -36,7 +36,7 @@ public:
private:
std::mutex mMutex; ///A mutex lock used to synchronize access to shared resources.
hloop_t *mLoop;
hloop_t *mLoop; ///Event loop, listening for io objects
hio_t *mIo; ///Socket handle
const TcpClientParam mParam; ///Basic information of the client, including port, ip, reading and closing.
std::thread mTcpClientThread;

View File

@ -25,7 +25,8 @@
* @brief Verify that object is a legitimate (existing) server.
*
* @param object Save the address of the character pointer variable.
* If the value of the character pointer pointed by *object is "tcp_server", return turn
* Should be substituted into the private member objectThis of the client instance.
* If the value of the character pointer pointed by *object is "tcp_server", return turn
* @return true Indicates that the server exists.
* @return false Indicates that the server does not exist
*/
@ -45,7 +46,7 @@ static bool TcpServerObjectCheck(void *object)
* @brief Verify that object is a legitimate (existing) client.
*
* @param object Save the address of the character pointer variable.
* The correct object is returned by the function NewTcpClient in Itcpclientlmpl.cpp file.
*
* @return true Indicates that the client exists.
* @return false Indicates that the client does not exist
*/

View File

@ -109,7 +109,7 @@ TcpServerImpl::TcpServerImpl(const TcpServerParam param) : mParam(param)
void TcpServerImpl::Init(void)
{
constexpr int NO_FALGS = 0;
mLoop = hloop_new(NO_FALGS);
mLoop = hloop_new(NO_FALGS); ///Initialize event loop
if (nullptr == mLoop) {
LogError("hloop_new failed\n");
return;

View File

@ -0,0 +1,16 @@
# UartDevice模块
该模块是UART设备接口模块提供了UART 设备操作接口通过uart通信操作相关的硬件设备。
# 涉及的知识
* uart通信协议
* 多线程
* 系统调用函数的使用
* C++类和对象
* 函数指针
# 各文件的作用
* **UartDevice.h**定义了一个名为uart_info的结构体存储UART设备的配置信息定义了用于UART通信的函数接口这些函数通常与UART硬件的底层实现相对应。
* **UartDevice.cpp**提供了一个跨平台的UART设备接口模块使得上层应用可以通过统一的接口来操作不同的UART硬件设备。
* **UartDeviceImpl.cpp**提供了UART 设备操作接口,允许用户打开、发送和接收数据到 UART 设备,实现了 UART 设备的配置、数据发送和接收等功能。
* **UartDeviceImpl.h**定义了一个用于UART设备操作的类 UartDeviceImpl 和相关的结构体和函数提供了一种通过接口和智能指针封装具体实现的方式来管理UART设备。