From d9dfbd5f9ae6b460f9de9391233b968cce1955e2 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Mon, 17 Jun 2024 14:40:09 +0800 Subject: [PATCH] Improve:TcpModule include cleaner. --- utils/TcpModule/src/ITcpClient.cpp | 2 +- utils/TcpModule/src/ITcpServer.cpp | 1 + utils/TcpModule/src/TcpClientImpl.cpp | 8 ++++++ utils/TcpModule/src/TcpModule.cpp | 7 +++-- utils/TcpModule/src/TcpModuleImpl.cpp | 27 +------------------ utils/TcpModule/src/TcpModuleImpl.h | 34 ------------------------ utils/TcpModule/src/TcpModuleMakePtr.cpp | 5 +++- utils/TcpModule/src/TcpServerHandle.cpp | 2 ++ utils/TcpModule/src/TcpServerImpl.cpp | 17 ++++++++---- 9 files changed, 34 insertions(+), 69 deletions(-) diff --git a/utils/TcpModule/src/ITcpClient.cpp b/utils/TcpModule/src/ITcpClient.cpp index 256ab40..397155e 100644 --- a/utils/TcpModule/src/ITcpClient.cpp +++ b/utils/TcpModule/src/ITcpClient.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ #include "ITcpClient.h" -#include "ILog.h" #include "TcpModule.h" #include +#include void ITcpClient::Init(void) { } diff --git a/utils/TcpModule/src/ITcpServer.cpp b/utils/TcpModule/src/ITcpServer.cpp index a26c05c..f34e78e 100644 --- a/utils/TcpModule/src/ITcpServer.cpp +++ b/utils/TcpModule/src/ITcpServer.cpp @@ -16,6 +16,7 @@ #include "ILog.h" #include "TcpModule.h" #include +#include void ITcpClientAccept::Close(void) { } diff --git a/utils/TcpModule/src/TcpClientImpl.cpp b/utils/TcpModule/src/TcpClientImpl.cpp index 5d76d64..346ed61 100644 --- a/utils/TcpModule/src/TcpClientImpl.cpp +++ b/utils/TcpModule/src/TcpClientImpl.cpp @@ -14,7 +14,15 @@ */ #include "TcpClientImpl.h" #include "ILog.h" +#include "ITcpClient.h" +#include "TcpModule.h" +#include "hloop.h" +#include #include +#include +#include +#include +#include static void on_message(hio_t *io, void *buf, int len) { LogInfo("onmessage: %.*s\n", len, (char *)buf); diff --git a/utils/TcpModule/src/TcpModule.cpp b/utils/TcpModule/src/TcpModule.cpp index 1cfa9df..59fd681 100644 --- a/utils/TcpModule/src/TcpModule.cpp +++ b/utils/TcpModule/src/TcpModule.cpp @@ -14,10 +14,13 @@ */ #include "TcpModule.h" #include "ILog.h" +#include "ITcpClient.h" #include "ITcpServer.h" -#include "TcpClientImpl.h" -#include "TcpModuleImpl.h" #include "TcpModuleMakePtr.h" +#include +#include +#include +#include static bool TcpServerObjectCheck(void *object) { if (nullptr == object) { diff --git a/utils/TcpModule/src/TcpModuleImpl.cpp b/utils/TcpModule/src/TcpModuleImpl.cpp index 08e20a8..6501855 100644 --- a/utils/TcpModule/src/TcpModuleImpl.cpp +++ b/utils/TcpModule/src/TcpModuleImpl.cpp @@ -12,29 +12,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "TcpModuleImpl.h" -#include "ILog.h" -#include -// static const char *TCP_MODULE_NAME = "tcp_module"; -// const char *GetTcpModuleName(void) -// { -// return TCP_MODULE_NAME; -// } -// void *NewTcpModuleImpl(const TcpClientParam &tcpParam) -// { -// if (nullptr == tcpParam.mIp) { -// LogError("Parament error, nullptr == tcpParam.mIp\n"); -// return nullptr; -// } -// LogInfo("Create the tcp module object.\n"); -// TcpServer *impl = (TcpServer *)malloc(sizeof(TcpServer)); -// TcpServer tmp; -// memcpy((void *)impl, (void *)&tmp, sizeof(TcpServer)); -// impl->mHeader.mCheckName = TCP_MODULE_NAME; -// impl->mTcpImpl = std::make_shared(tcpParam); -// return (void *)(((char *)impl) + sizeof(TcpModuleHeader)); -// } -// void *NewTcpServer(const TcpClientParam &tcpParam) -// { -// return nullptr; -// } \ No newline at end of file +// #include "TcpModuleImpl.h" \ No newline at end of file diff --git a/utils/TcpModule/src/TcpModuleImpl.h b/utils/TcpModule/src/TcpModuleImpl.h index 3320ea4..b853054 100644 --- a/utils/TcpModule/src/TcpModuleImpl.h +++ b/utils/TcpModule/src/TcpModuleImpl.h @@ -14,39 +14,5 @@ */ #ifndef TCP_MODULE_IMPL_H #define TCP_MODULE_IMPL_H -#include "StatusCode.h" -#include "TcpModule.h" #include -// #define TCP_MODULE_INIT_NAME "UART" -// typedef struct tcp_module_header -// { -// const char *mCheckName; -// } TcpModuleHeader; -// class TcpModuleImpl -// { -// public: -// TcpModuleImpl(const TcpClientParam &uatrInfo); -// virtual ~TcpModuleImpl() = default; - -// private: -// const StatusCode SetConfig(void); - -// private: -// const TcpClientParam mUatrInfo; -// int mFd; -// }; -// TODO: There may be a CPU byte alignment bug. -// typedef struct tcp_server TcpServer; -// typedef struct tcp_server -// { -// TcpModuleHeader mHeader; -// std::shared_ptr mTcpImpl; -// } TcpServer; -// void *NewTcpModuleImpl(const TcpClientParam &tcpParam); -// void *NewTcpServer(const TcpClientParam &tcpParam); -// static inline TcpServer *TcpModuleImplConvert(void *object) -// { -// return ((TcpServer *)(((char *)object) - sizeof(TcpModuleHeader))); -// } -// const char *GetTcpModuleName(void); #endif \ No newline at end of file diff --git a/utils/TcpModule/src/TcpModuleMakePtr.cpp b/utils/TcpModule/src/TcpModuleMakePtr.cpp index 975d350..235f4be 100644 --- a/utils/TcpModule/src/TcpModuleMakePtr.cpp +++ b/utils/TcpModule/src/TcpModuleMakePtr.cpp @@ -13,9 +13,12 @@ * limitations under the License. */ #include "TcpModuleMakePtr.h" -#include "ILog.h" +#include "ITcpClient.h" +#include "ITcpServer.h" #include "TcpClientImpl.h" +#include "TcpModule.h" #include "TcpServerImpl.h" +#include std::shared_ptr &TcpModuleMakePtr::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); diff --git a/utils/TcpModule/src/TcpServerHandle.cpp b/utils/TcpModule/src/TcpServerHandle.cpp index 3006dc0..3928fba 100644 --- a/utils/TcpModule/src/TcpServerHandle.cpp +++ b/utils/TcpModule/src/TcpServerHandle.cpp @@ -14,6 +14,8 @@ */ #include "TcpServerHandle.h" #include "ILog.h" +#include "ITcpServer.h" +#include std::shared_ptr &TcpServerHandle::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); diff --git a/utils/TcpModule/src/TcpServerImpl.cpp b/utils/TcpModule/src/TcpServerImpl.cpp index 231a1c2..7455c03 100644 --- a/utils/TcpModule/src/TcpServerImpl.cpp +++ b/utils/TcpModule/src/TcpServerImpl.cpp @@ -14,7 +14,16 @@ */ #include "TcpServerImpl.h" #include "ILog.h" -#include "TcpServerHandle.h" +#include "ITcpServer.h" +#include "TcpModule.h" +#include "hloop.h" +#include "hsocket.h" +#include +#include +#include +#include +#include +#include static void on_close(hio_t *io) { LogInfo("on_close fd=%d error=%d\n", hio_fd(io), hio_error(io)); @@ -172,10 +181,8 @@ std::shared_ptr *TcpServerImpl::GetClient(hio_t *io) if (it != mClients.end()) { return it->second; } - else { - LogError("GetClient failed, client not exit.\n"); - return nullptr; - } + LogError("GetClient failed, client not exit.\n"); + return nullptr; } void TcpServerImpl::RemoveClient(hio_t *io) {