Skip to content

Commit

Permalink
Migrate device provisioning service
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Sep 2, 2024
1 parent 360d6a3 commit 6e436bc
Show file tree
Hide file tree
Showing 49 changed files with 9,769 additions and 84 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ jobs:
- args: "-DOC_IPV4_ENABLED=ON -DOC_TCP_ENABLED=ON"
# ipv4 on, tcp on, pki off
- args: "-DOC_IPV4_ENABLED=ON -DOC_TCP_ENABLED=ON -DOC_PKI_ENABLED=OFF"
# cloud on (ipv4+tcp on), dynamic allocation off
- args: "-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF"
# cloud on (ipv4+tcp on), collections create on
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON"
# cloud on (ipv4+tcp on), dynamic allocation off, push notifications off
- args: "-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_PUSH_ENABLED=OFF"
# cloud on (ipv4+tcp on), collections create on, oscore off, device provisioning on
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON"
# cloud on (ipv4+tcp on), collections create on, custom message buffer size, custom message buffer pool size, custom app data buffer size, custom app data buffer pool size
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_INOUT_BUFFER_SIZE=2048 -DOC_INOUT_BUFFER_POOL=4 -DOC_APP_DATA_BUFFER_SIZE=2048 -DOC_APP_DATA_BUFFER_POOL=4"
# debug on
- args: "-DOC_DEBUG_ENABLED=ON"
# debug on, cloud on (ipv4+tcp on)
- args: "-DOC_CLOUD_ENABLED=ON -DOC_DEBUG_ENABLED=ON"
- args: "-DOC_CLOUD_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=OFF -DOC_DEBUG_ENABLED=ON"
# secure off, tcp on
- args: "-DOC_SECURITY_ENABLED=OFF -DOC_TCP_ENABLED=ON"
# secure off, ipv4 on, tcp on
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ on:

jobs:
clang-tidy-linux:
strategy:
fail-fast: false
matrix:
include:
- build_args:
- build_args: -DOC_OSCORE_ENABLED=OFF -DPLGD_DEV_TIME_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON
- build_args: -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_PUSH_ENABLED=OFF -DOC_JSON_ENCODER_ENABLED=OFF -DOC_DEBUG_ENABLED=ON

runs-on: ubuntu-22.04

