diff --git a/external/libhv/libhv-1.3.2/CMakeLists.txt b/external/libhv/libhv-1.3.2/CMakeLists.txt index 7f0308a..d55efb8 100644 --- a/external/libhv/libhv-1.3.2/CMakeLists.txt +++ b/external/libhv/libhv-1.3.2/CMakeLists.txt @@ -231,8 +231,11 @@ endif() list_source_directories(LIBHV_SRCS ${LIBHV_SRCDIRS}) -file(INSTALL ${LIBHV_HEADERS} DESTINATION include/hv) -file(INSTALL ${LIBHV_HEADERS} DESTINATION ${PROJECT_SOURCE_DIR}/include/hv) +set(folder_path "${PROJECT_SOURCE_DIR}/include/hv") # added by xiao +if(NOT EXISTS ${folder_path}) # added by xiao + file(INSTALL ${LIBHV_HEADERS} DESTINATION include/hv) + file(INSTALL ${LIBHV_HEADERS} DESTINATION ${PROJECT_SOURCE_DIR}/include/hv) +endif() # added by xiao if(BUILD_SHARED) add_library(hv SHARED ${LIBHV_SRCS}) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index d41f2d3..7607882 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -14,4 +14,5 @@ add_subdirectory(LedControl) add_subdirectory(KeyControl) add_subdirectory(MediaAdapter) add_subdirectory(FxHttpServer) -add_subdirectory(Servers) \ No newline at end of file +add_subdirectory(Servers) +add_subdirectory(TcpModule) \ No newline at end of file diff --git a/utils/TcpModule/CMakeLists.txt b/utils/TcpModule/CMakeLists.txt new file mode 100644 index 0000000..36a425c --- /dev/null +++ b/utils/TcpModule/CMakeLists.txt @@ -0,0 +1,51 @@ +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) +set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) + +include_directories( + ./src + ./include + ${UTILS_SOURCE_PATH}/LinuxApi/include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include +) +# link_directories( +# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs +# ) + +aux_source_directory(./src SRC_FILES) + +set(TARGET_NAME TcpModule) +add_library(${TARGET_NAME} STATIC ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} LinuxApi StatusCode Log) + +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + TcpModule_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/TcpModule +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + TcpModule_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/TcpModule +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make TcpModule_code_check + COMMAND make TcpModule_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/utils/TcpModule/include/TcpModule.h b/utils/TcpModule/include/TcpModule.h new file mode 100644 index 0000000..e3d9d09 --- /dev/null +++ b/utils/TcpModule/include/TcpModule.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef TCP_MODULE_H +#define TCP_MODULE_H +#ifdef __cplusplus +extern "C" { +#endif +typedef void (*TcpReadFunction)(void *, const int, void *); +typedef struct tcp_parm +{ + const char *mIp; + const int mPort; + const TcpReadFunction mReadFunc; +} TcpPram; +void *CreateTcpServer(const TcpPram param); +void FreeTcpServer(void *pointer); +int TcpServerWrite(void *object, void *buf, const int bufLenght); +void *CreateTcpClient(const TcpPram param); +void FreeTcpClient(void *pointer); +int TcpClientWrite(void *object, void *buf, const int bufLenght); +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/utils/TcpModule/src/TcpModule.cpp b/utils/TcpModule/src/TcpModule.cpp new file mode 100644 index 0000000..3c1b2d4 --- /dev/null +++ b/utils/TcpModule/src/TcpModule.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "TcpModule.h" +#include "TcpModuleImpl.h" +void *CreateTcpServer(const TcpPram param) { return NewTcpServer(param); } \ No newline at end of file diff --git a/utils/TcpModule/src/TcpModuleImpl.cpp b/utils/TcpModule/src/TcpModuleImpl.cpp new file mode 100644 index 0000000..3289f22 --- /dev/null +++ b/utils/TcpModule/src/TcpModuleImpl.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * 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 TcpPram &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 TcpPram &tcpParam) { return nullptr; } \ No newline at end of file diff --git a/utils/TcpModule/src/TcpModuleImpl.h b/utils/TcpModule/src/TcpModuleImpl.h new file mode 100644 index 0000000..e143026 --- /dev/null +++ b/utils/TcpModule/src/TcpModuleImpl.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#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 uart_device_header +{ + const char *mCheckName; +} TcpModuleHeader; +class TcpModuleImpl +{ +public: + TcpModuleImpl(const TcpPram &uatrInfo); + virtual ~TcpModuleImpl() = default; + +private: + const StatusCode SetConfig(void); + +private: + const TcpPram 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 TcpPram &tcpParam); +void *NewTcpServer(const TcpPram &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/UartDevice/CMakeLists.txt b/utils/UartDevice/CMakeLists.txt index 0b16db3..9224084 100644 --- a/utils/UartDevice/CMakeLists.txt +++ b/utils/UartDevice/CMakeLists.txt @@ -13,8 +13,6 @@ include_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ) - - aux_source_directory(./src SRC_FILES) set(TARGET_NAME UartDevice)