mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Add goahead module.
This commit is contained in:
parent
30aac0ee1b
commit
690f71e131
15
external/goahead-5.2.0/CMakeLists.txt
vendored
15
external/goahead-5.2.0/CMakeLists.txt
vendored
|
@ -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(
|
||||
|
|
9
external/goahead-5.2.0/goahead.cmake
vendored
Normal file
9
external/goahead-5.2.0/goahead.cmake
vendored
Normal file
|
@ -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}")
|
|
@ -2,5 +2,6 @@
|
|||
add_subdirectory(Config)
|
||||
add_subdirectory(Log)
|
||||
add_subdirectory(SharedData)
|
||||
add_subdirectory(WebServer)
|
||||
|
||||
|
||||
|
|
64
test/utils/WebServer/CMakeLists.txt
Normal file
64
test/utils/WebServer/CMakeLists.txt
Normal file
|
@ -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})
|
23
test/utils/WebServer/mainTest.cpp
Normal file
23
test/utils/WebServer/mainTest.cpp
Normal file
|
@ -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 <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
31
test/utils/WebServer/src/WebServer_Test.cpp
Normal file
31
test/utils/WebServer/src/WebServer_Test.cpp
Normal file
|
@ -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 <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <thread>
|
||||
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
|
|
@ -7,3 +7,4 @@ add_subdirectory(SharedData)
|
|||
add_subdirectory(UartDevice)
|
||||
add_subdirectory(LinuxApi)
|
||||
# add_subdirectory(MultiProcess)
|
||||
add_subdirectory(WebServer)
|
||||
|
|
53
utils/MultiProcess/CMakeLists.txt
Normal file
53
utils/MultiProcess/CMakeLists.txt
Normal file
|
@ -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})
|
55
utils/MultiProcess/include/MultiProcess.h
Normal file
55
utils/MultiProcess/include/MultiProcess.h
Normal file
|
@ -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
|
15
utils/MultiProcess/src/MultiProcess.cpp
Normal file
15
utils/MultiProcess/src/MultiProcess.cpp
Normal file
|
@ -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"
|
56
utils/WebServer/CMakeLists.txt
Normal file
56
utils/WebServer/CMakeLists.txt
Normal file
|
@ -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})
|
26
utils/WebServer/include/WebServer.h
Normal file
26
utils/WebServer/include/WebServer.h
Normal file
|
@ -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
|
40
utils/WebServer/src/WebServer.cpp
Normal file
40
utils/WebServer/src/WebServer.cpp
Normal file
|
@ -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 <signal.h>
|
||||
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); }
|
Loading…
Reference in New Issue
Block a user