steps:
Expand All @@ -40,5 +48,5 @@ jobs:
- name: Build with clang and analyze with clang-tidy
run: |
mkdir build && cd build
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DOC_CLANG_TIDY_ENABLED=ON -DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_DISCOVERY_RESOURCE_OBSERVABLE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=ON -DOC_ETAG_ENABLED=ON -DBUILD_TESTING=OFF ..
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DOC_CLANG_TIDY_ENABLED=ON -DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_DISCOVERY_RESOURCE_OBSERVABLE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON -DOC_ETAG_ENABLED=ON -DOC_JSON_ENCODER_ENABLED=ON ${{ matrix.build_args }} -DBUILD_TESTING=OFF ..
cmake --build .
107 changes: 33 additions & 74 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ set(OC_SIMPLE_MAIN_LOOP_ENABLED OFF CACHE BOOL "Compile with the single-threaded
if (BUILD_EXAMPLE_APPLICATIONS OR BUILD_TESTING)
set(OC_SIMPLE_MAIN_LOOP_ENABLED ON CACHE BOOL "" FORCE)
endif()
set(PLGD_DEV_TIME_ENABLED OFF CACHE BOOL "Enable plgd time feature.")

if (OC_DEBUG_ENABLED)
set(OC_LOG_MAXIMUM_LOG_LEVEL "TRACE" CACHE STRING "Maximum supported log level in compile time.")
else()
Expand All @@ -79,6 +77,10 @@ set(OC_APP_DATA_BUFFER_SIZE "" CACHE STRING "Custom static buffer size for appli
set(OC_APP_DATA_BUFFER_POOL "" CACHE STRING "Custom static size of application messages.")
set(OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS "" CACHE STRING "Maximum number of messages in the network event queue for a device.")

# plgd.dev features
set(PLGD_DEV_TIME_ENABLED OFF CACHE BOOL "Enable plgd time feature.")
set(PLGD_DEV_DEVICE_PROVISIONING_ENABLED OFF CACHE BOOL "Enable plgd's device provisioning feature.")

set(OC_ASAN_ENABLED OFF CACHE BOOL "Enable address sanitizer build.")
set(OC_LSAN_ENABLED OFF CACHE BOOL "Enable leak sanitizer build.")
set(OC_TSAN_ENABLED OFF CACHE BOOL "Enable thread sanitizer build.")
Expand Down Expand Up @@ -169,52 +171,7 @@ endif()
set(OC_CLANG_TIDY_ENABLED OFF CACHE BOOL "Enable clang-tidy analysis during compilation.")

include(tools/clang-tidy.cmake)

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
# function oc_add_compile_options([GLOBAL] [IX_CXX] FLAGS [flags...])
#
# Arguments:
# GLOBAL (option) flags are added as global compilation options
# FLAGS list of flags to check and add for both C and C++
# CFLAGS list of flags to check and add for C
# CXXFLAGS list of flags to check and add for C++
#
# Side-effect: C_COMPILER_SUPPORTS_${flag_name} / CXX_COMPILER_SUPPORTS_${flag_name}
# is created and set to ON/OFF based on the result of the check. This variable
# can be used in the context of the caller.
function(oc_add_compile_options)
set(options GLOBAL)
set(oneValueArgs)
set(multiValueArgs CFLAGS CXXFLAGS FLAGS)
cmake_parse_arguments(OC_ADD_COMPILE_OPTIONS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

foreach(flag IN LISTS OC_ADD_COMPILE_OPTIONS_FLAGS OC_ADD_COMPILE_OPTIONS_CFLAGS)
string(REPLACE "-" "_" flag_name ${flag})
string(REPLACE "=" "_" flag_name ${flag_name})
string(TOUPPER ${flag_name} flag_name)
set(flag_name "C_COMPILER_SUPPORTS${flag_name}")
unset(${flag_name})
check_c_compiler_flag(${flag} ${flag_name})
if((OC_ADD_COMPILE_OPTIONS_GLOBAL) AND (${${flag_name}}))
add_compile_options($<$<COMPILE_LANGUAGE:C>:${flag}>)
endif()
set(${flag_name} ${${flag_name}} PARENT_SCOPE)
endforeach()

foreach(flag IN LISTS OC_ADD_COMPILE_OPTIONS_FLAGS OC_ADD_COMPILE_OPTIONS_CXXFLAGS)
string(REPLACE "-" "_" flag_name ${flag})
string(REPLACE "=" "_" flag_name ${flag_name})
string(TOUPPER ${flag_name} flag_name)
set(flag_name "CXX_COMPILER_SUPPORTS${flag_name}")
unset(${flag_name})
check_cxx_compiler_flag(${flag} ${flag_name})
if((OC_ADD_COMPILE_OPTIONS_GLOBAL) AND (${${flag_name}}))
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${flag}>)
endif()
set(${flag_name} ${${flag_name}} PARENT_SCOPE)
endforeach()
endfunction()
include(tools/utils.cmake)

# Global compile options
set(PRIVATE_COMPILE_OPTIONS "")
Expand Down Expand Up @@ -278,24 +235,7 @@ if(BUILD_MBEDTLS)
endif()

set(OC_LOG_MAXIMUM_LOG_LEVEL_INT)
if(OC_LOG_MAXIMUM_LOG_LEVEL STREQUAL "DISABLED")
set(OC_LOG_MAXIMUM_LOG_LEVEL_INT -1)
elseif(OC_LOG_MAXIMUM_LOG_LEVEL STREQUAL "ERROR")
set(OC_LOG_MAXIMUM_LOG_LEVEL_INT 3)
elseif(OC_LOG_MAXIMUM_LOG_LEVEL STREQUAL "WARNING")
set(OC_LOG_MAXIMUM_LOG_LEVEL_INT 4)
elseif(OC_LOG_MAXIMUM_LOG_LEVEL STREQUAL "NOTICE")
set(OC_LOG_MAXIMUM_LOG_LEVEL_INT 5)
elseif(OC_LOG_MAXIMUM_LOG_LEVEL STREQUAL "INFO")
set(OC_LOG_MAXIMUM_LOG_LEVEL_INT 6)
elseif(OC_LOG_MAXIMUM_LOG_LEVEL STREQUAL "DEBUG")
set(OC_LOG_MAXIMUM_LOG_LEVEL_INT 7)
elseif(OC_LOG_MAXIMUM_LOG_LEVEL STREQUAL "TRACE")
set(OC_LOG_MAXIMUM_LOG_LEVEL_INT 8)
else()
message(FATAL_ERROR "Invalid OC_LOG_MAXIMUM_LOG_LEVEL: ${OC_LOG_MAXIMUM_LOG_LEVEL}")
endif()

oc_set_maximum_log_level(${OC_LOG_MAXIMUM_LOG_LEVEL} OC_LOG_MAXIMUM_LOG_LEVEL_INT)
set(OC_LOG_MAXIMUM_LEVEL ${OC_LOG_MAXIMUM_LOG_LEVEL_INT} CACHE INTERNAL "Maximum supported log level in compile time as integer.")

# clang-tidy triggers bugprone-macro-parentheses if the value is not in ()
Expand Down Expand Up @@ -417,13 +357,6 @@ if(OC_SIMPLE_MAIN_LOOP_ENABLED)
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_SIMPLE_MAIN_LOOP")
endif()

if(PLGD_DEV_TIME_ENABLED)
list(APPEND PUBLIC_COMPILE_DEFINITIONS "PLGD_DEV_TIME")
if(BUILD_MBEDTLS)
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "PLGD_DEV_TIME")
endif()
endif()

if(NOT("${OC_INOUT_BUFFER_SIZE}" STREQUAL ""))
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED)
message(FATAL_ERROR "Cannot OC_INOUT_BUFFER_SIZE without dynamic allocation")
Expand Down Expand Up @@ -471,6 +404,28 @@ if(NOT("${OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS}" STREQUAL ""))
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS=(${OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS})")
endif()

