diff --git a/external/goahead-5.2.0/CMakeLists.txt b/external/goahead-5.2.0/CMakeLists.txt index c7bdf87e..37f2dddc 100644 --- a/external/goahead-5.2.0/CMakeLists.txt +++ b/external/goahead-5.2.0/CMakeLists.txt @@ -1,12 +1,13 @@ include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +include(${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/goahead.cmake) set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) -if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) - SET(SET_ARCH "x86") -else() - SET(SET_ARCH "arm") -endif() +# if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) +# SET(SET_ARCH "x86") +# else() +# SET(SET_ARCH "arm") +# endif() # build goahead before make libgo.a add_custom_command( OUTPUT ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/Makefile @@ -17,8 +18,8 @@ add_custom_command( add_custom_command( OUTPUT ${EXTERNAL_LIBS_OUTPUT_PATH}/libgo.a DEPENDS ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/Makefile - COMMAND make CC=${CMAKE_C_COMPILER} ARCH=${SET_ARCH} PROFILE=static - COMMAND mv ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/build/linux-${SET_ARCH}-static/bin/libgo.a ${EXTERNAL_LIBS_OUTPUT_PATH}/libgo.a + COMMAND make CC=${CMAKE_C_COMPILER} ARCH=${SET_ARCH} PROFILE=${LIB_TYPE} + COMMAND mv ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/build/${GOAHEAD_INCLUDE_PATH}/bin/libgo.a ${EXTERNAL_LIBS_OUTPUT_PATH}/libgo.a WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead ) add_custom_target( diff --git a/external/goahead-5.2.0/goahead.cmake b/external/goahead-5.2.0/goahead.cmake new file mode 100644 index 00000000..22295225 --- /dev/null +++ b/external/goahead-5.2.0/goahead.cmake @@ -0,0 +1,9 @@ + +if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) + SET(SET_ARCH "x86") +else() + SET(SET_ARCH "arm") +endif() + +SET(LIB_TYPE "static") +SET(GOAHEAD_INCLUDE_PATH "linux-${SET_ARCH}-${LIB_TYPE}") \ No newline at end of file diff --git a/test/utils/CMakeLists.txt b/test/utils/CMakeLists.txt index fe883631..e6841d85 100644 --- a/test/utils/CMakeLists.txt +++ b/test/utils/CMakeLists.txt @@ -2,5 +2,6 @@ add_subdirectory(Config) add_subdirectory(Log) add_subdirectory(SharedData) +add_subdirectory(WebServer) diff --git a/test/utils/SharedData/src/SharedDataTest.cpp b/test/utils/SharedData/src/SharedData_Test.cpp similarity index 100% rename from test/utils/SharedData/src/SharedDataTest.cpp rename to test/utils/SharedData/src/SharedData_Test.cpp diff --git a/test/utils/WebServer/CMakeLists.txt b/test/utils/WebServer/CMakeLists.txt new file mode 100644 index 00000000..b065344e --- /dev/null +++ b/test/utils/WebServer/CMakeLists.txt @@ -0,0 +1,64 @@ +# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake) +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin) + +include_directories( + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + ${UTILS_SOURCE_PATH}/WebServer/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include +) + +link_directories( + ${LIBS_OUTPUT_PATH} + ${EXTERNAL_LIBS_OUTPUT_PATH} +) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +aux_source_directory(. SRC_FILES) +aux_source_directory(./src SRC_FILES) + +set(TARGET_NAME WebServerTest) +add_executable(${TARGET_NAME} ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} WebServer gtest gmock pthread Log) +if(${TEST_COVERAGE} MATCHES "true") + target_link_libraries(${TARGET_NAME} gcov) +endif() +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + WebServerTest_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + # --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/gtest.h\"}]' + --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]' + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/utils/WebServer +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + WebServerTest_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/utils/WebServer +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make WebServerTest_code_check + COMMAND make WebServerTest_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/test/utils/WebServer/mainTest.cpp b/test/utils/WebServer/mainTest.cpp new file mode 100644 index 00000000..475ceee4 --- /dev/null +++ b/test/utils/WebServer/mainTest.cpp @@ -0,0 +1,23 @@ +/* + * 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 +#include +#include +#include +int main(int argc, char *argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/test/utils/WebServer/src/WebServer_Test.cpp b/test/utils/WebServer/src/WebServer_Test.cpp new file mode 100644 index 00000000..feb642bb --- /dev/null +++ b/test/utils/WebServer/src/WebServer_Test.cpp @@ -0,0 +1,31 @@ +/* + * 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 "ILog.h" +#include "WebServer.h" +#include +#include +#include +namespace WebServerTest +{ +// ../output_files/test/bin/WebServerTest --gtest_filter=WebServerTest.Demo +TEST(WebServerTest, Demo) +{ + CreateLogModule(); + ILogInit(LOG_INSTANCE_TYPE_END); + WebServerInit(); + std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 10)); + ILogUnInit(); +} +} // namespace WebServerTest \ No newline at end of file diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 5082b1fa..878dcc94 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -7,3 +7,4 @@ add_subdirectory(SharedData) add_subdirectory(UartDevice) add_subdirectory(LinuxApi) # add_subdirectory(MultiProcess) +add_subdirectory(WebServer) diff --git a/utils/MultiProcess/CMakeLists.txt b/utils/MultiProcess/CMakeLists.txt new file mode 100644 index 00000000..bc3d2906 --- /dev/null +++ b/utils/MultiProcess/CMakeLists.txt @@ -0,0 +1,53 @@ +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}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include +) +# link_directories( +# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs +# ) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +aux_source_directory(./src SRC_FILES) + +set(TARGET_NAME MultiProcess) +add_library(${TARGET_NAME} STATIC ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} StatusCode Log) + +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + MultiProcess_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}/MultiProcess +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + MultiProcess_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/MultiProcess +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make MultiProcess_code_check + COMMAND make MultiProcess_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/utils/MultiProcess/include/MultiProcess.h b/utils/MultiProcess/include/MultiProcess.h new file mode 100644 index 00000000..48320201 --- /dev/null +++ b/utils/MultiProcess/include/MultiProcess.h @@ -0,0 +1,55 @@ +/* + * 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 MULTI_PROCESS_H +#define MULTI_PROCESS_H +#include "StatusCode.h" +#ifdef __cplusplus +extern "C" { +#endif +enum PROCESS_TYPE +{ + PROCESS_TYPE_PRIMARY = 0, + PROCESS_TYPE_MINOR, + PROCESS_TYPE_END +}; +typedef struct multi_process MultiProcess; +typedef struct multi_process +{ + const StatusCode (*mMakeSharedData)(MultiProcess *, const unsigned int, const unsigned int); + const StatusCode (*mCleanSharedData)(MultiProcess *); + const StatusCode (*mGetReadableData)(MultiProcess *, void *, const unsigned int); + void (*mSetWritableData)(MultiProcess *, void *, const unsigned int); + void (*mFree)(void *); +} MultiProcess; +MultiProcess *CreateProcessObject(const enum PROCESS_TYPE name, const char *path, const int projectId); +// static inline const StatusCode IMakeSharedData(MultiProcess *object, const unsigned int readableSize, +// const unsigned int writableSize) +// { +// return object->mMakeSharedData(object, readableSize, writableSize); +// } +// static inline const StatusCode ICleanSharedData(MultiProcess *object) { return object->mCleanSharedData(object); } +// static inline const StatusCode IGetReadableData(MultiProcess *object, void *buf, const unsigned int bufLength) +// { +// return object->mGetReadableData(object, buf, bufLength); +// } +// static inline void ISetWritableData(MultiProcess *object, void *buf, const unsigned int bufLength) +// { +// object->mSetWritableData(object, buf, bufLength); +// } +// static inline void IShareDataFree(MultiProcess *object) { object->mFree(object); } +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/utils/MultiProcess/src/MultiProcess.cpp b/utils/MultiProcess/src/MultiProcess.cpp new file mode 100644 index 00000000..0107a18c --- /dev/null +++ b/utils/MultiProcess/src/MultiProcess.cpp @@ -0,0 +1,15 @@ +/* + * 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 "MultiProcess.h" \ No newline at end of file diff --git a/utils/WebServer/CMakeLists.txt b/utils/WebServer/CMakeLists.txt new file mode 100644 index 00000000..2cb686fc --- /dev/null +++ b/utils/WebServer/CMakeLists.txt @@ -0,0 +1,56 @@ +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +include(${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/goahead.cmake) +set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) +set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) + +include_directories( + ./src + ./include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/build/${GOAHEAD_INCLUDE_PATH}/inc + # ${UTILS_SOURCE_PATH}/LinuxApi/include +) +# link_directories( +# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs +# ) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +aux_source_directory(./src SRC_FILES) + +set(TARGET_NAME WebServer) +add_library(${TARGET_NAME} STATIC ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} StatusCode Log) + +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + WebServer_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}/WebServer +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + WebServer_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/WebServer +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make WebServer_code_check + COMMAND make WebServer_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/utils/WebServer/include/WebServer.h b/utils/WebServer/include/WebServer.h new file mode 100644 index 00000000..49f9cec6 --- /dev/null +++ b/utils/WebServer/include/WebServer.h @@ -0,0 +1,26 @@ +/* + * 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 WEB_SERVER_H +#define WEB_SERVER_H +#include "StatusCode.h" +#ifdef __cplusplus +extern "C" { +#endif +StatusCode WebServerInit(void); +StatusCode WebServerUnInit(void); +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/utils/WebServer/src/WebServer.cpp b/utils/WebServer/src/WebServer.cpp new file mode 100644 index 00000000..33d87c62 --- /dev/null +++ b/utils/WebServer/src/WebServer.cpp @@ -0,0 +1,40 @@ +/* + * 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 "WebServer.h" +#include "goahead.h" +#include "js.h" +#include +static int finished = 0; +static void sigHandler(int signo) { finished = 1; } +void initPlatform(void) +{ + signal(SIGINT, sigHandler); + signal(SIGTERM, sigHandler); + signal(SIGKILL, sigHandler); + signal(SIGPIPE, SIG_IGN); +} + +StatusCode WebServerInit(void) +{ + const char *documents = ME_GOAHEAD_DOCUMENTS; + const char *route = "route.txt"; + initPlatform(); + if (websOpen(documents, route) < 0) { + error("Cannot initialize server. Exiting."); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode WebServerUnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } \ No newline at end of file