Improve:include cleaner.
This commit is contained in:
commit
39ab107f7d
137
.clang-format
Executable file
137
.clang-format
Executable file
|
@ -0,0 +1,137 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: false
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BinPackArguments: false
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: false
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: true
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: BeforeHash
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
...
|
||||
|
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
.vscode
|
||||
Doxygen
|
||||
cmake-shell/
|
||||
external/gtest/googletest-release-1.11.0/
|
||||
external/libconfig/libconfig-1.7.3/
|
||||
output_files/bin/
|
||||
output_files/libs/*a*
|
||||
output_files/libs/*so*
|
||||
output_files/libs/external
|
||||
output_files/test/
|
||||
# !output_files/libs/test_tools/
|
||||
# !output_files/libs/test_tools/*
|
||||
external/openssl/openssl-1.1.1s/
|
||||
external/openssl/openssl-3.1.0/
|
||||
external/openssl/build/
|
||||
external/curl/curl-8.1.2/
|
209
CMakeLists.txt
Normal file
209
CMakeLists.txt
Normal file
|
@ -0,0 +1,209 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
unset(CLANG_TIDY_EXE CACHE)
|
||||
set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING INTERNAL)
|
||||
include(build/global_config.cmake)
|
||||
|
||||
project(fancycode)
|
||||
|
||||
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
|
||||
|
||||
message("platform = ${TARGET_PLATFORM}")
|
||||
message("platform PATH = ${PLATFORM_PATH}")
|
||||
|
||||
add_custom_target(
|
||||
sdk_clean
|
||||
COMMAND echo "sdk clean finished."
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
|
||||
# Gdb debug
|
||||
include(build/sdk_config.cmake)
|
||||
|
||||
# 查看是工具链支持情况
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||
|
||||
# 获取所有修改过的文件
|
||||
execute_process(
|
||||
COMMAND git diff --name-only --diff-filter=ACMRT
|
||||
OUTPUT_VARIABLE MODIFIED_FILES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
set(ALL_MODEFIED_FILES "")
|
||||
string(LENGTH "${MODIFIED_FILES}" GIT_RESULT_STRING_LENGTH)
|
||||
if(GIT_RESULT_STRING_LENGTH EQUAL 0)
|
||||
message("Nothing changed.")
|
||||
else()
|
||||
string(REPLACE "\n" ";" MODIFIED_FILES_LIST ${MODIFIED_FILES})
|
||||
endif()
|
||||
# 遍历每个文件
|
||||
foreach(FILE ${MODIFIED_FILES_LIST})
|
||||
# 检查文件扩展名,只格式化.cpp和.h文件
|
||||
get_filename_component(FILE_EXT ${FILE} EXT)
|
||||
if(FILE_EXT MATCHES "\\.(c|cpp|h)$")
|
||||
set(ALL_MODEFIED_FILES "${ALL_MODEFIED_FILES};${FILE}")
|
||||
endif()
|
||||
endforeach()
|
||||
# 获取未跟踪的文件
|
||||
execute_process(
|
||||
COMMAND git ls-files --others --exclude-standard
|
||||
OUTPUT_VARIABLE UNTRACKED_FILES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
string(LENGTH "${UNTRACKED_FILES}" GIT_RESULT_STRING_LENGTH)
|
||||
if(GIT_RESULT_STRING_LENGTH EQUAL 0)
|
||||
else()
|
||||
string(REPLACE "\n" ";" UNTRACKED_FILES_LIST ${UNTRACKED_FILES})
|
||||
endif()
|
||||
# 遍历每个文件
|
||||
foreach(FILE ${UNTRACKED_FILES_LIST})
|
||||
# 检查文件扩展名,只格式化.cpp和.h文件
|
||||
get_filename_component(FILE_EXT ${FILE} EXT)
|
||||
if(FILE_EXT MATCHES "\\.(c|cpp|h)$")
|
||||
set(ALL_MODEFIED_FILES "${ALL_MODEFIED_FILES};${FILE}")
|
||||
endif()
|
||||
endforeach()
|
||||
string(LENGTH "${ALL_MODEFIED_FILES}" MODIFIED_STRING_LENGTH)
|
||||
# find the clang-tidy tools
|
||||
unset(CLANG_TIDY_EXE CACHE)
|
||||
unset(CLANG_TIDY_FIND CACHE)
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
find_program(CLANG_TIDY_FIND NAMES clang-tidy PATHS ${LLVM_PATH}/build/bin)
|
||||
if(CLANG_TIDY_FIND)
|
||||
message(STATUS "clang-tidy found: ${CLANG_TIDY_FIND}")
|
||||
# set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=no.h -system-headers=no.h -checks=modernize-use-override")
|
||||
set(CLANG_TIDY_EXE ${CLANG_TIDY_FIND} CACHE STRING INTERNAL)
|
||||
message("CLANG_TIDY_EXE = ${CLANG_TIDY_EXE}")
|
||||
|
||||
if(MODIFIED_STRING_LENGTH GREATER 0)
|
||||
add_custom_target(
|
||||
check_modified_code
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${ALL_MODEFIED_FILES}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
--line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]'
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}
|
||||
)
|
||||
endif()
|
||||
|
||||
else()
|
||||
# message(FATAL_ERROR "See ${CMAKE_SOURCE_DIR_IPCSDK}/doc.")
|
||||
message(FATAL_ERROR "You set support clang-tidy, but clang-tidy not found.
|
||||
Check path ${LLVM_PATH}/build/bin, weather clang-tidy exist.
|
||||
How to install tools?
|
||||
See ${IPC_SDK_PATH}/doc/clang-tidy_user_guide.md
|
||||
How to disable clang-tidy tool?
|
||||
Modify: set(CLANG_TIDY_SUPPORT \"false\")
|
||||
See:${IPC_SDK_PATH}/builde/global_config.cmake")
|
||||
endif()
|
||||
endif()
|
||||
# find the clang-format tools
|
||||
unset(CLANG_FORMAT_EXE CACHE)
|
||||
unset(CLANG_FORMAT_FIND CACHE)
|
||||
if ("${CLANG_FORMAT_SUPPORT}" MATCHES "true")
|
||||
find_program(CLANG_FORMAT_FIND NAMES clang-format PATHS ${LLVM_PATH}/build/bin)
|
||||
if(CLANG_FORMAT_FIND)
|
||||
message(STATUS "clang-format found: ${CLANG_FORMAT_FIND}")
|
||||
set(CLANG_FORMAT_EXE ${CLANG_FORMAT_FIND} CACHE STRING INTERNAL)
|
||||
message("CLANG_FORMAT_EXE = ${CLANG_FORMAT_EXE}")
|
||||
|
||||
if(MODIFIED_STRING_LENGTH GREATER 0)
|
||||
add_custom_target(
|
||||
format_modified_code
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${ALL_MODEFIED_FILES}
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}
|
||||
)
|
||||
endif()
|
||||
|
||||
else()
|
||||
message(FATAL_ERROR "You set support clang-format, but clang-format not found.
|
||||
Check path ${LLVM_PATH}/build/bin, weather clang-format exist.
|
||||
How to install tools?
|
||||
See ${IPC_SDK_PATH}/doc/clang-tidy_user_guide.md
|
||||
How to disable clang-format tool?
|
||||
Modify: set(CLANG_FORMAT_SUPPORT \"false\")
|
||||
See:${IPC_SDK_PATH}/builde/global_config.cmake")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MODIFIED_STRING_LENGTH GREATER 0)
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true" AND "${CLANG_FORMAT_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
improve_modified_code
|
||||
DEPENDS format_modified_code check_modified_code
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
# execute_process(COMMAND sh build_lvgl_for_cmakelist.sh ${TARGET_PLATFORM} ${CMAKE_SOURCE_DIR_IPCSDK} WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/lvglLinux-x86/)
|
||||
# add_subdirectory(external/lvglLinux-x86)
|
||||
endif()
|
||||
|
||||
#Add macro definition
|
||||
# add_definitions(-DCONFIG_FILE_PATH=\"${CONFIG_FILE_PATH}\")
|
||||
|
||||
# Config message of main thread
|
||||
unset(MAIN_INCLUDE_PATH CACHE)
|
||||
set(MAIN_INCLUDE_PATH "" CACHE STRING INTERNAL)
|
||||
unset(MAIN_SRC_FILE CACHE)
|
||||
set(MAIN_SRC_FILE "" CACHE STRING INTERNAL)
|
||||
unset(MAIN_LINK_LIB CACHE)
|
||||
set(MAIN_LINK_LIB "" CACHE STRING INTERNAL)
|
||||
|
||||
# Config message for test code.
|
||||
unset(TEST_LINK_LIB CACHE)
|
||||
set(TEST_LINK_LIB "" CACHE STRING INTERNAL)
|
||||
unset(TEST_LINUX_MOCK CACHE)
|
||||
set(TEST_LINUX_MOCK "" CACHE STRING INTERNAL)
|
||||
# if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
set(TEST_LINK_LIB "testUtils" CACHE STRING INTERNAL FORCE)
|
||||
# endif()
|
||||
|
||||
# 添加编译目录
|
||||
add_subdirectory(external)
|
||||
# 检查子目录 application 是否存在,存在再添加
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
||||
message(STATUS "application exists, add application to project.")
|
||||
add_subdirectory(application)
|
||||
else()
|
||||
message(STATUS "application not exists.")
|
||||
endif()
|
||||
add_subdirectory(middleware)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(hal)
|
||||
# add_subdirectory(customization)
|
||||
|
||||
string(COMPARE EQUAL "${PLATFORM_PATH}" "" value)
|
||||
message("The platform path is \"${PLATFORM_PATH}\".")
|
||||
if (value EQUAL 0) #变量被设置了
|
||||
message("build chip board code.")
|
||||
# add_subdirectory(${PLATFORM_PATH})
|
||||
# aux_source_directory(${PLATFORM_PATH})
|
||||
endif()
|
||||
|
||||
message("MAIN_INCLUDE_PATH = ${MAIN_INCLUDE_PATH}")
|
||||
message("MAIN_SRC_FILE = ${MAIN_SRC_FILE}")
|
||||
message("MAIN_LINK_LIB = ${MAIN_LINK_LIB}")
|
||||
# 检查子目录 test 是否存在,存在再添加
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
||||
message(STATUS "test exists, add test to project.")
|
||||
add_subdirectory(test)
|
||||
else()
|
||||
message(STATUS "test not exists.")
|
||||
endif()
|
||||
|
||||
# include(build/global_config.cmake)
|
40
Makefile
Executable file
40
Makefile
Executable file
|
@ -0,0 +1,40 @@
|
|||
gmock:
|
||||
$(MAKE) -C external/gtest all
|
||||
|
||||
gmock_clean:
|
||||
$(MAKE) -C external/gtest clean
|
||||
|
||||
cmake:
|
||||
$(MAKE) -C build/cmake all
|
||||
|
||||
cmake_clean:
|
||||
$(MAKE) -C build/cmake clean
|
||||
|
||||
clean_code:
|
||||
@rm -rf !(Makefile)
|
||||
|
||||
install_cmake:
|
||||
$(MAKE) -C tools/cmake all
|
||||
|
||||
compile_llvm:
|
||||
$(MAKE) -C tools/clang-tidy all
|
||||
|
||||
all:cmake
|
||||
$(MAKE) -C cmake-shell all
|
||||
|
||||
clean:
|
||||
@if [ -d "cmake-shell" ]; then \
|
||||
echo "cmake-shell exist"; \
|
||||
make -C cmake-shell clean; \
|
||||
fi
|
||||
@echo "IPC clean."
|
||||
@rm -rf external/gtest/googletest-release-1.11.0 \
|
||||
external/lvglLinux-x86/lv_sim_vscode_sdl \
|
||||
external/openssl/openssl-1.1.1s \
|
||||
external/openssl/build \
|
||||
external/curl/curl-8.1.2 \
|
||||
external/libconfig/libconfig-1.7.3 \
|
||||
external/goahead-5.2.0/GoAhead \
|
||||
output_files \
|
||||
cmake-shell
|
||||
@git checkout output_files
|
79
README.md
Normal file
79
README.md
Normal file
|
@ -0,0 +1,79 @@
|
|||
# 1. README
|
||||
|
||||
## 1.1. 概述
|
||||
|
||||
  基于IPC领域产品的SDK工程。
|
||||
|
||||
阅读小技巧:
|
||||
|
||||
* SDK工程所有开发文档均使用markdown语法编写,需要使用markdown语法解析器进行解析,方便阅读,如:Typora;开发工程师建议使用vscode安装markdownlint插件进行阅读;
|
||||
* SDK工程所有文档描述路径时,"//"双斜杠表示工程根目录;
|
||||
|
||||
## 1.2. 开发环境准备
|
||||
|
||||
  工程的开发,需要预安装一些开发工具。例如:cmake的特定版本,llvm工具等。
|
||||
|
||||
### 1.2.1. cmake安装
|
||||
|
||||
  cmake是一个跨平台的安装(编译)工具,它是由Kitware公司开发的一个开源软件,可以用来配置、构建、编译一个工程。
|
||||
|
||||
```code
|
||||
# 项目根目录执行:
|
||||
$ make install-cmake
|
||||
```
|
||||
|
||||
### 1.2.2. llvm工具安装
|
||||
|
||||
  LLVM是一个编译器工具链,包含clang编译器、llvm核心库等。此处只用了clang-tidy和clang-format工具,一个负责编码规范,一个负责代码格式化。
|
||||
|
||||
```code
|
||||
# 项目根目录执行:
|
||||
$ make compile_llvm
|
||||
```
|
||||
|
||||
## 1.3. 编译
|
||||
|
||||
  架构设计上支持去平台编译和运行,本仓库源码可仿真运行在ubuntu系统。
|
||||
|
||||
### 1.3.1. Ubuntu系统
|
||||
|
||||
在项目根目录下执行命令:
|
||||
|
||||
```code
|
||||
make clean // 如果之前有跨平台编译过,需要先make clean
|
||||
make cmake // 构建源码,生成Makefile文件
|
||||
cd cmake-shell/ // 在中间文件目录进行编译,把所有中间文件创建在此目录
|
||||
make // 编译全部输出构建文件
|
||||
```
|
||||
|
||||
### 1.3.2. 交叉编译
|
||||
|
||||
参考:
|
||||
|
||||
```code
|
||||
//build/cmake/toolchain/linux.toolchain.cmake
|
||||
//Makefile
|
||||
```
|
||||
|
||||
  参考上述文件新建一份配置文件,建议不要修改原文档,新建一个交叉编译工程,把IPC SDK工程作为子仓库进行git管理,维护SDK的绝对跨平台属性。
|
||||
|
||||
  交叉编译请参考基于IPC SDK作为子仓库的工程配置,此处忽略。
|
||||
|
||||
### 1.3.3. 小技巧
|
||||
|
||||
#### 1.3.3.1. 代码阅读辅助工具(基于vscode)
|
||||
|
||||
  为了方便代码跳转阅读,除了安装基本的c++插件外,结合cmake构建工具生成的compile_commands.json文件可实现代码之间的精准跳转。
|
||||
|
||||
**compile_commands.json文件生成路径:**
|
||||
|
||||
```code
|
||||
//cmake-shell/compile_commands.json
|
||||
```
|
||||
|
||||
**compile_commands.json文件配置方法:**
|
||||
|
||||
```code
|
||||
在//.vscode/settings.json配置文件中添加:
|
||||
"C_Cpp.default.compileCommands": "/home/xiaojiazhu/project/ipc-sdk/ipc/cmake-shell/compile_commands.json",
|
||||
```
|
3
application/CMakeLists.txt
Normal file
3
application/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
add_subdirectory(main)
|
||||
add_subdirectory(HuntingCamera)
|
||||
add_subdirectory(MissionManager)
|
74
application/HuntingCamera/CMakeLists.txt
Normal file
74
application/HuntingCamera/CMakeLists.txt
Normal file
|
@ -0,0 +1,74 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
include(${APPLICATION_SOURCE_PATH}/HuntingCamera/build/hunting_camera.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
${HUNTTING_MAIN_INCLUDE_PATH}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
${LIBS_OUTPUT_PATH}
|
||||
${EXTERNAL_LIBS_OUTPUT_PATH}
|
||||
${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig/lib
|
||||
)
|
||||
|
||||
aux_source_directory(. SRC_FILES)
|
||||
aux_source_directory(./src MAIN_SRC_FILE_THIS)
|
||||
|
||||
# Mark src files for test.
|
||||
# file(GLOB_RECURSE MAIN_SRC_FILE_THIS src/*.cpp src/*.c)
|
||||
# set(MAIN_SRC_FILE "${MAIN_SRC_FILE_THIS}" CACHE STRING INTERNAL FORCE)
|
||||
|
||||
set(TARGET_LIB HuntingMainLib)
|
||||
add_library(${TARGET_LIB} STATIC ${MAIN_SRC_FILE_THIS})
|
||||
set(TARGET_NAME HuntingCamera_x86)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
|
||||
target_link_libraries(${TARGET_LIB} ${HUNTTING_LINK_LIB})
|
||||
target_link_libraries(${TARGET_NAME} ${TARGET_LIB})
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
HuntingCamera_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${SRC_FILES}
|
||||
${MAIN_SRC_FILE_THIS}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/HuntingCamera
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make HuntingCamera_code_check
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
HuntingCamera_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${MAIN_SRC_FILE_THIS} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/HuntingCamera
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make HuntingCamera_code_check
|
||||
COMMAND make HuntingCamera_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
define_file_name(${TARGET_LIB})
|
||||
define_file_name(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES *.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
16
application/HuntingCamera/build/hunting_camera.cmake
Normal file
16
application/HuntingCamera/build/hunting_camera.cmake
Normal file
|
@ -0,0 +1,16 @@
|
|||
set(HUNTTING_MAIN_INCLUDE_PATH "${APPLICATION_SOURCE_PATH}/HuntingCamera/src")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${APPLICATION_SOURCE_PATH}/MissionManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/StateMachine/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/McuManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/AppManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/MediaManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/FilesManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/StorageManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/IpcConfig/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/StatusCode/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/Log/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${HAL_SOURCE_PATH}/include")
|
||||
|
||||
set(HUNTTING_LINK_LIB McuManager MissionManager StateMachine AppManager FilesManager StorageManager HuntingUpgrade IpcConfig DeviceManager StatusCode Log Hal pthread dl)
|
24
application/HuntingCamera/main.cpp
Normal file
24
application/HuntingCamera/main.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 "MainThread.h"
|
||||
#include <thread>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
MainThread::GetInstance()->Init();
|
||||
MainThread::GetInstance()->Runing();
|
||||
MainThread::GetInstance()->UnInit();
|
||||
return 0;
|
||||
}
|
132
application/HuntingCamera/src/MainThread.cpp
Normal file
132
application/HuntingCamera/src/MainThread.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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 "MainThread.h"
|
||||
#include "IAppManager.h"
|
||||
#include "IDeviceManager.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "IHalCpp.h"
|
||||
#include "IHuntingUpgrade.h"
|
||||
#include "IIpcConfig.h"
|
||||
#include "ILog.h"
|
||||
#include "IMcuManager.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include <signal.h>
|
||||
#include <thread>
|
||||
static void sigHandler(int signo)
|
||||
{
|
||||
LogInfo("Stop main application.\n");
|
||||
MainThread::GetInstance()->Exit();
|
||||
}
|
||||
void InitSignalHandle(void)
|
||||
{
|
||||
signal(SIGINT, sigHandler);
|
||||
signal(SIGTERM, sigHandler);
|
||||
signal(SIGKILL, sigHandler);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
MainThread::MainThread()
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MainThread>();
|
||||
if (impl) {
|
||||
if (instance.use_count() == 1) {
|
||||
LogInfo("Instance changed succeed.\n");
|
||||
instance = *impl;
|
||||
}
|
||||
else {
|
||||
LogError("Can't changing the instance becase of using by some one.\n");
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
StatusCode MainThread::Init(void)
|
||||
{
|
||||
InitSignalHandle();
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_EASYLOGGING);
|
||||
CustomizationInit();
|
||||
mMainThreadRuning = true;
|
||||
CreateAllModules();
|
||||
IHalCpp::GetInstance()->Init();
|
||||
IDeviceManager::GetInstance()->Init();
|
||||
IMcuManager::GetInstance()->Init();
|
||||
IStorageManager::GetInstance()->Init();
|
||||
IIpcConfig::GetInstance()->Init();
|
||||
IMediaManager::GetInstance()->Init();
|
||||
IMissionManager::GetInstance()->Init();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::UnInit(void)
|
||||
{
|
||||
IMissionManager::GetInstance()->UnInit();
|
||||
IMediaManager::GetInstance()->UnInit();
|
||||
IIpcConfig::GetInstance()->UnInit();
|
||||
IStorageManager::GetInstance()->UnInit();
|
||||
IMcuManager::GetInstance()->UnInit();
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
IHalCpp::GetInstance()->UnInit();
|
||||
DestoryAllModules();
|
||||
ILogUnInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::CreateAllModules(void)
|
||||
{
|
||||
CreateHalCppModule();
|
||||
CreateMcuManager();
|
||||
CreateStorageManagerModule();
|
||||
CreateFilesManagerModule();
|
||||
CreateMissionManagerModule();
|
||||
CreateStateMachine();
|
||||
CreateAppManagerModule();
|
||||
CreateMediaManagerModule();
|
||||
CreateHuntingUpgradeModule();
|
||||
CreateIpcConfigModule();
|
||||
CreateDeviceManagerModule();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MainThread::DestoryAllModules(void)
|
||||
{
|
||||
DestroyHuntingUpgradeModule();
|
||||
DestroyMediaManagerModule();
|
||||
DestroyAppManagerModule();
|
||||
DestroyStateMachine();
|
||||
DestroyMissionManagerModule();
|
||||
DestroyFilesManagerModule();
|
||||
DestroyStorageManagerModule();
|
||||
DestroyMcuManager();
|
||||
DestroyHalCppModule();
|
||||
DestroyIpcConfigModule();
|
||||
DestroyDeviceManagerModule();
|
||||
}
|
||||
void MainThread::ResetAllPtrMaker(void)
|
||||
{
|
||||
}
|
||||
void MainThread::Runing(void)
|
||||
{
|
||||
while (mMainThreadRuning) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
extern bool CreateProtocolHandleImpl(void);
|
||||
void MainThread::CustomizationInit(void)
|
||||
{
|
||||
CreateProtocolHandleImpl();
|
||||
}
|
42
application/HuntingCamera/src/MainThread.h
Normal file
42
application/HuntingCamera/src/MainThread.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 MAIN_THREAD_H
|
||||
#define MAIN_THREAD_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class MainThread
|
||||
{
|
||||
public:
|
||||
MainThread();
|
||||
virtual ~MainThread() = default;
|
||||
static std::shared_ptr<MainThread> &GetInstance(std::shared_ptr<MainThread> *impl = nullptr);
|
||||
virtual StatusCode Init(void);
|
||||
virtual StatusCode UnInit(void);
|
||||
void Runing(void);
|
||||
void Exit(void)
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
virtual void CustomizationInit(void);
|
||||
|
||||
private:
|
||||
StatusCode CreateAllModules(void);
|
||||
void DestoryAllModules(void);
|
||||
void ResetAllPtrMaker(void);
|
||||
|
||||
private:
|
||||
bool mMainThreadRuning;
|
||||
};
|
||||
#endif // !MAIN_THREAD_H
|
73
application/MissionManager/CMakeLists.txt
Normal file
73
application/MissionManager/CMakeLists.txt
Normal file
|
@ -0,0 +1,73 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
# include(${UTILS_SOURCE_PATH}/WebServer/build/webserver.cmake)
|
||||
include(${MIDDLEWARE_SOURCE_PATH}/AppManager/build/app_manager.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
|
||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||
${UTILS_SOURCE_PATH}/LedControl/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/StateMachine/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/AppManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/MediaManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/FilesManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/StorageManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
||||
)
|
||||
#do not rely on any other library
|
||||
#link_directories(
|
||||
#)
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME MissionManager)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
|
||||
target_link_libraries(${TARGET_NAME} McuAskBase StateMachine MediaManager StorageManager DeviceManager HuntingUpgrade KeyControl LedControl StatusCode Log)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
MissionManager_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 ${APPLICATION_SOURCE_PATH}/MissionManager
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make MissionManager_code_check
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
MissionManager_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/MissionManager
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make MissionManager_code_check
|
||||
COMMAND make MissionManager_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
82
application/MissionManager/README.md
Normal file
82
application/MissionManager/README.md
Normal file
|
@ -0,0 +1,82 @@
|
|||
|
||||
# 1. 相机任务管理
|
||||
|
||||
  相机主业务逻辑使用状态机机制进行管理。
|
||||
|
||||
## 1.1. 任务状态
|
||||
|
||||
  任务状态是指相机启动需要执行的任务,可能是拍照 / 视频,可能是其它任务。
|
||||
|
||||
**例如:**
|
||||
1. 移动物体侦测启动;
|
||||
2. 定时启动拍照 / 录像;
|
||||
3. 测试启动;
|
||||
|
||||
## 1.2. 状态机设计
|
||||
|
||||
### 1.2.1. 状态树设计图
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> TopState
|
||||
TopState --> PowerOff
|
||||
TopState --> MSDCState
|
||||
TopState --> DeviceAbnormal
|
||||
TopState --> MissionState
|
||||
MissionState --> 空闲
|
||||
MissionState --> 存储管理
|
||||
存储管理 --> EMMC
|
||||
存储管理 --> SD卡
|
||||
MissionState --> 媒体管理
|
||||
SD卡 --> 插卡
|
||||
SD卡 --> 拔卡
|
||||
SD卡 --> 卡异常
|
||||
MissionState --> 网络管理
|
||||
网络管理 --> 联网
|
||||
联网 --> 上传文件
|
||||
网络管理 --> 未联网
|
||||
MissionState --> 直播
|
||||
MissionState --> 4G管理
|
||||
4G管理 --> Sim卡初始化
|
||||
4G管理 --> 注网状态
|
||||
MissionState --> Upgrade
|
||||
```
|
||||
|
||||
1. 任意状态处理命令时,不能阻塞,否则整个应用将会瘫痪无法响应任意的命令;
|
||||
2. MissionState: 任务状态,在此状态下,由任务状态处理各种逻辑命令,根据逻辑命令定义,切换到相应的状态再处理数据,处理完数据会停留在当前状态,等待新的命令;
|
||||
|
||||
## 1.3. 任务状态获取启动
|
||||
|
||||
  应用程序运行后,首先需要知道主控是由于何种任务被唤醒,然后根据任务来执行相应的功能代码;
|
||||
|
||||
**时序图**
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant MCU
|
||||
participant 大核
|
||||
MCU ->> MCU:待机
|
||||
opt MCU上电
|
||||
MCU ->> 大核:上电
|
||||
activate 大核
|
||||
大核 ->> 大核:系统初始化
|
||||
大核 ->> 大核:启动脚本拉起APP
|
||||
大核 ->> +MCU:读取启动任务
|
||||
MCU -->> -大核:return
|
||||
alt PIR触发
|
||||
大核 ->> 大核:APP初始化
|
||||
大核 ->> 大核:抓拍并保存
|
||||
else 定时
|
||||
大核 ->> 大核:APP初始化
|
||||
大核 ->> 大核:抓拍并保存
|
||||
else TEST
|
||||
大核 ->> 大核:APP初始化
|
||||
大核 ->> 大核:待机
|
||||
end
|
||||
deactivate 大核
|
||||
end
|
||||
```
|
||||
|
||||
## 1.4. MCU监视器
|
||||
|
||||
  MCU监视器必须由其中一个状态继承,只有状态机运行之后才能处理串口命令。
|
63
application/MissionManager/include/IMissionManager.h
Normal file
63
application/MissionManager/include/IMissionManager.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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 I_MISSION_MANAGER
|
||||
#define I_MISSION_MANAGER
|
||||
#include "StatusCode.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
bool CreateMissionManagerModule(void);
|
||||
bool DestroyMissionManagerModule(void);
|
||||
enum class MissionEvent
|
||||
{
|
||||
TEST = 0,
|
||||
END
|
||||
};
|
||||
class VMissionData
|
||||
{
|
||||
public:
|
||||
VMissionData(const MissionEvent &event) : mEvent(event)
|
||||
{
|
||||
mRetryTimes = 0;
|
||||
mDelayTimeMs = 0;
|
||||
}
|
||||
virtual ~VMissionData() = default;
|
||||
const MissionEvent mEvent;
|
||||
int mRetryTimes;
|
||||
unsigned int mDelayTimeMs;
|
||||
std::function<void(bool, std::shared_ptr<VMissionData>)> mMissionFinshed;
|
||||
};
|
||||
template <typename T>
|
||||
class VMissionDataV2 : public VMissionData
|
||||
{
|
||||
|
||||
public:
|
||||
VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value)
|
||||
{
|
||||
}
|
||||
virtual ~VMissionDataV2() = default;
|
||||
|
||||
public:
|
||||
T mData;
|
||||
};
|
||||
class IMissionManager
|
||||
{
|
||||
public:
|
||||
IMissionManager() = default;
|
||||
virtual ~IMissionManager() = default;
|
||||
static std::shared_ptr<IMissionManager> &GetInstance(std::shared_ptr<IMissionManager> *impl = nullptr);
|
||||
virtual const StatusCode Init(void);
|
||||
virtual const StatusCode UnInit(void);
|
||||
};
|
||||
#endif
|
166
application/MissionManager/src/AppMonitor.cpp
Normal file
166
application/MissionManager/src/AppMonitor.cpp
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* 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 "AppMonitor.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "StatusCode.h"
|
||||
#include <vector>
|
||||
AppMonitor::AppMonitor() : mMicStatus(SwitchStatus::END)
|
||||
{
|
||||
}
|
||||
StatusCode AppMonitor::GetProductInfo(AppGetProductInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetProductInfo.\n");
|
||||
param.mModel = "test";
|
||||
param.mCompany = "test";
|
||||
param.mSoc = "test";
|
||||
param.mSp = "test";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetDeviceAttr.\n");
|
||||
param.mUUID = "test";
|
||||
param.mSoftVersion = "test";
|
||||
param.mOtaVersion = "test";
|
||||
param.mHardwareVersion = "test";
|
||||
param.mSSID = "test";
|
||||
param.mBSSID = "test";
|
||||
param.mCameraNumber = "test";
|
||||
param.mCurrentCameraID = "test";
|
||||
param.mWifiReboot = "test";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetMediaInfo(AppGetMediaInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetMediaInfo.\n");
|
||||
param.mRtspUrl = "rtsp://192.168.169.1/live/0";
|
||||
param.mTransport = "tcp";
|
||||
param.mPort = APP_MANAGER_TCP_SERVER_PORT;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetSdCardInfo.\n");
|
||||
SdCardInfo info;
|
||||
IStorageManager::GetInstance()->GetSdCardInfo(info);
|
||||
param.mStatus = SdCardStatusConvert(info.mEvent);
|
||||
param.mFree = info.mFreeSizeMB;
|
||||
param.mTotal = info.mTotalSizeMB;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetBatteryInfo.\n");
|
||||
param.mCapacity = 0;
|
||||
param.mChargeStatus = ChargeStatus::CHARGING;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
param.mMicStatus = mMicStatus;
|
||||
param.mRec = SwitchStatus::OFF;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetCapability(AppGetCapability ¶m)
|
||||
{
|
||||
param.mPlaybackType = PlaybackType::DOWNLOAD_PLAYBACK;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetLockVideoStatus(LockVideoStatus ¶m)
|
||||
{
|
||||
param = LockVideoStatus::LOCK;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
AppGetStorageInfo info;
|
||||
SdCardInfo sdInfo;
|
||||
IStorageManager::GetInstance()->GetSdCardInfo(sdInfo);
|
||||
info.mIndex = 0;
|
||||
info.mName = "TF card 1";
|
||||
info.mType = StorageType::SD_CARD_1;
|
||||
info.mFree = sdInfo.mFreeSizeMB;
|
||||
info.mTotal = sdInfo.mTotalSizeMB;
|
||||
param.push_back(info);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
if (StorageFileEvent::LOOP == fileInfo.mEvent) {
|
||||
AppGetFileList file;
|
||||
file.mCreateTime_s = 123456789;
|
||||
file.mDuration = 182;
|
||||
file.mName = "/DCIM/2024/01/15/20240115140207-20240115140509.mp4";
|
||||
file.mSize = 1024 * 182;
|
||||
file.mType = StorageFileType::VIDEO;
|
||||
param.push_back(file);
|
||||
AppGetFileList file2;
|
||||
file2.mCreateTime_s = 123456789;
|
||||
file2.mDuration = 0;
|
||||
file2.mName = "/34a396526922a33e97906920dbfef2a5.jpg";
|
||||
file2.mSize = 1024;
|
||||
file2.mType = StorageFileType::PICTURE;
|
||||
param.push_back(file2);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetTimeZone(const unsigned int &zone)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
LogInfo("SetParamValue: param = %s.\n", param.mName.c_str());
|
||||
if (param.mName == "mic") {
|
||||
mMicStatus = static_cast<SwitchStatus>(param.mValue);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::EnterRecorder(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::AppPlayback(const PlayBackEvent &event)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
||||
{
|
||||
param.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
SdCardStatus AppMonitor::SdCardStatusConvert(const StorageEvent &event)
|
||||
{
|
||||
switch (event) {
|
||||
case StorageEvent::SD_CARD_INSERT:
|
||||
return SdCardStatus::NORMAL;
|
||||
case StorageEvent::SD_CARD_REMOVE:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
case StorageEvent::SD_ABNORMAL:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
default:
|
||||
return SdCardStatus::END;
|
||||
}
|
||||
}
|
48
application/MissionManager/src/AppMonitor.h
Normal file
48
application/MissionManager/src/AppMonitor.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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 APP_MONITOR_H
|
||||
#define APP_MONITOR_H
|
||||
#include "IAppManager.h"
|
||||
#include "IStorageManager.h"
|
||||
class AppMonitor : public VAppMonitor
|
||||
{
|
||||
public:
|
||||
AppMonitor();
|
||||
virtual ~AppMonitor() = default;
|
||||
StatusCode GetProductInfo(AppGetProductInfo ¶m) override;
|
||||
StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m) override;
|
||||
StatusCode GetMediaInfo(AppGetMediaInfo ¶m) override;
|
||||
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
||||
StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override;
|
||||
StatusCode GetParamValue(AppParamValue ¶m) override;
|
||||
StatusCode GetCapability(AppGetCapability ¶m) override;
|
||||
StatusCode GetLockVideoStatus(LockVideoStatus ¶m) override;
|
||||
StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> ¶m) override;
|
||||
StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m) override;
|
||||
StatusCode SetDateTime(const AppSetDateTime ¶m) override;
|
||||
StatusCode SetTimeZone(const unsigned int &zone) override;
|
||||
StatusCode SetParamValue(const AppSetParamValue ¶m) override;
|
||||
StatusCode EnterRecorder(void) override;
|
||||
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||
StatusCode GetThumbnail(AppGetThumbnail ¶m) override;
|
||||
|
||||
private:
|
||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||
|
||||
private:
|
||||
SwitchStatus mMicStatus; // TODO: improve delete.
|
||||
};
|
||||
#endif
|
82
application/MissionManager/src/DataProcessing.cpp
Normal file
82
application/MissionManager/src/DataProcessing.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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 "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "KeyControl.h"
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
const bool NOT_EXECUTED = false;
|
||||
const bool EXECUTED = true;
|
||||
key_event_data::key_event_data(const std::string &keyName, const KeyEvent &keyEvent, const unsigned int &holdTime)
|
||||
: mKeyName(keyName), mKeyEvent(keyEvent), mHoldTime(holdTime)
|
||||
{
|
||||
}
|
||||
MissionData::MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
||||
{
|
||||
}
|
||||
MissionMessage::MissionMessage(const std::shared_ptr<VMissionData> &message) : mMissionData(message)
|
||||
{
|
||||
}
|
||||
DataProcessing::DataProcessing()
|
||||
{
|
||||
mEventHandle[InternalStateEvent::KEY_EVENT_HANDLE] = std::bind(&DataProcessing::KeyEventHandle, this, _1);
|
||||
}
|
||||
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
||||
{
|
||||
if (nullptr == msg) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
std::map<InternalStateEvent, DataProcessingFunc>::iterator iter;
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
InternalStateEvent event = static_cast<InternalStateEvent>(message->mMissionData->mEvent);
|
||||
iter = mEventHandle.find(event);
|
||||
if (iter != mEventHandle.end()) {
|
||||
return mEventHandle[event](msg);
|
||||
}
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
bool DataProcessing::KeyEventHandle(VStateMachineData *msg)
|
||||
{
|
||||
if (nullptr == msg) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
std::map<std::string, KeyHandleFunc>::iterator iter;
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<KeyEventData>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<KeyEventData>>(message->mMissionData);
|
||||
if (!data) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
iter = mKeyClickHandle.find(data->mData.mKeyName);
|
||||
if (iter != mKeyClickHandle.end() && KeyEvent::SHORT_CLICK == data->mData.mKeyEvent) {
|
||||
return mKeyClickHandle[data->mData.mKeyName](data->mData);
|
||||
}
|
||||
iter = mKeyHoldDownHandle.find(data->mData.mKeyName);
|
||||
if (iter != mKeyHoldDownHandle.end() && KeyEvent::HOLD_DOWN == data->mData.mKeyEvent) {
|
||||
return mKeyHoldDownHandle[data->mData.mKeyName](data->mData);
|
||||
}
|
||||
iter = mKeyHoldUpHandle.find(data->mData.mKeyName);
|
||||
if (iter != mKeyHoldUpHandle.end() && KeyEvent::HOLD_UP == data->mData.mKeyEvent) {
|
||||
return mKeyHoldUpHandle[data->mData.mKeyName](data->mData);
|
||||
}
|
||||
return NOT_EXECUTED;
|
||||
}
|
78
application/MissionManager/src/DataProcessing.h
Normal file
78
application/MissionManager/src/DataProcessing.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 DATA_PROCESSING_H
|
||||
#define DATA_PROCESSING_H
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "KeyControl.h"
|
||||
#include <functional>
|
||||
#include <map>
|
||||
using std::placeholders::_1;
|
||||
using DataProcessingFunc = std::function<bool(VStateMachineData *)>;
|
||||
enum class InternalStateEvent
|
||||
{
|
||||
STORAGE_HANDLE_STATE_INIT = static_cast<int>(MissionEvent::END),
|
||||
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED,
|
||||
ANY_STATE_SD_STATUS_PERORIED,
|
||||
CHECK_UPGRADE_FILE,
|
||||
MEDIA_REPORT_EVENT,
|
||||
KEY_EVENT_HANDLE,
|
||||
RESET_KEY_MEDIA_TASK,
|
||||
MEDIA_HANDLE_STATE_TASK_TIME_OUT,
|
||||
END
|
||||
};
|
||||
typedef struct key_event_data
|
||||
{
|
||||
key_event_data(const std::string &keyName, const KeyEvent &keyEvent, const unsigned int &holdTime);
|
||||
const std::string mKeyName;
|
||||
const KeyEvent mKeyEvent;
|
||||
const unsigned int mHoldTime;
|
||||
} KeyEventData;
|
||||
using KeyHandleFunc = std::function<bool(const KeyEventData &)>;
|
||||
class MissionData : public VStateMachineData
|
||||
{
|
||||
public:
|
||||
MissionData(const std::shared_ptr<VMissionData> &data);
|
||||
virtual ~MissionData() = default;
|
||||
const std::shared_ptr<VMissionData> mMissionData;
|
||||
};
|
||||
/**
|
||||
* @brief
|
||||
* MissionMessage abstracts user data into state machine data, enabling the transfer of arbitrary data within the state
|
||||
* machine.
|
||||
*/
|
||||
class MissionMessage : public VStateMessage
|
||||
{
|
||||
public:
|
||||
MissionMessage(const std::shared_ptr<VMissionData> &message);
|
||||
virtual ~MissionMessage() = default;
|
||||
const std::shared_ptr<VMissionData> mMissionData; // The message from users of state manager module.
|
||||
};
|
||||
class DataProcessing
|
||||
{
|
||||
public:
|
||||
DataProcessing();
|
||||
virtual ~DataProcessing() = default;
|
||||
bool EventHandle(VStateMachineData *msg);
|
||||
virtual bool KeyEventHandle(VStateMachineData *msg);
|
||||
|
||||
protected:
|
||||
std::map<InternalStateEvent, DataProcessingFunc> mEventHandle;
|
||||
std::map<std::string, DataProcessingFunc> mKeyEventHandle;
|
||||
std::map<std::string, KeyHandleFunc> mKeyClickHandle;
|
||||
std::map<std::string, KeyHandleFunc> mKeyHoldDownHandle;
|
||||
std::map<std::string, KeyHandleFunc> mKeyHoldUpHandle;
|
||||
};
|
||||
#endif
|
40
application/MissionManager/src/IMissionManager.cpp
Normal file
40
application/MissionManager/src/IMissionManager.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 "IMissionManager.h"
|
||||
#include "ILog.h"
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<IMissionManager> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<IMissionManager>();
|
||||
if (impl) {
|
||||
if (instance.use_count() == 1) {
|
||||
LogInfo("Instance changed succeed.\n");
|
||||
instance = *impl;
|
||||
}
|
||||
else {
|
||||
LogError("Can't changing the instance becase of using by some one.\n");
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
const StatusCode IMissionManager::Init(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IMissionManager::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
36
application/MissionManager/src/IdleState.cpp
Normal file
36
application/MissionManager/src/IdleState.cpp
Normal file
|
@ -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.
|
||||
*/
|
||||
#include "IdleState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "IStateMachine.h"
|
||||
IdleState::IdleState() : State("IdleState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&IdleState::MediaReportHandle, this, _1);
|
||||
// mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||
// std::bind(&IdleState::SdCardEventHandle, this, _1);
|
||||
}
|
||||
void IdleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== IdleState::GoInState.\n");
|
||||
}
|
||||
void IdleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== IdleState::GoOutState.\n");
|
||||
}
|
||||
bool IdleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
30
application/MissionManager/src/IdleState.h
Normal file
30
application/MissionManager/src/IdleState.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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 IDLE_STATE_H
|
||||
#define IDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IStateMachine.h"
|
||||
class IdleState : public State, public DataProcessing, public std::enable_shared_from_this<IdleState>
|
||||
{
|
||||
public:
|
||||
IdleState();
|
||||
virtual ~IdleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
};
|
||||
#endif
|
39
application/MissionManager/src/LedsHandle.cpp
Normal file
39
application/MissionManager/src/LedsHandle.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 "LedsHandle.h"
|
||||
#include "ILog.h"
|
||||
#include "LedControl.h"
|
||||
#include "SetLedState.h"
|
||||
void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long int &keepAliveTime,
|
||||
const unsigned int &blinkPeriod)
|
||||
{
|
||||
switch (status) {
|
||||
case DeviceStatus::NORMAL:
|
||||
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
|
||||
break;
|
||||
|
||||
default:
|
||||
LogWarning("unknow device status.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
void inline LedsHandle::DeleteDeviceStatusLed(void)
|
||||
{
|
||||
mDeviceStatus->DeleteState();
|
||||
}
|
||||
void LedsHandle::DeleteAllLeds(void)
|
||||
{
|
||||
DeleteDeviceStatusLed();
|
||||
}
|
46
application/MissionManager/src/LedsHandle.h
Normal file
46
application/MissionManager/src/LedsHandle.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 LEDS_HANDLE_H
|
||||
#define LEDS_HANDLE_H
|
||||
#include "SetLedState.h"
|
||||
enum class DeviceStatus
|
||||
{
|
||||
NORMAL = 0,
|
||||
TAKING_PICTURE_OR_VIDEO,
|
||||
END
|
||||
};
|
||||
class LedsHandle
|
||||
{
|
||||
public:
|
||||
LedsHandle() = default;
|
||||
virtual ~LedsHandle() = default;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief This function is designed as a virtual function so that when the board uses different LED circuits, this
|
||||
* function can be overloaded to achieve polymorphic control of the light.
|
||||
* @param status
|
||||
* @param keepAliveTime
|
||||
* @param blinkPeriod
|
||||
*/
|
||||
virtual void ControlDeviceStatusLed(const DeviceStatus &status, const long int &keepAliveTime = KEEP_ALIVE_FOREVER,
|
||||
const unsigned int &blinkPeriod = LED_NOT_BLINK);
|
||||
void DeleteDeviceStatusLed(void);
|
||||
void DeleteAllLeds(void);
|
||||
|
||||
private:
|
||||
std::shared_ptr<SetLedState> mDeviceStatus;
|
||||
};
|
||||
#endif
|
70
application/MissionManager/src/McuMonitor.cpp
Normal file
70
application/MissionManager/src/McuMonitor.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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 "McuMonitor.h"
|
||||
#include "ILog.h"
|
||||
#include "IMcuManager.h"
|
||||
#include <memory>
|
||||
void McuMonitor::Init(std::shared_ptr<VMcuMonitor> &monitor)
|
||||
{
|
||||
IMcuManager::GetInstance()->SetMcuMonitor(monitor);
|
||||
}
|
||||
void McuMonitor::UnInit(void)
|
||||
{
|
||||
}
|
||||
void McuMonitor::RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission)
|
||||
{
|
||||
}
|
||||
void McuMonitor::RecvMcuHeartBeatEvent(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
}
|
||||
void McuMonitor::RecvGetIntervalStartEvent(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
LogInfo("RecvGetIntervalStartEvent\n");
|
||||
std::shared_ptr<McuRecv<McuGetIntervalStart>> recvData =
|
||||
std::dynamic_pointer_cast<McuRecv<McuGetIntervalStart>>(recv);
|
||||
if (recvData) {
|
||||
recvData->mDataRecvReply.mHour = 10;
|
||||
recvData->mDataRecvReply.mMin = 10;
|
||||
recvData->mDataRecvReply.mSecond = 10;
|
||||
recv->ReplyFinished(true);
|
||||
}
|
||||
recv->ReplyFinished(false);
|
||||
}
|
||||
void McuMonitor::RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
LogInfo("RecvGetDateTime\n");
|
||||
std::shared_ptr<McuRecv<McuReplyDateTime>> recvData = std::dynamic_pointer_cast<McuRecv<McuReplyDateTime>>(recv);
|
||||
if (recvData) {
|
||||
recvData->mDataRecvReply.mYear = 2024;
|
||||
recvData->mDataRecvReply.mMon = 10;
|
||||
recvData->mDataRecvReply.mDay = 10;
|
||||
recvData->mDataRecvReply.mHour = 10;
|
||||
recvData->mDataRecvReply.mMin = 10;
|
||||
recvData->mDataRecvReply.mSecond = 10;
|
||||
recv->ReplyFinished(true);
|
||||
}
|
||||
recv->ReplyFinished(false);
|
||||
}
|
||||
void McuMonitor::RecvGetPirSensitivity(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
LogInfo("RecvGetPirSensitivity\n");
|
||||
std::shared_ptr<McuRecv<McuGetPirSensitivity>> recvData =
|
||||
std::dynamic_pointer_cast<McuRecv<McuGetPirSensitivity>>(recv);
|
||||
if (recvData) {
|
||||
recvData->mDataRecvReply.mSensitivity = 9;
|
||||
recv->ReplyFinished(true);
|
||||
}
|
||||
recv->ReplyFinished(false);
|
||||
}
|
31
application/MissionManager/src/McuMonitor.h
Normal file
31
application/MissionManager/src/McuMonitor.h
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.
|
||||
*/
|
||||
#ifndef MCU_MONITOR_H
|
||||
#define MCU_MONITOR_H
|
||||
#include "IMcuManager.h"
|
||||
class McuMonitor : public VMcuMonitor
|
||||
{
|
||||
public:
|
||||
McuMonitor() = default;
|
||||
virtual ~McuMonitor() = default;
|
||||
void Init(std::shared_ptr<VMcuMonitor> &monitor);
|
||||
void UnInit(void);
|
||||
void RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission) override;
|
||||
void RecvMcuHeartBeatEvent(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
void RecvGetIntervalStartEvent(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
void RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
void RecvGetPirSensitivity(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
};
|
||||
#endif
|
52
application/MissionManager/src/MediaHandleState.cpp
Normal file
52
application/MissionManager/src/MediaHandleState.cpp
Normal file
|
@ -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.
|
||||
*/
|
||||
#include "MediaHandleState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "MediaTaskHandle.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
MediaHandleState::MediaHandleState() : State("MediaHandleState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] =
|
||||
std::bind(&MediaHandleState::ResetKeyMediaTaskHandle, this, _1);
|
||||
}
|
||||
void MediaHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== MediaHandleState::GoInState.\n");
|
||||
if (!mMediaHandle) {
|
||||
MediaTaskHandle::Init();
|
||||
}
|
||||
}
|
||||
void MediaHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== MediaHandleState::GoOutState.\n");
|
||||
}
|
||||
bool MediaHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
void MediaHandleState::TaskResponse(const std::vector<MediaTaskResponse> &response)
|
||||
{
|
||||
}
|
||||
bool MediaHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
||||
{
|
||||
MakeSingleTask(InternalStateEvent::RESET_KEY_MEDIA_TASK, shared_from_this());
|
||||
return EXECUTED;
|
||||
}
|
37
application/MissionManager/src/MediaHandleState.h
Normal file
37
application/MissionManager/src/MediaHandleState.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 MEDIA_HANDLE_STATE_H
|
||||
#define MEDIA_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "MediaTaskHandle.h"
|
||||
class MediaHandleState : public State,
|
||||
public DataProcessing,
|
||||
public MediaTaskHandle,
|
||||
public VMediaTaskIniator,
|
||||
public std::enable_shared_from_this<MediaHandleState>
|
||||
{
|
||||
public:
|
||||
MediaHandleState();
|
||||
virtual ~MediaHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
void TaskResponse(const std::vector<MediaTaskResponse> &response) override;
|
||||
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
28
application/MissionManager/src/MediaTask.cpp
Normal file
28
application/MissionManager/src/MediaTask.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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 "MediaTask.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include <memory>
|
||||
MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||
const std::weak_ptr<VMediaTaskIniator> &iniator)
|
||||
: mType(type), mBindEvent(bindEvent), mIniator(iniator)
|
||||
{
|
||||
mResponseData.reset();
|
||||
}
|
||||
unsigned int MediaTask::GetTaskTimeOutMs(void)
|
||||
{
|
||||
return MEDIA_TASK_TIMEOUT_MS;
|
||||
}
|
42
application/MissionManager/src/MediaTask.h
Normal file
42
application/MissionManager/src/MediaTask.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 MEDIA_TASK_H
|
||||
#define MEDIA_TASK_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
constexpr unsigned int MEDIA_TASK_TIMEOUT_MS = 1000 * 60;
|
||||
class VMediaTaskIniator
|
||||
{
|
||||
public:
|
||||
VMediaTaskIniator() = default;
|
||||
virtual ~VMediaTaskIniator() = default;
|
||||
virtual void TaskResponse(const std::vector<MediaTaskResponse> &response) = 0;
|
||||
};
|
||||
class MediaTask : public VMediaTask
|
||||
{
|
||||
public:
|
||||
MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||
const std::weak_ptr<VMediaTaskIniator> &iniator);
|
||||
virtual ~MediaTask() = default;
|
||||
virtual unsigned int GetTaskTimeOutMs(void);
|
||||
|
||||
private:
|
||||
const MediaTaskType mType;
|
||||
const InternalStateEvent mBindEvent;
|
||||
const std::weak_ptr<VMediaTaskIniator> mIniator;
|
||||
bool mFinished = false;
|
||||
std::shared_ptr<MediaTaskResponse> mResponseData;
|
||||
};
|
||||
#endif
|
57
application/MissionManager/src/MediaTaskHandle.cpp
Normal file
57
application/MissionManager/src/MediaTaskHandle.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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 "MediaTaskHandle.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "MediaTask.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
MediaTaskHandle::MediaTaskHandle()
|
||||
{
|
||||
mMediaHandle.reset();
|
||||
// mMediaHandle = std::make_shared<VMediaHandle>();
|
||||
}
|
||||
void MediaTaskHandle::Init(void)
|
||||
{
|
||||
IMediaManager::GetInstance()->GetMediaChannel(MediaChannel::MEDIA_1, mMediaHandle);
|
||||
}
|
||||
void MediaTaskHandle::UnInit(void)
|
||||
{
|
||||
mMediaHandle->ClearTask();
|
||||
mMediaHandle.reset();
|
||||
}
|
||||
void MediaTaskHandle::MakeSingleTask(const InternalStateEvent &bindEvent,
|
||||
const std::shared_ptr<VMediaTaskIniator> &iniator)
|
||||
{
|
||||
std::shared_ptr<VMediaTask> task = std::make_shared<MediaTask>(MediaTaskType::END, bindEvent, iniator);
|
||||
if (!mMediaHandle) {
|
||||
LogError("MediaHandle is null");
|
||||
return;
|
||||
}
|
||||
auto code = mMediaHandle->ExecuteTask(task);
|
||||
if (IsCodeOK(code)) {
|
||||
mRuningTask = task;
|
||||
long long timeOut = std::dynamic_pointer_cast<MediaTask>(task)->GetTaskTimeOutMs();
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionData>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::MEDIA_HANDLE_STATE_TASK_TIME_OUT));
|
||||
MissionStateMachine::GetInstance()->MessageExecutedLater(message, timeOut);
|
||||
}
|
||||
// else if () {
|
||||
// mMediaHandle->StopTask();
|
||||
// }
|
||||
}
|
35
application/MissionManager/src/MediaTaskHandle.h
Normal file
35
application/MissionManager/src/MediaTaskHandle.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 MEDIA_TASK_HANDLE_H
|
||||
#define MEDIA_TASK_HANDLE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MediaTask.h"
|
||||
class MediaTaskHandle
|
||||
{
|
||||
public:
|
||||
MediaTaskHandle();
|
||||
virtual ~MediaTaskHandle() = default;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
void MakeSingleTask(const InternalStateEvent &bindEvent, const std::shared_ptr<VMediaTaskIniator> &iniator);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<VMediaHandle> mMediaHandle;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VMediaTask> mRuningTask;
|
||||
};
|
||||
#endif
|
29
application/MissionManager/src/MissionManager.cpp
Normal file
29
application/MissionManager/src/MissionManager.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 "MissionManager.h"
|
||||
#include "IAppManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
const StatusCode MissionManager::Init(void)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->Init();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode MissionManager::UnInit(void)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->UnInit();
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
26
application/MissionManager/src/MissionManager.h
Normal file
26
application/MissionManager/src/MissionManager.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 MISSION_MANAGER_H
|
||||
#define MISSION_MANAGER_H
|
||||
#include "IMissionManager.h"
|
||||
class MissionManager : public IMissionManager
|
||||
{
|
||||
public:
|
||||
MissionManager() = default;
|
||||
virtual ~MissionManager() = default;
|
||||
const StatusCode Init(void) override;
|
||||
const StatusCode UnInit(void) override;
|
||||
};
|
||||
#endif
|
123
application/MissionManager/src/MissionManagerMakePtr.cpp
Normal file
123
application/MissionManager/src/MissionManagerMakePtr.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* 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 "MissionManagerMakePtr.h"
|
||||
#include "ILog.h"
|
||||
#include "IMcuManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IdleState.h"
|
||||
#include "MediaHandleState.h"
|
||||
#include "MissionManager.h"
|
||||
#include "OnMissionState.h"
|
||||
#include "PirTriggeredMissionState.h"
|
||||
#include "SdCardHandleState.h"
|
||||
#include "StatusCode.h"
|
||||
#include "StorageHandleState.h"
|
||||
#include "TestMissionState.h"
|
||||
#include "TopState.h"
|
||||
#include "UpgradeState.h"
|
||||
#include <memory>
|
||||
bool CreateMissionManagerModule(void)
|
||||
{
|
||||
auto instance = std::make_shared<IMissionManager>();
|
||||
StatusCode code = MissionManagerMakePtr::GetInstance()->CreateMissionManagerInstance(instance);
|
||||
if (IsCodeOK(code)) {
|
||||
LogInfo("CreateMcuManager is ok.\n");
|
||||
IMissionManager::GetInstance(&instance);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool DestroyMissionManagerModule(void)
|
||||
{
|
||||
auto instance = std::make_shared<IMissionManager>();
|
||||
IMissionManager::GetInstance(&instance);
|
||||
return true;
|
||||
}
|
||||
std::shared_ptr<MissionManagerMakePtr> &MissionManagerMakePtr::GetInstance(std::shared_ptr<MissionManagerMakePtr> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MissionManagerMakePtr>();
|
||||
if (impl) {
|
||||
if (instance.use_count() == 1) {
|
||||
LogInfo("Instance changed succeed.\n");
|
||||
instance = *impl;
|
||||
}
|
||||
else {
|
||||
LogError("Can't changing the instance becase of using by some one.\n");
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
const StatusCode MissionManagerMakePtr::CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance)
|
||||
{
|
||||
instance = std::make_shared<MissionManager>();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateTopState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<TopState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateMissionState(const IpcMission &mission)
|
||||
{
|
||||
LogInfo("MissionManagerMakePtr::CreateMissionState\n");
|
||||
std::shared_ptr<State> state;
|
||||
switch (mission) {
|
||||
case IpcMission::PIR_TRIGGERED:
|
||||
LogInfo("Create PirTriggeredMissionState.\n");
|
||||
state = std::make_shared<PirTriggeredMissionState>();
|
||||
break;
|
||||
case IpcMission::TEST:
|
||||
LogInfo("Create TestMissionState.\n");
|
||||
state = std::make_shared<TestMissionState>();
|
||||
break;
|
||||
case IpcMission::ON:
|
||||
LogInfo("Create OnMissionState.\n");
|
||||
state = std::make_shared<OnMissionState>();
|
||||
break;
|
||||
|
||||
default:
|
||||
LogWarning("Unknown mission.\n");
|
||||
state = std::make_shared<TestMissionState>();
|
||||
break;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateStorageHandleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<StorageHandleState>();
|
||||
// std::dynamic_pointer_cast<StorageHandleState>(state)->Init();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateSdCardHandleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<SdCardHandleState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateUpgradeState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<UpgradeState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateMediaHandleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<MediaHandleState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateIdleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<IdleState>();
|
||||
return state;
|
||||
}
|
37
application/MissionManager/src/MissionManagerMakePtr.h
Normal file
37
application/MissionManager/src/MissionManagerMakePtr.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 MISSION_MANAGER_MAKE_PTR_H
|
||||
#define MISSION_MANAGER_MAKE_PTR_H
|
||||
#include "IMcuManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class MissionManagerMakePtr
|
||||
{
|
||||
public:
|
||||
MissionManagerMakePtr() = default;
|
||||
virtual ~MissionManagerMakePtr() = default;
|
||||
static std::shared_ptr<MissionManagerMakePtr> &GetInstance(std::shared_ptr<MissionManagerMakePtr> *impl = nullptr);
|
||||
virtual const StatusCode CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance);
|
||||
virtual std::shared_ptr<State> CreateTopState(void);
|
||||
virtual std::shared_ptr<State> CreateMissionState(const IpcMission &mission);
|
||||
virtual std::shared_ptr<State> CreateStorageHandleState(void);
|
||||
virtual std::shared_ptr<State> CreateSdCardHandleState(void);
|
||||
virtual std::shared_ptr<State> CreateUpgradeState(void);
|
||||
virtual std::shared_ptr<State> CreateMediaHandleState(void);
|
||||
virtual std::shared_ptr<State> CreateIdleState(void);
|
||||
};
|
||||
#endif
|
60
application/MissionManager/src/MissionState.cpp
Normal file
60
application/MissionManager/src/MissionState.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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 "MissionState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "LedsHandle.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
MissionState::MissionState(const std::string &name) : State(name)
|
||||
{
|
||||
mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&MissionState::MediaReportHandle, this, _1);
|
||||
mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||
std::bind(&MissionState::SdCardEventReportHandle, this, _1);
|
||||
mEventHandle[InternalStateEvent::CHECK_UPGRADE_FILE] = std::bind(&MissionState::CheckUpgradeFileHandle, this, _1);
|
||||
}
|
||||
void MissionState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== MissionState::GoInState.\n");
|
||||
}
|
||||
void MissionState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== MissionState::GoOutState.\n");
|
||||
LedsHandle::DeleteAllLeds();
|
||||
}
|
||||
bool MissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool MissionState::MediaReportHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
||||
bool MissionState::SdCardEventReportHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::SD_CARD_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
||||
bool MissionState::CheckUpgradeFileHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::UPGRADE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
39
application/MissionManager/src/MissionState.h
Normal file
39
application/MissionManager/src/MissionState.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 MISSION_STATE_H
|
||||
#define MISSION_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "LedsHandle.h"
|
||||
class MissionState : public State,
|
||||
public DataProcessing,
|
||||
public LedsHandle,
|
||||
public std::enable_shared_from_this<MissionState>
|
||||
{
|
||||
public:
|
||||
MissionState(const std::string &name);
|
||||
virtual ~MissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
protected:
|
||||
bool SdCardEventReportHandle(VStateMachineData *msg);
|
||||
|
||||
private:
|
||||
bool MediaReportHandle(VStateMachineData *msg);
|
||||
bool CheckUpgradeFileHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
129
application/MissionManager/src/MissionStateMachine.cpp
Normal file
129
application/MissionManager/src/MissionStateMachine.cpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* 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 "MissionStateMachine.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "IMcuManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "McuAskBase.h"
|
||||
#include "MissionManagerMakePtr.h"
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
// #include "TopState.h"
|
||||
std::shared_ptr<MissionStateMachine> &MissionStateMachine::GetInstance(std::shared_ptr<MissionStateMachine> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MissionStateMachine>();
|
||||
if (impl) {
|
||||
instance = *impl;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
MissionStateMachine::MissionStateMachine()
|
||||
{
|
||||
mStartMission = IpcMission::END;
|
||||
}
|
||||
void MissionStateMachine::Init(void)
|
||||
{
|
||||
mStateMachine = std::make_shared<VStateMachineHandle>();
|
||||
auto code = IStateMachine::GetInstance()->CreateStateMachine(mStateMachine);
|
||||
if (!IsCodeOK(code)) {
|
||||
LogError("Create state machine failed[%s].\n", code.mPrintStringCode(code));
|
||||
return;
|
||||
}
|
||||
if (!mStateMachine->InitialStateMachine()) {
|
||||
LogError("State machine init failed.\n");
|
||||
return;
|
||||
}
|
||||
mStartMission = GetStartMission();
|
||||
if (mStartMission == IpcMission::END) {
|
||||
LogError("ipcmission error, will start test mode.\n");
|
||||
mStartMission = IpcMission::TEST;
|
||||
}
|
||||
RunStateMachine(mStartMission);
|
||||
}
|
||||
void MissionStateMachine::UnInit(void)
|
||||
{
|
||||
mStateMachine->StopHandlerThread();
|
||||
mStateTree.clear();
|
||||
}
|
||||
StatusCode MissionStateMachine::SendStateMessage(const std::shared_ptr<VMissionData> &message)
|
||||
{
|
||||
std::shared_ptr<VStateMessage> msg = std::make_shared<MissionMessage>(message);
|
||||
mStateMachine->SendMessage(static_cast<int>(message->mEvent), msg);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MissionStateMachine::MessageExecutedLater(const std::shared_ptr<VMissionData> &message,
|
||||
long long &delayTimeMs)
|
||||
{
|
||||
std::shared_ptr<VStateMessage> msg = std::make_shared<MissionMessage>(message);
|
||||
mStateMachine->MessageExecutedLater(static_cast<int>(message->mEvent), msg, delayTimeMs);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MissionStateMachine::DelayMessage(VStateMachineData *msg)
|
||||
{
|
||||
mStateMachine->DelayMessage(msg);
|
||||
}
|
||||
void MissionStateMachine::SwitchState(const SystemState &state)
|
||||
{
|
||||
mStateMachine->SwitchState(mStateTree[state].get());
|
||||
}
|
||||
IpcMission MissionStateMachine::GetStartMission(void)
|
||||
{
|
||||
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskIpcMission() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
mDataReply = IpcMission::END;
|
||||
}
|
||||
virtual ~McuAskIpcMission() = default;
|
||||
};
|
||||
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskIpcMission>();
|
||||
IMcuManager::GetInstance()->GetIpcMission(ask);
|
||||
return std::dynamic_pointer_cast<McuAskIpcMission>(ask)->mDataReply;
|
||||
}
|
||||
void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||
{
|
||||
LogInfo("Make all states and start the state machine, ipc mission = %s.\n",
|
||||
IMcuManager::GetInstance()->PrintIpcMissionString(mission));
|
||||
mStateTree[SystemState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState();
|
||||
mStateTree[SystemState::MISSION_STATE] = MissionManagerMakePtr::GetInstance()->CreateMissionState(mission);
|
||||
mStateTree[SystemState::STORAGE_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateStorageHandleState();
|
||||
mStateTree[SystemState::SD_CARD_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateSdCardHandleState();
|
||||
mStateTree[SystemState::UPGRADE_STATE] = MissionManagerMakePtr::GetInstance()->CreateUpgradeState();
|
||||
mStateTree[SystemState::MEDIA_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateMediaHandleState();
|
||||
mStateTree[SystemState::IDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateIdleState();
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::TOP_STATE].get(), nullptr);
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::MISSION_STATE].get(), mStateTree[SystemState::TOP_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::STORAGE_HANDLE_STATE].get(),
|
||||
mStateTree[SystemState::MISSION_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::SD_CARD_HANDLE_STATE].get(),
|
||||
mStateTree[SystemState::STORAGE_HANDLE_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::UPGRADE_STATE].get(),
|
||||
mStateTree[SystemState::MISSION_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::MEDIA_HANDLE_STATE].get(),
|
||||
mStateTree[SystemState::MISSION_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::IDLE_STATE].get(), mStateTree[SystemState::MISSION_STATE].get());
|
||||
mStateMachine->SetCurrentState(mStateTree[SystemState::TOP_STATE].get());
|
||||
mStateMachine->StartStateMachine();
|
||||
/**
|
||||
* @brief The business can only be processed after the state machine is started.
|
||||
*
|
||||
*/
|
||||
std::shared_ptr<VMissionData> message =
|
||||
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::STORAGE_HANDLE_STATE_INIT));
|
||||
SendStateMessage(message);
|
||||
}
|
58
application/MissionManager/src/MissionStateMachine.h
Normal file
58
application/MissionManager/src/MissionStateMachine.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 MISSION_STATE_MACHINE_H
|
||||
#define MISSION_STATE_MACHINE_H
|
||||
// #include "IDeviceManager.h"
|
||||
#include "IMcuManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <map>
|
||||
const bool NOT_EXECUTED = false;
|
||||
const bool EXECUTED = true;
|
||||
enum class SystemState
|
||||
{
|
||||
TOP_STATE = 0,
|
||||
MISSION_STATE,
|
||||
STORAGE_HANDLE_STATE,
|
||||
SD_CARD_HANDLE_STATE,
|
||||
UPGRADE_STATE,
|
||||
MEDIA_HANDLE_STATE,
|
||||
IDLE_STATE,
|
||||
END
|
||||
};
|
||||
class MissionStateMachine
|
||||
{
|
||||
public:
|
||||
MissionStateMachine();
|
||||
virtual ~MissionStateMachine() = default;
|
||||
static std::shared_ptr<MissionStateMachine> &GetInstance(std::shared_ptr<MissionStateMachine> *impl = nullptr);
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
StatusCode SendStateMessage(const std::shared_ptr<VMissionData> &message);
|
||||
StatusCode MessageExecutedLater(const std::shared_ptr<VMissionData> &message, long long &delayTimeMs);
|
||||
void DelayMessage(VStateMachineData *msg);
|
||||
void SwitchState(const SystemState &state);
|
||||
|
||||
private:
|
||||
IpcMission GetStartMission(void);
|
||||
void RunStateMachine(const IpcMission &mission);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
||||
std::map<SystemState, std::shared_ptr<State>> mStateTree;
|
||||
IpcMission mStartMission;
|
||||
};
|
||||
#endif
|
38
application/MissionManager/src/OnMissionState.cpp
Normal file
38
application/MissionManager/src/OnMissionState.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 "OnMissionState.h"
|
||||
#include "ILog.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "MissionState.h"
|
||||
#include "MissionStateMachine.h"
|
||||
OnMissionState::OnMissionState() : MissionState("OnMissionState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
// std::bind(&OnMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
}
|
||||
void OnMissionState::GoInState()
|
||||
{
|
||||
MissionState::GoInState();
|
||||
LogInfo(" ========== OnMissionState::GoInState.\n");
|
||||
}
|
||||
void OnMissionState::GoOutState()
|
||||
{
|
||||
MissionState::GoOutState();
|
||||
LogInfo(" ========== OnMissionState::GoOutState.\n");
|
||||
}
|
||||
bool OnMissionState::SdCardEventReportSendToApp(VStateMachineData *msg)
|
||||
{
|
||||
return EXECUTED;
|
||||
}
|
31
application/MissionManager/src/OnMissionState.h
Normal file
31
application/MissionManager/src/OnMissionState.h
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.
|
||||
*/
|
||||
#ifndef ON_MISSION_STATE_H
|
||||
#define ON_MISSION_STATE_H
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionState.h"
|
||||
class OnMissionState : public MissionState
|
||||
{
|
||||
public:
|
||||
OnMissionState();
|
||||
virtual ~OnMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
|
||||
private:
|
||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
38
application/MissionManager/src/PirTrggeredMissionState.cpp
Normal file
38
application/MissionManager/src/PirTrggeredMissionState.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 "IStateMachine.h"
|
||||
#include "MissionState.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include "PirTriggeredMissionState.h"
|
||||
PirTriggeredMissionState::PirTriggeredMissionState() : MissionState("PirTriggeredMissionState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
// std::bind(&PirTriggeredMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
}
|
||||
void PirTriggeredMissionState::GoInState()
|
||||
{
|
||||
MissionState::GoInState();
|
||||
LogInfo(" ========== PirTriggeredMissionState::GoInState.\n");
|
||||
}
|
||||
void PirTriggeredMissionState::GoOutState()
|
||||
{
|
||||
MissionState::GoOutState();
|
||||
LogInfo(" ========== PirTriggeredMissionState::GoOutState.\n");
|
||||
}
|
||||
bool PirTriggeredMissionState::SdCardEventReportSendToApp(VStateMachineData *msg)
|
||||
{
|
||||
return EXECUTED;
|
||||
}
|
31
application/MissionManager/src/PirTriggeredMissionState.h
Normal file
31
application/MissionManager/src/PirTriggeredMissionState.h
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.
|
||||
*/
|
||||
#ifndef PIR_TRIGGERED_MISSION_STATE_H
|
||||
#define PIR_TRIGGERED_MISSION_STATE_H
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionState.h"
|
||||
class PirTriggeredMissionState : public MissionState
|
||||
{
|
||||
public:
|
||||
PirTriggeredMissionState();
|
||||
virtual ~PirTriggeredMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
|
||||
private:
|
||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
94
application/MissionManager/src/SdCardHandleState.cpp
Normal file
94
application/MissionManager/src/SdCardHandleState.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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 "SdCardHandleState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
using std::placeholders::_1;
|
||||
SdCardHandleState::SdCardHandleState() : State("SdCardHandleState"), mSdCardStatus(StorageEvent::END)
|
||||
{
|
||||
mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&SdCardHandleState::MediaReportHandle, this, _1);
|
||||
mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||
std::bind(&SdCardHandleState::SdCardEventHandle, this, _1);
|
||||
}
|
||||
void SdCardHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== SdCardHandleState::GoInState.\n");
|
||||
}
|
||||
void SdCardHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== SdCardHandleState::GoOutState.\n");
|
||||
}
|
||||
bool SdCardHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool SdCardHandleState::MediaReportHandle(VStateMachineData *msg)
|
||||
{
|
||||
LogInfo(" MediaReportHandle.\n");
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<MediaReportEvent>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<MediaReportEvent>>(message->mMissionData);
|
||||
if (!data) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
if (StorageEvent::SD_CARD_INSERT != mSdCardStatus) {
|
||||
/**
|
||||
* @brief The SD card has not been mounted yet, cache the data for the quick start first.
|
||||
*
|
||||
*/
|
||||
LogWarning("Sd card is not inserted, cache data.\n");
|
||||
mFileNeedToSave = std::make_shared<SaveFileInfo>(data->mData.mFileName);
|
||||
return EXECUTED;
|
||||
}
|
||||
LogInfo("file = %s.\n", data->mData.mFileName.c_str());
|
||||
SaveFileInfo saveFileInfo(data->mData.mFileName);
|
||||
StatusCode code = IFilesManager::GetInstance()->SaveFile(saveFileInfo);
|
||||
if (IsCodeOK(code) == false) {
|
||||
LogError("SaveFile failed.\n");
|
||||
}
|
||||
return EXECUTED;
|
||||
}
|
||||
bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg)
|
||||
{
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<StorageEvent>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<StorageEvent>>(message->mMissionData);
|
||||
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
||||
if (mFileNeedToSave && StorageEvent::SD_CARD_INSERT == data->mData) {
|
||||
LogInfo("Sd card is inserted for the first time.\n");
|
||||
StatusCode code = IFilesManager::GetInstance()->SaveFile(*(mFileNeedToSave.get()));
|
||||
if (IsCodeOK(code) == false) {
|
||||
LogError("SaveFile failed.\n");
|
||||
}
|
||||
mFileNeedToSave.reset();
|
||||
}
|
||||
mSdCardStatus = data->mData;
|
||||
if (StorageEvent::SD_CARD_INSERT == mSdCardStatus) {
|
||||
std::shared_ptr<VMissionData> message =
|
||||
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::CHECK_UPGRADE_FILE));
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
}
|
||||
return EXECUTED;
|
||||
}
|
39
application/MissionManager/src/SdCardHandleState.h
Normal file
39
application/MissionManager/src/SdCardHandleState.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 SD_CARD_HANDLE_STATE_H
|
||||
#define SD_CARD_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
class SdCardHandleState : public State, public DataProcessing, public std::enable_shared_from_this<SdCardHandleState>
|
||||
{
|
||||
public:
|
||||
SdCardHandleState();
|
||||
virtual ~SdCardHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
protected:
|
||||
bool MediaReportHandle(VStateMachineData *msg);
|
||||
bool SdCardEventHandle(VStateMachineData *msg);
|
||||
|
||||
private:
|
||||
StorageEvent mSdCardStatus;
|
||||
std::shared_ptr<SaveFileInfo> mFileNeedToSave;
|
||||
};
|
||||
#endif
|
49
application/MissionManager/src/SetLedState.cpp
Normal file
49
application/MissionManager/src/SetLedState.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 "SetLedState.h"
|
||||
#include "IDeviceManager.h"
|
||||
#include "LedControl.h"
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
SetLedState::SetLedState(const LedState &state, const unsigned int &keepAliveTime, const unsigned int &blinkPeriod)
|
||||
: mState(state), mKeepAliveTime(keepAliveTime), mBlinkPeriod(blinkPeriod)
|
||||
{
|
||||
}
|
||||
StatusCode SetLedState::GetLedState(LedState &state)
|
||||
{
|
||||
state = mState;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
unsigned int SetLedState::GetKeepAliveTimeMs(void)
|
||||
{
|
||||
return mKeepAliveTime;
|
||||
}
|
||||
unsigned int SetLedState::GetBlinkTimeMs(void)
|
||||
{
|
||||
return mBlinkPeriod;
|
||||
}
|
||||
void SetLedState::DeleteState(void)
|
||||
{
|
||||
mKeepAliveTime = DELETED_LED_STATE;
|
||||
}
|
||||
std::shared_ptr<SetLedState> SetLedState::ControlLed(const std::string &ledName, const LedState &state,
|
||||
const long int &keepAliveTime, const unsigned int &blinkPeriod)
|
||||
{
|
||||
std::shared_ptr<SetLedState> ledState = std::make_shared<SetLedState>(state, keepAliveTime, blinkPeriod);
|
||||
std::shared_ptr<LedControlContext> ledState2 = ledState;
|
||||
IDeviceManager::GetInstance()->ControlLed(ledName, ledState2);
|
||||
return ledState;
|
||||
}
|
42
application/MissionManager/src/SetLedState.h
Normal file
42
application/MissionManager/src/SetLedState.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 SET_LED_STATE_H
|
||||
#define SET_LED_STATE_H
|
||||
#include "IDeviceManager.h"
|
||||
#include "LedControl.h"
|
||||
constexpr int LED_BLINKING_FAST_PERIOD = 500;
|
||||
constexpr int LED_BLINKING_SLOW_PERIOD = 1000;
|
||||
class SetLedState : public LedControlContext, public VSingleControl
|
||||
{
|
||||
public:
|
||||
SetLedState(const LedState &state, const unsigned int &keepAliveTime = KEEP_ALIVE_FOREVER,
|
||||
const unsigned int &blinkPeriod = LED_NOT_BLINK);
|
||||
virtual ~SetLedState() = default;
|
||||
StatusCode GetLedState(LedState &state) override;
|
||||
unsigned int GetKeepAliveTimeMs(void) override;
|
||||
unsigned int GetBlinkTimeMs(void) override;
|
||||
void DeleteState(void);
|
||||
|
||||
public:
|
||||
static std::shared_ptr<SetLedState> ControlLed(const std::string &ledName, const LedState &state,
|
||||
const long int &keepAliveTime = KEEP_ALIVE_FOREVER,
|
||||
const unsigned int &blinkPeriod = LED_NOT_BLINK);
|
||||
|
||||
private:
|
||||
const LedState mState;
|
||||
unsigned int mKeepAliveTime;
|
||||
const unsigned int mBlinkPeriod;
|
||||
};
|
||||
#endif
|
64
application/MissionManager/src/StorageHandleState.cpp
Normal file
64
application/MissionManager/src/StorageHandleState.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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 "StorageHandleState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
StorageHandleState::StorageHandleState() : State("StorageHandleState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::STORAGE_HANDLE_STATE_INIT] =
|
||||
std::bind(&StorageHandleState::StorageStartInitHandle, this, _1);
|
||||
}
|
||||
void StorageHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== StorageHandleState::GoInState.\n");
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::SD_CARD_HANDLE_STATE);
|
||||
}
|
||||
void StorageHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== StorageHandleState::GoOutState.\n");
|
||||
}
|
||||
bool StorageHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
void StorageHandleState::Init(void)
|
||||
{
|
||||
std::shared_ptr<VStorageMoniter> monitor = shared_from_this();
|
||||
IStorageManager::GetInstance()->SetMonitor(monitor);
|
||||
}
|
||||
void StorageHandleState::UnInit(void)
|
||||
{
|
||||
}
|
||||
void StorageHandleState::ReportEvent(const StorageEvent &event)
|
||||
{
|
||||
LogInfo("StorageHandleState::ReportEvent.\n");
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<StorageEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
std::shared_ptr<VMissionData> message2 = std::make_shared<VMissionDataV2<StorageEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message2);
|
||||
}
|
||||
bool StorageHandleState::StorageStartInitHandle(VStateMachineData *msg)
|
||||
{
|
||||
Init();
|
||||
return EXECUTED;
|
||||
}
|
39
application/MissionManager/src/StorageHandleState.h
Normal file
39
application/MissionManager/src/StorageHandleState.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 STORAGE_HANDLE_STATE_H
|
||||
#define STORAGE_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
class StorageHandleState : public State,
|
||||
public DataProcessing,
|
||||
public VStorageMoniter,
|
||||
public std::enable_shared_from_this<StorageHandleState>
|
||||
{
|
||||
public:
|
||||
StorageHandleState();
|
||||
virtual ~StorageHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
|
||||
private: // About VStorageMoniter
|
||||
void ReportEvent(const StorageEvent &event) override;
|
||||
bool StorageStartInitHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
91
application/MissionManager/src/TestMissionState.cpp
Normal file
91
application/MissionManager/src/TestMissionState.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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 "TestMissionState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "LedsHandle.h"
|
||||
#include "MissionState.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
TestMissionState::TestMissionState() : MissionState("TestMissionState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
std::bind(&TestMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] =
|
||||
std::bind(&TestMissionState::ResetKeyMediaTaskHandle, this, _1);
|
||||
mKeyClickHandle["reset"] = std::bind(&TestMissionState::ClickResetKey, this, _1);
|
||||
}
|
||||
void TestMissionState::GoInState()
|
||||
{
|
||||
MissionState::GoInState();
|
||||
LogInfo(" ========== TestMissionState::GoInState.\n");
|
||||
AppParam mAppParam(APP_MANAGER_DEVICE_IP, APP_MANAGER_HTTP_SERVER_PORT, APP_MANAGER_TCP_SERVER_PORT); // TODO:
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
std::shared_ptr<VAppMonitor> monitor =
|
||||
std::dynamic_pointer_cast<TestMissionState>(MissionState::shared_from_this());
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
ControlDeviceStatusLed(DeviceStatus::NORMAL);
|
||||
}
|
||||
void TestMissionState::GoOutState()
|
||||
{
|
||||
MissionState::GoOutState();
|
||||
LogInfo(" ========== TestMissionState::GoOutState.\n");
|
||||
}
|
||||
bool TestMissionState::SdCardEventReportSendToApp(VStateMachineData *msg)
|
||||
{
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<StorageEvent>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<StorageEvent>>(message->mMissionData);
|
||||
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
||||
SdCardStatus status = SdCardStatusConvert(data->mData);
|
||||
IAppManager::GetInstance()->SetSdCardStatus(status);
|
||||
return EXECUTED;
|
||||
}
|
||||
bool TestMissionState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::MEDIA_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
||||
bool TestMissionState::ClickResetKey(const KeyEventData &data)
|
||||
{
|
||||
LogInfo("reset key click:make a media task.\n");
|
||||
// std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<MediaReportEvent>>(
|
||||
// static_cast<MissionEvent>(InternalStateEvent::MEDIA_REPORT_EVENT), event);
|
||||
// MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
std::shared_ptr<VMissionData> message =
|
||||
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::RESET_KEY_MEDIA_TASK));
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
return EXECUTED;
|
||||
}
|
||||
SdCardStatus TestMissionState::SdCardStatusConvert(const StorageEvent &event)
|
||||
{
|
||||
switch (event) {
|
||||
case StorageEvent::SD_CARD_INSERT:
|
||||
return SdCardStatus::NORMAL;
|
||||
case StorageEvent::SD_CARD_REMOVE:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
case StorageEvent::SD_ABNORMAL:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
default:
|
||||
LogError("SdCardStatusConvert failed.\n");
|
||||
return SdCardStatus::END;
|
||||
}
|
||||
}
|
37
application/MissionManager/src/TestMissionState.h
Normal file
37
application/MissionManager/src/TestMissionState.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 TEST_MISSION_STATE_H
|
||||
#define TEST_MISSION_STATE_H
|
||||
#include "AppMonitor.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionState.h"
|
||||
class TestMissionState : public MissionState, public AppMonitor
|
||||
{
|
||||
public:
|
||||
TestMissionState();
|
||||
virtual ~TestMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
|
||||
private:
|
||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||
bool ClickResetKey(const KeyEventData &data);
|
||||
|
||||
private:
|
||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||
};
|
||||
#endif
|
77
application/MissionManager/src/TopState.cpp
Normal file
77
application/MissionManager/src/TopState.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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 "TopState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "IDeviceManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IMcuManager.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "KeyControl.h"
|
||||
#include "McuMonitor.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
TopState::TopState() : State("TopState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::STORAGE_HANDLE_STATE_INIT] =
|
||||
std::bind(&TopState::StorageStartInitHandle, this, _1);
|
||||
}
|
||||
void TopState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== TopState::GoInState.\n");
|
||||
std::shared_ptr<VMcuMonitor> mcuMonitor = std::dynamic_pointer_cast<VMcuMonitor>(shared_from_this());
|
||||
McuMonitor::Init(mcuMonitor);
|
||||
std::shared_ptr<VMediaMonitor> mediaMonitor = std::dynamic_pointer_cast<VMediaMonitor>(shared_from_this());
|
||||
IMediaManager::GetInstance()->SetMediaMonitor(mediaMonitor);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::MISSION_STATE);
|
||||
std::shared_ptr<VKeyMonitor> keysMonitor = std::dynamic_pointer_cast<VKeyMonitor>(shared_from_this());
|
||||
IDeviceManager::GetInstance()->SetAllKeysMonitor(keysMonitor);
|
||||
}
|
||||
void TopState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== TopState::GoOutState.\n");
|
||||
}
|
||||
bool TopState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
StatusCode TopState::ReportEvent(const MediaReportEvent &event)
|
||||
{
|
||||
LogInfo(" ReportEvent:\n");
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<MediaReportEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::MEDIA_REPORT_EVENT), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void TopState::KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs)
|
||||
{
|
||||
LogInfo(" KeyEventReport:key name = %s, key event = %s, time = %d\n",
|
||||
keyName.c_str(),
|
||||
PrintKeyEvent(static_cast<KeyEvent>(event)),
|
||||
timeMs);
|
||||
KeyEventData data(keyName, static_cast<KeyEvent>(event), timeMs);
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<KeyEventData>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::KEY_EVENT_HANDLE), data);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
}
|
||||
bool TopState::StorageStartInitHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
45
application/MissionManager/src/TopState.h
Normal file
45
application/MissionManager/src/TopState.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 TOP_STATE_H
|
||||
#define TOP_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IDeviceManager.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "McuMonitor.h"
|
||||
class TopState : public State,
|
||||
public DataProcessing,
|
||||
public VMediaMonitor,
|
||||
public McuMonitor,
|
||||
public VKeyMonitor,
|
||||
public std::enable_shared_from_this<TopState>
|
||||
{
|
||||
public:
|
||||
TopState();
|
||||
virtual ~TopState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private: // About VMediaMonitor
|
||||
StatusCode ReportEvent(const MediaReportEvent &event) override;
|
||||
|
||||
private: // About KeyMonitor
|
||||
void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) override;
|
||||
|
||||
private:
|
||||
bool StorageStartInitHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
44
application/MissionManager/src/UpgradeState.cpp
Normal file
44
application/MissionManager/src/UpgradeState.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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 "UpgradeState.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "IHuntingUpgrade.h"
|
||||
#include "ILog.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include <functional>
|
||||
UpgradeState::UpgradeState() : State("UpgradeState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::CHECK_UPGRADE_FILE] = std::bind(&UpgradeState::CheckUpgradeFileHandle, this, _1);
|
||||
}
|
||||
void UpgradeState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== UpgradeState::GoInState.\n");
|
||||
}
|
||||
void UpgradeState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== UpgradeState::GoOutState.\n");
|
||||
}
|
||||
bool UpgradeState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool UpgradeState::CheckUpgradeFileHandle(VStateMachineData *msg)
|
||||
{
|
||||
// TODO: need to improve:It cannot be blocked.
|
||||
IHuntingUpgrade::GetInstance()->CheckUpgradeFile();
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
32
application/MissionManager/src/UpgradeState.h
Normal file
32
application/MissionManager/src/UpgradeState.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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 UPGRADE_STATE_H
|
||||
#define UPGRADE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
class UpgradeState : public State, public DataProcessing, public std::enable_shared_from_this<UpgradeState>
|
||||
{
|
||||
public:
|
||||
UpgradeState();
|
||||
virtual ~UpgradeState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
bool CheckUpgradeFileHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
65
application/main/CMakeLists.txt
Normal file
65
application/main/CMakeLists.txt
Normal file
|
@ -0,0 +1,65 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
|
||||
set(MAIN_INCLUDE_PATH "${APPLICATION_SOURCE_PATH}/main/src" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/StatusCode/include" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/Log/include" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${HAL_SOURCE_PATH}/include" CACHE STRING INTERNAL FORCE)
|
||||
include_directories(${MAIN_INCLUDE_PATH})
|
||||
|
||||
link_directories(
|
||||
${LIBS_OUTPUT_PATH}
|
||||
${HAL_SOURCE_PATH}/include
|
||||
)
|
||||
|
||||
aux_source_directory(./ SRC_FILES)
|
||||
# aux_source_directory(./src SRC_FILES)
|
||||
|
||||
# Mark src files for test.
|
||||
file(GLOB_RECURSE MAIN_SRC_FILE_THIS src/*.cpp src/*.c)
|
||||
set(MAIN_SRC_FILE "${MAIN_SRC_FILE_THIS}" CACHE STRING INTERNAL FORCE)
|
||||
|
||||
|
||||
set(TARGET_LIB MainLib)
|
||||
add_library(${TARGET_LIB} STATIC ${MAIN_SRC_FILE_THIS})
|
||||
set(TARGET_NAME ipc_x86)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
|
||||
set(LINK_LIB StatusCode Log Hal pthread dl)
|
||||
set(MAIN_LINK_LIB "${LINK_LIB}" CACHE STRING INTERNAL FORCE)
|
||||
target_link_libraries(${TARGET_LIB} ${MAIN_LINK_LIB})
|
||||
target_link_libraries(${TARGET_NAME} ${TARGET_LIB})
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
ipc_x86_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${MAIN_SRC_FILE_THIS}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/main
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
ipc_x86_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES} ${MAIN_SRC_FILE_THIS}
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/main
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make ipc_x86_code_check
|
||||
COMMAND make ipc_x86_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
24
application/main/main.cpp
Normal file
24
application/main/main.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 "MainThread.h"
|
||||
#include <thread>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
MainThread::GetInstance()->Init();
|
||||
MainThread::GetInstance()->Runing();
|
||||
MainThread::GetInstance()->UnInit();
|
||||
return 0;
|
||||
}
|
73
application/main/src/MainThread.cpp
Normal file
73
application/main/src/MainThread.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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 "MainThread.h"
|
||||
#include "IHalCpp.h"
|
||||
#include "ILog.h"
|
||||
#include <thread>
|
||||
MainThread::MainThread()
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MainThread>();
|
||||
if (impl) {
|
||||
if (instance.use_count() == 1) {
|
||||
LogInfo("Instance changed succeed.\n");
|
||||
instance = *impl;
|
||||
}
|
||||
else {
|
||||
LogError("Can't changing the instance becase of using by some one.\n");
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
StatusCode MainThread::Init(void)
|
||||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_EASYLOGGING);
|
||||
CustomizationInit();
|
||||
mMainThreadRuning = true;
|
||||
CreateAllModules();
|
||||
// IHalInit();
|
||||
IHalCpp::GetInstance()->Init();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::UnInit(void)
|
||||
{
|
||||
IHalCpp::GetInstance()->UnInit();
|
||||
DestoryAllModules();
|
||||
ILogUnInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::CreateAllModules(void)
|
||||
{
|
||||
// CreateLogModule();
|
||||
// CreateHalModule();
|
||||
CreateHalCppModule();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MainThread::DestoryAllModules(void)
|
||||
{
|
||||
}
|
||||
void MainThread::ResetAllPtrMaker(void)
|
||||
{
|
||||
}
|
||||
void MainThread::Runing(void)
|
||||
{
|
||||
while (mMainThreadRuning) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
44
application/main/src/MainThread.h
Normal file
44
application/main/src/MainThread.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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 MAIN_THREAD_H
|
||||
#define MAIN_THREAD_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class MainThread
|
||||
{
|
||||
public:
|
||||
MainThread();
|
||||
virtual ~MainThread() = default;
|
||||
static std::shared_ptr<MainThread> &GetInstance(std::shared_ptr<MainThread> *impl = nullptr);
|
||||
virtual StatusCode Init(void);
|
||||
virtual StatusCode UnInit(void);
|
||||
void Runing(void);
|
||||
void Exit(void)
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
virtual void CustomizationInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
StatusCode CreateAllModules(void);
|
||||
void DestoryAllModules(void);
|
||||
void ResetAllPtrMaker(void);
|
||||
|
||||
private:
|
||||
bool mMainThreadRuning;
|
||||
};
|
||||
#endif // !MAIN_THREAD_H
|
3
build/README.md
Normal file
3
build/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# cmake编译配置
|
||||
## 目录
|
||||
./toolchain:配置编译工具链
|
8
build/cmake/Makefile
Normal file
8
build/cmake/Makefile
Normal file
|
@ -0,0 +1,8 @@
|
|||
all:
|
||||
@mkdir -p ../../cmake-shell;\
|
||||
cd ../../cmake-shell;\
|
||||
pwd;\
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE="./build/cmake/toolchain/linux.toolchain.cmake" ..;\
|
||||
cd ..
|
||||
clean:
|
||||
rm -rf ../../cmake-shell
|
2
build/cmake/README.md
Normal file
2
build/cmake/README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# cmake
|
||||
|
89
build/cmake/toolchain/linux.toolchain.cmake
Executable file
89
build/cmake/toolchain/linux.toolchain.cmake
Executable file
|
@ -0,0 +1,89 @@
|
|||
|
||||
INCLUDE(CMakeForceCompiler)
|
||||
|
||||
set(LINUX_TEST "true")
|
||||
set(CROSS_COMPILE_PREFIX "")
|
||||
set(CMAKE_C_COMPILER "${CROSS_COMPILE_PREFIX}gcc")
|
||||
set(CMAKE_CXX_COMPILER "${CROSS_COMPILE_PREFIX}g++")
|
||||
|
||||
# path to compiler and utilities
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
# Name of the target platform
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
# Version of the system
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
cmake_policy(SET CMP0011 NEW)
|
||||
cmake_policy(SET CMP0005 NEW)
|
||||
|
||||
add_definitions(-Wall -O2 -Os)
|
||||
add_definitions(-Wno-unused-local-typedefs)
|
||||
add_definitions(-Wstrict-aliasing -Wwrite-strings)
|
||||
|
||||
set(TOOLCHAIN_NAME arm-linux-gnueabihf)
|
||||
|
||||
set(TARGET_PLATFORM "linux")
|
||||
set(SUBMODULE_PATH_OF_IPC_SDK "")
|
||||
set(PLATFORM_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(TEST_COVERAGE "true")
|
||||
add_definitions(-DPLATFORM_PATH=\"${PLATFORM_PATH}\")
|
||||
set(PROJECT_OUTPUT_FOLDER "output_files")
|
||||
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_OUTPUT_FOLDER}")
|
||||
|
||||
# ------------ build curl + openssl ------------ #
|
||||
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
||||
# ------------ build curl + openssl end ------------ #
|
||||
|
||||
# ------------ build IpcConfig ------------ #
|
||||
set(IPC_CONFIG_FILE_PATH "./ipc_config")
|
||||
set(USERDATA_MOUNT_PATH "/userdata")
|
||||
# ------------ build IpcConfig end ------------ #
|
||||
|
||||
# ------------ build log ------------ #
|
||||
set(LOG_SUPPORT "true")
|
||||
# ------------ build log end ------------ #
|
||||
|
||||
# ------------ build GoAhead ------------ #
|
||||
set(GOAHEAD_DOCUMENTS_PATH "web")
|
||||
set(GOAHEAD_UPLOAD_TMP_PATH "./goahead")
|
||||
set(GOAHEAD_UPLOAD_PATH "${GOAHEAD_UPLOAD_TMP_PATH}")
|
||||
set(GOAHEAD_LIMIT_POST "335544320") # If not defined means using default setting. See goahead-linux-static-fancy.mk
|
||||
# GOAHEAD_CONFIG_FILE_PATH should be set when cross compile
|
||||
set(GOAHEAD_CONFIG_FILE_PATH ".")
|
||||
# ------------ build GoAhead end ------------ #
|
||||
|
||||
# ------------ build McuManager ------------ #
|
||||
set(MCU_UART_DEVICE "dev/s1")
|
||||
# ------------ build McuManager end ------------ #
|
||||
|
||||
# ------------ build curl + openssl ------------ start
|
||||
set(CROSS_COMPILE_PREFIX "")
|
||||
# set(CROSS_COMPILE_PREFIX "")
|
||||
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
||||
set(CURL_SHARED_LIBS_PATH "/mnt/mmc")
|
||||
# ------------ build curl + openssl ------------ end
|
||||
|
||||
# ------------ build AppManager ------------ #
|
||||
set(APP_MANAGER_DEVICE_IP "localhost")
|
||||
# set(APP_MANAGER_DEVICE_IP "192.168.1.29")
|
||||
set(APP_MANAGER_HTTP_SERVER_PORT "8080")
|
||||
set(APP_MANAGER_TCP_SERVER_PORT "9876")
|
||||
# ------------ build AppManager end ------------ #
|
||||
|
||||
# ------------ build sd card ------------ #
|
||||
set(SD_CARD_DEV "/dev/test")
|
||||
set(SD_CARD_MOUNT_PATH "./sdcard")
|
||||
# ------------ build sd card end ------------ #
|
||||
|
||||
# ------------ build upgrade ------------ #
|
||||
set(APPLICATION_CHECK_PATH "/application.bin")
|
||||
set(APPLICATION_UPGRADE_PATH "./fastboot_server")
|
||||
set(APPLICATION_VERSION_1 1)
|
||||
set(APPLICATION_VERSION_2 0)
|
||||
set(APPLICATION_VERSION_3 0)
|
||||
set(APPLICATION_VERSION_4 0)
|
||||
# ------------ build upgrade end ------------ #
|
88
build/global_config.cmake
Executable file
88
build/global_config.cmake
Executable file
|
@ -0,0 +1,88 @@
|
|||
set(DEFINE_LINUX "linux")
|
||||
# set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_SOURCE_DIR}")
|
||||
# set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_SOURCE_DIR_IPCSDK}${SUBMODULE_PATH_OF_IPC_SDK}")
|
||||
set(EXEC_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/bin")
|
||||
set(LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs")
|
||||
set(TEST_TOOLS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs/test_tools")
|
||||
set(EXTERNAL_LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs/external")
|
||||
set(TEST_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/test")
|
||||
|
||||
set(PROJECT_ROOT_PATH "${PLATFORM_PATH}")
|
||||
set(APPLICATION_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/application")
|
||||
set(MIDDLEWARE_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/middleware")
|
||||
set(UTILS_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/utils")
|
||||
set(HAL_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/hal")
|
||||
set(TEST_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/test")
|
||||
set(EXTERNAL_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/external")
|
||||
|
||||
# -------------------------- clang-tidy tools -------------------------- #
|
||||
set(CLANG_TIDY_CHECKS "-*,\
|
||||
llvm-else-after-return,\
|
||||
-llvm-include-order,\
|
||||
llvm-namespace-comment,\
|
||||
llvm-prefer-isa-or-dyn-cast-in-conditionals,\
|
||||
llvm-prefer-register-over-unsigned,\
|
||||
llvm-qualified-auto,\
|
||||
llvm-twine-local,\
|
||||
misc-confusable-identifiers,\
|
||||
misc-definitions-in-headers,\
|
||||
misc-header-include-cycle,\
|
||||
misc-include-cleaner,\
|
||||
misc-misleading-bidirectional,\
|
||||
misc-misleading-identifier,\
|
||||
misc-misplaced-const,\
|
||||
misc-new-delete-overloads,\
|
||||
misc-non-copyable-objects,\
|
||||
misc-redundant-expression,\
|
||||
misc-static-assert,\
|
||||
misc-throw-by-value-catch-by-reference,\
|
||||
misc-unconventional-assign-operator,\
|
||||
misc-uniqueptr-reset-release,\
|
||||
misc-unused-alias-decls,\
|
||||
misc-unused-using-decls,\
|
||||
readability-identifier-naming")
|
||||
|
||||
# set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},llvm-header-guard")
|
||||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-clang-diagnostic-error")
|
||||
|
||||
set(CLANG_TIDY_CONFIG "-header-filter=\'.*\'")
|
||||
set(CLANG_TIDY_CONFIG "${CLANG_TIDY_CONFIG} -p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell")
|
||||
|
||||
# set(CLANG_FORMAT_FILE "${CMAKE_SOURCE_DIR_IPCSDK}/tools/clang-format/.clang-format")
|
||||
set(CLANG_FORMAT_FILE "LLVM ${CMAKE_SOURCE_DIR_IPCSDK}/tools/clang-format/.clang-format")
|
||||
# -------------------------- clang-tidy tools end -------------------------- #
|
||||
# ------------ build clang-tools ------------ #
|
||||
if(${LINUX_TEST} MATCHES "true")
|
||||
set(CLANG_TIDY_SUPPORT "true")
|
||||
set(CLANG_FORMAT_SUPPORT "true")
|
||||
set(COMPILE_IMPROVE_SUPPORT "false") # 开启后每次编译可能会很慢
|
||||
set(LLVM_PATH "$ENV{HOME}/llvm-project")
|
||||
endif()
|
||||
# ------------ build clang-tools end ------------ #
|
||||
|
||||
# -------------------------- log setting -------------------------- #
|
||||
function(define_file_name target)
|
||||
get_target_property(source_files "${target}" SOURCES)
|
||||
foreach(source_file ${source_files})
|
||||
get_property(defs SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS)
|
||||
get_filename_component(file_name "${source_file}" NAME)
|
||||
list(APPEND defs "__F_FILE__=\"${file_name}\"")
|
||||
set_property(
|
||||
SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS ${defs})
|
||||
endforeach()
|
||||
endfunction()
|
||||
function(log_disable target)
|
||||
get_target_property(source_files "${target}" SOURCES)
|
||||
foreach(source_file ${source_files})
|
||||
get_property(defs SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS)
|
||||
get_filename_component(file_name "${source_file}" NAME)
|
||||
list(APPEND defs "LOG_DISABLE")
|
||||
set_property(
|
||||
SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS ${defs})
|
||||
endforeach()
|
||||
endfunction()
|
||||
# -------------------------- log setting end -------------------------- #
|
14
build/independent_source.cmake
Normal file
14
build/independent_source.cmake
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
# This config file is only for independent source files.
|
||||
|
||||
# Never leave over any warning in independt project.
|
||||
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra")
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
|
||||
|
||||
# For build coverage report in linux-x86
|
||||
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
endif()
|
27
build/sdk_config.cmake
Executable file
27
build/sdk_config.cmake
Executable file
|
@ -0,0 +1,27 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# Gdb debug
|
||||
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
message("---------------------------Debug mode.-----------------------")
|
||||
SET(CMAKE_BUILD_TYPE "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -Wall -g -ggdb")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -Wall -g -ggdb")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
|
||||
# asan
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined")
|
||||
else()
|
||||
message("---------------------------Release mode.-----------------------")
|
||||
SET(CMAKE_BUILD_TYPE "Release")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os")
|
||||
endif()
|
||||
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
message("you choose to build gcno file")
|
||||
add_definitions("-fprofile-arcs")
|
||||
add_definitions("-ftest-coverage")
|
||||
endif()
|
66
customization/README.md
Normal file
66
customization/README.md
Normal file
|
@ -0,0 +1,66 @@
|
|||
# 1. 客制化目录
|
||||
|
||||
## 1.1. 概述
|
||||
   客制化目录,依赖整个项目源码(含各层目录),继承并重载接口实现客制化功能,用于管理定制化版本 / Debug版本 / 生产版本等,使特殊功能代码与公版代码解耦合,保持公版版本功能稳定性和一致性。
|
||||
|
||||
## 1.2. Debug版本
|
||||
|
||||
### 1.2.1. Debug版本概述
|
||||
   Debug版本用于满足测试需求,例如:开启log / 特殊的功能。
|
||||
|
||||
### 1.2.2. 生产测试版本
|
||||
   生产时使用的验证产品功能的版本。
|
||||
|
||||
### 1.2.3. 其它定制版本
|
||||
|
||||
   基于公版,继承派生出来的特殊功能的商业化版本。
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int is_mounted(const char *dirpath) {
|
||||
FILE *fp;
|
||||
char line[1024];
|
||||
char mount_point[1024];
|
||||
|
||||
// 尝试打开 /proc/mounts 文件
|
||||
fp = fopen("/proc/mounts", "r");
|
||||
if (fp == NULL) {
|
||||
perror("Error opening /proc/mounts");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 逐行读取并查找挂载点
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
if (sscanf(line, "%*s %1023s %*s %*s %*d %*d\n", mount_point) == 1) {
|
||||
// 检查当前行中的挂载点是否与所查找的目录匹配
|
||||
if (strcmp(dirpath, mount_point) == 0) {
|
||||
fclose(fp);
|
||||
return 1; // 已挂载
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return 0; // 未挂载
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <directory>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *dirpath = argv[1];
|
||||
|
||||
if (is_mounted(dirpath)) {
|
||||
printf("Directory '%s' is mounted.\n", dirpath);
|
||||
} else {
|
||||
printf("Directory '%s' is not mounted.\n", dirpath);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
42
doc/clang-tidy_user_guide.md
Normal file
42
doc/clang-tidy_user_guide.md
Normal file
|
@ -0,0 +1,42 @@
|
|||
# 1. clang-tidy使用指南
|
||||
|
||||
   使用clang-tidy工具进行代码规范管理。
|
||||
1. 编译时实时报错;
|
||||
2. 指定自研源码检测;
|
||||
|
||||
## 1.1. 环境搭建
|
||||
|
||||
1. llvm使用cmake编译,cmake版本要求 3.20以上,此处使用cmake-3.27.4
|
||||
```
|
||||
// cmake源码目录://tools/cmake/cmake-3.27.4.tar.gz
|
||||
// cmake源码安装:
|
||||
tar zxvf cmake-3.27.4.tar.gz
|
||||
cd cmake-3.27.4/
|
||||
sudo apt-get install openssl // 如果执行./bootstrap提示缺少ssl相关资源,执行此安装命令
|
||||
./bootstrap
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
2. 安装llvm
|
||||
```
|
||||
// 下载源码
|
||||
git clone https://github.com/llvm/llvm-project.git
|
||||
cd llvm-project/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
|
||||
make -j8
|
||||
find ./ -name clang-tidy // 确认编译完成
|
||||
```
|
||||
|
||||
## 1.2. clang-tidy使用
|
||||
修改配置:< IPC-SDK >/build/global_config.cmake
|
||||
```
|
||||
# ------------ build clang-tools ------------ #
|
||||
if(${LINUX_TEST} MATCHES "true")
|
||||
set(CLANG_TIDY_SUPPORT "true") // 使能工具
|
||||
set(CLANG_FORMAT_SUPPORT "true")
|
||||
set(LLVM_PATH "/home/xiaojiazhu/project/tmp/llvm-project") // llvm安装目录
|
||||
endif()
|
||||
# ------------ build clang-tools end ------------ #
|
||||
```
|
54
doc/cmake_exploitReport.md
Normal file
54
doc/cmake_exploitReport.md
Normal file
|
@ -0,0 +1,54 @@
|
|||
# 1.cmake开发报告
|
||||
|
||||
## 1.1 前言
|
||||
该篇md用于ipc项目下log功能的cmakelist的开发报告,以阐述其功能和组成。
|
||||
|
||||
## 1.2 功能介绍
|
||||
* 设置库文件输出路径:`set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})`.
|
||||
该语句用于设置该功能的静态库的生成路径,其中`${LIBS_OUTPUT_PATH}`在/build/cmake/global_config.cmake被定义在项目根目录的/output_files/libs/。
|
||||
|
||||
* 添加实现功能的文件目录:`include_directories(./)`.
|
||||
该语句旨在向编译器告知该功能的实现文件和头文件的所在位置。
|
||||
|
||||
* 添加功能目录到搜索路径:`set(CMAKE_AUTOMOC ON);set(CMAKE_INCLUDE_CURRENT_DIR ON)`
|
||||
这些 CMake 命令支持自动处理 Qt moc(元对象编译器),并将当前目录设置为包含在包含文件的搜索路径中;在构建过程中自动运行Qt moc编译器,用于包含Q_OBJECT宏的任何源文件。这对于为信号和插槽生成必要的C++代码是必需的;该选项将当前源目录添加到包含文件的搜索路径中。这允许构建系统查找与正在编译的源文件位于同一目录中的头文件。
|
||||
|
||||
* 收集、生成头文件列表:`file(GLOB_RECURSE HEADER_FILES "*.h")`
|
||||
该语句的功能是搜索当前目录及其子目录中扩展名为 .h 的所有文件。生成的文件列表存储在 HEADER_FILES 变量中。
|
||||
|
||||
* 收集源文件列表:`aux_source_directory(. SRC_FILES)`
|
||||
在本语句中,aux_source_directory(.SRC_FILES) 从当前目录(由 .) 及其子目录中收集所有源文件(例如,.cpp 个文件),生成的文件列表存储在 SRC_FILES 变量中。
|
||||
|
||||
* 添加编译器标志和定义到当前目录及其子目录:`add_definitions("-fexceptions")`
|
||||
添加编译器标志`-fexceptions`以在代码中启用异常处理。此标志告诉编译器生成支持捕获和引发异常的代码。通过使用 add_definitions(),可以将特定的编译器标志或定义全局应用于项目或特定源文件。
|
||||
|
||||
* 创建静态库目标:`add_library(xlog STATIC ${SRC_FILES} ${HEADER_FILES})`
|
||||
在这种情况下,本语句使用提供的源文件和头文件列表创建一个名为“xlog”的静态库目标;`STATIC`关键字指定库将构建为静态库,这意味着库代码将在编译时直接链接到最终可执行文件中;`${SRC_FILES}`变量包含应编译并链接到库中的源文件(通常.cpp文件)的列表。${HEADER_FILES} 变量包含头文件(通常为 .h 文件)的列表,这些文件定义库使用的接口和声明。
|
||||
|
||||
## 1.3 总结
|
||||
该篇cmakelists.txt的主要用途是对ipc项目下xlog功能的显现文件的编译和汇总。
|
||||
|
||||
## 2.1 返回码管理库概述
|
||||
提供整个应用程序的返回码管理功能,例如:打印返回码的字符串含义。提供C语言接口,内部实现不限于C或者C++,形成项目内部唯一返回码标准。
|
||||
|
||||
## 2.2 功能介绍
|
||||
* 设置可执行文件的输出路径:`set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})`;`set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})`
|
||||
|
||||
* 引入头文件目录:`include_directories`。`include_directories`表示引入头文件搜索路径,当工程要用到某个头文件的时候,就会去该路径下搜索。
|
||||
|
||||
* 开启自动编译:`set(CMAKE_AUTOMOC ON)` `set(CMAKE_INCLUDE_CURRENT_DIR ON)`. 这段代码开启了 CMake 的元对象编译器、界面编译器和资源编译器自动编译,这样当项目使用了包含元对象的文件、界面文件和资源文件时 CMake 可以自动检测并编译。
|
||||
|
||||
* 查找在./src路径下的所有源文件:`aux_source_directory(./src SRC_FILES)` 。
|
||||
|
||||
* 设置ReturnCode地址:`set(TARGET_NAME ReturnCode)`。根据提供的源文件创建一个叫ReturnCode的静态库。然后将目标文件与库文件进行链接:`target_link_libraries(${TARGET_NAME} Log)`。
|
||||
|
||||
## 2.3 返回码test
|
||||
* 添加test文件到目录,本目录为测试代码目录,目录结构保持与源码目录结构一致。
|
||||
|
||||
* 在test各个文件夹里添加相对应的CMakeLists.txt文件,通过`add_subdirectory(utils)`添加与源码目录结构相对应的子文件夹。
|
||||
|
||||
* 在src文件夹下创建ReturnCodeTest.cpp,调用返回码管理接口。在根目录添加第三方库文件,存放需要用到的第三方库。
|
||||
|
||||
## 2.4 总结
|
||||
Cmake的语句都在CMakeLists.txt的文件中,Cmake运行之后就会产生想要的makefile文件,然后再直接make就可以编译出可执行程序。
|
||||
|
299
doc/cmake_guide.md
Normal file
299
doc/cmake_guide.md
Normal file
|
@ -0,0 +1,299 @@
|
|||
# 1. CMake构建工具使用
|
||||
|
||||
  SDK使用CMake工具构建。
|
||||
|
||||
## 1.1. 安装
|
||||
|
||||
```code
|
||||
详见://tools/cmake/Makefile
|
||||
$ cd tools/cmake
|
||||
$ make
|
||||
$ cmake --version
|
||||
cmake version 3.27.4
|
||||
```
|
||||
|
||||
## 1.2. SDK构建配置脚本
|
||||
|
||||
* build目录下是基本的配置脚本。
|
||||
|
||||
```code
|
||||
build/
|
||||
├── cmake
|
||||
│ ├── Makefile // 调用cmake命令生成Makefile文件;
|
||||
│ └── toolchain
|
||||
│ └── linux.toolchain.cmake // 工具链配置文件已经一些全局变量;
|
||||
├── global_config.cmake // 配置文件
|
||||
└── sdk_config.cmake // 配置文件
|
||||
```
|
||||
|
||||
### 1.2.1. //build/cmake/Makefile
|
||||
|
||||
  调用cmake命令生成Makefile文件。
|
||||
|
||||
```code
|
||||
all:
|
||||
@mkdir -p ../../cmake-shell;\ // 创建cmake输出目录,这一步很关键,所有cmake的中间文件都将会存放在此目录。
|
||||
cd ../../cmake-shell;\
|
||||
pwd;\
|
||||
# 调用cmake命令,并指定工具链配置文件,生成Makefile文件。
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE="./build/cmake/toolchain/linux.toolchain.cmake" ..;\
|
||||
cd ..
|
||||
clean:
|
||||
rm -rf ../../cmake-shell
|
||||
```
|
||||
|
||||
在根目录执行:make cmake 的时候,即是调用上述Makefile生成Makefile文件。
|
||||
|
||||
### 1.2.2. //build/cmake/toolchain/linux.toolchain.cmake
|
||||
|
||||
  工具链配置文件或者一些跨平台差异化的配置文件。该文件在//build/cmake/Makefile中被指定,当需要交叉编译时,此文件的变量需要被重新配置。
|
||||
|
||||
```code
|
||||
|
||||
INCLUDE(CMakeForceCompiler)
|
||||
|
||||
set(LINUX_TEST "true")
|
||||
set(CROSS_COMPILE_PREFIX "") // 工具链前缀
|
||||
set(CMAKE_C_COMPILER "${CROSS_COMPILE_PREFIX}gcc") // 配置工具链
|
||||
set(CMAKE_CXX_COMPILER "${CROSS_COMPILE_PREFIX}g++") // 配置工具链
|
||||
|
||||
# path to compiler and utilities
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
# Name of the target platform
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
# Version of the system
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
cmake_policy(SET CMP0011 NEW)
|
||||
cmake_policy(SET CMP0005 NEW)
|
||||
|
||||
add_definitions(-Wall -O2 -Os)
|
||||
add_definitions(-Wno-unused-local-typedefs)
|
||||
add_definitions(-Wstrict-aliasing -Wwrite-strings)
|
||||
|
||||
set(TOOLCHAIN_NAME arm-linux-gnueabihf)
|
||||
|
||||
set(TARGET_PLATFORM "linux") // 编译系统平台,Linux表示在PC的ubuntu系统上编译
|
||||
set(SUBMODULE_PATH_OF_IPC_SDK "") // 子仓库路面,此处为空,交叉编译时设置
|
||||
set(PLATFORM_PATH "${CMAKE_CURRENT_SOURCE_DIR}") // 平台路径
|
||||
set(TEST_COVERAGE "true") // 覆盖率报告开关
|
||||
add_definitions(-DPLATFORM_PATH=\"${PLATFORM_PATH}\") // 定义一个宏
|
||||
set(PROJECT_OUTPUT_FOLDER "output_files") // 编译的目标文件输出目录
|
||||
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_OUTPUT_FOLDER}")
|
||||
|
||||
... // 此处省略不同模块的配置参数,一般是一些宏定义;
|
||||
```
|
||||
|
||||
### 1.2.3. //CMakeLists.txt
|
||||
|
||||
  SDK跟目录下的第一个CMakeLists.txt文件,cmake命令执行的时候会指定根目录,到此目录下寻找CMakeLists.txt文件作为整个项目的构建起点。
|
||||
|
||||
## 1.3. 重要的配置
|
||||
|
||||
### 1.3.1. 目录设置
|
||||
|
||||
  目录结构都是通过.cmake脚本来配置的。
|
||||
|
||||
#### 1.3.1.1. 源码目录结构配置
|
||||
|
||||
详见://build/global_config.cmake
|
||||
|
||||
```code
|
||||
set(EXEC_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/bin")
|
||||
set(LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs")
|
||||
set(TEST_TOOLS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs/test_tools")
|
||||
set(EXTERNAL_LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs/external")
|
||||
set(TEST_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/test")
|
||||
|
||||
set(PROJECT_ROOT_PATH "${PLATFORM_PATH}")
|
||||
set(APPLICATION_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/application") # 应用层目录
|
||||
set(MIDDLEWARE_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/middleware") # 中间件层目录
|
||||
set(UTILS_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/utils") # 工具层目录
|
||||
set(HAL_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/hal") # 硬件抽象层目录
|
||||
set(TEST_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/test") # 自动化测试代码/example目录
|
||||
set(EXTERNAL_SOURCE_PATH "${CMAKE_SOURCE_DIR_IPCSDK}/external") # 外部依赖库目录
|
||||
```
|
||||
|
||||
## 1.4. CMakeLists.txt基本语法
|
||||
|
||||
### 1.4.1. 概述
|
||||
|
||||
  概括性描述就是,只需要告诉CMakeLists.txt文件,构建时包含哪些配置文件,依赖的头文件目录,需要编译的源码文件,依赖的目标目录(如有),输出的目标,依赖的目标(一般是库),CMakeLists.txt即可生成一个Makefile代码来构建这个目标。
|
||||
|
||||
  整个SDK由很多的CMakeLists.txt文件组成,绝大多数的CMakeLists.txt文件负责把该目录的源码编译成一个库,SDK通过链接不同功能的库来构建不同的应用程序。
|
||||
|
||||
```code
|
||||
./application/CMakeLists.txt
|
||||
./application/HuntingCamera/CMakeLists.txt
|
||||
./CMakeLists.txt
|
||||
./hal/CMakeLists.txt
|
||||
./middleware/AppManager/CMakeLists.txt
|
||||
./middleware/CMakeLists.txt
|
||||
./test/all/CMakeLists.txt
|
||||
./test/application/CMakeLists.txt
|
||||
./test/application/HuntingCamera/CMakeLists.txt
|
||||
./test/application/MissionManager/CMakeLists.txt
|
||||
./test/application/MissionManager/tool/CMakeLists.txt
|
||||
./test/application/VersionReleaseTool/CMakeLists.txt
|
||||
./test/CMakeLists.txt
|
||||
./test/hal/CMakeLists.txt
|
||||
./test/hal/tool/CMakeLists.txt
|
||||
./test/middleware/AppManager/CMakeLists.txt
|
||||
./tools/clang-tidy/CMakeLists.txt
|
||||
./utils/CMakeLists.txt
|
||||
./utils/Config/CMakeLists.txt
|
||||
./utils/ConfigBase/CMakeLists.txt
|
||||
```
|
||||
|
||||
### 1.4.2. 一个CMakeLists.txt示例
|
||||
|
||||
  CMakeLists.txt可以通过调用一些shell脚本来完成除编译之外的其它工具,例如:格式化代码。
|
||||
|
||||
```code
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
#do not rely on any other library
|
||||
#link_directories( // 该目标需要链接依赖的库的目录,因为是目标是库,无需链接,此设置无
|
||||
#)
|
||||
|
||||
aux_source_directory(./src SRC_FILES) // 需要编译的源码文件,此处是src目录下的所有文件
|
||||
|
||||
set(TARGET_NAME StatusCode) // 设置输出目标名称
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} Log) // 该目标需要依赖的库,这一步很关键,cmake将会根据依赖关系自动去编译需要的依赖库;
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target( // 静态检测代码
|
||||
StatusCode_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}/StatusCode
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target( // 格式化代码
|
||||
StatusCode_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/StatusCode
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make StatusCode_code_check
|
||||
COMMAND make StatusCode_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
define_file_name(${TARGET_NAME}) // 该函数实现log库打印时,可打印文件名
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include) // 拷贝头文件到安装目录
|
||||
```
|
||||
|
||||
### 1.4.3. 通过CMakeLists.txt构建开源库
|
||||
|
||||
  通过CMakeLists.txt构建开源库,可以自动关联第三方的依赖库,编译的时候自动按需编译对应的开源库。
|
||||
|
||||
```code
|
||||
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
include(build/config_base.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}/libconfig/libconfig-1.7.3/lib
|
||||
)
|
||||
# link_directories(
|
||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
# )
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME ConfigBase)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} StatusCode Log libconfig.a)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
ConfigBase_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}/ConfigBase
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make ConfigBase_code_check
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
ConfigBase_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/ConfigBase
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make ConfigBase_code_check
|
||||
COMMAND make ConfigBase_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
# build libconfig before make libConfigBase.a
|
||||
add_custom_command(
|
||||
# OUTPUT ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a
|
||||
OUTPUT ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a // 创建这个开源库输出文件的生成方法
|
||||
COMMAND echo "Build libconfig-1.7.3. COMPILE_HOST = ${COMPILE_HOST}"
|
||||
# COMMAND tar zxvf libconfig-1.7.3.tar.gz
|
||||
COMMAND sh build_libconfig.sh ${TARGET_PLATFORM} ${COMPILE_HOST}
|
||||
# 把生成的开源库拷贝到输出目录
|
||||
COMMAND mv ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/libconfig/
|
||||
)
|
||||
add_custom_target(
|
||||
libconfig.a // 创建一个库目标
|
||||
# DEPENDS ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a
|
||||
DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a // 这个目标依赖开源库的编译输出文件
|
||||
)
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
||||
config_owner(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
||||
```
|
1103
doc/design.md
Normal file
1103
doc/design.md
Normal file
File diff suppressed because it is too large
Load Diff
111
doc/develop_standard.md
Normal file
111
doc/develop_standard.md
Normal file
|
@ -0,0 +1,111 @@
|
|||
# 1. SDK开发规范
|
||||
|
||||
## 1.1. 编码规范
|
||||
|
||||
### 1.1.1. 指针/智能指针
|
||||
|
||||
* C++编码只能使用智能指针;
|
||||
* 指针遵循谁使用谁进行“非空”判断,且无比使用前进行“非空”判断;
|
||||
* 智能指针经过转换后务必进行“非空”判断;
|
||||
|
||||
理论上,**明显不可能为空的指针,可以不进行“非空”判断**,可以不进行“非空”判断的场景:
|
||||
|
||||
```
|
||||
void McuManagerImpl::OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission)
|
||||
{
|
||||
class McuRecvIpcMission : public McuRecvImpl, public McuRecv<unsigned char>
|
||||
{
|
||||
public:
|
||||
McuRecvIpcMission(std::shared_ptr<McuManagerImpl> &mcuManager, const unsigned int &serialNumber,
|
||||
const OtherSideSendType &sendType, const unsigned char &mission)
|
||||
: McuRecvImpl(serialNumber, sendType)
|
||||
{
|
||||
McuRecv::mDataRecvReply = mission;
|
||||
McuRecvImpl::mMcuManager = mcuManager;
|
||||
}
|
||||
~McuRecvIpcMission() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
// 此处可以不进行“非空”判断,该值在有限范围内(OtherSideSendIpcMission函数内部)就能看出是否为空
|
||||
McuRecvImpl::mMcuManager->ReplyOtherSideSendIpcMission(ASK_RESULT::SUCCEED, McuRecvImpl::mSerialNumber);
|
||||
}
|
||||
};
|
||||
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
|
||||
std::shared_ptr<McuManagerImpl> manager = std::dynamic_pointer_cast<McuManagerImpl>(SharedFromThis());
|
||||
std::shared_ptr<VMcuRecv> recv =
|
||||
std::make_shared<McuRecvIpcMission>(manager, serialNumber, OtherSideSendType::SEND_IPC_MISSION, mission);
|
||||
if (monitor) {
|
||||
monitor->RecvIpcMissionEvent(recv, static_cast<IpcMission>(mission));
|
||||
}
|
||||
else {
|
||||
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
||||
AddMcuRecv(recv);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**没有进行“非空”判断的代码,应该开发测试用例,保证“空指针”的报错。**
|
||||
|
||||
### 1.1.2. 注释
|
||||
|
||||
* 注释必须使用英文,且使用翻译器翻译;
|
||||
  避免编码问题导致的乱码,且需要保证阅读困难时可使用翻译器翻译成可读的中文;
|
||||
|
||||
**注:** 注释翻译工具使用[百度翻译](https://fanyi.baidu.com/);翻译的注释在使用doxygen工具生成接口文档时,在网页上方便翻译成中文。
|
||||
|
||||
### 1.1.3. C++继承
|
||||
|
||||
* 子类使用父类的函数时,函数前必须加父类名,降低阅读难度,没有父类名的一律为本类函数(有可能是虚函数);
|
||||
|
||||
### 1.1.4. 变量命名
|
||||
|
||||
#### 1.1.4.1. 结构体/类成员
|
||||
|
||||
* 结构体和类成员必须要使用驼峰命名法,且首字母必须为m表示成员变量;
|
||||
|
||||
```
|
||||
typedef struct app_get_product_info
|
||||
{
|
||||
app_get_product_info();
|
||||
std::string mModel;
|
||||
std::string mCompany;
|
||||
std::string mSoc;
|
||||
std::string mSp;
|
||||
} AppGetProductInfo;
|
||||
```
|
||||
|
||||
### 1.1.5. 文件命名
|
||||
|
||||
* 文件名必须使用驼峰命名法,且首字母大写;
|
||||
|
||||
### 1.1.6. 代码排版
|
||||
|
||||
* 使用统一标准的代码排版风格,保持多人开发时代码的整洁,避免因为排版(特别是编辑工具的自动排版功能)导致每次提交时都产生大量的排版修改,影响后续代码异常排查;
|
||||
|
||||
  请使用仓库跟目录下.clang-format配置文件进行排版,如果使用vscode编辑器开发代码,可直接使用快捷键ctrl+alt+f进行排版;也可以使用构建脚本对代码进行排版。
|
||||
|
||||
**对发生修改的代码进行格式化:**
|
||||
|
||||
```code
|
||||
$ make cmake // 在仓库根目录执行,对发生修改的文件创建格式化命令
|
||||
$ cd cmake-shell/
|
||||
$ make improve_modified_code // 文件格式化命令,统一排版,此命名只对发生修改的文件进行格式化
|
||||
```
|
||||
|
||||
**对全部文件进行格式化:**
|
||||
|
||||
```code
|
||||
详见配置文件://build/global_config.cmake
|
||||
把 COMPILE_IMPROVE_SUPPORT 设置为 true 时,将会在每次编译代码时进行格式化。
|
||||
if(${LINUX_TEST} MATCHES "true")
|
||||
set(CLANG_TIDY_SUPPORT "true")
|
||||
set(CLANG_FORMAT_SUPPORT "true")
|
||||
set(COMPILE_IMPROVE_SUPPORT "false") # 开启后每次编译可能会很慢
|
||||
set(LLVM_PATH "$ENV{HOME}/llvm-project")
|
||||
endif()
|
||||
```
|
||||
|
||||
### 1.1.7. 函数
|
||||
|
||||
* 单个函数代码行控制在50行内,阅读时无需上下滚动去理解代码逻辑;极少数初始化数据的无逻辑推理的代码除外;
|
||||
* 函数参数不能超过10个;
|
21
doc/doxygen_user_guide.md
Normal file
21
doc/doxygen_user_guide.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# 1. Linux嵌入式项目使用Doxygen生成API文档
|
||||
|
||||
## 1.1. Doxygen简介
|
||||
|
||||
  Doxygen是一个开源的文档生成工具,可以用来生成项目源代码的API文档。
|
||||
|
||||
## 1.2. Doxygen安装
|
||||
|
||||
  Doxygen安装非常简单,直接在官网下载最新版本即可。
|
||||
|
||||
```
|
||||
$ sudo apt-get install doxygen
|
||||
```
|
||||
|
||||
## 1.3. 安装Graphviz
|
||||
|
||||
  Doxygen本身不直接支持画图功能,但它可以生成DOT格式的图形描述文件,然后使用Graphviz工具进行渲染。
|
||||
|
||||
```
|
||||
$ sudo apt-get install graphviz
|
||||
```
|
209
doc/gdb_coredump_guide.md
Normal file
209
doc/gdb_coredump_guide.md
Normal file
|
@ -0,0 +1,209 @@
|
|||
# 1. gdb coredump分析
|
||||
|
||||
  本文介绍ubuntu系统环境下coredump文件的分析方法。
|
||||
|
||||
**一个coredump示例:**
|
||||
|
||||
```
|
||||
$ ../output_files/test/bin/McuManagerTest --gtest_filter=McuManagerTest.RH_INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission
|
||||
Note: Google Test filter = McuManagerTest.RH_INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission
|
||||
[==========] Running 1 test from 1 test suite.
|
||||
[----------] Global test environment set-up.
|
||||
[----------] 1 test from McuManagerTest
|
||||
NewLog succeed.
|
||||
LogImplInit
|
||||
[ RUN ] McuManagerTest.RH_INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission
|
||||
2024-05-15 17:43:04,782 INFO [default] [McuManagerMakePtr.cpp:23]:CreateMcuManager is ok.
|
||||
|
||||
2024-05-15 17:43:04,783 INFO [default] [IMcuManager.cpp:72]:Instance changed succeed.
|
||||
|
||||
2024-05-15 17:43:04,783 INFO [default] [UartDeviceImpl.cpp:277]:Create the uart device object.
|
||||
|
||||
Can't Open Serial Port: No such file or directory
|
||||
2024-05-15 17:43:04,784 ERROR [default] [McuDevice.cpp:51]:IUartOpen failed.
|
||||
|
||||
2024-05-15 17:43:04,787 INFO [default] [UartDeviceImpl.cpp:277]:Create the uart device object.
|
||||
|
||||
Can't Open Serial Port: No such file or directory
|
||||
2024-05-15 17:43:04,787 ERROR [default] [McuDevice.cpp:51]:IUartOpen failed.
|
||||
|
||||
terminate called without an active exception
|
||||
Aborted (core dumped)
|
||||
```
|
||||
|
||||
## 1.1. coredump文件生成路径查询
|
||||
|
||||
```
|
||||
$ cat /proc/sys/kernel/core_pattern
|
||||
|/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E
|
||||
```
|
||||
|
||||
修改coredump文件生成路径:
|
||||
|
||||
```
|
||||
$ sudo sh -c 'echo /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/cmake-shell/core.%e.%p > /proc/sys/kernel/core_pattern'
|
||||
$ cat /proc/sys/kernel/core_pattern
|
||||
/home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/cmake-shell/core.%e.%p
|
||||
```
|
||||
命令:
|
||||
sudo sh -c 'echo /path/core.%e.%p > /proc/sys/kernel/core_pattern'
|
||||
|
||||
例如:
|
||||
```
|
||||
sudo sh -c 'echo /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/cmake-shell/core.%e.%p > /proc/sys/kernel/core_pattern'
|
||||
```
|
||||
|
||||
**发现路径下并未生成coredump文件**
|
||||
|
||||
```
|
||||
$ ulimit -a
|
||||
core file size (blocks, -c) 0 // 0表示终端未开启core dump
|
||||
data seg size (kbytes, -d) unlimited
|
||||
scheduling priority (-e) 0
|
||||
file size (blocks, -f) unlimited
|
||||
pending signals (-i) 63499
|
||||
max locked memory (kbytes, -l) 65536
|
||||
max memory size (kbytes, -m) unlimited
|
||||
open files (-n) 1024
|
||||
pipe size (512 bytes, -p) 8
|
||||
POSIX message queues (bytes, -q) 819200
|
||||
real-time priority (-r) 0
|
||||
stack size (kbytes, -s) 8192
|
||||
cpu time (seconds, -t) unlimited
|
||||
max user processes (-u) 63499
|
||||
virtual memory (kbytes, -v) unlimited
|
||||
file locks (-x) unlimited
|
||||
```
|
||||
|
||||
解决:
|
||||
```
|
||||
$ ulimit -c unlimited
|
||||
```
|
||||
|
||||
sudo echo /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/cmake-shell/core.%e.%p > /proc/sys/kernel/core_pattern
|
||||
|
||||
## 1.2. gdb查看堆栈信息
|
||||
|
||||
**Ubuntu系统需要加sudo执行程序才会生成coredump文件。**
|
||||
|
||||
### 1.2.1. 无法识别coredump文件
|
||||
|
||||
  在gdb中无法识别coredump文件,如下所示:
|
||||
|
||||
```
|
||||
$ sudo gdb ../output_files/test/bin/McuManagerTest core.smbd.3390383
|
||||
[sudo] password for xiaojiazhu:
|
||||
Sorry, try again.
|
||||
[sudo] password for xiaojiazhu:
|
||||
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
Type "show copying" and "show warranty" for details.
|
||||
This GDB was configured as "x86_64-linux-gnu".
|
||||
Type "show configuration" for configuration details.
|
||||
For bug reporting instructions, please see:
|
||||
<http://www.gnu.org/software/gdb/bugs/>.
|
||||
Find the GDB manual and other documentation resources online at:
|
||||
<http://www.gnu.org/software/gdb/documentation/>.
|
||||
|
||||
For help, type "help".
|
||||
Type "apropos word" to search for commands related to "word"...
|
||||
Reading symbols from ../output_files/test/bin/McuManagerTest...
|
||||
|
||||
warning: core file may not match specified executable file. // 表示coredump文件与可执行文件不匹配
|
||||
[New LWP 3390383]
|
||||
Core was generated by `/usr/sbin/smbd --foreground --no-process-group'.
|
||||
Program terminated with signal SIGABRT, Aborted.
|
||||
#0 0x00007fd59718600b in ?? ()
|
||||
(gdb) bt
|
||||
#0 0x00007fd59718600b in ?? ()
|
||||
#1 0x0000000000001c80 in ?? ()
|
||||
#2 0x0000000000000000 in ?? ()
|
||||
```
|
||||
|
||||
由于gdb和asan同时启用会冲突,导致无法识别coredump文件。解决办法如下:
|
||||
|
||||
修改://build/sdk_config.cmake
|
||||
|
||||
```
|
||||
# Gdb debug
|
||||
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
message("---------------------------Debug mode.-----------------------")
|
||||
SET(CMAKE_BUILD_TYPE "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -Wall -g -ggdb")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -Wall -g -ggdb")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
|
||||
# asan
|
||||
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined")
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined")
|
||||
else()
|
||||
message("---------------------------Release mode.-----------------------")
|
||||
SET(CMAKE_BUILD_TYPE "Release")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os")
|
||||
endif()
|
||||
```
|
||||
|
||||
解决后:
|
||||
|
||||
```
|
||||
$ sudo gdb ../output_files/test/bin/McuManagerTest core.McuManagerTest.3406751
|
||||
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
Type "show copying" and "show warranty" for details.
|
||||
This GDB was configured as "x86_64-linux-gnu".
|
||||
Type "show configuration" for configuration details.
|
||||
For bug reporting instructions, please see:
|
||||
<http://www.gnu.org/software/gdb/bugs/>.
|
||||
Find the GDB manual and other documentation resources online at:
|
||||
<http://www.gnu.org/software/gdb/documentation/>.
|
||||
|
||||
For help, type "help".
|
||||
Type "apropos word" to search for commands related to "word"...
|
||||
Reading symbols from ../output_files/test/bin/McuManagerTest...
|
||||
[New LWP 3406751]
|
||||
[New LWP 3406753]
|
||||
[New LWP 3406752]
|
||||
[Thread debugging using libthread_db enabled]
|
||||
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
|
||||
Core was generated by `../output_files/test/bin/McuManagerTest --gtest_filter=McuManagerTest.RH_INTEGR'.
|
||||
Program terminated with signal SIGABRT, Aborted.
|
||||
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
|
||||
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
|
||||
[Current thread is 1 (Thread 0x7fd355968740 (LWP 3406751))]
|
||||
(gdb) bt
|
||||
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
|
||||
#1 0x00007fd35598f859 in __GI_abort () at abort.c:79
|
||||
#2 0x00007fd355d678d1 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
|
||||
#3 0x00007fd355d7337c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
|
||||
#4 0x00007fd355d733e7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
|
||||
#5 0x000055c247b3ae41 in std::thread::operator= (__t=..., this=0x55c248d19748) at /usr/include/c++/9/thread:152
|
||||
#6 McuProtocol::Init (this=this@entry=0x55c248d196f8) at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/src/McuProtocol.cpp:58
|
||||
#7 0x000055c247b03e57 in McuManagerImpl::Init (this=0x55c248d19680)
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/middleware/McuManager/src/McuManagerImpl.cpp:46
|
||||
#8 0x000055c247acd3d4 in McuManagerTest::McuManagerTest_RH_INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission_Test::TestBody (this=<optimized out>)
|
||||
at /usr/include/c++/9/bits/shared_ptr_base.h:1020
|
||||
#9 0x000055c247b303fd in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) () at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/./include/McuProtocol.h:121
|
||||
#10 0x000055c247b23343 in testing::Test::Run() () at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/./include/McuProtocol.h:121
|
||||
#11 0x000055c247b2342b in testing::TestInfo::Run() ()
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/./include/McuProtocol.h:121
|
||||
#12 0x000055c247b2376e in testing::TestSuite::Run() ()
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/./include/McuProtocol.h:121
|
||||
#13 0x000055c247b2a0fa in testing::internal::UnitTestImpl::RunAllTests() ()
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/./include/McuProtocol.h:121
|
||||
#14 0x000055c247b3085e in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ()
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/./include/McuProtocol.h:121
|
||||
#15 0x000055c247b23529 in testing::UnitTest::Run() ()
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/utils/McuProtocol/./include/McuProtocol.h:121
|
||||
#16 0x000055c247ac9287 in RUN_ALL_TESTS ()
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/external/gtest/googletest-release-1.11.0/googletest/include/gtest/gtest.h:2490
|
||||
#17 main (argc=<optimized out>, argv=<optimized out>)
|
||||
at /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/test/middleware/McuManager/mainTest.cpp:22
|
||||
(gdb)
|
||||
```
|
239
doc/git_guide.md
Normal file
239
doc/git_guide.md
Normal file
|
@ -0,0 +1,239 @@
|
|||
# 1. git使用手册
|
||||
|
||||
## 1.1. 概述
|
||||
|
||||
  git是分布式版本控制系统,在多人开发中,git可以很好的管理代码的版本。
|
||||
|
||||
## 1.2. 源码托管服务器
|
||||
|
||||
  github和gitlab还有gitee(国产)都是开源的代码托管服务器,可以用来管理源码。
|
||||
|
||||
## 1.3. git安装
|
||||
|
||||
## 1.4. git分支管理
|
||||
|
||||
### 1.4.1. git创建本地分支
|
||||
|
||||
* 基于远端分支创建一个本地分支,同时新建一个对应的远端分支:
|
||||
|
||||
  当主干发生较大变化,例如:原厂更新sdk时,需要新建分支,划分界限。
|
||||
|
||||
```code
|
||||
$ git branch -a
|
||||
----------------
|
||||
* master
|
||||
remotes/origin/HEAD -> origin/master
|
||||
remotes/origin/app_test
|
||||
remotes/origin/master
|
||||
$ git checkout -b master-sdk-202405 origin/master
|
||||
-------------------------------------------------
|
||||
M ipc-sdk
|
||||
Branch 'master-sdk-202405' set up to track remote branch 'master' from 'origin'.
|
||||
Switched to a new branch 'master-sdk-202405'
|
||||
$ git branch -a
|
||||
----------------
|
||||
master
|
||||
* master-sdk-202405
|
||||
remotes/origin/HEAD -> origin/master
|
||||
remotes/origin/app_test
|
||||
remotes/origin/master
|
||||
$ git push origin master-sdk-202405:sdk-202405
|
||||
----------------------------------------------
|
||||
Enumerating objects: 3, done.
|
||||
Counting objects: 100% (3/3), done.
|
||||
Delta compression using up to 8 threads
|
||||
Compressing objects: 100% (2/2), done.
|
||||
Writing objects: 100% (2/2), 250 bytes | 250.00 KiB/s, done.
|
||||
Total 2 (delta 1), reused 0 (delta 0)
|
||||
remote: Powered by GITEE.COM [GNK-6.4]
|
||||
remote: Create a pull request for 'sdk-202405' on Gitee by visiting:
|
||||
remote: https://gitee.com/shenzhen-jiuyilian/ipc-rk1106/pull/new/shenzhen-jiuyilian:sdk-202405...shenzhen-jiuyilian:master
|
||||
To gitee.com:shenzhen-jiuyilian/ipc-rk1106.git
|
||||
* [new branch] master-sdk-202405 -> sdk-202405
|
||||
$ git branch -a
|
||||
---------------
|
||||
master
|
||||
* master-sdk-202405
|
||||
remotes/origin/HEAD -> origin/master
|
||||
remotes/origin/app_test
|
||||
remotes/origin/master
|
||||
remotes/origin/sdk-202405
|
||||
```
|
||||
|
||||
### 1.4.2. git获取远端分支
|
||||
|
||||
  当想知道远端是否新建了分支,可使用git fetch命令获取远端分支。
|
||||
|
||||
**git fetch示例:**
|
||||
|
||||
```code
|
||||
$ git fetch
|
||||
------------
|
||||
remote: Enumerating objects: 21, done.
|
||||
remote: Counting objects: 100% (21/21), done.
|
||||
remote: Compressing objects: 100% (11/11), done.
|
||||
remote: Total 14 (delta 8), reused 0 (delta 0), pack-reused 0
|
||||
Unpacking objects: 100% (14/14), 2.14 KiB | 156.00 KiB/s, done.
|
||||
From gitee.com:shenzhen-jiuyilian/ipc-rk1106
|
||||
bf71a01..2b9b803 master -> origin/master
|
||||
* [new branch] sdk-202402 -> origin/sdk-202402 // 此处发现远端新建了分支
|
||||
Fetching submodule ipc-sdk
|
||||
From gitee.com:shenzhen-jiuyilian/ipc
|
||||
7c261bd..eec9fb4 master-develop -> origin/master-develop
|
||||
```
|
||||
|
||||
**多个远端仓库git fetch示例:**
|
||||
|
||||
```code
|
||||
$ git remote -v
|
||||
----------------
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (fetch)
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (push)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (fetch)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (push)
|
||||
$ git fetch dgiot // git fetch + 远端仓库名称
|
||||
---------------------------------------------
|
||||
remote: Enumerating objects: 9, done.
|
||||
remote: Counting objects: 100% (9/9), done.
|
||||
remote: Compressing objects: 100% (7/7), done.
|
||||
remote: Total 9 (delta 3), reused 5 (delta 2), pack-reused 0
|
||||
Unpacking objects: 100% (9/9), 8.74 KiB | 746.00 KiB/s, done.
|
||||
From gitee.com:shenzhen-jiuyilian/fastbootserver
|
||||
* [new branch] sdk-202405 -> dgiot/sdk-202405
|
||||
```
|
||||
|
||||
### 1.4.3. git新增远端地址
|
||||
|
||||
  在一个git仓库中,可以同时管理多个远端地址,例如:在原厂的git仓库中,可以在仓库添加一个私人的git仓库,这样后续把修改提交到自己的仓库进行代码管理。
|
||||
|
||||
**git remote add示例:**
|
||||
|
||||
命令格式:
|
||||
|
||||
```code
|
||||
git remote add <remote-name> <remote-url>
|
||||
```
|
||||
|
||||
示例:
|
||||
|
||||
```code
|
||||
$ git remote add dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git
|
||||
---------------------------------------------------------------------------
|
||||
$ git remote -v
|
||||
----------------
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (fetch)
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (push)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (fetch)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (push)
|
||||
$ git fetch dgiot
|
||||
------------------
|
||||
remote: Enumerating objects: 107, done.
|
||||
remote: Counting objects: 100% (104/104), done.
|
||||
remote: Compressing objects: 100% (45/45), done.
|
||||
remote: Total 99 (delta 47), reused 89 (delta 42), pack-reused 0
|
||||
Unpacking objects: 100% (99/99), 29.55 KiB | 315.00 KiB/s, done.
|
||||
From gitee.com:shenzhen-jiuyilian/fastbootserver
|
||||
* [new branch] master -> dgiot/master
|
||||
* [new branch] sdk-202405 -> dgiot/sdk-202405
|
||||
$ git branch -a
|
||||
----------------
|
||||
* (HEAD detached at bf91101)
|
||||
remotes/dgiot/master
|
||||
remotes/dgiot/sdk-202405
|
||||
remotes/m/master
|
||||
remotes/rk/master
|
||||
$ git checkout -b sdk-202405 m/master
|
||||
--------------------------------------
|
||||
Switched to a new branch 'sdk-202405'
|
||||
$ git branch -a
|
||||
----------------
|
||||
* sdk-202405
|
||||
remotes/dgiot/master
|
||||
remotes/dgiot/sdk-202405
|
||||
remotes/m/master
|
||||
remotes/rk/master
|
||||
$ git pull dgiot sdk-202405
|
||||
---------------------------
|
||||
From gitee.com:shenzhen-jiuyilian/fastbootserver
|
||||
* branch sdk-202405 -> FETCH_HEAD
|
||||
Updating bf91101..dc76264
|
||||
Fast-forward
|
||||
.clang-format | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
.gitmodules | 3 +++
|
||||
README.md | 30 ++++++++++++++++++++++++++++++
|
||||
rv1106_ipc_sdk | 1 +
|
||||
4 files changed, 170 insertions(+)
|
||||
create mode 100644 .clang-format
|
||||
create mode 100644 .gitmodules
|
||||
create mode 100755 README.md
|
||||
create mode 160000 rv1106_ipc_sdk
|
||||
$ git submodule update --init
|
||||
-----------------------------
|
||||
Submodule 'rv1106_ipc_sdk' (git@gitee.com:shenzhen-jiuyilian/ipc-rk1106.git) registered for path 'rv1106_ipc_sdk'
|
||||
Cloning into '/home/xiaojiazhu/project/rkipc/ipc_20240517/project/app/component/fastboot_server/rv1106_ipc_sdk'...
|
||||
Submodule path 'rv1106_ipc_sdk': checked out 'ff8da760b201d365300aed78190de8564f0d2171'
|
||||
```
|
||||
|
||||
### 1.4.4. git删除远端地址
|
||||
|
||||
```code
|
||||
# git remote remove <remote-name>
|
||||
$ git remote -v
|
||||
---------------
|
||||
Germany payton@git.affgt.com:Germany/hunting.git (fetch)
|
||||
Germany payton@git.affgt.com:Germany/hunting.git (push)
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (fetch)
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (push)
|
||||
$ git remote remove Germany
|
||||
---------------------------
|
||||
$ git remote -v
|
||||
----------------
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (fetch)
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (push)
|
||||
```
|
||||
|
||||
### 1.4.5. git删除一个远端分支
|
||||
|
||||
```code
|
||||
# git push <remote-name> --delete <branch-name>
|
||||
$ git branch -r
|
||||
---------------
|
||||
origin/Branch_QT
|
||||
origin/HEAD -> origin/master
|
||||
origin/master
|
||||
origin/master-develop
|
||||
origin/without-testtools
|
||||
$ git push origin --delete Branch_QT
|
||||
-------------------------------------
|
||||
remote: Powered by GITEE.COM [GNK-6.4]
|
||||
To gitee.com:shenzhen-jiuyilian/ipc.git
|
||||
- [deleted] Branch_QT
|
||||
```
|
||||
|
||||
## 1.5. 多仓库管理
|
||||
|
||||
### 1.5.1. 合并两个无关联记录的仓库
|
||||
|
||||
  在一个仓库上合并另外一个无关联记录的仓库。
|
||||
|
||||
```code
|
||||
# 假设A仓库的代码合入到B仓库
|
||||
# 在需要合并的仓库A下面执行
|
||||
$ rm -rf .git # 如果不需要A仓库的修改记录,需要重新创建一个新的本地分支和记录;
|
||||
$ git init # 初始化一个空的仓库,并创建.git目录;
|
||||
$ git add . # 添加A仓库的代码;
|
||||
$ git commit -m "new log" # 保存代码,创建新的log;此时创建了一个本地的master分支;
|
||||
$ git remote add B <B仓库的地址> # 添加B仓库的地址;
|
||||
$ git fetch B # 拉取B仓库的信息;
|
||||
$ git checkout -b open B/master # 创建一个B仓库的本地分支,并切换到该分支;
|
||||
$ git merge master --allow-unrelated-histories # 合并A仓库的代码,并允许两个分支没有关联记录;
|
||||
$ git checkout --theirs . # 合并如果有冲突,选择A仓库的代码;
|
||||
$ git restore --source=master output_files/libs/ # 按需,恢复A仓库的某些代码;
|
||||
$ git add . # 添加需要合并的代码;
|
||||
$ git commit -m "merge log" # 合并后的代码,保存到本地仓库;
|
||||
$ git push B open:master # 推送到B仓库的master分支;
|
||||
```
|
||||
|
||||
## 1.6. 存疑
|
||||
|
||||
* 不同的分支之间如何同步某个文件?
|
20
doc/huntting_project_report.md
Normal file
20
doc/huntting_project_report.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# 1. 项目进度汇总
|
||||
|
||||
## 1.1. 软件开发进度
|
||||
|
||||
```mermaid
|
||||
gantt
|
||||
dateFormat YYYY-MM-DD
|
||||
title 软件进度-3月
|
||||
section 3月
|
||||
6帧探RTSP推流 : done, rtsp_media, 2024-03-18,3d
|
||||
SC230AI快启验证(快启报错) : crit, active, 2024-03-21,3d
|
||||
6帧探视频回放 : active, 2024-03-25,3d
|
||||
```
|
||||
|
||||
### 1.1.1. 总结
|
||||
|
||||
* 截至2024-3-25:
|
||||
1. 6侦探协议框架含http和tcp,http协议框架开发完成,rtsp推流到手机APP完成;
|
||||
2. 存在问题:rtsp推流存在卡顿问题,待优化;
|
||||
3. 更换SC230AI调试快启,快启报错,需要提问题单找原厂协助;
|
101
doc/markdown_user_guide.md
Normal file
101
doc/markdown_user_guide.md
Normal file
|
@ -0,0 +1,101 @@
|
|||
# 1. Markdown使用手册
|
||||
|
||||
## 1.1. 概述
|
||||
|
||||
使用markdown编辑开发文档有以下好处:
|
||||
|
||||
* markdown语法是一种语言,类似代码一样可以方便git管理,查看修改记录;
|
||||
* 对代码显示支持良好;
|
||||
* 可以进行UML类图和时序图的编辑/迭代/维护(强烈推荐);
|
||||
|
||||
## 1.2. 如何使用Markdown
|
||||
|
||||
此处介绍基于vscode编辑环境下使用Markdown的方法:
|
||||
|
||||
* 首先安装vscode插件:
|
||||
1. Markdown All in One
|
||||
2. Markdown Preview Enhanced
|
||||
* 使用Markdown语法编辑开发文档,并使用vscode预览;
|
||||
* 右键使用浏览器打开并打印可生成PDF文档;
|
||||
|
||||
## 1.3. 基本语法介绍
|
||||
|
||||
提供常用语法参考,直接copy模块代码进行编辑。
|
||||
|
||||
### 1.3.1. 常用命令
|
||||
|
||||
```
|
||||
Markdown All in One: Create Table of Contents 创建目录
|
||||
Markdown All in One: Update Table of Contents 更新目录
|
||||
Markdown All in One: Add/Update section numbers 添加 / 更新章节编号
|
||||
Markdown All in One: Remove section numbers 删除章节编号
|
||||
Markdown All in One: Toggle code span 触发设置代码范围(`code`)
|
||||
Markdown All in One: Toggle code block 触发设置代码块(```codes```)
|
||||
Markdown All in One: Print current document to HTML
|
||||
Markdown All in One: Toggle math environment 触发设置数学环境
|
||||
Markdown All in One: Toggle list 触发设置列表环境
|
||||
```
|
||||
|
||||
### 1.3.2. 代码段
|
||||
|
||||
```
|
||||
/*This is your code.*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### 1.3.3. UML类图语法
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
Animal <|-- Fish:继承
|
||||
Animal <|.. Zebra:实现
|
||||
Animal : +int age
|
||||
Animal : +String gender
|
||||
Animal: +isMammal()
|
||||
Animal: +mate()
|
||||
class Animal{
|
||||
<<interface>>
|
||||
+call() int
|
||||
}
|
||||
class Fish{
|
||||
-int sizeInFeet
|
||||
-canEat()
|
||||
}
|
||||
class Zebra{
|
||||
<<class>>
|
||||
-func(int, int) int
|
||||
+bool is_wild
|
||||
+run(void)
|
||||
}
|
||||
```
|
||||
|
||||
实现:一般指对抽象类的实例类 \
|
||||
继承:一般指对普通功能基类的派生/重载
|
||||
|
||||
### 1.3.4. UML时序图
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
Alice->>+Jhon:Call function
|
||||
Jhon->>Jhon:handle
|
||||
Jhon-->>-Alice:Call return
|
||||
note left of Alice:function
|
||||
|
||||
Alice->>+Jhon:Call function
|
||||
Jhon->>+Fancy:Call
|
||||
Fancy-->>-Jhon:Call return
|
||||
Jhon-->>-Alice:Call return
|
||||
|
||||
Alice->>+Jhon:Call function
|
||||
Jhon->>+Fancy:Call
|
||||
Fancy->>-Fancy:End
|
||||
Jhon-->>-Alice:Call return
|
||||
```
|
||||
|
||||
### 1.3.5. 踩坑记录
|
||||
|
||||
1. 状态图不能使用default关键字作为一个状态名称,无法画图;
|
9
doc/sdk_build_guide.md
Normal file
9
doc/sdk_build_guide.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# 1. SDK构建设计文档
|
||||
|
||||
## 1.1. 概述
|
||||
|
||||
  SDK使用cmake构建,把分层解耦合的独立模块编译成静态库,应用程序根据依赖关系进行自动关联链接。
|
||||
|
||||
## 1.2. 启用/禁用功能模块
|
||||
|
||||
  根据不同的产品需求来启用/禁用功能模块,避免编译不需要的模块。
|
89
doc/vscode_ssh_guide.md
Normal file
89
doc/vscode_ssh_guide.md
Normal file
|
@ -0,0 +1,89 @@
|
|||
# 1. vscode使用ssh链接虚拟机服务器
|
||||
|
||||
# 2. 前言
|
||||
|
||||
   在vscode使用ssh工具远程登录虚拟机服务器进行代码编辑。
|
||||
|
||||
| 内容 | 时间 | 作者 | 备注 |
|
||||
|----|----|----|----|
|
||||
| 首版 | 2024-2-26 | xjz | - |
|
||||
|
||||
## 2.1. Windows系统
|
||||
|
||||
* 安装ssh
|
||||
|
||||
   直接安装git工具即可支持ssh
|
||||
|
||||
安装完后确认:
|
||||
```
|
||||
xiaojiazhu@ubuntu:~/project/rkipc/battery/ipc-rk1106/ipc-sdk/cmake-shell$ ssh
|
||||
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
|
||||
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
|
||||
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
|
||||
[-i identity_file] [-J [user@]host[:port]] [-L address]
|
||||
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
|
||||
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
|
||||
[-w local_tun[:remote_tun]] destination [command]
|
||||
```
|
||||
|
||||
* vscode安装ssh插件
|
||||
|
||||
   使用 Remote - SSH 插件
|
||||
|
||||
* ssh密钥配置
|
||||
|
||||
1. Windows生成密钥;
|
||||
2. 把xxx.pub文件内容拷贝到虚拟机的ssh目录下的authorized_keys文件;
|
||||
此处是:
|
||||
|
||||
```
|
||||
xiaojiazhu@ubuntu:~/project/.ssh$ pwd
|
||||
/home/xiaojiazhu/project/.ssh
|
||||
xiaojiazhu@ubuntu:~/project/.ssh$ ls
|
||||
authorized_keys id_rsa id_rsa.pub
|
||||
```
|
||||
|
||||
这样设置后,每次登录ssh无需手动输入密码;
|
||||
|
||||
3. 在Windows远程登录虚拟机:
|
||||
|
||||
参考命令:ssh xiaojiazhu@192.168.1.29
|
||||
|
||||
```
|
||||
PS C:\Users\xjz\.ssh> ssh xiaojiazhu@192.168.1.29
|
||||
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-94-generic x86_64)
|
||||
|
||||
* Documentation: https://help.ubuntu.com
|
||||
* Management: https://landscape.canonical.com
|
||||
* Support: https://ubuntu.com/advantage
|
||||
|
||||
Expanded Security Maintenance for Applications is not enabled.
|
||||
|
||||
75 updates can be applied immediately.
|
||||
To see these additional updates run: apt list --upgradable
|
||||
|
||||
9 additional security updates can be applied with ESM Apps.
|
||||
Learn more about enabling ESM Apps service at https://ubuntu.com/esm
|
||||
|
||||
New release '22.04.3 LTS' available.
|
||||
Run 'do-release-upgrade' to upgrade to it.
|
||||
|
||||
Your Hardware Enablement Stack (HWE) is supported until April 2025.
|
||||
*** System restart required ***
|
||||
Last login: Sun Feb 25 17:20:04 2024 from 192.168.1.29
|
||||
xiaojiazhu@ubuntu:~$
|
||||
```
|
||||
## 2.2. vscode设置
|
||||
|
||||
配置文件参考
|
||||
|
||||
```
|
||||
Host dgiot // 自定义的主机名
|
||||
HostName 192.168.1.29 // 远端的IP地址
|
||||
User xiaojiazhu 用户名
|
||||
Port 22
|
||||
IdentityFile "C:\Users\xjz\.ssh\id_ed25519" // 本端的私钥文件路径
|
||||
ForwardAgent yes // 忽略
|
||||
```
|
||||
|
||||
多个远端IP复制即可。
|
3
external/.gitignore
vendored
Normal file
3
external/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
goahead-5.2.0/GoAhead
|
||||
ffmpeg/ffmpeg-6.1.1
|
24
external/CMakeLists.txt
vendored
Normal file
24
external/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
add_subdirectory(sqlite3/sqlite-3430000)
|
||||
add_subdirectory(goahead-5.2.0)
|
||||
|
||||
# ================= httpserver ================= #
|
||||
find_program(M4 m4)
|
||||
if(NOT M4)
|
||||
message("m4 not found. Install before continuing.")
|
||||
execute_process(COMMAND sudo apt-get install m4
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/gtest/)
|
||||
endif()
|
||||
find_program(RAGEL ragel)
|
||||
if(NOT RAGEL)
|
||||
message(FATAL_ERROR "ragel not found. Install before continuing.")
|
||||
execute_process(COMMAND sudo apt-get install ragel
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/gtest/)
|
||||
endif()
|
||||
add_subdirectory(httpserver.h-master/src)
|
||||
# ================= httpserver end ================= #
|
||||
|
||||
add_subdirectory(cJSON-1.7.17)
|
||||
add_subdirectory(libhv/libhv-1.3.2)
|
||||
add_subdirectory(ffmpeg)
|
||||
add_subdirectory(libconfig)
|
7
external/README.md
vendored
Normal file
7
external/README.md
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# 1. 第三方库
|
||||
|
||||
   该目录存放仓库依赖的三方库源码。
|
||||
|
||||
## 1.1. goahead
|
||||
|
||||
make CC=arm-rockchip830-linux-uclibcgnueabihf-gcc ARCH=arm PROFILE=static
|
454
external/cJSON-1.7.17/CHANGELOG.md
vendored
Normal file
454
external/cJSON-1.7.17/CHANGELOG.md
vendored
Normal file
|
@ -0,0 +1,454 @@
|
|||
1.7.17 (Dec 26, 2023)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix null reference in cJSON_SetValuestring(CVE-2023-50472), see #809
|
||||
* Fix null reference in cJSON_InsertItemInArray(CVE-2023-50471), see #809 and #810
|
||||
|
||||
1.7.16 (Jul 5, 2023)
|
||||
======
|
||||
Features:
|
||||
------
|
||||
* Add an option for ENABLE_CJSON_VERSION_SO in CMakeLists.txt, see #534
|
||||
* Add cmake_policy to CMakeLists.txt, see #163
|
||||
* Add cJSON_SetBoolValue, see #639
|
||||
* Add meson documentation, see #761
|
||||
|
||||
Fixes:
|
||||
------
|
||||
* Fix memory leak in merge_patch, see #611
|
||||
* Fix conflicting target names 'uninstall', see #617
|
||||
* Bump cmake version to 3.0 and use new version syntax, see #587
|
||||
* Print int without decimal places, see #630
|
||||
* Fix 'cjson_utils-static' target not exist, see #625
|
||||
* Add allocate check for replace_item_in_object, see #675
|
||||
* Fix a null pointer crash in cJSON_ReplaceItemViaPointer, see #726
|
||||
|
||||
1.7.15 (Aug 25, 2021)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix potential core dumped for strrchr, see [#546](https://github.com/DaveGamble/cJSON/pull/546)
|
||||
* Fix null pointer crash in cJSON_CreateXxArray, see [#538](https://github.com/DaveGamble/cJSON/pull/538)
|
||||
* Fix several null pointer problems on allocation failure, see [#526](https://github.com/DaveGamble/cJSON/pull/526)
|
||||
* Fix a possible dereference of null pointer, see [#519](https://github.com/DaveGamble/cJSON/pull/519)
|
||||
* Fix windows build failure about defining nan, see [#518](https://github.com/DaveGamble/cJSON/pull/518)
|
||||
|
||||
1.7.14 (Sep 3, 2020)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* optimize the way to find tail node, see [#503](https://github.com/DaveGamble/cJSON/pull/503)
|
||||
* Fix WError error on macosx because NAN is a float. Thanks @sappo, see [#484](https://github.com/DaveGamble/cJSON/pull/484)
|
||||
* Fix some bugs in detach and replace. Thanks @miaoerduo, see [#456](https://github.com/DaveGamble/cJSON/pull/456)
|
||||
|
||||
1.7.13 (Apr 2, 2020)
|
||||
======
|
||||
Features:
|
||||
---------
|
||||
* add new API of cJSON_ParseWithLength without breaking changes. Thanks @caglarivriz, see [#358](https://github.com/DaveGamble/cJSON/pull/358)
|
||||
* add new API of cJSON_GetNumberValue. Thanks @Intuition, see[#385](https://github.com/DaveGamble/cJSON/pull/385)
|
||||
* add uninstall target function for CMake. See [#402](https://github.com/DaveGamble/cJSON/pull/402)
|
||||
* Improve performance of adding item to array. Thanks @xiaomianhehe, see [#430](https://github.com/DaveGamble/cJSON/pull/430), [#448](https://github.com/DaveGamble/cJSON/pull/448)
|
||||
* add new API of cJSON_SetValuestring, for changing the valuestring safely. See [#451](https://github.com/DaveGamble/cJSON/pull/451)
|
||||
* add return value for cJSON_AddItemTo... and cJSON_ReplaceItem... (check if the operation successful). See [#453](https://github.com/DaveGamble/cJSON/pull/453)
|
||||
|
||||
Fixes:
|
||||
------
|
||||
* Fix clang -Wfloat-equal warning. Thanks @paulmalovanyi, see [#368](https://github.com/DaveGamble/cJSON/pull/368)
|
||||
* Fix make failed in mac os. See [#405](https://github.com/DaveGamble/cJSON/pull/405)
|
||||
* Fix memory leak in cJSONUtils_FindPointerFromObjectTo. Thanks @andywolk for reporting, see [#414](https://github.com/DaveGamble/cJSON/issues/414)
|
||||
* Fix bug in encode_string_as_pointer. Thanks @AIChangJiang for reporting, see [#439](https://github.com/DaveGamble/cJSON/issues/439)
|
||||
|
||||
1.7.12 (May 17, 2019)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix infinite loop in `cJSON_Minify` (potential Denial of Service). Thanks @Alanscut for reporting, see [#354](https://github.com/DaveGamble/cJSON/issues/354)
|
||||
* Fix link error for Visual Studio. Thanks @tan-wei, see [#352](https://github.com/DaveGamble/cJSON/pull/352).
|
||||
* Undefine `true` and `false` for `cJSON_Utils` before redefining them. Thanks @raiden00pl, see [#347](https://github.com/DaveGamble/cJSON/pull/347).
|
||||
|
||||
1.7.11 (Apr 15, 2019)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix a bug where cJSON_Minify could overflow it's buffer, both reading and writing. This is a security issue, see [#338](https://github.com/DaveGamble/cJSON/issues/338). Big thanks @bigric3 for reporting.
|
||||
* Unset `true` and `false` macros before setting them if they exist. See [#339](https://github.com/DaveGamble/cJSON/issues/339), thanks @raiden00pl for reporting
|
||||
|
||||
1.7.10 (Dec 21, 2018)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix package config file for `libcjson`. Thanks @shiluotang for reporting [#321](https://github.com/DaveGamble/cJSON/issues/321)
|
||||
* Correctly split lists in `cJSON_Utils`'s merge sort. Thanks @andysCaplin for the fix [#322](https://github.com/DaveGamble/cJSON/issues/322)
|
||||
|
||||
1.7.9 (Dec 16, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix a bug where `cJSON_GetObjectItemCaseSensitive` would pass a nullpointer to `strcmp` when called on an array, see [#315](https://github.com/DaveGamble/cJSON/issues/315). Thanks @yuweol for reporting.
|
||||
* Fix error in `cJSON_Utils` where the case sensitivity was not respected, see [#317](https://github.com/DaveGamble/cJSON/pull/317). Thanks @yuta-oxo for fixing.
|
||||
* Fix some warnings detected by the Visual Studio Static Analyzer, see [#307](https://github.com/DaveGamble/cJSON/pull/307). Thanks @bnason-nf
|
||||
|
||||
1.7.8 (Sep 22, 2018)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* cJSON now works with the `__stdcall` calling convention on Windows, see [#295](https://github.com/DaveGamble/cJSON/pull/295), thanks @zhindes for contributing
|
||||
|
||||
1.7.7 (May 22, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix a memory leak when realloc fails, see [#267](https://github.com/DaveGamble/cJSON/issues/267), thanks @AlfieDeng for reporting
|
||||
* Fix a typo in the header file, see [#266](https://github.com/DaveGamble/cJSON/pull/266), thanks @zhaozhixu
|
||||
|
||||
1.7.6 (Apr 13, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Add `SONAME` to the ELF files built by the Makefile, see [#252](https://github.com/DaveGamble/cJSON/issues/252), thanks @YanhaoMo for reporting
|
||||
* Add include guards and `extern "C"` to `cJSON_Utils.h`, see [#256](https://github.com/DaveGamble/cJSON/issues/256), thanks @daschfg for reporting
|
||||
|
||||
Other changes:
|
||||
* Mark the Makefile as deprecated in the README.
|
||||
|
||||
1.7.5 (Mar 23, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix a bug in the JSON Patch implementation of `cJSON Utils`, see [#251](https://github.com/DaveGamble/cJSON/pull/251), thanks @bobkocisko.
|
||||
|
||||
1.7.4 (Mar 3, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix potential use after free if the `string` parameter to `cJSON_AddItemToObject` is an alias of the `string` property of the object that is added,see [#248](https://github.com/DaveGamble/cJSON/issues/248). Thanks @hhallen for reporting.
|
||||
|
||||
1.7.3 (Feb 8, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix potential double free, thanks @projectgus for reporting [#241](https://github.com/DaveGamble/cJSON/issues/241)
|
||||
|
||||
1.7.2 (Feb 6, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix the use of GNUInstallDirs variables and the pkgconfig file. Thanks @zeerd for reporting [#240](https://github.com/DaveGamble/cJSON/pull/240)
|
||||
|
||||
1.7.1 (Jan 10, 2018)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fixed an Off-By-One error that could lead to an out of bounds write. Thanks @liuyunbin for reporting [#230](https://github.com/DaveGamble/cJSON/issues/230)
|
||||
* Fixed two errors with buffered printing. Thanks @liuyunbin for reporting [#230](https://github.com/DaveGamble/cJSON/issues/230)
|
||||
|
||||
1.7.0 (Dec 31, 2017)
|
||||
=====
|
||||
Features:
|
||||
---------
|
||||
* Large rewrite of the documentation, see [#215](https://github.com/DaveGamble/cJSON/pull/215)
|
||||
* Added the `cJSON_GetStringValue` function
|
||||
* Added the `cJSON_CreateStringReference` function
|
||||
* Added the `cJSON_CreateArrayReference` function
|
||||
* Added the `cJSON_CreateObjectReference` function
|
||||
* The `cJSON_Add...ToObject` macros are now functions that return a pointer to the added item, see [#226](https://github.com/DaveGamble/cJSON/pull/226)
|
||||
|
||||
Fixes:
|
||||
------
|
||||
* Fix a problem with `GNUInstallDirs` in the CMakeLists.txt, thanks @yangfl, see [#210](https://github.com/DaveGamble/cJSON/pull/210)
|
||||
* Fix linking the tests when building as static library, see [#213](https://github.com/DaveGamble/cJSON/issues/213)
|
||||
* New overrides for the CMake option `BUILD_SHARED_LIBS`, see [#207](https://github.com/DaveGamble/cJSON/issues/207)
|
||||
|
||||
Other Changes:
|
||||
--------------
|
||||
* Readme: Explain how to include cJSON, see [#211](https://github.com/DaveGamble/cJSON/pull/211)
|
||||
* Removed some trailing spaces in the code, thanks @yangfl, see [#212](https://github.com/DaveGamble/cJSON/pull/212)
|
||||
* Updated [Unity](https://github.com/ThrowTheSwitch/Unity) and [json-patch-tests](https://github.com/json-patch/json-patch-tests)
|
||||
|
||||
1.6.0 (Oct 9, 2017)
|
||||
=====
|
||||
Features:
|
||||
---------
|
||||
* You can now build cJSON as both shared and static library at once with CMake using `-DBUILD_SHARED_AND_STATIC_LIBS=On`, see [#178](https://github.com/DaveGamble/cJSON/issues/178)
|
||||
* UTF-8 byte order marks are now ignored, see [#184](https://github.com/DaveGamble/cJSON/issues/184)
|
||||
* Locales can now be disabled with the option `-DENABLE_LOCALES=Off`, see [#202](https://github.com/DaveGamble/cJSON/issues/202), thanks @Casperinous
|
||||
* Better support for MSVC and Visual Studio
|
||||
|
||||
Other Changes:
|
||||
--------------
|
||||
* Add the new warnings `-Wswitch-enum`, `-Wused-but-makred-unused`, `-Wmissing-variable-declarations`, `-Wunused-macro`
|
||||
* More number printing tests.
|
||||
* Continuous integration testing with AppVeyor (semi automatic at this point), thanks @simon-p-r
|
||||
|
||||
1.5.9 (Sep 8, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Set the global error pointer even if `return_parse_end` is passed to `cJSON_ParseWithOpts`, see [#200](https://github.com/DaveGamble/cJSON/pull/200), thanks @rmallins
|
||||
|
||||
1.5.8 (Aug 21, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix `make test` in the Makefile, thanks @YanhaoMo for reporting this [#195](https://github.com/DaveGamble/cJSON/issues/195)
|
||||
|
||||
1.5.7 (Jul 13, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix a bug where realloc failing would return a pointer to an invalid memory address. This is a security issue as it could potentially be used by an attacker to write to arbitrary memory addresses, see [#189](https://github.com/DaveGamble/cJSON/issues/189), fixed in [954d61e](https://github.com/DaveGamble/cJSON/commit/954d61e5e7cb9dc6c480fc28ac1cdceca07dd5bd), big thanks @timothyjohncarney for reporting this issue
|
||||
* Fix a spelling mistake in the AFL fuzzer dictionary, see [#185](https://github.com/DaveGamble/cJSON/pull/185), thanks @jwilk
|
||||
|
||||
1.5.6 (Jun 28, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Make cJSON a lot more tolerant about passing NULL pointers to its functions, it should now fail safely instead of dereferencing the pointer, see [#183](https://github.com/DaveGamble/cJSON/pull/183). Thanks @msichal for reporting [#182](https://github.com/DaveGamble/cJSON/issues/182)
|
||||
|
||||
1.5.5 (Jun 15, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix pointers to nested arrays in cJSON_Utils, see [9abe](https://github.com/DaveGamble/cJSON/commit/9abe75e072050f34732a7169740989a082b65134)
|
||||
* Fix an error with case sensitivity handling in cJSON_Utils, see [b9cc911](https://github.com/DaveGamble/cJSON/commit/b9cc911831b0b3e1bb72f142389428e59f882b38)
|
||||
* Fix cJSON_Compare for arrays that are prefixes of the other and objects that are a subset of the other, see [03ba72f](https://github.com/DaveGamble/cJSON/commit/03ba72faec115160d1f3aea5582d9b6af5d3e473) and [#180](https://github.com/DaveGamble/cJSON/issues/180), thanks @zhengqb for reporting
|
||||
|
||||
1.5.4 (Jun 5, 2017)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix build with GCC 7.1.1 and optimization level `-O2`, see [bfbd8fe](https://github.com/DaveGamble/cJSON/commit/bfbd8fe0d85f1dd21e508748fc10fc4c27cc51be)
|
||||
|
||||
Other Changes:
|
||||
--------------
|
||||
* Update [Unity](https://github.com/ThrowTheSwitch/Unity) to 3b69beaa58efc41bbbef70a32a46893cae02719d
|
||||
|
||||
1.5.3 (May 23, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix `cJSON_ReplaceItemInObject` not keeping the name of an item, see [#174](https://github.com/DaveGamble/cJSON/issues/174)
|
||||
|
||||
1.5.2 (May 10, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix a reading buffer overflow in `parse_string`, see [a167d9e](https://github.com/DaveGamble/cJSON/commit/a167d9e381e5c84bc03de4e261757b031c0c690d)
|
||||
* Fix compiling with -Wcomma, see [186cce3](https://github.com/DaveGamble/cJSON/commit/186cce3ece6ce6dfcb58ac8b2a63f7846c3493ad)
|
||||
* Remove leftover attribute from tests, see [b537ca7](https://github.com/DaveGamble/cJSON/commit/b537ca70a35680db66f1f5b8b437f7114daa699a)
|
||||
|
||||
1.5.1 (May 6, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Add gcc version guard to the Makefile, see [#164](https://github.com/DaveGamble/cJSON/pull/164), thanks @juvasquezg
|
||||
* Fix incorrect free in `cJSON_Utils` if custom memory allocator is used, see [#166](https://github.com/DaveGamble/cJSON/pull/166), thanks @prefetchnta
|
||||
|
||||
1.5.0 (May 2, 2017)
|
||||
=====
|
||||
Features:
|
||||
* cJSON finally prints numbers without losing precision, see [#153](https://github.com/DaveGamble/cJSON/pull/153), thanks @DeboraG
|
||||
* `cJSON_Compare` recursively checks if two cJSON items contain the same values, see [#148](https://github.com/DaveGamble/cJSON/pull/148)
|
||||
* Provide case sensitive versions of every function where it matters, see [#158](https://github.com/DaveGamble/cJSON/pull/158) and [#159](https://github.com/DaveGamble/cJSON/pull/159)
|
||||
* Added `cJSON_ReplaceItemViaPointer` and `cJSON_DetachItemViaPointer`
|
||||
* Added `cJSON_free` and `cJSON_malloc` that expose the internal configured memory allocators. see [02a05ee](https://github.com/DaveGamble/cJSON/commit/02a05eea4e6ba41811f130b322660bea8918e1a0)
|
||||
|
||||
|
||||
Enhancements:
|
||||
-------------
|
||||
* Parse into a buffer, this will allow parsing `\u0000` in the future (not quite yet though)
|
||||
* General simplifications and readability improvements
|
||||
* More unit tests
|
||||
* Update [unity](https://github.com/ThrowTheSwitch/Unity) testing library to 2.4.1
|
||||
* Add the [json-patch-tests](https://github.com/json-patch/json-patch-tests) test suite to test cJSON_Utils.
|
||||
* Move all tests from `test_utils.c` to unit tests with unity.
|
||||
|
||||
Fixes:
|
||||
------
|
||||
* Fix some warnings with the Microsoft compiler, see [#139](https://github.com/DaveGamble/cJSON/pull/139), thanks @PawelWMS
|
||||
* Fix several bugs in cJSON_Utils, mostly found with [json-patch-tests](https://github.com/json-patch/json-patch-tests)
|
||||
* Prevent a stack overflow by specifying a maximum nesting depth `CJSON_NESTING_LIMIT`
|
||||
|
||||
Other Changes:
|
||||
--------------
|
||||
* Move generated files in the `library_config` subdirectory.
|
||||
|
||||
1.4.7 (Apr 19, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix `cJSONUtils_ApplyPatches`, it was completely broken and apparently nobody noticed (or at least reported it), see [075a06f](https://github.com/DaveGamble/cJSON/commit/075a06f40bdc4f836c7dd7cad690d253a57cfc50)
|
||||
* Fix inconsistent prototype for `cJSON_GetObjectItemCaseSensitive`, see [51d3df6](https://github.com/DaveGamble/cJSON/commit/51d3df6c9f7b56b860c8fb24abe7bab255cd4fa9), thanks @PawelWMS
|
||||
|
||||
1.4.6 (Apr 9, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Several corrections in the README
|
||||
* Making clear that `valueint` should not be written to
|
||||
* Fix overflow detection in `ensure`, see [2683d4d](https://github.com/DaveGamble/cJSON/commit/2683d4d9873df87c4bdccc523903ddd78d1ad250)
|
||||
* Fix a potential null pointer dereference in cJSON_Utils, see [795c3ac](https://github.com/DaveGamble/cJSON/commit/795c3acabed25c9672006b2c0f40be8845064827)
|
||||
* Replace incorrect `sizeof('\0')` with `sizeof("")`, see [84237ff](https://github.com/DaveGamble/cJSON/commit/84237ff48e69825c94261c624eb0376d0c328139)
|
||||
* Add caveats section to the README, see [50b3c30](https://github.com/DaveGamble/cJSON/commit/50b3c30dfa89830f8f477ce33713500740ac3b79)
|
||||
* Make cJSON locale independent, see [#146](https://github.com/DaveGamble/cJSON/pull/146), Thanks @peterh for reporting
|
||||
* Fix compiling without CMake with MSVC, see [#147](https://github.com/DaveGamble/cJSON/pull/147), Thanks @dertuxmalwieder for reporting
|
||||
|
||||
1.4.5 (Mar 28, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix bug in `cJSON_SetNumberHelper`, thanks @mmkeeper, see [#138](https://github.com/DaveGamble/cJSON/issues/138) and [ef34500](https://github.com/DaveGamble/cJSON/commit/ef34500693e8c4a2849d41a4bd66fd19c9ec46c2)
|
||||
* Workaround for internal compiler error in GCC 5.4.0 and 6.3.1 on x86 (2f65e80a3471d053fdc3f8aed23d01dd1782a5cb [GCC bugreport](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80097))
|
||||
|
||||
1.4.4 (Mar 24, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix a theoretical integer overflow, (not sure if it is possible on actual hardware), see [e58f7ec](https://github.com/DaveGamble/cJSON/commit/e58f7ec027d00b7cdcbf63e518c1b5268b29b3da)
|
||||
* Fix an off by one error, see [cc84a44](https://github.com/DaveGamble/cJSON/commit/cc84a446be20cc283bafdc4d94c050ba1111ac02), thanks @gatzka
|
||||
* Double check the offset of the print buffer in `ensure`, see [1934059](https://github.com/DaveGamble/cJSON/commit/1934059554b9a0971e00f79e96900f422cfdd114)
|
||||
|
||||
Improvements:
|
||||
* Add a note in the header about required buffer size when using `cJSON_PrintPreallocated`, see [4bfb8800](https://github.com/DaveGamble/cJSON/commit/4bfb88009342fb568295a7f6dc4b7fee74fbf022)
|
||||
|
||||
1.4.3 (Mar 19, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix compilation of the tests on 32 bit PowerPC and potentially other systems, see [4ec6e76](https://github.com/DaveGamble/cJSON/commit/4ec6e76ea2eec16f54b58e8c95b4c734e59481e4)
|
||||
* Fix compilation with old GCC compilers (4.3+ were tested), see [227d33](https://github.com/DaveGamble/cJSON/commit/227d3398d6b967879761ebe02c1b63dbd6ea6e0d), [466eb8e](https://github.com/DaveGamble/cJSON/commit/466eb8e3f8a65080f2b3ca4a79ab7b72bd539dba), see also [#126](https://github.com/DaveGamble/cJSON/issues/126)
|
||||
|
||||
1.4.2 (Mar 16, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix minimum required cmake version, see [30e1e7a](https://github.com/DaveGamble/cJSON/commit/30e1e7af7c63db9b55f5a3cda977a6c032f0b132)
|
||||
* Fix detection of supported compiler flags, see [76e5296](https://github.com/DaveGamble/cJSON/commit/76e5296d0d05ceb3018a9901639e0e171b44a557)
|
||||
* Run `cJSON_test` and `cJSON_test_utils` along with unity tests, see [c597601](https://github.com/DaveGamble/cJSON/commit/c597601cf151a757dcf800548f18034d4ddfe2cb)
|
||||
|
||||
1.4.1 (Mar 16, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Make `print_number` abort with a failure in out of memory situations, see [cf1842](https://github.com/DaveGamble/cJSON/commit/cf1842dc6f64c49451a022308b4415e4d468be0a)
|
||||
|
||||
1.4.0 (Mar 4, 2017)
|
||||
=====
|
||||
Features
|
||||
--------
|
||||
* Functions to check the type of an item, see [#120](https://github.com/DaveGamble/cJSON/pull/120)
|
||||
* Use dllexport on windows and fvisibility on Unix systems for public functions, see [#116](https://github.com/DaveGamble/cJSON/pull/116), thanks @mjerris
|
||||
* Remove trailing zeroes from printed numbers, see [#123](https://github.com/DaveGamble/cJSON/pull/123)
|
||||
* Expose the internal boolean type `cJSON_bool` in the header, see [2d3520e](https://github.com/DaveGamble/cJSON/commit/2d3520e0b9d0eb870e8886e8a21c571eeddbb310)
|
||||
|
||||
Fixes
|
||||
* Fix handling of NULL pointers in `cJSON_ArrayForEach`, see [b47d0e3](https://github.com/DaveGamble/cJSON/commit/b47d0e34caaef298edfb7bd09a72cfff21d231ff)
|
||||
* Make it compile with GCC 7 (fix -Wimplicit-fallthrough warning), see [9d07917](https://github.com/DaveGamble/cJSON/commit/9d07917feb1b613544a7513d19233d4c851ad7ad)
|
||||
|
||||
Other Improvements
|
||||
* internally use realloc if available ([#110](https://github.com/DaveGamble/cJSON/pull/110))
|
||||
* builtin support for fuzzing with [afl](http://lcamtuf.coredump.cx/afl/) ([#111](https://github.com/DaveGamble/cJSON/pull/111))
|
||||
* unit tests for the print functions ([#112](https://github.com/DaveGamble/cJSON/pull/112))
|
||||
* Always use buffered printing ([#113](https://github.com/DaveGamble/cJSON/pull/113))
|
||||
* simplify the print functions ([#114](https://github.com/DaveGamble/cJSON/pull/114))
|
||||
* Add the compiler flags `-Wdouble-conversion`, `-Wparentheses` and `-Wcomma` ([#122](https://github.com/DaveGamble/cJSON/pull/122))
|
||||
|
||||
1.3.2 (Mar 1, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Don't build the unity library if testing is disabled, see [#121](https://github.com/DaveGamble/cJSON/pull/121). Thanks @ffontaine
|
||||
|
||||
1.3.1 (Feb 27, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Bugfix release that fixes an out of bounds read, see [#118](https://github.com/DaveGamble/cJSON/pull/118). This shouldn't have any security implications.
|
||||
|
||||
1.3.0 (Feb 17, 2017)
|
||||
=====
|
||||
This release includes a lot of rework in the parser and includes the Cunity unit testing framework, as well as some fixes. I increased the minor version number because there were quite a lot of internal changes.
|
||||
|
||||
Features:
|
||||
* New type for cJSON structs: `cJSON_Invalid`, see [#108](https://github.com/DaveGamble/cJSON/pull/108)
|
||||
|
||||
Fixes:
|
||||
------
|
||||
* runtime checks for a lot of potential integer overflows
|
||||
* fix incorrect return in cJSON_PrintBuffered [cf9d57d](https://github.com/DaveGamble/cJSON/commit/cf9d57d56cac21fc59465b8d26cf29bf6d2a87b3)
|
||||
* fix several potential issues found by [Coverity](https://scan.coverity.com/projects/cjson)
|
||||
* fix potentially undefined behavior when assigning big numbers to `valueint` ([41e2837](https://github.com/DaveGamble/cJSON/commit/41e2837df1b1091643aff073f2313f6ff3cc10f4))
|
||||
* Numbers exceeding `INT_MAX` or lower than `INT_MIN` will be explicitly assigned to `valueint` as `INT_MAX` and `INT_MIN` respectively (saturation on overflow).
|
||||
* fix the `cJSON_SetNumberValue` macro ([87f7727](https://github.com/DaveGamble/cJSON/commit/87f77274de6b3af00fb9b9a7f3b900ef382296c2)), this slightly changes the behavior, see commit message
|
||||
|
||||
Introduce unit tests
|
||||
--------------------
|
||||
|
||||
* Started writing unit tests with the [Cunity](https://github.com/ThrowTheSwitch/Unity) testing framework. Currently this covers the parser functions.
|
||||
|
||||
Also:
|
||||
* Support for running the tests with [Valgrind](http://valgrind.org)
|
||||
* Support for compiling the tests with [AddressSanitizer](https://github.com/google/sanitizers) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html).
|
||||
* `travis.yml` file for running unit tests on travis. (not enabled for the repository yet though [#102](https://github.com/DaveGamble/cJSON/issues/102)
|
||||
|
||||
Simplifications
|
||||
---------------
|
||||
|
||||
After having unit tests for the parser function in place, I started refactoring the parser functions (as well as others) and making them easier to read and maintain.
|
||||
* Use `strtod` from the standard library for parsing numbers ([0747669](https://github.com/DaveGamble/cJSON/commit/074766997246481dfc72bfa78f07898a2716473f))
|
||||
* Use goto-fail in several parser functions ([#100](https://github.com/DaveGamble/cJSON/pull/100))
|
||||
* Rewrite/restructure all of the parsing functions to be easier to understand and have less code paths doing the same as another. ([#109](https://github.com/DaveGamble/cJSON/pull/109))
|
||||
* Simplify the buffer allocation strategy to always doubling the needed amount ([9f6fa94](https://github.com/DaveGamble/cJSON/commit/9f6fa94c91a87b71e4c6868dbf2ce431a48517b0))
|
||||
* Combined `cJSON_AddItemToObject` and `cJSON_AddItemToObjectCS` to one function ([cf862d](https://github.com/DaveGamble/cJSON/commit/cf862d0fed7f9407e4b046d78d3d8050d2080d12))
|
||||
|
||||
Other changes
|
||||
-------------
|
||||
* Prevent the usage of incompatible C and header versions via preprocessor directive ([123bb1](https://github.com/DaveGamble/cJSON/commit/123bb1af7bfae41d805337fef4b41045ef6c7d25))
|
||||
* Let CMake automatically detect compiler flags
|
||||
* Add new compiler flags (`-Wundef`, `-Wswitch-default`, `-Wconversion`, `-fstack-protector-strong`) ([#98](https://github.com/DaveGamble/cJSON/pull/98))
|
||||
* Change internal sizes from `int` to `size_t` ([ecd5678](https://github.com/DaveGamble/cJSON/commit/ecd5678527a6bc422da694e5be9e9979878fe6a0))
|
||||
* Change internal strings from `char*` to `unsigned char*` ([28b9ba4](https://github.com/DaveGamble/cJSON/commit/28b9ba4334e0f7309e867e874a31f395c0ac2474))
|
||||
* Add `const` in more places
|
||||
|
||||
1.2.1 (Jan 31, 2017)
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fixes a potential null pointer dereference in cJSON_Utils, discovered using clang's static analyzer by @bnason-nf, see [#96](https://github.com/DaveGamble/cJSON/issues/96)
|
||||
|
||||
1.2.0 (Jan 9, 2017)
|
||||
=====
|
||||
Features:
|
||||
---------
|
||||
* Add a new type of cJSON item for raw JSON and support printing it. Thanks @loigu, see [#65](https://github.com/DaveGamble/cJSON/pull/65), [#90](https://github.com/DaveGamble/cJSON/pull/90)
|
||||
|
||||
Fixes:
|
||||
------
|
||||
* Compiler warning if const is casted away, Thanks @gatzka, see [#83](https://github.com/DaveGamble/cJSON/pull/83)
|
||||
* Fix compile error with strict-overflow on PowerPC, see [#85](https://github.com/DaveGamble/cJSON/issues/85)
|
||||
* Fix typo in the README, thanks @MicroJoe, see [#88](https://github.com/DaveGamble/cJSON/pull/88)
|
||||
* Add compile flag for compatibility with C++ compilers
|
||||
|
||||
1.1.0 (Dec 6, 2016)
|
||||
=====
|
||||
* Add a function `cJSON_PrintPreallocated` to print to a preallocated buffer, thanks @ChisholmKyle, see [#72](https://github.com/DaveGamble/cJSON/pull/72)
|
||||
* More compiler warnings when using Clang or GCC, thanks @gatzka, see [#75](https://github.com/DaveGamble/cJSON/pull/75), [#78](https://github.com/DaveGamble/cJSON/pull/78)
|
||||
* fixed a memory leak in `cJSON_Duplicate`, thanks @alperakcan, see [#81](https://github.com/DaveGamble/cJSON/pull/81)
|
||||
* fix the `ENABLE_CUSTOM_COMPILER_FLAGS` cmake option
|
||||
|
||||
1.0.2 (Nov 25, 2016)
|
||||
=====
|
||||
* Rename internal boolean type, see [#71](https://github.com/DaveGamble/cJSON/issues/71).
|
||||
|
||||
1.0.1 (Nov 20, 2016)
|
||||
=====
|
||||
Small bugfix release.
|
||||
* Fixes a bug with the use of the cJSON structs type in cJSON_Utils, see [d47339e](https://github.com/DaveGamble/cJSON/commit/d47339e2740360e6e0994527d5e4752007480f3a)
|
||||
* improve code readability
|
||||
* initialize all variables
|
||||
|
||||
1.0.0 (Nov 17, 2016)
|
||||
=====
|
||||
This is the first official versioned release of cJSON. It provides an API version for the shared library and improved Makefile and CMake build files.
|
286
external/cJSON-1.7.17/CMakeLists.txt
vendored
Normal file
286
external/cJSON-1.7.17/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,286 @@
|
|||
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
project(cJSON
|
||||
VERSION 1.7.17
|
||||
LANGUAGES C)
|
||||
|
||||
cmake_policy(SET CMP0054 NEW) # set CMP0054 policy
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(CJSON_VERSION_SO 1)
|
||||
set(CJSON_UTILS_VERSION_SO 1)
|
||||
|
||||
set(custom_compiler_flags)
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags" ON)
|
||||
if (ENABLE_CUSTOM_COMPILER_FLAGS)
|
||||
if (("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU"))
|
||||
list(APPEND custom_compiler_flags
|
||||
-std=c89
|
||||
-pedantic
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wstrict-prototypes
|
||||
-Wwrite-strings
|
||||
-Wshadow
|
||||
-Winit-self
|
||||
-Wcast-align
|
||||
-Wformat=2
|
||||
-Wmissing-prototypes
|
||||
-Wstrict-overflow=2
|
||||
-Wcast-qual
|
||||
-Wundef
|
||||
-Wswitch-default
|
||||
-Wconversion
|
||||
-Wc++-compat
|
||||
-fstack-protector-strong
|
||||
-Wcomma
|
||||
-Wdouble-promotion
|
||||
-Wparentheses
|
||||
-Wformat-overflow
|
||||
-Wunused-macros
|
||||
-Wmissing-variable-declarations
|
||||
-Wused-but-marked-unused
|
||||
-Wswitch-enum
|
||||
)
|
||||
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# Disable warning c4001 - nonstandard extension 'single line comment' was used
|
||||
# Define _CRT_SECURE_NO_WARNINGS to disable deprecation warnings for "insecure" C library functions
|
||||
list(APPEND custom_compiler_flags
|
||||
/GS
|
||||
/Za
|
||||
/sdl
|
||||
/W4
|
||||
/wd4001
|
||||
/D_CRT_SECURE_NO_WARNINGS
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF)
|
||||
if (ENABLE_SANITIZERS)
|
||||
list(APPEND custom_compiler_flags
|
||||
-fno-omit-frame-pointer
|
||||
-fsanitize=address
|
||||
-fsanitize=undefined
|
||||
-fsanitize=float-cast-overflow
|
||||
-fsanitize-address-use-after-scope
|
||||
-fsanitize=integer
|
||||
-01
|
||||
-fno-sanitize-recover
|
||||
)
|
||||
endif()
|
||||
|
||||
option(ENABLE_SAFE_STACK "Enables the SafeStack instrumentation pass by the Code Pointer Integrity Project" OFF)
|
||||
if (ENABLE_SAFE_STACK)
|
||||
if (ENABLE_SANITIZERS)
|
||||
message(FATAL_ERROR "ENABLE_SAFE_STACK cannot be used in combination with ENABLE_SANITIZERS")
|
||||
endif()
|
||||
list(APPEND custom_compiler_flags
|
||||
-fsanitize=safe-stack
|
||||
)
|
||||
endif()
|
||||
|
||||
option(ENABLE_PUBLIC_SYMBOLS "Export library symbols." On)
|
||||
if (ENABLE_PUBLIC_SYMBOLS)
|
||||
list(APPEND custom_compiler_flags -fvisibility=hidden)
|
||||
add_definitions(-DCJSON_EXPORT_SYMBOLS -DCJSON_API_VISIBILITY)
|
||||
endif()
|
||||
option(ENABLE_HIDDEN_SYMBOLS "Hide library symbols." Off)
|
||||
if (ENABLE_HIDDEN_SYMBOLS)
|
||||
add_definitions(-DCJSON_HIDE_SYMBOLS -UCJSON_API_VISIBILITY)
|
||||
endif()
|
||||
|
||||
# apply custom compiler flags
|
||||
foreach(compiler_flag ${custom_compiler_flags})
|
||||
#remove problematic characters
|
||||
string(REGEX REPLACE "[^a-zA-Z0-9]" "" current_variable ${compiler_flag})
|
||||
|
||||
CHECK_C_COMPILER_FLAG(${compiler_flag} "FLAG_SUPPORTED_${current_variable}")
|
||||
if (FLAG_SUPPORTED_${current_variable})
|
||||
list(APPEND supported_compiler_flags)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${compiler_flag}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${supported_compiler_flags}")
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON)
|
||||
|
||||
#cJSON
|
||||
set(CJSON_LIB cjson)
|
||||
|
||||
file(GLOB HEADERS cJSON.h)
|
||||
set(SOURCES cJSON.c)
|
||||
|
||||
option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" ON)
|
||||
option(CJSON_OVERRIDE_BUILD_SHARED_LIBS "Override BUILD_SHARED_LIBS with CJSON_BUILD_SHARED_LIBS" OFF)
|
||||
option(CJSON_BUILD_SHARED_LIBS "Overrides BUILD_SHARED_LIBS if CJSON_OVERRIDE_BUILD_SHARED_LIBS is enabled" OFF)
|
||||
option(ENABLE_CJSON_VERSION_SO "Enables cJSON so version" ON)
|
||||
|
||||
if ((CJSON_OVERRIDE_BUILD_SHARED_LIBS AND CJSON_BUILD_SHARED_LIBS) OR ((NOT CJSON_OVERRIDE_BUILD_SHARED_LIBS) AND BUILD_SHARED_LIBS))
|
||||
set(CJSON_LIBRARY_TYPE SHARED)
|
||||
else()
|
||||
set(CJSON_LIBRARY_TYPE STATIC)
|
||||
endif()
|
||||
|
||||
|
||||
if (NOT BUILD_SHARED_AND_STATIC_LIBS)
|
||||
add_library("${CJSON_LIB}" "${CJSON_LIBRARY_TYPE}" "${HEADERS}" "${SOURCES}")
|
||||
else()
|
||||
# See https://cmake.org/Wiki/CMake_FAQ#How_do_I_make_my_shared_and_static_libraries_have_the_same_root_name.2C_but_different_suffixes.3F
|
||||
add_library("${CJSON_LIB}" SHARED "${HEADERS}" "${SOURCES}")
|
||||
add_library("${CJSON_LIB}-static" STATIC "${HEADERS}" "${SOURCES}")
|
||||
set_target_properties("${CJSON_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_LIB}")
|
||||
set_target_properties("${CJSON_LIB}-static" PROPERTIES PREFIX "lib")
|
||||
endif()
|
||||
if (NOT WIN32)
|
||||
target_link_libraries("${CJSON_LIB}" m)
|
||||
endif()
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)
|
||||
|
||||
install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
|
||||
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
|
||||
install(TARGETS "${CJSON_LIB}"
|
||||
EXPORT "${CJSON_LIB}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||
)
|
||||
if (BUILD_SHARED_AND_STATIC_LIBS)
|
||||
install(TARGETS "${CJSON_LIB}-static"
|
||||
EXPORT "${CJSON_LIB}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||
)
|
||||
endif()
|
||||
if(ENABLE_TARGET_EXPORT)
|
||||
# export library information for CMake projects
|
||||
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
endif()
|
||||
|
||||
if(ENABLE_CJSON_VERSION_SO)
|
||||
set_target_properties("${CJSON_LIB}"
|
||||
PROPERTIES
|
||||
SOVERSION "${CJSON_VERSION_SO}"
|
||||
VERSION "${PROJECT_VERSION}")
|
||||
endif()
|
||||
|
||||
#cJSON_Utils
|
||||
option(ENABLE_CJSON_UTILS "Enable building the cJSON_Utils library." OFF)
|
||||
if(ENABLE_CJSON_UTILS)
|
||||
set(CJSON_UTILS_LIB cjson_utils)
|
||||
|
||||
file(GLOB HEADERS_UTILS cJSON_Utils.h)
|
||||
set(SOURCES_UTILS cJSON_Utils.c)
|
||||
|
||||
if (NOT BUILD_SHARED_AND_STATIC_LIBS)
|
||||
add_library("${CJSON_UTILS_LIB}" "${CJSON_LIBRARY_TYPE}" "${HEADERS_UTILS}" "${SOURCES_UTILS}")
|
||||
target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}")
|
||||
else()
|
||||
add_library("${CJSON_UTILS_LIB}" SHARED "${HEADERS_UTILS}" "${SOURCES_UTILS}")
|
||||
target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}")
|
||||
add_library("${CJSON_UTILS_LIB}-static" STATIC "${HEADERS_UTILS}" "${SOURCES_UTILS}")
|
||||
target_link_libraries("${CJSON_UTILS_LIB}-static" "${CJSON_LIB}-static")
|
||||
set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_UTILS_LIB}")
|
||||
set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES PREFIX "lib")
|
||||
endif()
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)
|
||||
|
||||
install(TARGETS "${CJSON_UTILS_LIB}"
|
||||
EXPORT "${CJSON_UTILS_LIB}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||
)
|
||||
if (BUILD_SHARED_AND_STATIC_LIBS)
|
||||
install(TARGETS "${CJSON_UTILS_LIB}-static"
|
||||
EXPORT "${CJSON_UTILS_LIB}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||
)
|
||||
endif()
|
||||
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
|
||||
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
|
||||
if(ENABLE_TARGET_EXPORT)
|
||||
# export library information for CMake projects
|
||||
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
endif()
|
||||
|
||||
if(ENABLE_CJSON_VERSION_SO)
|
||||
set_target_properties("${CJSON_UTILS_LIB}"
|
||||
PROPERTIES
|
||||
SOVERSION "${CJSON_UTILS_VERSION_SO}"
|
||||
VERSION "${PROJECT_VERSION}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# create the other package config files
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfig.cmake.in"
|
||||
${PROJECT_BINARY_DIR}/cJSONConfig.cmake @ONLY)
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfigVersion.cmake.in"
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY)
|
||||
|
||||
if(ENABLE_TARGET_EXPORT)
|
||||
# Install package config files
|
||||
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
|
||||
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
endif()
|
||||
|
||||
option(ENABLE_CJSON_TEST "Enable building cJSON test" OFF)
|
||||
if(ENABLE_CJSON_TEST)
|
||||
enable_testing()
|
||||
|
||||
set(TEST_CJSON cJSON_test)
|
||||
add_executable("${TEST_CJSON}" test.c)
|
||||
target_link_libraries("${TEST_CJSON}" "${CJSON_LIB}")
|
||||
|
||||
add_test(NAME ${TEST_CJSON} COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${TEST_CJSON}")
|
||||
|
||||
# Disable -fsanitize=float-divide-by-zero for cJSON_test
|
||||
if (FLAG_SUPPORTED_fsanitizefloatdividebyzero)
|
||||
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=float-divide-by-zero")
|
||||
else()
|
||||
target_compile_options(${TEST_CJSON} PRIVATE "-fno-sanitize=float-divide-by-zero")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#"check" target that automatically builds everything and runs the tests
|
||||
add_custom_target(check
|
||||
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
|
||||
DEPENDS ${TEST_CJSON})
|
||||
endif()
|
||||
|
||||
#Create the uninstall target
|
||||
option(ENABLE_CJSON_UNINSTALL "Enable creating uninstall target" OFF)
|
||||
if(ENABLE_CJSON_UNINSTALL)
|
||||
add_custom_target(uninstall "${CMAKE_COMMAND}" -P
|
||||
"${PROJECT_SOURCE_DIR}/library_config/uninstall.cmake")
|
||||
endif()
|
||||
|
||||
# Enable the use of locales
|
||||
option(ENABLE_LOCALES "Enable the use of locales" ON)
|
||||
if(ENABLE_LOCALES)
|
||||
add_definitions(-DENABLE_LOCALES)
|
||||
endif()
|
||||
|
||||
# add_subdirectory(tests)
|
||||
# add_subdirectory(fuzzing)
|
91
external/cJSON-1.7.17/CONTRIBUTORS.md
vendored
Normal file
91
external/cJSON-1.7.17/CONTRIBUTORS.md
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
Contributors
|
||||
============
|
||||
|
||||
Original Author:
|
||||
- [Dave Gamble](https://github.com/DaveGamble)
|
||||
|
||||
Current Maintainer:
|
||||
- [Max Bruckner](https://github.com/FSMaxB)
|
||||
- [Alan Wang](https://github.com/Alanscut)
|
||||
|
||||
Contributors:
|
||||
* [Ajay Bhargav](https://github.com/ajaybhargav)
|
||||
* [AlexanderVasiljev](https://github.com/AlexanderVasiljev)
|
||||
* [Alper Akcan](https://github.com/alperakcan)
|
||||
* [Andrew Tang](https://github.com/singku)
|
||||
* [Andy](https://github.com/mlh0101)
|
||||
* [Anton Sergeev](https://github.com/anton-sergeev)
|
||||
* [Benbuck Nason](https://github.com/bnason-nf)
|
||||
* [Bernt Johan Damslora](https://github.com/bjda)
|
||||
* [Bob Kocisko](https://github.com/bobkocisko)
|
||||
* [Christian Schulze](https://github.com/ChristianSch)
|
||||
* [Casperinous](https://github.com/Casperinous)
|
||||
* [ChenYuan](https://github.com/zjuchenyuan)
|
||||
* [Debora Grosse](https://github.com/DeboraG)
|
||||
* [dieyushi](https://github.com/dieyushi)
|
||||
* [Dōngwén Huáng (黄东文)](https://github.com/DongwenHuang)
|
||||
* [Donough Liu](https://github.com/ldm0)
|
||||
* [Erez Oxman](https://github.com/erez-o)
|
||||
* Eswar Yaganti
|
||||
* [Evan Todd](https://github.com/etodd)
|
||||
* [Fabrice Fontaine](https://github.com/ffontaine)
|
||||
* Ian Mobley
|
||||
* Irwan Djadjadi
|
||||
* [hopper-vul](https://github.com/hopper-vul)
|
||||
* [HuKeping](https://github.com/HuKeping)
|
||||
* [IvanVoid](https://github.com/npi3pak)
|
||||
* [Jakub Wilk](https://github.com/jwilk)
|
||||
* [Jiri Zouhar](https://github.com/loigu)
|
||||
* [Jonathan Fether](https://github.com/jfether)
|
||||
* [Joshua Arulsamy](https://github.com/jarulsamy)
|
||||
* [Julian Ste](https://github.com/julian-st)
|
||||
* [Julián Vásquez](https://github.com/juvasquezg)
|
||||
* [Junbo Zheng](https://github.com/Junbo-Zheng)
|
||||
* [Kevin Branigan](https://github.com/kbranigan)
|
||||
* [Kevin Sapper](https://github.com/sappo)
|
||||
* [Kyle Chisholm](https://github.com/ChisholmKyle)
|
||||
* [Linus Wallgren](https://github.com/ecksun)
|
||||
* [MaxBrandtner](https://github.com/MaxBrandtner)
|
||||
* [Mateusz Szafoni](https://github.com/raiden00pl)
|
||||
* Mike Pontillo
|
||||
* [miaoerduo](https://github.com/miaoerduo)
|
||||
* [mohawk2](https://github.com/mohawk2)
|
||||
* [Mike Jerris](https://github.com/mjerris)
|
||||
* [Mike Robinson](https://github.com/mhrobinson)
|
||||
* [Moorthy](https://github.com/moorthy-bs)
|
||||
* [myd7349](https://github.com/myd7349)
|
||||
* [NancyLi1013](https://github.com/NancyLi1013)
|
||||
* Paulo Antonio Alvarez
|
||||
* [Paweł Malowany](https://github.com/PawelMalowany)
|
||||
* [Pawel Winogrodzki](https://github.com/PawelWMS)
|
||||
* [prefetchnta](https://github.com/prefetchnta)
|
||||
* [Rafael Leal Dias](https://github.com/rafaeldias)
|
||||
* [Randy](https://github.com/randy408)
|
||||
* [raiden00pl](https://github.com/raiden00pl)
|
||||
* [Robin Mallinson](https://github.com/rmallins)
|
||||
* [Rod Vagg](https://github.com/rvagg)
|
||||
* [Roland Meertens](https://github.com/rmeertens)
|
||||
* [Romain Porte](https://github.com/MicroJoe)
|
||||
* [SANJEEV BA](https://github.com/basanjeev)
|
||||
* [Sang-Heon Jeon](https://github.com/lntuition)
|
||||
* [Sayan Bandyopadhyay](https://github.com/saynb)
|
||||
* [Simon Sobisch](https://github.com/GitMensch)
|
||||
* [Simon Ricaldone](https://github.com/simon-p-r)
|
||||
* [Stoian Ivanov](https://github.com/sdrsdr)
|
||||
* [SuperH-0630](https://github.com/SuperH-0630)
|
||||
* [Square789](https://github.com/Square789)
|
||||
* [Stephan Gatzka](https://github.com/gatzka)
|
||||
* [Tony Langhammer](https://github.com/BigBrainAFK)
|
||||
* [Vemake](https://github.com/vemakereporter)
|
||||
* [Wei Tan](https://github.com/tan-wei)
|
||||
* [Weston Schmidt](https://github.com/schmidtw)
|
||||
* [xiaomianhehe](https://github.com/xiaomianhehe)
|
||||
* [yangfl](https://github.com/yangfl)
|
||||
* [yuta-oxo](https://github.com/yuta-oxo)
|
||||
* [Zach Hindes](https://github.com/zhindes)
|
||||
* [Zhao Zhixu](https://github.com/zhaozhixu)
|
||||
* [10km](https://github.com/10km)
|
||||
|
||||
And probably more people on [SourceForge](https://sourceforge.net/p/cjson/bugs/search/?q=status%3Aclosed-rejected+or+status%3Aclosed-out-of-date+or+status%3Awont-fix+or+status%3Aclosed-fixed+or+status%3Aclosed&page=0)
|
||||
|
||||
Also thanks to all the people who reported bugs and suggested new features.
|
20
external/cJSON-1.7.17/LICENSE
vendored
Normal file
20
external/cJSON-1.7.17/LICENSE
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
163
external/cJSON-1.7.17/Makefile
vendored
Normal file
163
external/cJSON-1.7.17/Makefile
vendored
Normal file
|
@ -0,0 +1,163 @@
|
|||
CJSON_OBJ = cJSON.o
|
||||
UTILS_OBJ = cJSON_Utils.o
|
||||
CJSON_LIBNAME = libcjson
|
||||
UTILS_LIBNAME = libcjson_utils
|
||||
CJSON_TEST = cJSON_test
|
||||
|
||||
CJSON_TEST_SRC = cJSON.c test.c
|
||||
|
||||
LDLIBS = -lm
|
||||
|
||||
LIBVERSION = 1.7.17
|
||||
CJSON_SOVERSION = 1
|
||||
UTILS_SOVERSION = 1
|
||||
|
||||
CJSON_SO_LDFLAG=-Wl,-soname=$(CJSON_LIBNAME).so.$(CJSON_SOVERSION)
|
||||
UTILS_SO_LDFLAG=-Wl,-soname=$(UTILS_LIBNAME).so.$(UTILS_SOVERSION)
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
INCLUDE_PATH ?= include/cjson
|
||||
LIBRARY_PATH ?= lib
|
||||
|
||||
INSTALL_INCLUDE_PATH = $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH)
|
||||
INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
|
||||
|
||||
INSTALL ?= cp -a
|
||||
|
||||
CC = gcc -std=c89
|
||||
|
||||
# validate gcc version for use fstack-protector-strong
|
||||
MIN_GCC_VERSION = "4.9"
|
||||
GCC_VERSION := "`$(CC) -dumpversion`"
|
||||
IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
|
||||
ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1"
|
||||
CFLAGS += -fstack-protector-strong
|
||||
else
|
||||
CFLAGS += -fstack-protector
|
||||
endif
|
||||
|
||||
PIC_FLAGS = -fPIC
|
||||
R_CFLAGS = $(PIC_FLAGS) -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion $(CFLAGS)
|
||||
|
||||
uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')
|
||||
|
||||
#library file extensions
|
||||
SHARED = so
|
||||
STATIC = a
|
||||
|
||||
## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS)
|
||||
ifeq (Darwin, $(uname))
|
||||
SHARED = dylib
|
||||
CJSON_SO_LDFLAG = ""
|
||||
UTILS_SO_LDFLAG = ""
|
||||
endif
|
||||
|
||||
#cJSON library names
|
||||
CJSON_SHARED = $(CJSON_LIBNAME).$(SHARED)
|
||||
CJSON_SHARED_VERSION = $(CJSON_LIBNAME).$(SHARED).$(LIBVERSION)
|
||||
CJSON_SHARED_SO = $(CJSON_LIBNAME).$(SHARED).$(CJSON_SOVERSION)
|
||||
CJSON_STATIC = $(CJSON_LIBNAME).$(STATIC)
|
||||
|
||||
#cJSON_Utils library names
|
||||
UTILS_SHARED = $(UTILS_LIBNAME).$(SHARED)
|
||||
UTILS_SHARED_VERSION = $(UTILS_LIBNAME).$(SHARED).$(LIBVERSION)
|
||||
UTILS_SHARED_SO = $(UTILS_LIBNAME).$(SHARED).$(UTILS_SOVERSION)
|
||||
UTILS_STATIC = $(UTILS_LIBNAME).$(STATIC)
|
||||
|
||||
SHARED_CMD = $(CC) -shared -o
|
||||
|
||||
.PHONY: all shared static tests clean install
|
||||
|
||||
all: shared static tests
|
||||
|
||||
shared: $(CJSON_SHARED) $(UTILS_SHARED)
|
||||
|
||||
static: $(CJSON_STATIC) $(UTILS_STATIC)
|
||||
|
||||
tests: $(CJSON_TEST)
|
||||
|
||||
test: tests
|
||||
./$(CJSON_TEST)
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(R_CFLAGS) $<
|
||||
|
||||
#tests
|
||||
#cJSON
|
||||
$(CJSON_TEST): $(CJSON_TEST_SRC) cJSON.h
|
||||
$(CC) $(R_CFLAGS) $(CJSON_TEST_SRC) -o $@ $(LDLIBS) -I.
|
||||
|
||||
#static libraries
|
||||
#cJSON
|
||||
$(CJSON_STATIC): $(CJSON_OBJ)
|
||||
$(AR) rcs $@ $<
|
||||
#cJSON_Utils
|
||||
$(UTILS_STATIC): $(UTILS_OBJ)
|
||||
$(AR) rcs $@ $<
|
||||
|
||||
#shared libraries .so.1.0.0
|
||||
#cJSON
|
||||
$(CJSON_SHARED_VERSION): $(CJSON_OBJ)
|
||||
$(CC) -shared -o $@ $< $(CJSON_SO_LDFLAG) $(LDFLAGS)
|
||||
#cJSON_Utils
|
||||
$(UTILS_SHARED_VERSION): $(UTILS_OBJ)
|
||||
$(CC) -shared -o $@ $< $(CJSON_OBJ) $(UTILS_SO_LDFLAG) $(LDFLAGS)
|
||||
|
||||
#objects
|
||||
#cJSON
|
||||
$(CJSON_OBJ): cJSON.c cJSON.h
|
||||
#cJSON_Utils
|
||||
$(UTILS_OBJ): cJSON_Utils.c cJSON_Utils.h cJSON.h
|
||||
|
||||
|
||||
#links .so -> .so.1 -> .so.1.0.0
|
||||
#cJSON
|
||||
$(CJSON_SHARED_SO): $(CJSON_SHARED_VERSION)
|
||||
ln -s $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO)
|
||||
$(CJSON_SHARED): $(CJSON_SHARED_SO)
|
||||
ln -s $(CJSON_SHARED_SO) $(CJSON_SHARED)
|
||||
#cJSON_Utils
|
||||
$(UTILS_SHARED_SO): $(UTILS_SHARED_VERSION)
|
||||
ln -s $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO)
|
||||
$(UTILS_SHARED): $(UTILS_SHARED_SO)
|
||||
ln -s $(UTILS_SHARED_SO) $(UTILS_SHARED)
|
||||
|
||||
#install
|
||||
#cJSON
|
||||
install-cjson:
|
||||
mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
|
||||
$(INSTALL) cJSON.h $(INSTALL_INCLUDE_PATH)
|
||||
$(INSTALL) $(CJSON_SHARED) $(CJSON_SHARED_SO) $(CJSON_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
|
||||
#cJSON_Utils
|
||||
install-utils: install-cjson
|
||||
$(INSTALL) cJSON_Utils.h $(INSTALL_INCLUDE_PATH)
|
||||
$(INSTALL) $(UTILS_SHARED) $(UTILS_SHARED_SO) $(UTILS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
|
||||
|
||||
install: install-cjson install-utils
|
||||
|
||||
#uninstall
|
||||
#cJSON
|
||||
uninstall-cjson: uninstall-utils
|
||||
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED)
|
||||
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_VERSION)
|
||||
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_SO)
|
||||
$(RM) $(INSTALL_INCLUDE_PATH)/cJSON.h
|
||||
|
||||
#cJSON_Utils
|
||||
uninstall-utils:
|
||||
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED)
|
||||
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_VERSION)
|
||||
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_SO)
|
||||
$(RM) $(INSTALL_INCLUDE_PATH)/cJSON_Utils.h
|
||||
|
||||
remove-dir:
|
||||
$(if $(wildcard $(INSTALL_LIBRARY_PATH)/*.*),,rmdir $(INSTALL_LIBRARY_PATH))
|
||||
$(if $(wildcard $(INSTALL_INCLUDE_PATH)/*.*),,rmdir $(INSTALL_INCLUDE_PATH))
|
||||
|
||||
uninstall: uninstall-utils uninstall-cjson remove-dir
|
||||
|
||||
clean:
|
||||
$(RM) $(CJSON_OBJ) $(UTILS_OBJ) #delete object files
|
||||
$(RM) $(CJSON_SHARED) $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) $(CJSON_STATIC) #delete cJSON
|
||||
$(RM) $(UTILS_SHARED) $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) $(UTILS_STATIC) #delete cJSON_Utils
|
||||
$(RM) $(CJSON_TEST) #delete test
|
590
external/cJSON-1.7.17/README.md
vendored
Normal file
590
external/cJSON-1.7.17/README.md
vendored
Normal file
|
@ -0,0 +1,590 @@
|
|||
# cJSON
|
||||
|
||||
Ultralightweight JSON parser in ANSI C.
|
||||
|
||||
## Table of contents
|
||||
* [License](#license)
|
||||
* [Usage](#usage)
|
||||
* [Welcome to cJSON](#welcome-to-cjson)
|
||||
* [Building](#building)
|
||||
* [Copying the source](#copying-the-source)
|
||||
* [CMake](#cmake)
|
||||
* [Makefile](#makefile)
|
||||
* [Meson](#meson)
|
||||
* [Vcpkg](#Vcpkg)
|
||||
* [Including cJSON](#including-cjson)
|
||||
* [Data Structure](#data-structure)
|
||||
* [Working with the data structure](#working-with-the-data-structure)
|
||||
* [Basic types](#basic-types)
|
||||
* [Arrays](#arrays)
|
||||
* [Objects](#objects)
|
||||
* [Parsing JSON](#parsing-json)
|
||||
* [Printing JSON](#printing-json)
|
||||
* [Example](#example)
|
||||
* [Printing](#printing)
|
||||
* [Parsing](#parsing)
|
||||
* [Caveats](#caveats)
|
||||
* [Zero Character](#zero-character)
|
||||
* [Character Encoding](#character-encoding)
|
||||
* [C Standard](#c-standard)
|
||||
* [Floating Point Numbers](#floating-point-numbers)
|
||||
* [Deep Nesting Of Arrays And Objects](#deep-nesting-of-arrays-and-objects)
|
||||
* [Thread Safety](#thread-safety)
|
||||
* [Case Sensitivity](#case-sensitivity)
|
||||
* [Duplicate Object Members](#duplicate-object-members)
|
||||
* [Enjoy cJSON!](#enjoy-cjson)
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
|
||||
> Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
> of this software and associated documentation files (the "Software"), to deal
|
||||
> in the Software without restriction, including without limitation the rights
|
||||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
> copies of the Software, and to permit persons to whom the Software is
|
||||
> furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in
|
||||
> all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
> THE SOFTWARE.
|
||||
|
||||
## Usage
|
||||
|
||||
### Welcome to cJSON.
|
||||
|
||||
cJSON aims to be the dumbest possible parser that you can get your job done with.
|
||||
It's a single file of C, and a single header file.
|
||||
|
||||
JSON is described best here: http://www.json.org/
|
||||
It's like XML, but fat-free. You use it to move data around, store things, or just
|
||||
generally represent your program's state.
|
||||
|
||||
As a library, cJSON exists to take away as much legwork as it can, but not get in your way.
|
||||
As a point of pragmatism (i.e. ignoring the truth), I'm going to say that you can use it
|
||||
in one of two modes: Auto and Manual. Let's have a quick run-through.
|
||||
|
||||
I lifted some JSON from this page: http://www.json.org/fatfree.html
|
||||
That page inspired me to write cJSON, which is a parser that tries to share the same
|
||||
philosophy as JSON itself. Simple, dumb, out of the way.
|
||||
|
||||
### Building
|
||||
|
||||
There are several ways to incorporate cJSON into your project.
|
||||
|
||||
#### copying the source
|
||||
|
||||
Because the entire library is only one C file and one header file, you can just copy `cJSON.h` and `cJSON.c` to your projects source and start using it.
|
||||
|
||||
cJSON is written in ANSI C (C89) in order to support as many platforms and compilers as possible.
|
||||
|
||||
#### CMake
|
||||
|
||||
With CMake, cJSON supports a full blown build system. This way you get the most features. CMake with an equal or higher version than 2.8.5 is supported. With CMake it is recommended to do an out of tree build, meaning the compiled files are put in a directory separate from the source files. So in order to build cJSON with CMake on a Unix platform, make a `build` directory and run CMake inside it.
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
```
|
||||
|
||||
This will create a Makefile and a bunch of other files. You can then compile it:
|
||||
|
||||
```
|
||||
make
|
||||
```
|
||||
|
||||
And install it with `make install` if you want. By default it installs the headers `/usr/local/include/cjson` and the libraries to `/usr/local/lib`. It also installs files for pkg-config to make it easier to detect and use an existing installation of CMake. And it installs CMake config files, that can be used by other CMake based projects to discover the library.
|
||||
|
||||
You can change the build process with a list of different options that you can pass to CMake. Turn them on with `On` and off with `Off`:
|
||||
|
||||
* `-DENABLE_CJSON_TEST=On`: Enable building the tests. (on by default)
|
||||
* `-DENABLE_CJSON_UTILS=On`: Enable building cJSON_Utils. (off by default)
|
||||
* `-DENABLE_TARGET_EXPORT=On`: Enable the export of CMake targets. Turn off if it makes problems. (on by default)
|
||||
* `-DENABLE_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang, GCC and MSVC). Turn off if it makes problems. (on by default)
|
||||
* `-DENABLE_VALGRIND=On`: Run tests with [valgrind](http://valgrind.org). (off by default)
|
||||
* `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default)
|
||||
* `-DENABLE_SAFE_STACK`: Enable the [SafeStack](https://clang.llvm.org/docs/SafeStack.html) instrumentation pass. Currently only works with the Clang compiler. (off by default)
|
||||
* `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default)
|
||||
* `-DBUILD_SHARED_AND_STATIC_LIBS=On`: Build both shared and static libraries. (off by default)
|
||||
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation.
|
||||
* `-DENABLE_LOCALES=On`: Enable the usage of localeconv method. ( on by default )
|
||||
* `-DCJSON_OVERRIDE_BUILD_SHARED_LIBS=On`: Enable overriding the value of `BUILD_SHARED_LIBS` with `-DCJSON_BUILD_SHARED_LIBS`.
|
||||
* `-DENABLE_CJSON_VERSION_SO`: Enable cJSON so version. ( on by default )
|
||||
|
||||
If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example:
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off -DCMAKE_INSTALL_PREFIX=/usr
|
||||
make
|
||||
make DESTDIR=$pkgdir install
|
||||
```
|
||||
|
||||
On Windows CMake is usually used to create a Visual Studio solution file by running it inside the Developer Command Prompt for Visual Studio, for exact steps follow the official documentation from CMake and Microsoft and use the online search engine of your choice. The descriptions of the the options above still generally apply, although not all of them work on Windows.
|
||||
|
||||
#### Makefile
|
||||
|
||||
**NOTE:** This Method is deprecated. Use CMake if at all possible. Makefile support is limited to fixing bugs.
|
||||
|
||||
If you don't have CMake available, but still have GNU make. You can use the makefile to build cJSON:
|
||||
|
||||
Run this command in the directory with the source code and it will automatically compile static and shared libraries and a little test program (not the full test suite).
|
||||
|
||||
```
|
||||
make all
|
||||
```
|
||||
|
||||
If you want, you can install the compiled library to your system using `make install`. By default it will install the headers in `/usr/local/include/cjson` and the libraries in `/usr/local/lib`. But you can change this behavior by setting the `PREFIX` and `DESTDIR` variables: `make PREFIX=/usr DESTDIR=temp install`. And uninstall them with: `make PREFIX=/usr DESTDIR=temp uninstall`.
|
||||
|
||||
#### Meson
|
||||
|
||||
To make cjson work in a project using meson, the libcjson dependency has to be included:
|
||||
|
||||
```meson
|
||||
project('c-json-example', 'c')
|
||||
|
||||
cjson = dependency('libcjson')
|
||||
|
||||
example = executable(
|
||||
'example',
|
||||
'example.c',
|
||||
dependencies: [cjson],
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
#### Vcpkg
|
||||
|
||||
You can download and install cJSON using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
||||
```
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
vcpkg install cjson
|
||||
```
|
||||
|
||||
The cJSON port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
### Including cJSON
|
||||
|
||||
If you installed it via CMake or the Makefile, you can include cJSON like this:
|
||||
|
||||
```c
|
||||
#include <cjson/cJSON.h>
|
||||
```
|
||||
|
||||
### Data Structure
|
||||
|
||||
cJSON represents JSON data using the `cJSON` struct data type:
|
||||
|
||||
```c
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON
|
||||
{
|
||||
struct cJSON *next;
|
||||
struct cJSON *prev;
|
||||
struct cJSON *child;
|
||||
int type;
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
double valuedouble;
|
||||
char *string;
|
||||
} cJSON;
|
||||
```
|
||||
|
||||
An item of this type represents a JSON value. The type is stored in `type` as a bit-flag (**this means that you cannot find out the type by just comparing the value of `type`**).
|
||||
|
||||
To check the type of an item, use the corresponding `cJSON_Is...` function. It does a `NULL` check followed by a type check and returns a boolean value if the item is of this type.
|
||||
|
||||
The type can be one of the following:
|
||||
|
||||
* `cJSON_Invalid` (check with `cJSON_IsInvalid`): Represents an invalid item that doesn't contain any value. You automatically have this type if you set the item to all zero bytes.
|
||||
* `cJSON_False` (check with `cJSON_IsFalse`): Represents a `false` boolean value. You can also check for boolean values in general with `cJSON_IsBool`.
|
||||
* `cJSON_True` (check with `cJSON_IsTrue`): Represents a `true` boolean value. You can also check for boolean values in general with `cJSON_IsBool`.
|
||||
* `cJSON_NULL` (check with `cJSON_IsNull`): Represents a `null` value.
|
||||
* `cJSON_Number` (check with `cJSON_IsNumber`): Represents a number value. The value is stored as a double in `valuedouble` and also in `valueint`. If the number is outside of the range of an integer, `INT_MAX` or `INT_MIN` are used for `valueint`.
|
||||
* `cJSON_String` (check with `cJSON_IsString`): Represents a string value. It is stored in the form of a zero terminated string in `valuestring`.
|
||||
* `cJSON_Array` (check with `cJSON_IsArray`): Represent an array value. This is implemented by pointing `child` to a linked list of `cJSON` items that represent the values in the array. The elements are linked together using `next` and `prev`, where the first element has `prev.next == NULL` and the last element `next == NULL`.
|
||||
* `cJSON_Object` (check with `cJSON_IsObject`): Represents an object value. Objects are stored same way as an array, the only difference is that the items in the object store their keys in `string`.
|
||||
* `cJSON_Raw` (check with `cJSON_IsRaw`): Represents any kind of JSON that is stored as a zero terminated array of characters in `valuestring`. This can be used, for example, to avoid printing the same static JSON over and over again to save performance. cJSON will never create this type when parsing. Also note that cJSON doesn't check if it is valid JSON.
|
||||
|
||||
Additionally there are the following two flags:
|
||||
|
||||
* `cJSON_IsReference`: Specifies that the item that `child` points to and/or `valuestring` is not owned by this item, it is only a reference. So `cJSON_Delete` and other functions will only deallocate this item, not its `child`/`valuestring`.
|
||||
* `cJSON_StringIsConst`: This means that `string` points to a constant string. This means that `cJSON_Delete` and other functions will not try to deallocate `string`.
|
||||
|
||||
### Working with the data structure
|
||||
|
||||
For every value type there is a `cJSON_Create...` function that can be used to create an item of that type.
|
||||
All of these will allocate a `cJSON` struct that can later be deleted with `cJSON_Delete`.
|
||||
Note that you have to delete them at some point, otherwise you will get a memory leak.
|
||||
**Important**: If you have added an item to an array or an object already, you **mustn't** delete it with `cJSON_Delete`. Adding it to an array or object transfers its ownership so that when that array or object is deleted,
|
||||
it gets deleted as well. You also could use `cJSON_SetValuestring` to change a `cJSON_String`'s `valuestring`, and you needn't to free the previous `valuestring` manually.
|
||||
|
||||
#### Basic types
|
||||
|
||||
* **null** is created with `cJSON_CreateNull`
|
||||
* **booleans** are created with `cJSON_CreateTrue`, `cJSON_CreateFalse` or `cJSON_CreateBool`
|
||||
* **numbers** are created with `cJSON_CreateNumber`. This will set both `valuedouble` and `valueint`. If the number is outside of the range of an integer, `INT_MAX` or `INT_MIN` are used for `valueint`
|
||||
* **strings** are created with `cJSON_CreateString` (copies the string) or with `cJSON_CreateStringReference` (directly points to the string. This means that `valuestring` won't be deleted by `cJSON_Delete` and you are responsible for its lifetime, useful for constants)
|
||||
|
||||
#### Arrays
|
||||
|
||||
You can create an empty array with `cJSON_CreateArray`. `cJSON_CreateArrayReference` can be used to create an array that doesn't "own" its content, so its content doesn't get deleted by `cJSON_Delete`.
|
||||
|
||||
To add items to an array, use `cJSON_AddItemToArray` to append items to the end.
|
||||
Using `cJSON_AddItemReferenceToArray` an element can be added as a reference to another item, array or string. This means that `cJSON_Delete` will not delete that items `child` or `valuestring` properties, so no double frees are occurring if they are already used elsewhere.
|
||||
To insert items in the middle, use `cJSON_InsertItemInArray`. It will insert an item at the given 0 based index and shift all the existing items to the right.
|
||||
|
||||
If you want to take an item out of an array at a given index and continue using it, use `cJSON_DetachItemFromArray`, it will return the detached item, so be sure to assign it to a pointer, otherwise you will have a memory leak.
|
||||
|
||||
Deleting items is done with `cJSON_DeleteItemFromArray`. It works like `cJSON_DetachItemFromArray`, but deletes the detached item via `cJSON_Delete`.
|
||||
|
||||
You can also replace an item in an array in place. Either with `cJSON_ReplaceItemInArray` using an index or with `cJSON_ReplaceItemViaPointer` given a pointer to an element. `cJSON_ReplaceItemViaPointer` will return `0` if it fails. What this does internally is to detach the old item, delete it and insert the new item in its place.
|
||||
|
||||
To get the size of an array, use `cJSON_GetArraySize`. Use `cJSON_GetArrayItem` to get an element at a given index.
|
||||
|
||||
Because an array is stored as a linked list, iterating it via index is inefficient (`O(n²)`), so you can iterate over an array using the `cJSON_ArrayForEach` macro in `O(n)` time complexity.
|
||||
|
||||
#### Objects
|
||||
|
||||
You can create an empty object with `cJSON_CreateObject`. `cJSON_CreateObjectReference` can be used to create an object that doesn't "own" its content, so its content doesn't get deleted by `cJSON_Delete`.
|
||||
|
||||
To add items to an object, use `cJSON_AddItemToObject`. Use `cJSON_AddItemToObjectCS` to add an item to an object with a name that is a constant or reference (key of the item, `string` in the `cJSON` struct), so that it doesn't get freed by `cJSON_Delete`.
|
||||
Using `cJSON_AddItemReferenceToArray` an element can be added as a reference to another object, array or string. This means that `cJSON_Delete` will not delete that items `child` or `valuestring` properties, so no double frees are occurring if they are already used elsewhere.
|
||||
|
||||
If you want to take an item out of an object, use `cJSON_DetachItemFromObjectCaseSensitive`, it will return the detached item, so be sure to assign it to a pointer, otherwise you will have a memory leak.
|
||||
|
||||
Deleting items is done with `cJSON_DeleteItemFromObjectCaseSensitive`. It works like `cJSON_DetachItemFromObjectCaseSensitive` followed by `cJSON_Delete`.
|
||||
|
||||
You can also replace an item in an object in place. Either with `cJSON_ReplaceItemInObjectCaseSensitive` using a key or with `cJSON_ReplaceItemViaPointer` given a pointer to an element. `cJSON_ReplaceItemViaPointer` will return `0` if it fails. What this does internally is to detach the old item, delete it and insert the new item in its place.
|
||||
|
||||
To get the size of an object, you can use `cJSON_GetArraySize`, this works because internally objects are stored as arrays.
|
||||
|
||||
If you want to access an item in an object, use `cJSON_GetObjectItemCaseSensitive`.
|
||||
|
||||
To iterate over an object, you can use the `cJSON_ArrayForEach` macro the same way as for arrays.
|
||||
|
||||
cJSON also provides convenient helper functions for quickly creating a new item and adding it to an object, like `cJSON_AddNullToObject`. They return a pointer to the new item or `NULL` if they failed.
|
||||
|
||||
### Parsing JSON
|
||||
|
||||
Given some JSON in a zero terminated string, you can parse it with `cJSON_Parse`.
|
||||
|
||||
```c
|
||||
cJSON *json = cJSON_Parse(string);
|
||||
```
|
||||
|
||||
Given some JSON in a string (whether zero terminated or not), you can parse it with `cJSON_ParseWithLength`.
|
||||
|
||||
```c
|
||||
cJSON *json = cJSON_ParseWithLength(string, buffer_length);
|
||||
```
|
||||
|
||||
It will parse the JSON and allocate a tree of `cJSON` items that represents it. Once it returns, you are fully responsible for deallocating it after use with `cJSON_Delete`.
|
||||
|
||||
The allocator used by `cJSON_Parse` is `malloc` and `free` by default but can be changed (globally) with `cJSON_InitHooks`.
|
||||
|
||||
If an error occurs a pointer to the position of the error in the input string can be accessed using `cJSON_GetErrorPtr`. Note though that this can produce race conditions in multithreading scenarios, in that case it is better to use `cJSON_ParseWithOpts` with `return_parse_end`.
|
||||
By default, characters in the input string that follow the parsed JSON will not be considered as an error.
|
||||
|
||||
If you want more options, use `cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)`.
|
||||
`return_parse_end` returns a pointer to the end of the JSON in the input string or the position that an error occurs at (thereby replacing `cJSON_GetErrorPtr` in a thread safe way). `require_null_terminated`, if set to `1` will make it an error if the input string contains data after the JSON.
|
||||
|
||||
If you want more options giving buffer length, use `cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated)`.
|
||||
|
||||
### Printing JSON
|
||||
|
||||
Given a tree of `cJSON` items, you can print them as a string using `cJSON_Print`.
|
||||
|
||||
```c
|
||||
char *string = cJSON_Print(json);
|
||||
```
|
||||
|
||||
It will allocate a string and print a JSON representation of the tree into it. Once it returns, you are fully responsible for deallocating it after use with your allocator. (usually `free`, depends on what has been set with `cJSON_InitHooks`).
|
||||
|
||||
`cJSON_Print` will print with whitespace for formatting. If you want to print without formatting, use `cJSON_PrintUnformatted`.
|
||||
|
||||
If you have a rough idea of how big your resulting string will be, you can use `cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt)`. `fmt` is a boolean to turn formatting with whitespace on and off. `prebuffer` specifies the first buffer size to use for printing. `cJSON_Print` currently uses 256 bytes for its first buffer size. Once printing runs out of space, a new buffer is allocated and the old gets copied over before printing is continued.
|
||||
|
||||
These dynamic buffer allocations can be completely avoided by using `cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format)`. It takes a buffer to a pointer to print to and its length. If the length is reached, printing will fail and it returns `0`. In case of success, `1` is returned. Note that you should provide 5 bytes more than is actually needed, because cJSON is not 100% accurate in estimating if the provided memory is enough.
|
||||
|
||||
### Example
|
||||
|
||||
In this example we want to build and parse the following JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Awesome 4K",
|
||||
"resolutions": [
|
||||
{
|
||||
"width": 1280,
|
||||
"height": 720
|
||||
},
|
||||
{
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
},
|
||||
{
|
||||
"width": 3840,
|
||||
"height": 2160
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Printing
|
||||
|
||||
Let's build the above JSON and print it to a string:
|
||||
|
||||
```c
|
||||
//create a monitor with a list of supported resolutions
|
||||
//NOTE: Returns a heap allocated string, you are required to free it after use.
|
||||
char *create_monitor(void)
|
||||
{
|
||||
const unsigned int resolution_numbers[3][2] = {
|
||||
{1280, 720},
|
||||
{1920, 1080},
|
||||
{3840, 2160}
|
||||
};
|
||||
char *string = NULL;
|
||||
cJSON *name = NULL;
|
||||
cJSON *resolutions = NULL;
|
||||
cJSON *resolution = NULL;
|
||||
cJSON *width = NULL;
|
||||
cJSON *height = NULL;
|
||||
size_t index = 0;
|
||||
|
||||
cJSON *monitor = cJSON_CreateObject();
|
||||
if (monitor == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
name = cJSON_CreateString("Awesome 4K");
|
||||
if (name == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
/* after creation was successful, immediately add it to the monitor,
|
||||
* thereby transferring ownership of the pointer to it */
|
||||
cJSON_AddItemToObject(monitor, "name", name);
|
||||
|
||||
resolutions = cJSON_CreateArray();
|
||||
if (resolutions == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(monitor, "resolutions", resolutions);
|
||||
|
||||
for (index = 0; index < (sizeof(resolution_numbers) / (2 * sizeof(int))); ++index)
|
||||
{
|
||||
resolution = cJSON_CreateObject();
|
||||
if (resolution == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToArray(resolutions, resolution);
|
||||
|
||||
width = cJSON_CreateNumber(resolution_numbers[index][0]);
|
||||
if (width == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(resolution, "width", width);
|
||||
|
||||
height = cJSON_CreateNumber(resolution_numbers[index][1]);
|
||||
if (height == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(resolution, "height", height);
|
||||
}
|
||||
|
||||
string = cJSON_Print(monitor);
|
||||
if (string == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to print monitor.\n");
|
||||
}
|
||||
|
||||
end:
|
||||
cJSON_Delete(monitor);
|
||||
return string;
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively we can use the `cJSON_Add...ToObject` helper functions to make our lives a little easier:
|
||||
|
||||
```c
|
||||
//NOTE: Returns a heap allocated string, you are required to free it after use.
|
||||
char *create_monitor_with_helpers(void)
|
||||
{
|
||||
const unsigned int resolution_numbers[3][2] = {
|
||||
{1280, 720},
|
||||
{1920, 1080},
|
||||
{3840, 2160}
|
||||
};
|
||||
char *string = NULL;
|
||||
cJSON *resolutions = NULL;
|
||||
size_t index = 0;
|
||||
|
||||
cJSON *monitor = cJSON_CreateObject();
|
||||
|
||||
if (cJSON_AddStringToObject(monitor, "name", "Awesome 4K") == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
resolutions = cJSON_AddArrayToObject(monitor, "resolutions");
|
||||
if (resolutions == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (index = 0; index < (sizeof(resolution_numbers) / (2 * sizeof(int))); ++index)
|
||||
{
|
||||
cJSON *resolution = cJSON_CreateObject();
|
||||
|
||||
if (cJSON_AddNumberToObject(resolution, "width", resolution_numbers[index][0]) == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (cJSON_AddNumberToObject(resolution, "height", resolution_numbers[index][1]) == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
cJSON_AddItemToArray(resolutions, resolution);
|
||||
}
|
||||
|
||||
string = cJSON_Print(monitor);
|
||||
if (string == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to print monitor.\n");
|
||||
}
|
||||
|
||||
end:
|
||||
cJSON_Delete(monitor);
|
||||
return string;
|
||||
}
|
||||
```
|
||||
|
||||
#### Parsing
|
||||
|
||||
In this example we will parse a JSON in the above format and check if the monitor supports a Full HD resolution while printing some diagnostic output:
|
||||
|
||||
```c
|
||||
/* return 1 if the monitor supports full hd, 0 otherwise */
|
||||
int supports_full_hd(const char * const monitor)
|
||||
{
|
||||
const cJSON *resolution = NULL;
|
||||
const cJSON *resolutions = NULL;
|
||||
const cJSON *name = NULL;
|
||||
int status = 0;
|
||||
cJSON *monitor_json = cJSON_Parse(monitor);
|
||||
if (monitor_json == NULL)
|
||||
{
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL)
|
||||
{
|
||||
fprintf(stderr, "Error before: %s\n", error_ptr);
|
||||
}
|
||||
status = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
name = cJSON_GetObjectItemCaseSensitive(monitor_json, "name");
|
||||
if (cJSON_IsString(name) && (name->valuestring != NULL))
|
||||
{
|
||||
printf("Checking monitor \"%s\"\n", name->valuestring);
|
||||
}
|
||||
|
||||
resolutions = cJSON_GetObjectItemCaseSensitive(monitor_json, "resolutions");
|
||||
cJSON_ArrayForEach(resolution, resolutions)
|
||||
{
|
||||
cJSON *width = cJSON_GetObjectItemCaseSensitive(resolution, "width");
|
||||
cJSON *height = cJSON_GetObjectItemCaseSensitive(resolution, "height");
|
||||
|
||||
if (!cJSON_IsNumber(width) || !cJSON_IsNumber(height))
|
||||
{
|
||||
status = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if ((width->valuedouble == 1920) && (height->valuedouble == 1080))
|
||||
{
|
||||
status = 1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
cJSON_Delete(monitor_json);
|
||||
return status;
|
||||
}
|
||||
```
|
||||
|
||||
Note that there are no NULL checks except for the result of `cJSON_Parse` because `cJSON_GetObjectItemCaseSensitive` checks for `NULL` inputs already, so a `NULL` value is just propagated and `cJSON_IsNumber` and `cJSON_IsString` return `0` if the input is `NULL`.
|
||||
|
||||
### Caveats
|
||||
|
||||
#### Zero Character
|
||||
|
||||
cJSON doesn't support strings that contain the zero character `'\0'` or `\u0000`. This is impossible with the current API because strings are zero terminated.
|
||||
|
||||
#### Character Encoding
|
||||
|
||||
cJSON only supports UTF-8 encoded input. In most cases it doesn't reject invalid UTF-8 as input though, it just propagates it through as is. As long as the input doesn't contain invalid UTF-8, the output will always be valid UTF-8.
|
||||
|
||||
#### C Standard
|
||||
|
||||
cJSON is written in ANSI C (or C89, C90). If your compiler or C library doesn't follow this standard, correct behavior is not guaranteed.
|
||||
|
||||
NOTE: ANSI C is not C++ therefore it shouldn't be compiled with a C++ compiler. You can compile it with a C compiler and link it with your C++ code however. Although compiling with a C++ compiler might work, correct behavior is not guaranteed.
|
||||
|
||||
#### Floating Point Numbers
|
||||
|
||||
cJSON does not officially support any `double` implementations other than IEEE754 double precision floating point numbers. It might still work with other implementations but bugs with these will be considered invalid.
|
||||
|
||||
The maximum length of a floating point literal that cJSON supports is currently 63 characters.
|
||||
|
||||
#### Deep Nesting Of Arrays And Objects
|
||||
|
||||
cJSON doesn't support arrays and objects that are nested too deeply because this would result in a stack overflow. To prevent this cJSON limits the depth to `CJSON_NESTING_LIMIT` which is 1000 by default but can be changed at compile time.
|
||||
|
||||
#### Thread Safety
|
||||
|
||||
In general cJSON is **not thread safe**.
|
||||
|
||||
However it is thread safe under the following conditions:
|
||||
|
||||
* `cJSON_GetErrorPtr` is never used (the `return_parse_end` parameter of `cJSON_ParseWithOpts` can be used instead)
|
||||
* `cJSON_InitHooks` is only ever called before using cJSON in any threads.
|
||||
* `setlocale` is never called before all calls to cJSON functions have returned.
|
||||
|
||||
#### Case Sensitivity
|
||||
|
||||
When cJSON was originally created, it didn't follow the JSON standard and didn't make a distinction between uppercase and lowercase letters. If you want the correct, standard compliant, behavior, you need to use the `CaseSensitive` functions where available.
|
||||
|
||||
#### Duplicate Object Members
|
||||
|
||||
cJSON supports parsing and printing JSON that contains objects that have multiple members with the same name. `cJSON_GetObjectItemCaseSensitive` however will always only return the first one.
|
||||
|
||||
# Enjoy cJSON!
|
||||
|
||||
- Dave Gamble (original author)
|
||||
- Max Bruckner and Alan Wang (current maintainer)
|
||||
- and the other [cJSON contributors](CONTRIBUTORS.md)
|
86
external/cJSON-1.7.17/appveyor.yml
vendored
Normal file
86
external/cJSON-1.7.17/appveyor.yml
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
os: Visual Studio 2015
|
||||
|
||||
# ENABLE_CUSTOM_COMPILER_FLAGS - on by default
|
||||
# ENABLE_SANITIZERS - off by default
|
||||
# ENABLE_PUBLIC_SYMBOLS - on by default
|
||||
# BUILD_SHARED_LIBS - on by default
|
||||
# ENABLE_TARGET_EXPORT - on by default
|
||||
# ENABLE_CJSON_UTILS - off by default
|
||||
# ENABLE_CJSON_TEST -on by default
|
||||
# ENABLE_VALGRIND - off by default
|
||||
# ENABLE_FUZZING - off by default
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- GENERATOR: "Visual Studio 14 2015"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 14 2015"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 12 2013"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 12 2013"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 11 2012"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 11 2012"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 10 2010"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 10 2010"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 9 2008"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 9 2008"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
matrix:
|
||||
exclude:
|
||||
- platform: x64
|
||||
GENERATOR: "Visual Studio 9 2008"
|
||||
|
||||
configuration:
|
||||
- Release
|
||||
|
||||
|
||||
build_script:
|
||||
- ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" }
|
||||
- cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DENABLE_CJSON_TEST=%ENABLE_CJSON_TEST% -H. -Bbuild
|
||||
- cmake --build build --config "%CONFIGURATION%"
|
||||
|
||||
|
||||
on_failure:
|
||||
- ps: if(Test-Path builds/CMakeFiles/CMakeOutput.log) { cat builds/CMakeFiles/CMakeOutput.log }
|
||||
- ps: if(Test-Path builds/CMakeFiles/CMakeError.log) { cat builds/CMakeFiles/CMakeError.log }
|
3129
external/cJSON-1.7.17/cJSON.c
vendored
Normal file
3129
external/cJSON-1.7.17/cJSON.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
300
external/cJSON-1.7.17/cJSON.h
vendored
Normal file
300
external/cJSON-1.7.17/cJSON.h
vendored
Normal file
|
@ -0,0 +1,300 @@
|
|||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||
|
||||
setting default visibility to hidden by adding
|
||||
-fvisibility=hidden (for gcc)
|
||||
or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
#define CJSON_CDECL __cdecl
|
||||
#define CJSON_STDCALL __stdcall
|
||||
|
||||
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_EXPORT_SYMBOLS
|
||||
#endif
|
||||
|
||||
#if defined(CJSON_HIDE_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
||||
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||
#endif
|
||||
#else /* !__WINDOWS__ */
|
||||
#define CJSON_CDECL
|
||||
#define CJSON_STDCALL
|
||||
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||
#else
|
||||
#define CJSON_PUBLIC(type) type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 17
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_Invalid (0)
|
||||
#define cJSON_False (1 << 0)
|
||||
#define cJSON_True (1 << 1)
|
||||
#define cJSON_NULL (1 << 2)
|
||||
#define cJSON_Number (1 << 3)
|
||||
#define cJSON_String (1 << 4)
|
||||
#define cJSON_Array (1 << 5)
|
||||
#define cJSON_Object (1 << 6)
|
||||
#define cJSON_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
#define cJSON_StringIsConst 512
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON
|
||||
{
|
||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *next;
|
||||
struct cJSON *prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
struct cJSON *child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
/* The item's number, if type==cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string;
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks
|
||||
{
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
typedef int cJSON_bool;
|
||||
|
||||
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_NESTING_LIMIT
|
||||
#define CJSON_NESTING_LIMIT 1000
|
||||
#endif
|
||||
|
||||
/* returns the version of cJSON as a string */
|
||||
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||
/* raw json */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||
|
||||
/* Create a string where valuestring references a string so
|
||||
* it will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||
/* Create an object/array that only references it's elements so
|
||||
* they will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||
|
||||
/* These utilities create an Array of count items.
|
||||
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
||||
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
||||
* writing to `item->string` */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||
|
||||
/* Remove/Detach items from Arrays/Objects. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable address area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||
/* helper for the cJSON_SetNumberValue macro */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||
|
||||
/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
|
||||
#define cJSON_SetBoolValue(object, boolValue) ( \
|
||||
(object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
|
||||
(object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
|
||||
cJSON_Invalid\
|
||||
)
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
1481
external/cJSON-1.7.17/cJSON_Utils.c
vendored
Normal file
1481
external/cJSON-1.7.17/cJSON_Utils.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
88
external/cJSON-1.7.17/cJSON_Utils.h
vendored
Normal file
88
external/cJSON-1.7.17/cJSON_Utils.h
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON_Utils__h
|
||||
#define cJSON_Utils__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
/* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *pointer);
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointerCaseSensitive(cJSON * const object, const char *pointer);
|
||||
|
||||
/* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */
|
||||
/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to);
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from, cJSON * const to);
|
||||
/* Utility for generating patch array entries. */
|
||||
CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value);
|
||||
/* Returns 0 for success. */
|
||||
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches);
|
||||
CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, const cJSON * const patches);
|
||||
|
||||
/*
|
||||
// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:
|
||||
//int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches)
|
||||
//{
|
||||
// cJSON *modme = cJSON_Duplicate(*object, 1);
|
||||
// int error = cJSONUtils_ApplyPatches(modme, patches);
|
||||
// if (!error)
|
||||
// {
|
||||
// cJSON_Delete(*object);
|
||||
// *object = modme;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cJSON_Delete(modme);
|
||||
// }
|
||||
//
|
||||
// return error;
|
||||
//}
|
||||
// Code not added to library since this strategy is a LOT slower.
|
||||
*/
|
||||
|
||||
/* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */
|
||||
/* target will be modified by patch. return value is new ptr for target. */
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, const cJSON * const patch);
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON * const patch);
|
||||
/* generates a patch to move from -> to */
|
||||
/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatch(cJSON * const from, cJSON * const to);
|
||||
CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatchCaseSensitive(cJSON * const from, cJSON * const to);
|
||||
|
||||
/* Given a root object and a target object, construct a pointer from one to the other. */
|
||||
CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(const cJSON * const object, const cJSON * const target);
|
||||
|
||||
/* Sorts the members of the object into alphabetical order. */
|
||||
CJSON_PUBLIC(void) cJSONUtils_SortObject(cJSON * const object);
|
||||
CJSON_PUBLIC(void) cJSONUtils_SortObjectCaseSensitive(cJSON * const object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
34
external/cJSON-1.7.17/fuzzing/CMakeLists.txt
vendored
Normal file
34
external/cJSON-1.7.17/fuzzing/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
option(ENABLE_FUZZING "Create executables and targets for fuzzing cJSON with afl." Off)
|
||||
if (ENABLE_FUZZING)
|
||||
find_program(AFL_FUZZ afl-fuzz)
|
||||
if ("${AFL_FUZZ}" MATCHES "AFL_FUZZ-NOTFOUND")
|
||||
message(FATAL_ERROR "Couldn't find afl-fuzz.")
|
||||
endif()
|
||||
|
||||
add_executable(afl-main afl.c)
|
||||
target_link_libraries(afl-main "${CJSON_LIB}")
|
||||
|
||||
if (NOT ENABLE_SANITIZERS)
|
||||
message(FATAL_ERROR "Enable sanitizers with -DENABLE_SANITIZERS=On to do fuzzing.")
|
||||
endif()
|
||||
|
||||
option(ENABLE_FUZZING_PRINT "Fuzz printing functions together with parser." On)
|
||||
set(fuzz_print_parameter "no")
|
||||
if (ENABLE_FUZZING_PRINT)
|
||||
set(fuzz_print_parameter "yes")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
|
||||
|
||||
add_custom_target(afl
|
||||
COMMAND "${AFL_FUZZ}" -i "${CMAKE_CURRENT_SOURCE_DIR}/inputs" -o "${CMAKE_CURRENT_BINARY_DIR}/findings" -x "${CMAKE_CURRENT_SOURCE_DIR}/json.dict" -- "${CMAKE_CURRENT_BINARY_DIR}/afl-main" "@@" "${fuzz_print_parameter}"
|
||||
DEPENDS afl-main)
|
||||
|
||||
|
||||
endif()
|
||||
|
||||
if(ENABLE_CJSON_TEST)
|
||||
ADD_EXECUTABLE(fuzz_main fuzz_main.c cjson_read_fuzzer.c)
|
||||
TARGET_LINK_LIBRARIES(fuzz_main cjson)
|
||||
endif()
|
||||
|
5
external/cJSON-1.7.17/fuzzing/afl-prepare-linux.sh
vendored
Executable file
5
external/cJSON-1.7.17/fuzzing/afl-prepare-linux.sh
vendored
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
echo core | sudo tee /proc/sys/kernel/core_pattern
|
||||
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
176
external/cJSON-1.7.17/fuzzing/afl.c
vendored
Normal file
176
external/cJSON-1.7.17/fuzzing/afl.c
vendored
Normal file
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../cJSON.h"
|
||||
|
||||
static char *read_file(const char *filename)
|
||||
{
|
||||
FILE *file = NULL;
|
||||
long length = 0;
|
||||
char *content = NULL;
|
||||
size_t read_chars = 0;
|
||||
|
||||
/* open in read binary mode */
|
||||
file = fopen(filename, "rb");
|
||||
if (file == NULL)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* get the length */
|
||||
if (fseek(file, 0, SEEK_END) != 0)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
length = ftell(file);
|
||||
if (length < 0)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
if (fseek(file, 0, SEEK_SET) != 0)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* allocate content buffer */
|
||||
content = (char*)malloc((size_t)length + sizeof(""));
|
||||
if (content == NULL)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* read the file into memory */
|
||||
read_chars = fread(content, sizeof(char), (size_t)length, file);
|
||||
if ((long)read_chars != length)
|
||||
{
|
||||
free(content);
|
||||
content = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
content[read_chars] = '\0';
|
||||
|
||||
|
||||
cleanup:
|
||||
if (file != NULL)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char *filename = NULL;
|
||||
cJSON *item = NULL;
|
||||
char *json = NULL;
|
||||
int status = EXIT_FAILURE;
|
||||
char *printed_json = NULL;
|
||||
|
||||
if ((argc < 2) || (argc > 3))
|
||||
{
|
||||
printf("Usage:\n");
|
||||
printf("%s input_file [enable_printing]\n", argv[0]);
|
||||
printf("\t input_file: file containing the test data\n");
|
||||
printf("\t enable_printing: print after parsing, 'yes' or 'no', defaults to 'no'\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
filename = argv[1];
|
||||
|
||||
#if __AFL_HAVE_MANUAL_CONTROL
|
||||
while (__AFL_LOOP(1000))
|
||||
{
|
||||
#endif
|
||||
status = EXIT_SUCCESS;
|
||||
|
||||
json = read_file(filename);
|
||||
if ((json == NULL) || (json[0] == '\0') || (json[1] == '\0'))
|
||||
{
|
||||
status = EXIT_FAILURE;
|
||||
goto cleanup;
|
||||
}
|
||||
item = cJSON_Parse(json + 2);
|
||||
if (item == NULL)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((argc == 3) && (strncmp(argv[2], "yes", 3) == 0))
|
||||
{
|
||||
int do_format = 0;
|
||||
if (json[1] == 'f')
|
||||
{
|
||||
do_format = 1;
|
||||
}
|
||||
|
||||
if (json[0] == 'b')
|
||||
{
|
||||
/* buffered printing */
|
||||
printed_json = cJSON_PrintBuffered(item, 1, do_format);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* unbuffered printing */
|
||||
if (do_format)
|
||||
{
|
||||
printed_json = cJSON_Print(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
printed_json = cJSON_PrintUnformatted(item);
|
||||
}
|
||||
}
|
||||
if (printed_json == NULL)
|
||||
{
|
||||
status = EXIT_FAILURE;
|
||||
goto cleanup;
|
||||
}
|
||||
printf("%s\n", printed_json);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (item != NULL)
|
||||
{
|
||||
cJSON_Delete(item);
|
||||
item = NULL;
|
||||
}
|
||||
if (json != NULL)
|
||||
{
|
||||
free(json);
|
||||
json = NULL;
|
||||
}
|
||||
if (printed_json != NULL)
|
||||
{
|
||||
free(printed_json);
|
||||
printed_json = NULL;
|
||||
}
|
||||
#if __AFL_HAVE_MANUAL_CONTROL
|
||||
}
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
9
external/cJSON-1.7.17/fuzzing/afl.sh
vendored
Executable file
9
external/cJSON-1.7.17/fuzzing/afl.sh
vendored
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
mkdir -p afl-build || exit 1
|
||||
cd afl-build || exit 1
|
||||
#cleanup
|
||||
rm -r -- *
|
||||
|
||||
CC=afl-clang-fast cmake ../.. -DENABLE_FUZZING=On -DENABLE_SANITIZERS=On -DBUILD_SHARED_LIBS=Off
|
||||
make afl
|
77
external/cJSON-1.7.17/fuzzing/cjson_read_fuzzer.c
vendored
Normal file
77
external/cJSON-1.7.17/fuzzing/cjson_read_fuzzer.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cJSON.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); /* required by C89 */
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
cJSON *json;
|
||||
size_t offset = 4;
|
||||
unsigned char *copied;
|
||||
char *printed_json = NULL;
|
||||
int minify, require_termination, formatted, buffered;
|
||||
|
||||
|
||||
if(size <= offset) return 0;
|
||||
if(data[size-1] != '\0') return 0;
|
||||
if(data[0] != '1' && data[0] != '0') return 0;
|
||||
if(data[1] != '1' && data[1] != '0') return 0;
|
||||
if(data[2] != '1' && data[2] != '0') return 0;
|
||||
if(data[3] != '1' && data[3] != '0') return 0;
|
||||
|
||||
minify = data[0] == '1' ? 1 : 0;
|
||||
require_termination = data[1] == '1' ? 1 : 0;
|
||||
formatted = data[2] == '1' ? 1 : 0;
|
||||
buffered = data[3] == '1' ? 1 : 0;
|
||||
|
||||
json = cJSON_ParseWithOpts((const char*)data + offset, NULL, require_termination);
|
||||
|
||||
if(json == NULL) return 0;
|
||||
|
||||
if(buffered)
|
||||
{
|
||||
printed_json = cJSON_PrintBuffered(json, 1, formatted);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* unbuffered printing */
|
||||
if(formatted)
|
||||
{
|
||||
printed_json = cJSON_Print(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
printed_json = cJSON_PrintUnformatted(json);
|
||||
}
|
||||
}
|
||||
|
||||
if(printed_json != NULL) free(printed_json);
|
||||
|
||||
if(minify)
|
||||
{
|
||||
copied = (unsigned char*)malloc(size);
|
||||
if(copied == NULL) return 0;
|
||||
|
||||
memcpy(copied, data, size);
|
||||
|
||||
cJSON_Minify((char*)copied + offset);
|
||||
|
||||
free(copied);
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
54
external/cJSON-1.7.17/fuzzing/fuzz_main.c
vendored
Normal file
54
external/cJSON-1.7.17/fuzzing/fuzz_main.c
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); /* required by C89 */
|
||||
|
||||
/* fuzz target entry point, works without libFuzzer */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
char *buf = NULL;
|
||||
long siz_buf;
|
||||
|
||||
if(argc < 2)
|
||||
{
|
||||
fprintf(stderr, "no input file\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
f = fopen(argv[1], "rb");
|
||||
if(f == NULL)
|
||||
{
|
||||
fprintf(stderr, "error opening input file %s\n", argv[1]);
|
||||
goto err;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
siz_buf = ftell(f);
|
||||
rewind(f);
|
||||
|
||||
if(siz_buf < 1) goto err;
|
||||
|
||||
buf = (char*)malloc((size_t)siz_buf);
|
||||
if(buf == NULL)
|
||||
{
|
||||
fprintf(stderr, "malloc() failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if(fread(buf, (size_t)siz_buf, 1, f) != 1)
|
||||
{
|
||||
fprintf(stderr, "fread() failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
(void)LLVMFuzzerTestOneInput((uint8_t*)buf, (size_t)siz_buf);
|
||||
|
||||
err:
|
||||
free(buf);
|
||||
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user