if(PLGD_DEV_TIME_ENABLED)
list(APPEND PUBLIC_COMPILE_DEFINITIONS "PLGD_DEV_TIME")
if(BUILD_MBEDTLS)
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "PLGD_DEV_TIME")
endif()
endif()

if(PLGD_DEV_DEVICE_PROVISIONING_ENABLED)
if(OC_OSCORE_ENABLED)
message(WARNING "Cannot set PLGD_DEV_DEVICE_PROVISIONING_ENABLED with OC_OSCORE_ENABLED")
endif()
if(NOT OC_CLOUD_ENABLED)
message(FATAL_ERROR "Cannot set PLGD_DEV_DEVICE_PROVISIONING_ENABLED without OC_CLOUD_ENABLED")
endif()
if(NOT OC_SECURITY_ENABLED)
message(FATAL_ERROR "Cannot set PLGD_DEV_DEVICE_PROVISIONING_ENABLED without OC_SECURITY_ENABLED")
endif()
if(NOT PLGD_DEV_TIME_ENABLED)
message(FATAL_ERROR "Cannot set PLGD_DEV_DEVICE_PROVISIONING_ENABLED without PLGD_DEV_TIME_ENABLED")
endif()
endif()

if(BUILD_TESTING)
list(APPEND PRIVATE_COMPILE_DEFINITIONS "OC_TEST")
if(BUILD_MBEDTLS)
Expand Down Expand Up @@ -712,7 +667,11 @@ if(OC_SECURITY_ENABLED)
target_link_libraries(server-obj PRIVATE ${MBEDTLS_DEP})
endif()

add_library(client-server-obj OBJECT ${COMMON_SRC} ${CLIENT_SRC})
if(PLGD_DEV_DEVICE_PROVISIONING_ENABLED)
include(api/plgd/plgd.cmake)
endif()

add_library(client-server-obj OBJECT ${COMMON_SRC} ${CLIENT_SRC} ${PLGD_DPS_SRC})
target_compile_definitions(client-server-obj PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} PUBLIC ${PUBLIC_COMPILE_DEFINITIONS} "OC_CLIENT" "OC_SERVER")
target_compile_options(client-server-obj PRIVATE ${PRIVATE_COMPILE_OPTIONS})
target_include_directories(client-server-obj PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/port ${PORT_INCLUDE_DIR})
Expand Down
Loading

0 comments on commit 6e436bc

Please sign in to comment.