├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── ReadMe_OSS.htm ├── ReadMe_OSS.html ├── SonySpresenseGuide.md ├── build_helper_cross_compile_for_rpi.sh ├── build_helper_linux.sh ├── build_helper_win64.bat ├── mcl_connectivity ├── .mbedignore ├── CMakeLists.txt ├── doc │ ├── CMakeLists.txt │ └── mcl_connectivity.doxyfile ├── examples │ ├── callbacks.c │ ├── callbacks.h │ ├── create_mapping.c │ ├── dsc_upload.c │ ├── event_upload.c │ ├── file_upload.c │ ├── store_upload.c │ └── timeseries_upload.c ├── include │ └── mcl_connectivity │ │ ├── mcl_connectivity.h │ │ ├── mcl_connectivity_common.h │ │ ├── mcl_connectivity_configuration.h │ │ ├── mcl_custom_data.h │ │ ├── mcl_data_point.h │ │ ├── mcl_data_source.h │ │ ├── mcl_data_source_configuration.h │ │ ├── mcl_event.h │ │ ├── mcl_file.h │ │ ├── mcl_mapping.h │ │ ├── mcl_store.h │ │ ├── mcl_timeseries.h │ │ ├── mcl_timeseries_value.h │ │ └── mcl_timeseries_value_list.h ├── src │ ├── CMakeLists.txt │ ├── connectivity.c │ ├── connectivity.h │ ├── connectivity_common.c │ ├── connectivity_common.h │ ├── connectivity_configuration.c │ ├── connectivity_configuration.h │ ├── connectivity_processor.c │ ├── connectivity_processor.h │ ├── custom_data.c │ ├── custom_data.h │ ├── data_point.c │ ├── data_point.h │ ├── data_source.c │ ├── data_source.h │ ├── data_source_configuration.c │ ├── data_source_configuration.h │ ├── event.c │ ├── event.h │ ├── file.c │ ├── file.h │ ├── item.h │ ├── json.c │ ├── json.h │ ├── mapping.c │ ├── mapping.h │ ├── multipart.c │ ├── multipart.h │ ├── store.c │ ├── store.h │ ├── timeseries.c │ ├── timeseries.h │ ├── timeseries_value.c │ ├── timeseries_value.h │ ├── timeseries_value_list.c │ └── timeseries_value_list.h └── test │ ├── CMakeLists.txt │ ├── integration │ ├── CMakeLists.txt │ ├── test_create_mapping.c │ ├── test_exchange.c │ └── test_get_data_source_configuration.c │ └── unit │ ├── CMakeLists.txt │ ├── cmock.yml.in │ ├── test_connectivity_configuration.c │ ├── test_custom_data.c │ ├── test_data_point.c │ ├── test_data_source.c │ ├── test_data_source_configuration.c │ ├── test_event.c │ ├── test_file.c │ ├── test_json.c │ ├── test_mapping.c │ ├── test_multipart.c │ ├── test_processor.c │ ├── test_store.c │ ├── test_timeseries.c │ ├── test_timeseries_value.c │ └── test_timeseries_value_list.c ├── mcl_core ├── .mbedignore ├── CMakeLists.txt ├── doc │ ├── CMakeLists.txt │ └── mcl_core.doxyfile ├── examples │ ├── callbacks.c │ ├── callbacks.h │ └── onboard.c ├── include │ └── mcl_core │ │ ├── mcl_assert.h │ │ ├── mcl_config.h │ │ ├── mcl_config_setup.h │ │ ├── mcl_core.h │ │ ├── mcl_core_common.h │ │ ├── mcl_core_configuration.h │ │ ├── mcl_file_util.h │ │ ├── mcl_http_client.h │ │ ├── mcl_http_request.h │ │ ├── mcl_http_response.h │ │ ├── mcl_json_util.h │ │ ├── mcl_list.h │ │ ├── mcl_log_util.h │ │ ├── mcl_memory.h │ │ ├── mcl_random.h │ │ ├── mcl_string_util.h │ │ ├── mcl_time_util.h │ │ └── mcl_version.h ├── lib │ └── cJSON │ │ ├── CMakeLists.txt │ │ ├── cJSON.c │ │ └── cJSON.h ├── src │ ├── CMakeLists.txt │ ├── base64.c │ ├── base64.h │ ├── core.c │ ├── core.h │ ├── core_common.c │ ├── core_common.h │ ├── core_configuration.c │ ├── core_configuration.h │ ├── core_processor.c │ ├── core_processor.h │ ├── crypto │ │ ├── mbedtls │ │ │ ├── CMakeLists.txt │ │ │ └── security_mbedtls.c │ │ └── openssl │ │ │ ├── CMakeLists.txt │ │ │ ├── security_libcrypto.c │ │ │ └── security_libcrypto.h │ ├── definitions.h │ ├── file_util │ │ └── standard │ │ │ ├── CMakeLists.txt │ │ │ ├── file_util.c │ │ │ └── file_util.h │ ├── hmac.c │ ├── hmac.h │ ├── http_client │ │ ├── basic │ │ │ ├── CMakeLists.txt │ │ │ ├── http_client_basic.c │ │ │ ├── http_client_basic.h │ │ │ ├── mbed_os │ │ │ │ └── tls_socket_mbed.cpp │ │ │ ├── mbedtls │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── tls_socket_mbedtls.c │ │ │ └── mcl_tls_socket.h │ │ └── curl │ │ │ ├── CMakeLists.txt │ │ │ ├── http_client_libcurl.c │ │ │ └── http_client_libcurl.h │ ├── http_definitions.c │ ├── http_definitions.h │ ├── http_request.c │ ├── http_request.h │ ├── http_response.c │ ├── http_response.h │ ├── json_util.c │ ├── json_util.h │ ├── jwt.c │ ├── jwt.h │ ├── list.c │ ├── list.h │ ├── log_util.c │ ├── log_util.h │ ├── memory │ │ └── standard │ │ │ ├── CMakeLists.txt │ │ │ ├── memory.c │ │ │ └── memory.h │ ├── random.c │ ├── random.h │ ├── security.h │ ├── security_handler.c │ ├── security_handler.h │ ├── string_util.c │ ├── string_util.h │ ├── time_util.c │ └── time_util.h └── test │ ├── CMakeLists.txt │ ├── integration │ ├── CMakeLists.txt │ ├── test_mcl_http_client.c │ ├── test_onboard_rsa.c │ ├── test_onboard_shared_secret.c │ ├── test_rotate_key_rsa.c │ └── test_rotate_key_shared_secret.c │ ├── lib │ └── CMock │ │ ├── CMakeLists.txt │ │ ├── Gemfile │ │ ├── Rakefile │ │ ├── config │ │ ├── production_environment.rb │ │ └── test_environment.rb │ │ ├── lib │ │ ├── cmock.rb │ │ ├── cmock_config.rb │ │ ├── cmock_file_writer.rb │ │ ├── cmock_generator.rb │ │ ├── cmock_generator_plugin_array.rb │ │ ├── cmock_generator_plugin_callback.rb │ │ ├── cmock_generator_plugin_cexception.rb │ │ ├── cmock_generator_plugin_expect.rb │ │ ├── cmock_generator_plugin_expect_any_args.rb │ │ ├── cmock_generator_plugin_ignore.rb │ │ ├── cmock_generator_plugin_ignore_arg.rb │ │ ├── cmock_generator_plugin_return_thru_ptr.rb │ │ ├── cmock_generator_utils.rb │ │ ├── cmock_header_parser.rb │ │ ├── cmock_plugin_manager.rb │ │ └── cmock_unityhelper_parser.rb │ │ ├── rakefile_helper.rb │ │ ├── scripts │ │ ├── create_makefile.rb │ │ ├── create_mock.rb │ │ ├── create_runner.rb │ │ └── test_summary.rb │ │ ├── src │ │ ├── cmock.c │ │ ├── cmock.h │ │ └── cmock_internals.h │ │ └── vendor │ │ └── unity │ │ ├── auto │ │ ├── colour_prompt.rb │ │ ├── colour_reporter.rb │ │ ├── generate_config.yml │ │ ├── generate_module.rb │ │ ├── generate_test_runner.rb │ │ ├── parseOutput.rb │ │ ├── stylize_as_junit.rb │ │ ├── test_file_filter.rb │ │ ├── type_sanitizer.rb │ │ ├── unity_test_summary.py │ │ └── unity_test_summary.rb │ │ └── src │ │ ├── unity.c │ │ ├── unity.h │ │ └── unity_internals.h │ └── unit │ ├── CMakeLists.txt │ ├── cmock.yml.in │ ├── test_base64.c │ ├── test_core.c │ ├── test_core_configuration.c │ ├── test_core_processor.c │ ├── test_crypto_openssl.c │ ├── test_file_util_standard.c │ ├── test_hmac.c │ ├── test_http_client_curl.c │ ├── test_http_request.c │ ├── test_http_response.c │ ├── test_json_util.c │ ├── test_jwt.c │ ├── test_jwt.c.orig │ ├── test_list.c │ ├── test_log_util.c │ ├── test_mcl_string_util.c │ ├── test_memory_standard.c │ ├── test_random.c │ ├── test_security_handler.c │ └── test_time_util.c ├── mcl_data_lake ├── .mbedignore ├── CMakeLists.txt ├── doc │ ├── CMakeLists.txt │ └── mcl_data_lake.doxyfile ├── examples │ ├── callbacks.c │ ├── callbacks.h │ └── data_lake_upload.c ├── include │ └── mcl_data_lake │ │ ├── mcl_data_lake.h │ │ ├── mcl_data_lake_common.h │ │ ├── mcl_data_lake_configuration.h │ │ └── mcl_data_lake_object.h ├── src │ ├── CMakeLists.txt │ ├── data_lake.c │ ├── data_lake.h │ ├── data_lake_common.c │ ├── data_lake_common.h │ ├── data_lake_configuration.c │ ├── data_lake_configuration.h │ ├── data_lake_json.c │ ├── data_lake_json.h │ ├── data_lake_object.c │ ├── data_lake_object.h │ ├── data_lake_processor.c │ └── data_lake_processor.h └── test │ ├── CMakeLists.txt │ ├── integration │ ├── CMakeLists.txt │ └── test_mcl_data_lake.c │ └── unit │ ├── CMakeLists.txt │ ├── cmock.yml.in │ ├── test_data_lake.c │ ├── test_data_lake_configuration.c │ ├── test_data_lake_json.c │ ├── test_data_lake_object.c │ └── test_data_lake_processor.c └── mcl_deployment ├── CMakeLists.txt ├── doc ├── CMakeLists.txt └── mcl_deployment.doxyfile ├── examples ├── callbacks.c ├── callbacks.h └── manage_deployment.c ├── include └── mcl_deployment │ ├── mcl_deployment.h │ ├── mcl_deployment_common.h │ ├── mcl_deployment_configuration.h │ ├── mcl_deployment_workflow.h │ ├── mcl_deployment_workflow_filter.h │ ├── mcl_deployment_workflow_model.h │ ├── mcl_deployment_workflow_model_state.h │ ├── mcl_deployment_workflow_model_state_group.h │ ├── mcl_deployment_workflow_model_transition.h │ └── mcl_deployment_workflow_state.h ├── src ├── CMakeLists.txt ├── deployment.c ├── deployment.h ├── deployment_common.c ├── deployment_common.h ├── deployment_configuration.c ├── deployment_configuration.h ├── deployment_json.c ├── deployment_json.h ├── deployment_processor.c ├── deployment_processor.h ├── deployment_workflow.c ├── deployment_workflow.h ├── deployment_workflow_filter.c ├── deployment_workflow_filter.h ├── deployment_workflow_model.c ├── deployment_workflow_model.h ├── deployment_workflow_model_state.c ├── deployment_workflow_model_state.h ├── deployment_workflow_model_state_group.c ├── deployment_workflow_model_state_group.h ├── deployment_workflow_model_transition.c ├── deployment_workflow_model_transition.h ├── deployment_workflow_state.c └── deployment_workflow_state.h └── test ├── CMakeLists.txt ├── integration ├── CMakeLists.txt └── test_deployment_component.c └── unit ├── CMakeLists.txt ├── cmock.yml.in ├── test_deployment.c ├── test_deployment_configuration.c ├── test_deployment_workflow.c ├── test_deployment_workflow_filter.c ├── test_deployment_workflow_model.c ├── test_deployment_workflow_model_state.c ├── test_deployment_workflow_model_state_group.c ├── test_deployment_workflow_model_transition.c └── test_deployment_workflow_state.c /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [4.4.0] (2024-09-01) 2 | 3 | ## Update dependencies and certificates 4 | 5 | * cJSON library version is upgraded to 1.7.18. 6 | * Minimum required OpenSSL version is updated to 3.0.13 for users using OpenSSL as security library. 7 | * Minimum required libCurl version is updated to 8.6.0 for users using libCurl as http client. 8 | * QuoVadis Root CA 2 G3" certificate will be retired on 2024-10-15T04:00:00.000Z hence code examples are updated to use existing certificate as well as new certificate i.e. "DigiCert Global Root G2". 9 | 10 | # [4.3.4] (2023-04-03) 11 | ## Certificate updates 12 | * Insights Hub certificate update information publication 13 | 14 | # [4.3.3] (2023-04-03) 15 | ## Documentation 16 | * Documentation Changes. 17 | 18 | # [4.3.2] (2022-03-19) 19 | 20 | ## Security 21 | 22 | * cJSON library version is upgraded to 1.7.15 since the old version had security vulnerabilities. 23 | * Minimum required OpenSSL version is updated to 1.1.1m for users using OpenSSL as security library and CMake as the build tool. 24 | * Minimum required libCurl version is updated to 7.81.0 for users using libCurl as http client and CMake as the build tool. 25 | 26 | # [4.3.1] (2021-05-15) 27 | 28 | ## Bug Fixes 29 | 30 | * Cmake build related issues reported from github repository are fixed. 31 | 32 | # [4.3.0] (2021-03-27) 33 | 34 | ## Features 35 | 36 | * MCL Deployment component is introduced for agents to access Deployment Workflow API's. 37 | 38 | # [4.2.4] (2020-11-28) 39 | 40 | ## Features 41 | 42 | * MCL is ported to be used by mbedOS applications. 43 | 44 | # [4.2.3] (2020-10-10) 45 | 46 | ## Bug Fixes 47 | 48 | * Missing http header is added to requests to data lake on Azure. 49 | 50 | # [4.2.2] (2020-09-05) 51 | 52 | ## Features 53 | 54 | * Updated Sony Spresense port for Spresense SDK 2.0. 55 | 56 | # [4.2.1] (2020-06-13) 57 | 58 | ## Features 59 | 60 | * Basic http client using tcp sockets and mbedtls for tls is introduced as an alternative to curl-openssl pair. 61 | * MCL is ported to Sony Spresense board using basic http client and mbedtls. 62 | 63 | # [4.2.0] (2020-04-16) 64 | 65 | ## Features 66 | 67 | * Data Point Mapping support is added to MCL Connectivity component. 68 | 69 | # [4.1.1] (2020-03-19) 70 | 71 | ## Bug Fixes 72 | 73 | * Type mismatch checks added to json utility get functions. 74 | 75 | # [4.1.0] (2020-02-03) 76 | 77 | ## Features 78 | 79 | * MCL Data Lake component is released for agents to upload unstructured data. 80 | 81 | ## Bug Fixes 82 | 83 | * Missing C linkage specifications in some headers are added. 84 | 85 | # [4.0.1] (2019-12-06) 86 | 87 | ## Security 88 | 89 | * Minimum required OpenSSL version is updated from 1.1.1c to 1.1.1d for users using OpenSSL. 90 | 91 | ## Features 92 | 93 | * mcl_http_client_add_certificate function is added. 94 | 95 | ## Refactor 96 | 97 | * max_http_payload_size parameter of mcl_core_configuration_t structure is removed. Setting it with mcl_core_configuration_set_parameter function will have no effect. 98 | * mcl_core_is_initialized function is removed, hence MCL_NOT_INITIALIZED error code is removed. 99 | * mcl_http_client_configuration_t structure is refactored. 100 | 101 | # [4.0.0] (2019-09-13) 102 | 103 | ## Features 104 | 105 | * First release. 106 | -------------------------------------------------------------------------------- /build_helper_cross_compile_for_rpi.sh: -------------------------------------------------------------------------------- 1 | # This is deprecated. Use build_helper_linux.sh and modify accordingly. 2 | 3 | #!/bin/bash 4 | openssl_version=3.0.13 5 | curl_version=8.6.0 6 | main_directory=../mcl_sandbox_for_rpi 7 | mcl_directory=$(pwd) 8 | 9 | mkdir $main_directory 10 | cd $main_directory 11 | 12 | #Change relative path to absolute. 13 | main_directory=$(pwd) 14 | 15 | git clone --depth 1 https://github.com/raspberrypi/tools.git raspberrypi_tools 16 | rpi_tool_path=$main_directory/raspberrypi_tools/arm-bcm2708/arm-linux-gnueabihf 17 | 18 | wget -c https://www.openssl.org/source/openssl-$openssl_version.tar.gz 19 | tar -xvzf openssl-$openssl_version.tar.gz 20 | 21 | wget https://curl.se/download/curl-$curl_version.tar.gz 22 | tar -xvzf curl-$curl_version.tar.gz 23 | 24 | cd openssl-$openssl_version 25 | ./Configure --cross-compile-prefix=$rpi_tool_path/bin/arm-linux-gnueabihf- --prefix=$main_directory/install -Wl,-rpath=$main_directory/install/lib linux-generic32 shared -fPIC && make install_sw 26 | cd .. 27 | 28 | cd curl-$curl_version 29 | export PATH=$PATH:$rpi_tool_path/bin 30 | export CPPFLAGS="-I$rpi_tool_path/include" 31 | export AR=arm-linux-gnueabihf-ar 32 | export AS=arm-linux-gnueabihf-as 33 | export LD=arm-linux-gnueabihf-ld 34 | export RANLIB=arm-linux-gnueabihf-ranlib 35 | export CC=arm-linux-gnueabihf-cc 36 | export NM=arm-linux-gnueabihf-nm 37 | 38 | LDFLAGS="-Wl,-R$main_directory/install/lib" ./configure --enable-http --with-ssl=$main_directory/install --prefix=$main_directory/install --without-libssh2 --disable-ftp --disable-tftp --disable-file --disable-ldap --disable-rtsp --disable-dict --disable-telnet --disable-pop3 --disable-imap --disable-smb --disable-scp --disable-sftp --disable-smtp --disable-gopher --disable-manual --host arm-linux-gnueabihf && make install 39 | cd .. 40 | 41 | echo "SET(CMAKE_SYSTEM_NAME Linux)" > toolchain_rpi.cmake 42 | echo "SET(CMAKE_C_COMPILER $rpi_tool_path/bin/arm-linux-gnueabihf-gcc)" >> toolchain_rpi.cmake 43 | echo "SET(CMAKE_CXX_COMPILER $rpi_tool_path/bin/arm-linux-gnueabihf-g++)" >> toolchain_rpi.cmake 44 | echo "SET(CMAKE_FIND_ROOT_PATH $rpi_tool_path/arm-linux-gnueabihf/sysroot/)" >> toolchain_rpi.cmake 45 | echo "SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> toolchain_rpi.cmake 46 | echo "SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)" >> toolchain_rpi.cmake 47 | echo "SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)" >> toolchain_rpi.cmake 48 | 49 | mkdir mcl_build 50 | cd mcl_build 51 | cmake -DCMAKE_PREFIX_PATH="$main_directory/install" -DCMAKE_TOOLCHAIN_FILE="$main_directory/toolchain_rpi.cmake" -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX:PATH=$main_directory/install -DMCL_STATICLIB=OFF -DMCL_LOG_LEVEL=MCL_LOG_LEVEL_NONE $mcl_directory 52 | cmake --build . --clean-first --target install 53 | -------------------------------------------------------------------------------- /build_helper_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | openssl_version=3.0.13 3 | curl_version=8.6.0 4 | main_directory=../mcl_sandbox 5 | mcl_directory=$(pwd) 6 | 7 | mkdir $main_directory 8 | cd $main_directory 9 | 10 | #Change relative path to absolute. 11 | main_directory=$(pwd) 12 | 13 | wget -c https://www.openssl.org/source/openssl-$openssl_version.tar.gz 14 | tar -xvzf openssl-$openssl_version.tar.gz 15 | 16 | wget https://curl.se/download/curl-$curl_version.tar.gz 17 | tar -xvzf curl-$curl_version.tar.gz 18 | 19 | cd openssl-$openssl_version 20 | ./config --prefix=$main_directory/install -Wl,-rpath=$main_directory/install/lib shared -fPIC --libdir=lib && make install_sw 21 | cd .. 22 | 23 | cd curl-$curl_version 24 | LDFLAGS="-Wl,-R$main_directory/install/lib" ./configure --enable-http --with-ssl=$main_directory/install --prefix=$main_directory/install --without-libssh2 --without-libpsl --disable-ftp --disable-tftp --disable-file --disable-ldap --disable-rtsp --disable-dict --disable-telnet --disable-pop3 --disable-imap --disable-smb --disable-scp --disable-sftp --disable-smtp --disable-gopher --disable-manual && make install 25 | cd .. 26 | 27 | mkdir mcl_build 28 | cd mcl_build 29 | cmake -DCMAKE_PREFIX_PATH="$main_directory/install" -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX:PATH=$main_directory/install -DMCL_STATICLIB=OFF -DMCL_LOG_LEVEL=MCL_LOG_LEVEL_NONE $mcl_directory 30 | cmake --build . --clean-first --target install 31 | -------------------------------------------------------------------------------- /build_helper_win64.bat: -------------------------------------------------------------------------------- 1 | set openssl_version=3.0.13 2 | set curl_version=8.6.0 3 | set path_to_7zip="C:\Program Files\7-Zip" 4 | set path_to_visual_studio="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" 5 | set main_directory=..\mcl_sandbox 6 | set mcl_directory=%cd% 7 | 8 | mkdir %main_directory% 9 | cd %main_directory% 10 | 11 | rem Change relative path to absolute. 12 | set main_directory="%cd%" 13 | 14 | powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; wget https://www.openssl.org/source/openssl-%openssl_version%.tar.gz -OutFile openssl-%openssl_version%.tar.gz}" 15 | %path_to_7zip%\7z e openssl-%openssl_version%.tar.gz 16 | %path_to_7zip%\7z x openssl-%openssl_version%.tar 17 | 18 | powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; wget https://curl.se/download/curl-%curl_version%.tar.gz -OutFile curl-%curl_version%.tar.gz}" 19 | %path_to_7zip%\7z e curl-%curl_version%.tar.gz 20 | %path_to_7zip%\7z x curl-%curl_version%.tar 21 | 22 | set path_to_visual_studio_build=%path_to_visual_studio%\VC\Auxiliary\Build 23 | 24 | if not defined DevEnvDir (call %path_to_visual_studio_build%\vcvars64.bat) 25 | 26 | cd openssl-%openssl_version% 27 | perl Configure VC-WIN64A --prefix=%main_directory%\install no-asm 28 | nmake install_sw 29 | cd .. 30 | 31 | cd curl-%curl_version%\winbuild 32 | nmake /f Makefile.vc mode=dll VC=16 WITH_SSL=dll MACHINE=x64 WITH_PREFIX=%main_directory%\install\ SSL_PATH=%main_directory%\install 33 | cd ../.. 34 | 35 | mkdir mcl_build 36 | cd mcl_build 37 | cmake -DCMAKE_PREFIX_PATH="%main_directory%/install" -A x64 -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX:PATH=%main_directory%/install -DMCL_STATICLIB=OFF -DMCL_LOG_LEVEL=MCL_LOG_LEVEL_NONE %mcl_directory% 38 | cmake --build . --clean-first --target install 39 | -------------------------------------------------------------------------------- /mcl_connectivity/.mbedignore: -------------------------------------------------------------------------------- 1 | doc/* 2 | examples/* 3 | test/* -------------------------------------------------------------------------------- /mcl_connectivity/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Set component name. 2 | SET(MCL_COMPONENT "connectivity") 3 | 4 | # Set path of MCL Connectivity's root Cmake directory. 5 | SET(MCL_CONNECTIVITY_CMAKE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | # Set MCL_CONNECTIVITY_SOURCES to collect source files from different locations. 8 | SET(MCL_CONNECTIVITY_SOURCES "" CACHE INTERNAL "MCL_CONNECTIVITY_SOURCES" FORCE) 9 | SET(MCL_CONNECTIVITY_LIBS "" CACHE INTERNAL "MCL_CONNECTIVITY_LIBS" FORCE) 10 | SET(MCL_CONNECTIVITY_INCLUDE_DIRECTORIES "" CACHE INTERNAL "MCL_CONNECTIVITY_INCLUDE_DIRECTORIES" FORCE) 11 | 12 | IF(MCL_CONNECTIVITY) 13 | MESSAGE(STATUS "MCL Connectivity build is ${MCL_CONNECTIVITY}.") 14 | ADD_DEFINITIONS(-DMCL_CONNECTIVITY_BUILD=1) 15 | ENDIF() 16 | 17 | IF(MCL_STATICLIB) 18 | SET(MCL_USER_DEFINED_DYNAMIC_OR_STATIC STATIC) 19 | ADD_DEFINITIONS(-DMCL_STATICLIB=1) 20 | ELSE() 21 | SET(MCL_USER_DEFINED_DYNAMIC_OR_STATIC SHARED) 22 | ADD_DEFINITIONS(-DMCL_STATICLIB=0) 23 | ENDIF() 24 | 25 | MESSAGE(STATUS "MCL Connectivity will be built as ${MCL_USER_DEFINED_DYNAMIC_OR_STATIC} library.") 26 | 27 | # MCL CONNECTIVITY sources. 28 | ADD_SUBDIRECTORY(src) 29 | 30 | IF(MCL_TEST AND RUBY_FOUND) 31 | # Turn on CMake testing capabilities. 32 | ENABLE_TESTING() 33 | ADD_SUBDIRECTORY(test) 34 | ENDIF() 35 | 36 | # Doxygen. 37 | IF(MCL_DOC) 38 | ADD_SUBDIRECTORY(doc) 39 | ADD_DEPENDENCIES(mcl_connectivity mcl_connectivity_doc) 40 | MESSAGE(STATUS "Creation of reference documentation is enabled.") 41 | ELSE() 42 | MESSAGE(STATUS "Creation of reference documentation is disabled.") 43 | ENDIF() 44 | 45 | # Get all interface header files of mcl connectivity component. 46 | FILE(GLOB MCL_CONNECTIVITY_INTERFACE_HEADER_FILES "${MCL_CONNECTIVITY_CMAKE_ROOT_DIR}/include/mcl_connectivity/*.h") 47 | 48 | # Install directory for interface header files of mcl connectivity component. 49 | INSTALL(FILES ${MCL_CONNECTIVITY_INTERFACE_HEADER_FILES} DESTINATION "${PACKAGE_DESTINATION_INCLUDE}/mcl_connectivity") 50 | -------------------------------------------------------------------------------- /mcl_connectivity/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add a target to generate API documentation with Doxygen. 2 | FIND_PACKAGE(Doxygen) 3 | MESSAGE(STATUS "Create and install the HTML based API documentation (requires Doxygen). Doxygen found = " ${DOXYGEN_FOUND}) 4 | 5 | SET(DOXYGEN_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_connectivity") 6 | SET(DOXYGEN_DOCUMENTATION_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_connectivity/html") 7 | 8 | IF(DOXYGEN_FOUND) 9 | MESSAGE(STATUS "Using Doxygen (${DOXYGEN_EXECUTABLE}) to build reference documentation.") 10 | SET(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/mcl_connectivity.doxyfile) 11 | SET(DOXYFILE ${DOXYGEN_WORKING_DIRECTORY}/mcl_connectivity.doxyfile) 12 | CONFIGURE_FILE(${DOXYFILE_IN} ${DOXYFILE} @ONLY) 13 | 14 | ADD_CUSTOM_TARGET(mcl_connectivity_doc 15 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE} 16 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build/doc 17 | COMMENT "Generating API documentation with Doxygen" 18 | VERBATIM) 19 | 20 | # Install doxygen documents. 21 | INSTALL(DIRECTORY ${DOXYGEN_DOCUMENTATION_DIRECTORY} DESTINATION "${PACKAGE_DESTINATION_DOC}/mcl_connectivity") 22 | 23 | ELSE() 24 | MESSAGE(FATAL_ERROR "Doxygen is required to build the documentation.") 25 | ENDIF() 26 | -------------------------------------------------------------------------------- /mcl_connectivity/examples/callbacks.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file callbacks.h 3 | * @brief Sample callback functions for MCL. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CALLBACKS_H_ 10 | #define CALLBACKS_H_ 11 | 12 | #include "mcl_core/mcl_core.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | mcl_error_t custom_load_function_shared_secret(char **client_id, char **client_secret, char **registration_access_token, char **registration_uri); 20 | mcl_error_t custom_save_function_shared_secret(const char *client_id, const char *client_secret, const char *registration_access_token, const char *registration_uri); 21 | 22 | mcl_error_t custom_load_function_rsa(char **client_id, char **public_key, char **private_key, char **registration_access_token, char **registration_uri); 23 | mcl_error_t custom_save_function_rsa(const char *client_id, const char *public_key, const char *private_key, const char *registration_access_token, const char *registration_uri); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif //CALLBACKS_H_ 30 | -------------------------------------------------------------------------------- /mcl_connectivity/include/mcl_connectivity/mcl_connectivity_common.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_connectivity_common.h 3 | * @brief Common module interface header file. 4 | * 5 | * This module contains common type definitions used in various MCL Connectivity modules. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef MCL_CONNECTIVITY_COMMON_H_ 12 | #define MCL_CONNECTIVITY_COMMON_H_ 13 | 14 | #include "mcl_core/mcl_assert.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | #ifndef MCL_CONNECTIVITY_EXPORT 22 | #if MCL_STATICLIB 23 | #define MCL_CONNECTIVITY_EXPORT 24 | #elif defined(WIN32) || defined(WIN64) 25 | #if MCL_CONNECTIVITY_BUILD 26 | #define MCL_CONNECTIVITY_EXPORT __declspec(dllexport) 27 | #else 28 | #define MCL_CONNECTIVITY_EXPORT __declspec(dllimport) 29 | #endif 30 | #else 31 | #define MCL_CONNECTIVITY_EXPORT 32 | #endif 33 | #endif 34 | 35 | /** 36 | * MCL connectivity return code definitions. Every function returning a status code uses this enum values. 37 | */ 38 | typedef enum E_MCL_CONNECTIVITY_RETURN_CODE 39 | { 40 | MCL_FILE_CANNOT_BE_OPENED = MCL_CORE_RETURN_CODE_END, //!< File can not be opened. 41 | MCL_ITEM_EXCEEDS_MAX_HTTP_REQUEST_SIZE, //!< Item exceeds max http payload request. 42 | MCL_STORE_IS_EMPTY, //!< The store trying to be exchanged has no data inside. 43 | MCL_CONNECTIVITY_RETURN_CODE_END //!< End of return codes. 44 | } E_MCL_CONNECTIVITY_RETURN_CODE; 45 | 46 | extern MCL_CONNECTIVITY_EXPORT const char *mcl_connectivity_return_code_strings[MCL_CONNECTIVITY_RETURN_CODE_END - MCL_CORE_RETURN_CODE_END]; 47 | 48 | // This function converts the given return code to its string value for connectivity module. 49 | #define MCL_CONNECTIVITY_CODE_TO_STRING(code) (code >= MCL_CORE_RETURN_CODE_END) ? mcl_connectivity_return_code_strings[code - MCL_CORE_RETURN_CODE_END] : MCL_CORE_CODE_TO_STRING(code) 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif //MCL_CONNECTIVITY_COMMON_H_ 56 | -------------------------------------------------------------------------------- /mcl_connectivity/include/mcl_connectivity/mcl_custom_data.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_custom_data.h 3 | * @brief Custom data module interface header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef MCL_CUSTOM_DATA_H_ 10 | #define MCL_CUSTOM_DATA_H_ 11 | 12 | #include "mcl_connectivity/mcl_connectivity_common.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | /** 20 | * Parameters for custom data. 21 | */ 22 | typedef enum E_MCL_CUSTOM_DATA_PARAMETER 23 | { 24 | MCL_CUSTOM_DATA_PARAMETER_CONTENT_TYPE = 0, //!< Custom data content type parameter as char*. 25 | MCL_CUSTOM_DATA_PARAMETER_TYPE, //!< Custom data type parameter as char*. 26 | MCL_CUSTOM_DATA_PARAMETER_BUFFER, //!< Custom data buffer parameter as char*. 27 | MCL_CUSTOM_DATA_PARAMETER_BUFFER_SIZE, //!< Custom data buffer size parameter as mcl_size_t. 28 | MCL_CUSTOM_DATA_PARAMETER_DETAILS, //!< Custom data details parameter as mcl_json_t* (optional). 29 | MCL_CUSTOM_DATA_PARAMETER_END 30 | } E_MCL_CUSTOM_DATA_PARAMETER; 31 | 32 | /** 33 | * Handle for custom data. 34 | */ 35 | typedef struct mcl_custom_data_t mcl_custom_data_t; 36 | 37 | /** 38 | * This function creates and initializes a data struct of #mcl_custom_data_t. 39 | * 40 | * @param [in] version Version of the custom data. 41 | * @param [out] custom_data Custom data handle which is going to be initialized. 42 | * @return 43 | * 48 | */ 49 | extern MCL_CONNECTIVITY_EXPORT mcl_error_t mcl_custom_data_initialize(const char *version, mcl_custom_data_t **custom_data); 50 | 51 | /** 52 | * This function is used to set a parameter of a custom data. 53 | * 54 | * @param [in] custom_data Custom data to set its parameter. 55 | * @param [in] parameter One of the parameters listed in #E_MCL_CUSTOM_DATA_PARAMETER. 56 | * @param [in] value New value of the @p parameter. 57 | * @return 58 | * 64 | */ 65 | extern MCL_CONNECTIVITY_EXPORT mcl_error_t mcl_custom_data_set_parameter(mcl_custom_data_t *custom_data, E_MCL_CUSTOM_DATA_PARAMETER parameter, const void *value); 66 | 67 | /** 68 | * This function destroys custom data data structure. 69 | * 70 | * @param [in] custom_data Custom data handle which is going to be destroyed. 71 | */ 72 | extern MCL_CONNECTIVITY_EXPORT void mcl_custom_data_destroy(mcl_custom_data_t **custom_data); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif //MCL_CUSTOM_DATA_H_ 79 | -------------------------------------------------------------------------------- /mcl_connectivity/include/mcl_connectivity/mcl_store.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_store.h 3 | * @brief Store module interface header file. 4 | * 5 | * Store is the container for all types of data such as #mcl_custom_data_t, #mcl_event_t, #mcl_file_t, 6 | * #mcl_data_source_configuration_t and #mcl_timeseries_t to be exchanged using MCL. 7 | * 8 | * Agents can upload store to MindSphere. This module enables the agent to initialize a store 9 | * data type using #mcl_store_initialize function. Following initialization, all types of data can 10 | * be added to the store using #mcl_store_add function. Once the store data type is ready, it can be 11 | * uploaded to MindSphere using #mcl_connectivity_exchange function. After the exchange operation, 12 | * the agent is expected to destroy the store using #mcl_store_destroy function. 13 | * 14 | * For more information, please look at example file "mcl_connectivity/examples/store_upload.c". 15 | * 16 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 17 | * All rights reserved. 18 | */ 19 | 20 | #ifndef MCL_STORE_H_ 21 | #define MCL_STORE_H_ 22 | 23 | #include "mcl_connectivity/mcl_connectivity_common.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | /** 31 | * Handle for store. 32 | */ 33 | typedef struct mcl_store_t mcl_store_t; 34 | 35 | /** 36 | * This function creates and initializes an object of type #mcl_store_t. 37 | * 38 | * Store is used to hold different types of data. These data will be processed later by connectivity module. 39 | * to perform exchange operation. 40 | * 41 | * @param [out] store The newly initialized store. 42 | * @return 43 | * 49 | */ 50 | extern MCL_CONNECTIVITY_EXPORT mcl_error_t mcl_store_initialize(mcl_store_t **store); 51 | 52 | /** 53 | * This function adds a new item to store. 54 | * 55 | * @param [in] store MCL store which will contain any type of item created. 56 | * @param [in] item Item to be added to store. 57 | * @return 58 | * 64 | */ 65 | extern MCL_CONNECTIVITY_EXPORT mcl_error_t mcl_store_add(mcl_store_t *store, void *item); 66 | 67 | /** 68 | * This function destroys the #mcl_store_t object and frees any memory allocated. 69 | * 70 | * @param [in] store Preinitialized #mcl_store_t object to destroy. 71 | * @return 72 | * 76 | */ 77 | extern MCL_CONNECTIVITY_EXPORT void mcl_store_destroy(mcl_store_t **store); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif //MCL_STORE_H_ 84 | -------------------------------------------------------------------------------- /mcl_connectivity/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set sources 2 | FILE(GLOB SOURCES *.c) 3 | LIST(APPEND MCL_CONNECTIVITY_SOURCES ${SOURCES}) 4 | 5 | SET(MCL_CONNECTIVITY_SOURCES ${MCL_CONNECTIVITY_SOURCES} CACHE INTERNAL "MCL_CONNECTIVITY_SOURCES" FORCE) 6 | 7 | #Specify library as target 8 | SET(PROJECT_LIBRARY_OUTPUT mcl_connectivity CACHE INTERNAL "PROJECT_LIBRARY_OUTPUT" FORCE) 9 | ADD_LIBRARY(${PROJECT_LIBRARY_OUTPUT} ${MCL_USER_DEFINED_DYNAMIC_OR_STATIC} $ ${MCL_CONNECTIVITY_SOURCES}) 10 | 11 | SET_TARGET_PROPERTIES(${PROJECT_LIBRARY_OUTPUT} PROPERTIES FOLDER ${MCL_COMPONENT}) 12 | SET_TARGET_PROPERTIES(${PROJECT_LIBRARY_OUTPUT} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${PACKAGE_DESTINATION_LIB}) 13 | 14 | ADD_DEPENDENCIES(mcl_connectivity mcl_core) 15 | 16 | #Set include directories 17 | LIST(APPEND MCL_CONNECTIVITY_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) 18 | LIST(APPEND MCL_CONNECTIVITY_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) 19 | LIST(APPEND MCL_CONNECTIVITY_INCLUDE_DIRECTORIES ${MCL_CMAKE_ROOT_DIR}/mcl_core/include) 20 | LIST(APPEND MCL_CONNECTIVITY_INCLUDE_DIRECTORIES ${MCL_CONNECTIVITY_CMAKE_ROOT_DIR}/include) 21 | 22 | IF(WIN32 OR WIN64) 23 | LIST(APPEND MCL_CONNECTIVITY_LIBS ${MCL_OUTPUT_DIR}/mcl_core.lib) 24 | ELSE() 25 | IF(MCL_STATICLIB) 26 | LIST(APPEND MCL_CONNECTIVITY_LIBS ${MCL_OUTPUT_DIR}/libmcl_core.a) 27 | ELSE() 28 | LIST(APPEND MCL_CONNECTIVITY_LIBS ${MCL_OUTPUT_DIR}/libmcl_core.so) 29 | ENDIF() 30 | ENDIF() 31 | 32 | LIST(APPEND MCL_CONNECTIVITY_LIBS ${MCL_CORE_LIBS}) 33 | 34 | SET(MCL_CONNECTIVITY_INCLUDE_DIRECTORIES ${MCL_CONNECTIVITY_INCLUDE_DIRECTORIES} CACHE INTERNAL "MCL_CONNECTIVITY_INCLUDE_DIRECTORIES" FORCE) 35 | TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY_OUTPUT} PUBLIC ${MCL_CONNECTIVITY_INCLUDE_DIRECTORIES}) 36 | 37 | TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY_OUTPUT} ${MCL_CONNECTIVITY_LIBS}) 38 | 39 | #Install MCL target 40 | INSTALL(TARGETS mcl_connectivity 41 | RUNTIME DESTINATION "${PACKAGE_DESTINATION_LIB}" 42 | LIBRARY DESTINATION "${PACKAGE_DESTINATION_LIB}" 43 | ARCHIVE DESTINATION "${PACKAGE_DESTINATION_LIB}") 44 | -------------------------------------------------------------------------------- /mcl_connectivity/src/connectivity.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file connectivity.h 3 | * @brief Connectivity module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CONNECTIVITY_H_ 10 | #define CONNECTIVITY_H_ 11 | 12 | #include "mcl_connectivity/mcl_connectivity.h" 13 | #include "connectivity_processor.h" 14 | 15 | /** 16 | * This is the main handle for connectivity component. 17 | */ 18 | typedef struct mcl_connectivity_t 19 | { 20 | mcl_connectivity_configuration_t *configuration; 21 | connectivity_processor_t processor; 22 | } connectivity_t; 23 | 24 | #endif //CONNECTIVITY_H_ 25 | -------------------------------------------------------------------------------- /mcl_connectivity/src/connectivity_common.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file connectivity_common.c 3 | * @brief Strings for connectivity error codes. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "connectivity_common.h" 10 | 11 | const char *mcl_connectivity_return_code_strings[MCL_CONNECTIVITY_RETURN_CODE_END - MCL_CORE_RETURN_CODE_END] = 12 | { 13 | "MCL_FILE_CANNOT_BE_OPENED", 14 | "MCL_ITEM_EXCEEDS_MAX_HTTP_REQUEST_SIZE", 15 | "MCL_STORE_IS_EMPTY" 16 | }; 17 | -------------------------------------------------------------------------------- /mcl_connectivity/src/connectivity_common.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file connectivity_common.h 3 | * @brief Strings for connectivity error codes. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CONNECTIVITY_COMMON_H_ 10 | #define CONNECTIVITY_COMMON_H_ 11 | 12 | #include "mcl_connectivity/mcl_connectivity_common.h" 13 | 14 | #endif //CONNECTIVITY_COMMON_H_ 15 | -------------------------------------------------------------------------------- /mcl_connectivity/src/connectivity_configuration.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file connectivity_configuration.h 3 | * @brief Connectivity configuration module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CONNECTIVITY_CONFIGURATION_H_ 10 | #define CONNECTIVITY_CONFIGURATION_H_ 11 | 12 | #include "mcl_core/mcl_core.h" 13 | 14 | typedef struct mcl_connectivity_configuration_t 15 | { 16 | mcl_core_t *core; 17 | char *exchange_url; 18 | char *mapping_url; 19 | mcl_size_t max_http_payload_size; 20 | } connectivity_configuration_t; 21 | 22 | /** 23 | * This function checks whether all mandatory parameters of a connectivity configuration are set or not. 24 | * 25 | * @param [in] configuration Connectivity configuration to validate. 26 | * @return 27 | * 31 | */ 32 | MCL_LOCAL mcl_error_t connectivity_configuration_validate(connectivity_configuration_t *configuration); 33 | 34 | #endif //CONNECTIVITY_CONFIGURATION_H_ 35 | -------------------------------------------------------------------------------- /mcl_connectivity/src/custom_data.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file custom_data.h 3 | * @brief Custom data module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CUSTOM_DATA_H_ 10 | #define CUSTOM_DATA_H_ 11 | 12 | #include "item.h" 13 | #include "mcl_core/mcl_json_util.h" 14 | 15 | /** 16 | * Handle for custom data payload. 17 | */ 18 | typedef struct custom_data_payload_t 19 | { 20 | char *version; //!< Version of custom data. 21 | const mcl_uint8_t *buffer; //!< Buffer of custom data. 22 | char *content_type; //!< Content type of custom data. 23 | char *type; //!< Type of custom data. 24 | mcl_size_t size; //!< Size of custom data. 25 | mcl_json_t *details; //!< Details of custom data. 26 | } custom_data_payload_t; 27 | 28 | /** 29 | * Handle for custom data. 30 | */ 31 | typedef struct mcl_custom_data_t 32 | { 33 | mcl_item_t item_base; //!< Item base of custom data. 34 | custom_data_payload_t *payload; //!< Payload of custom data. 35 | } custom_data_t; 36 | 37 | /** 38 | * This function checks whether all mandatory parameters of a custom data are set or not. 39 | * 40 | * @param [in] custom_data Custom data to validate. 41 | * @return 42 | * 46 | */ 47 | MCL_LOCAL mcl_error_t custom_data_validate(custom_data_t *custom_data); 48 | 49 | #endif //CUSTOM_DATA_H_ 50 | -------------------------------------------------------------------------------- /mcl_connectivity/src/data_point.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_point.h 3 | * @brief Data point module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_POINT_H_ 10 | #define DATA_POINT_H_ 11 | 12 | #include "mcl_core/mcl_json_util.h" 13 | 14 | /** 15 | * Handle for data point. 16 | */ 17 | typedef struct mcl_data_point_t 18 | { 19 | char *id; //!< Agent-unique identifier of the data point. 20 | char *name; //!< Name of the data point. 21 | char *description; //!< Description of the data point. 22 | char *type; //!< Type of the data point. 23 | char *unit; //!< Measurement unit of the data point. 24 | mcl_json_t *custom_data; //!< Custom parameters for the data point. 25 | } data_point_t; 26 | 27 | /** 28 | * This function checks whether all mandatory parameters of a data point are set or not. 29 | * 30 | * @param [in] data_point Data point to validate. 31 | * @return 32 | * 36 | */ 37 | MCL_LOCAL mcl_error_t data_point_validate(data_point_t *data_point); 38 | 39 | #endif //DATA_POINT_H_ 40 | -------------------------------------------------------------------------------- /mcl_connectivity/src/data_source.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_source.h 3 | * @brief Data source module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_SOURCE_H_ 10 | #define DATA_SOURCE_H_ 11 | 12 | #include "data_point.h" 13 | #include "mcl_core/mcl_list.h" 14 | 15 | /** 16 | * Handle for data source. 17 | */ 18 | typedef struct mcl_data_source_t 19 | { 20 | char *name; //!< Name of the data source. 21 | char *description; //!< Description of the data source. 22 | mcl_list_t *data_points; //!< List of data points in the data source. 23 | mcl_json_t *custom_data; //!< Custom parameters for data source. 24 | } data_source_t; 25 | 26 | /** 27 | * This function checks whether all mandatory parameters of a data source are set or not. 28 | * 29 | * @param [in] data_source Data source to validate. 30 | * @return 31 | * 35 | */ 36 | MCL_LOCAL mcl_error_t data_source_validate(data_source_t *data_source); 37 | 38 | #endif //DATA_SOURCE_H_ 39 | -------------------------------------------------------------------------------- /mcl_connectivity/src/data_source_configuration.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_source_configuration.h 3 | * @brief Data source configuration module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_SOURCE_CONFIGURATION_H_ 10 | #define DATA_SOURCE_CONFIGURATION_H_ 11 | 12 | #include "data_source.h" 13 | #include "item.h" 14 | 15 | /** 16 | * Handle for data source configuration payload. 17 | */ 18 | typedef struct data_source_configuration_payload_t 19 | { 20 | char *configuration_id; //!< Unique identifier of the configuration. 21 | mcl_list_t *data_sources; //!< List of data sources definitions. 22 | } data_source_configuration_payload_t; 23 | 24 | /** 25 | * Handle for data source configuration. 26 | */ 27 | typedef struct mcl_data_source_configuration_t 28 | { 29 | mcl_item_t item_base; 30 | data_source_configuration_payload_t *payload; 31 | } data_source_configuration_t; 32 | 33 | /** 34 | * This array is used to get the data source configuration version. 35 | */ 36 | extern const char *mcl_data_source_configuration_versions[]; 37 | 38 | /** 39 | * This function checks whether all mandatory parameters of a data source configuration are set or not. 40 | * 41 | * @param [in] data_source_configuration Data source configuration to validate. 42 | * @return 43 | * 47 | */ 48 | MCL_LOCAL mcl_error_t data_source_configuration_validate(data_source_configuration_t *data_source_configuration); 49 | 50 | #endif //DATA_SOURCE_CONFIGURATION_H_ 51 | -------------------------------------------------------------------------------- /mcl_connectivity/src/event.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file event.h 3 | * @brief Event module header file. 4 | * 5 | * Meta and payload parts of event type are initialized and filled in this module. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef EVENT_H_ 12 | #define EVENT_H_ 13 | 14 | #include "item.h" 15 | #include "mcl_core/mcl_json_util.h" 16 | #include "mcl_core/mcl_time_util.h" 17 | 18 | /** 19 | * Handle for event payload. 20 | */ 21 | typedef struct event_payload_t 22 | { 23 | char *id; //!< Unique identifier of the event. 24 | char *correlation_id; //!< Parent event id. 25 | char timestamp[MCL_TIMESTAMP_LENGTH]; //!< Creation time of the event in ISO format. 26 | mcl_int32_t severity; //!< Severity level. 27 | char *description; //!< Event description. 28 | char *type; //!< Type of the event. 29 | char *version; //!< Version of the event/alarm type. 30 | mcl_json_t *details; //!< Event/alarm details. 31 | } event_payload_t; 32 | 33 | /** 34 | * Handle for event. 35 | */ 36 | typedef struct mcl_event_t 37 | { 38 | mcl_item_t item_base; //!< Item base of event. 39 | event_payload_t *payload; //!< Payload of event. 40 | } event_t; 41 | 42 | /** 43 | * This function checks whether all mandatory parameters of an event are set or not. 44 | * 45 | * @param [in] event Event to validate. 46 | * @return 47 | * 51 | */ 52 | MCL_LOCAL mcl_error_t event_validate(event_t *event); 53 | 54 | extern const char *mcl_event_versions[]; 55 | 56 | #endif //EVENT_H_ 57 | -------------------------------------------------------------------------------- /mcl_connectivity/src/file.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file file.h 3 | * @brief File module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef FILE_H_ 10 | #define FILE_H_ 11 | 12 | #include "item.h" 13 | #include "mcl_core/mcl_time_util.h" 14 | 15 | /** 16 | * Handle for file payload. 17 | */ 18 | typedef struct file_payload_t 19 | { 20 | char *creation_date; //!< Creation date of file. 21 | char *local_path; //!< Local path of file. 22 | char *remote_name; //!< Remote name of file. 23 | char *type; //!< Type of file. 24 | mcl_size_t size; //!< Size of file. 25 | void *file_descriptor; //!< Descriptor of file. 26 | } file_payload_t; 27 | 28 | /** 29 | * Handle for file. 30 | */ 31 | typedef struct mcl_file_t 32 | { 33 | mcl_item_t item_base; //!< Item base of file. 34 | file_payload_t *payload; //!< Payload of file. 35 | } file_t; 36 | 37 | /** 38 | * This function checks whether all mandatory parameters of a file are set or not. 39 | * 40 | * @param [in] file File to validate. 41 | * @return 42 | * 47 | */ 48 | MCL_LOCAL mcl_error_t file_validate(file_t *file); 49 | 50 | extern const char *mcl_file_versions[]; 51 | 52 | #endif //FILE_H_ 53 | -------------------------------------------------------------------------------- /mcl_connectivity/src/item.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file item.h 3 | * @brief Item module header file. 4 | * 5 | * This module contains item definition. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef ITEM_H_ 12 | #define ITEM_H_ 13 | 14 | #include "mcl_connectivity/mcl_connectivity_common.h" 15 | 16 | // Preamble code is an integer data to verify items that will be stored. 17 | #define MCL_ITEM_PREAMBLE (('M' << 24) | ('C' << 16) | ('L' << 8)) 18 | 19 | /** 20 | * Item type. 21 | */ 22 | typedef enum E_MCL_ITEM_TYPE 23 | { 24 | MCL_ITEM_TYPE_TIMESERIES, //!< Item type timeseries. 25 | MCL_ITEM_TYPE_EVENT, //!< Item type event. 26 | MCL_ITEM_TYPE_FILE, //!< Item type file. 27 | MCL_ITEM_TYPE_CUSTOM_DATA, //!< Item type custom data. 28 | MCL_ITEM_TYPE_DATA_SOURCE_CONFIGURATION, //!< Item type data source configuration. 29 | MCL_ITEM_TYPE_STORE //!< Item type store. 30 | } E_MCL_ITEM_TYPE; 31 | 32 | /** 33 | * Handle for item. 34 | */ 35 | typedef struct mcl_item_t 36 | { 37 | mcl_uint32_t preamble; //!< Item preamble. 38 | E_MCL_ITEM_TYPE type; //!< Item type. 39 | mcl_uint32_t version; //!< Item version. 40 | } mcl_item_t; 41 | 42 | #endif //ITEM_H_ 43 | -------------------------------------------------------------------------------- /mcl_connectivity/src/json.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file json.h 3 | * @brief Json module header file. 4 | * 5 | * This module creates json strings for all data types. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef JSON_H_ 12 | #define JSON_H_ 13 | 14 | #include "mcl_connectivity/mcl_connectivity_common.h" 15 | #include "mapping.h" 16 | 17 | /** 18 | * This function creates json representation of an item meta. 19 | * 20 | * @param [in] item MCL item (Event, Timeseries, etc.). 21 | * @param [out] json_string Json string representation of item meta. 22 | * @return 23 | * 27 | */ 28 | MCL_LOCAL mcl_error_t json_from_item_meta(void *item, char **json_string); 29 | 30 | /** 31 | * This function creates json representation of an item payload in a json array. 32 | * 33 | * @param [in] item Item which will be used to create json string. 34 | * @param [out] json_string Json string representation of item payload. 35 | * @return 36 | * 40 | */ 41 | MCL_LOCAL mcl_error_t json_from_item_payload(void *item, char **json_string); 42 | 43 | /** 44 | * This function calculates the item size. 45 | * 46 | * @param [in] item Item to calculate its size. 47 | * @return Size of the item. 48 | */ 49 | MCL_LOCAL mcl_size_t json_get_item_size(void *item); 50 | 51 | /** 52 | * This function parses json representation of an item to its struct (Currently, only for data source configuration). 53 | * 54 | * @param [in] json_string Json string. 55 | * @param [in] string_length Length of json string. 56 | * @param [out] item Item struct. 57 | * @return 58 | * 63 | */ 64 | MCL_LOCAL mcl_error_t json_parse_item(const char *json_string, mcl_size_t string_length, void **item); 65 | 66 | #endif //JSON_H_ 67 | -------------------------------------------------------------------------------- /mcl_connectivity/src/mapping.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mapping.h 3 | * @brief Mapping module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef MAPPING_H_ 10 | #define MAPPING_H_ 11 | 12 | #include "mcl_core/mcl_core_common.h" 13 | 14 | /** 15 | * Handle for mapping. 16 | */ 17 | typedef struct mcl_mapping_t 18 | { 19 | char *data_point_id; //!< Mapping ID. 20 | char *entity_id; //!< Entity ID. 21 | char *property_set_name; //!< Property set name. 22 | char *property_name; //!< Property name. 23 | mcl_bool_t keep_mapping; //!< Custom parameters for the mapping. 24 | } mapping_t; 25 | 26 | /** 27 | * This function checks whether all mandatory parameters of a mapping are set or not. 28 | * 29 | * @param [in] mapping Mapping to validate. 30 | * @return 31 | * 35 | */ 36 | MCL_LOCAL mcl_error_t mapping_validate(mapping_t *mapping); 37 | 38 | #endif //MAPPING_H_ 39 | -------------------------------------------------------------------------------- /mcl_connectivity/src/store.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file store.h 3 | * @brief Store module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef STORE_H_ 10 | #define STORE_H_ 11 | 12 | #include "mcl_core/mcl_list.h" 13 | #include "item.h" 14 | 15 | /** 16 | * Store item status. 17 | */ 18 | typedef enum E_MCL_STORE_ITEM_STATUS 19 | { 20 | STORE_ITEM_STATUS_READY, //!< This item is not processed before. 21 | STORE_ITEM_STATUS_SELECTED, //!< This item is not processed before, selected for current request. 22 | STORE_ITEM_STATUS_PROCESSED, //!< Current item has been added to the current http request. 23 | STORE_ITEM_STATUS_IGNORED, //!< There is not enough space in the http request for the current item. 24 | } E_MCL_STORE_ITEM_STATUS; 25 | 26 | /** 27 | * General data type for item in #store_item_t. 28 | * Data can be one of the following (distinguish by type): 29 | * 36 | */ 37 | typedef struct mcl_store_item_t 38 | { 39 | void *item; //!< Item to be added to the store. 40 | E_MCL_STORE_ITEM_STATUS status; //!< Status of item in the store. 41 | mcl_size_t id; //!< Id of the item in the store. 42 | mcl_size_t item_size; //!< Size of the item in the store. 43 | } store_item_t; 44 | 45 | /** 46 | * Handle for store. 47 | */ 48 | typedef struct mcl_store_t 49 | { 50 | mcl_item_t item_base; //!< Item base of an item. 51 | mcl_list_t *item_list; //!< Contains #store_item_t items. 52 | mcl_size_t last_item_id; //!< Id of the last item in the store. 53 | } store_t; 54 | 55 | /** 56 | * This function is called to destroy store item. 57 | * 58 | * @param [in] store_item Store item to be destroyed. 59 | */ 60 | MCL_LOCAL void store_item_destroy(store_item_t **store_item); 61 | 62 | #endif //STORE_H_ 63 | -------------------------------------------------------------------------------- /mcl_connectivity/src/timeseries.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file timeseries.h 3 | * @brief Timeseries module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef TIMESERIES_H_ 10 | #define TIMESERIES_H_ 11 | 12 | #include "timeseries_value_list.h" 13 | #include "item.h" 14 | 15 | /** 16 | * Handle for timeseries paylaod. 17 | */ 18 | typedef struct timeseries_payload_t 19 | { 20 | char *configuration_id; //!< Configuration ID of timeseries. 21 | mcl_list_t *value_lists; //!< List of timeseries value lists. 22 | } timeseries_payload_t; 23 | 24 | /** 25 | * Handle for timeseries. 26 | */ 27 | typedef struct mcl_timeseries_t 28 | { 29 | mcl_item_t item_base; //!< Item base of timeseries. 30 | timeseries_payload_t *payload; //!< Payload of timeseries. 31 | } timeseries_t; 32 | 33 | extern const char *mcl_timeseries_versions[]; 34 | 35 | /** 36 | * This function checks whether all mandatory parameters of a timeseries are set or not. 37 | * 38 | * @param [in] timeseries Timeseries to validate. 39 | * @return 40 | * 44 | */ 45 | MCL_LOCAL mcl_error_t timeseries_validate(timeseries_t *timeseries); 46 | 47 | #endif //TIMESERIES_H_ 48 | -------------------------------------------------------------------------------- /mcl_connectivity/src/timeseries_value.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file timeseries_value.h 3 | * @brief Timeseries value module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef TIMESERIES_VALUE_H_ 10 | #define TIMESERIES_VALUE_H_ 11 | 12 | #include "mcl_connectivity/mcl_connectivity_common.h" 13 | 14 | /** 15 | * Handle for timeseries value. 16 | */ 17 | typedef struct mcl_timeseries_value_t 18 | { 19 | char *data_point_id; //!< Data point id of the timeseries value. 20 | char *quality_code; //!< Quality code of the timeseries value. 21 | char *value; //!< Value of the timeseries value. 22 | } timeseries_value_t; 23 | 24 | /** 25 | * This function checks whether all mandatory parameters of a timeseries value are set or not. 26 | * 27 | * @param [in] timeseries_value Timeseries value to validate. 28 | * @return 29 | * 33 | */ 34 | MCL_LOCAL mcl_error_t timeseries_value_validate(timeseries_value_t *timeseries_value); 35 | 36 | #endif //TIMESERIES_VALUE_H_ 37 | -------------------------------------------------------------------------------- /mcl_connectivity/src/timeseries_value_list.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file timeseries_value_list.h 3 | * @brief Timeseries value list header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef TIMESERIES_VALUE_LIST_H_ 10 | #define TIMESERIES_VALUE_LIST_H_ 11 | 12 | #include "timeseries_value.h" 13 | #include "mcl_core/mcl_list.h" 14 | #include "mcl_core/mcl_time_util.h" 15 | 16 | /** 17 | * Handle for timeseries value list. 18 | */ 19 | typedef struct mcl_timeseries_value_list_t 20 | { 21 | mcl_list_t *values; //!< List of timeseries values. 22 | char timestamp[MCL_TIMESTAMP_LENGTH]; //!< Time of values in yyyy-MM-ddTHH:mm:ss.SSSZ format. 23 | } timeseries_value_list_t; 24 | 25 | /** 26 | * This function checks whether all mandatory parameters of a timeseries value list are set or not. 27 | * 28 | * @param [in] timeseries_value_list Timeseries value list to validate. 29 | * @return 30 | * 34 | */ 35 | MCL_LOCAL mcl_error_t timeseries_value_list_validate(timeseries_value_list_t *timeseries_value_list); 36 | 37 | #endif //TIMESERIES_VALUE_LIST_H_ 38 | -------------------------------------------------------------------------------- /mcl_connectivity/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(integration) 2 | ADD_SUBDIRECTORY(unit) -------------------------------------------------------------------------------- /mcl_connectivity/test/integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set name of the test framework. 2 | SET(TEST_FRAMEWORK unity_and_cmock) 3 | 4 | #Set paths. 5 | SET(INTEGRATION_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") 6 | SET(TEST_RUNNER_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testrunner") 7 | SET(GENERATE_TEST_RUNNER_SCRIPT_PATH "mcl_core/test/lib/CMock/vendor/unity/auto/generate_test_runner.rb") 8 | 9 | #Set Ruby Command. 10 | SET(RUBY_CMD "ruby") 11 | 12 | #Create test runner directory. 13 | FILE(MAKE_DIRECTORY ${TEST_RUNNER_DIRECTORY}) 14 | 15 | #Loop over each integration test file. 16 | FILE(GLOB INTEGRATION_TEST_FILE_LIST RELATIVE "${INTEGRATION_TEST_DIRECTORY}" "${INTEGRATION_TEST_DIRECTORY}/*.c") 17 | FOREACH(INTEGRATION_TEST_FILE ${INTEGRATION_TEST_FILE_LIST}) 18 | 19 | #Remove file extension from the testcase file 20 | STRING(REPLACE ".c" "" INTEGRATION_TEST_FILE_NAME ${INTEGRATION_TEST_FILE}) 21 | 22 | #Create test runner. 23 | SET(TEST_RUNNER_FILE "${INTEGRATION_TEST_FILE_NAME}_runner.c") 24 | EXECUTE_PROCESS(COMMAND ${RUBY_CMD} ${GENERATE_TEST_RUNNER_SCRIPT_PATH} "${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE}" "${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}" 25 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 26 | RESULT_VARIABLE ruby_result 27 | OUTPUT_VARIABLE ruby_output) 28 | 29 | #Set test source files. 30 | SET(TEST_SOURCES ${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE} ${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}) 31 | 32 | #Set the name of the test executable. 33 | SET(INTEGRATION_TEST_NAME "${INTEGRATION_TEST_FILE_NAME}") 34 | 35 | #Create integration test executable. 36 | ADD_EXECUTABLE(${INTEGRATION_TEST_NAME} ${TEST_SOURCES}) 37 | 38 | #Link libraries to executable. 39 | TARGET_LINK_LIBRARIES(${INTEGRATION_TEST_NAME} ${MCL_CONNECTIVITY_LIBS} ${PROJECT_LIBRARY_OUTPUT} ${TEST_FRAMEWORK}) 40 | 41 | #Include required directories 42 | TARGET_INCLUDE_DIRECTORIES(${INTEGRATION_TEST_NAME} PUBLIC ${MCL_CONNECTIVITY_INCLUDE_DIRECTORIES}) 43 | 44 | ADD_TEST(${INTEGRATION_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${INTEGRATION_TEST_NAME}) 45 | 46 | SET_TARGET_PROPERTIES(${INTEGRATION_TEST_NAME} PROPERTIES FOLDER "${MCL_COMPONENT}/integration_tests") 47 | 48 | ENDFOREACH(INTEGRATION_TEST_FILE) 49 | -------------------------------------------------------------------------------- /mcl_connectivity/test/unit/cmock.yml.in: -------------------------------------------------------------------------------- 1 | :cmock: 2 | :plugins: [ignore, return_thru_ptr, expect_any_args] 3 | :includes: ${CMOCK_YML_INCLUDES} 4 | :mock_path: '${CMAKE_CURRENT_BINARY_DIR}/mock' 5 | :mock_prefix: mock_ 6 | :framework: unity 7 | :verbosity: 3 8 | :treat_externs: :include -------------------------------------------------------------------------------- /mcl_core/.mbedignore: -------------------------------------------------------------------------------- 1 | doc/* 2 | examples/* 3 | test/* 4 | src/crypto/openssl/* 5 | src/http_client/curl/* 6 | src/http_client/basic/mbedtls* -------------------------------------------------------------------------------- /mcl_core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Set component name. 2 | SET(MCL_COMPONENT "core") 3 | 4 | # Set path of MCL's root Cmake directory. 5 | SET(MCL_CORE_CMAKE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | # Set MCL_CORE_SOURCES to collect source files from different locations. 8 | SET(MCL_CORE_SOURCES "" CACHE INTERNAL "MCL_CORE_SOURCES" FORCE) 9 | SET(MCL_CORE_LIBS "" CACHE INTERNAL "MCL_CORE_LIBS" FORCE) 10 | SET(MCL_CORE_INCLUDE_DIRECTORIES "" CACHE INTERNAL "MCL_CORE_INCLUDE_DIRECTORIES" FORCE) 11 | 12 | ADD_DEFINITIONS(-DMCL_CORE_BUILD=1) 13 | 14 | IF(MCL_STATICLIB) 15 | SET(MCL_CORE_DYNAMIC_OR_STATIC STATIC) 16 | ADD_DEFINITIONS(-DMCL_STATICLIB=1) 17 | ELSE() 18 | SET(MCL_CORE_DYNAMIC_OR_STATIC SHARED) 19 | ADD_DEFINITIONS(-DMCL_STATICLIB=0) 20 | ENDIF() 21 | 22 | MESSAGE(STATUS "MCL Core will be built as ${MCL_CORE_DYNAMIC_OR_STATIC} library.") 23 | 24 | ADD_SUBDIRECTORY(lib/cJSON) 25 | 26 | OPTION(MCL_MOCKSERVER_INTEGRATION "MCL integration test with mock server" OFF) 27 | 28 | IF(MCL_MOCKSERVER_INTEGRATION) 29 | ADD_DEFINITIONS(-DMCL_MOCKSERVER_INTEGRATION) 30 | ENDIF() 31 | 32 | # MCL Core sources. 33 | ADD_SUBDIRECTORY(src) 34 | 35 | IF(MCL_TEST OR MCL_MOCKSERVER_INTEGRATION) 36 | IF(RUBY_FOUND) 37 | # Turn on CMake testing capabilities. 38 | ENABLE_TESTING() 39 | MESSAGE(STATUS "Ruby found on path (${RUBY_FOUND}) and MCL testing is ${MCL_TEST}.") 40 | ELSE() 41 | MESSAGE(STATUS "Ruby not found on path. Skipping MCL testing...") 42 | ENDIF() 43 | 44 | IF(MCL_TEST) 45 | ADD_SUBDIRECTORY(test) 46 | ELSE() 47 | ADD_SUBDIRECTORY(test/lib/CMock) 48 | ADD_SUBDIRECTORY(test/integration) 49 | ENDIF() 50 | ENDIF() 51 | 52 | IF(MCL_DOC) 53 | 54 | # Install README document. 55 | INSTALL(FILES "${MCL_CMAKE_ROOT_DIR}/README.md" DESTINATION ${PACKAGE_DESTINATION_DOC}) 56 | 57 | ADD_SUBDIRECTORY(doc) 58 | ADD_DEPENDENCIES(mcl_core mcl_core_doc) 59 | MESSAGE(STATUS "Creation of reference documentation is enabled.") 60 | ELSE() 61 | MESSAGE(STATUS "Creation of reference documentation is disabled.") 62 | ENDIF() 63 | 64 | # Get all interface header files of mcl core component. 65 | FILE(GLOB MCL_CORE_INTERFACE_HEADER_FILES "${MCL_CORE_CMAKE_ROOT_DIR}/include/mcl_core/*.h") 66 | 67 | # Install directory for interface header files of mcl core component. 68 | INSTALL(FILES ${MCL_CORE_INTERFACE_HEADER_FILES} DESTINATION "${PACKAGE_DESTINATION_INCLUDE}/mcl_core") 69 | 70 | MARK_AS_ADVANCED(MCL_CORE_INCLUDE_DIRECTORIES MCL_CORE_LIBS) 71 | -------------------------------------------------------------------------------- /mcl_core/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add a target to generate API documentation with Doxygen. 2 | FIND_PACKAGE(Doxygen) 3 | MESSAGE(STATUS "Create and install the HTML based API documentation (requires Doxygen). Doxygen found = " ${DOXYGEN_FOUND}) 4 | 5 | SET(DOXYGEN_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_core") 6 | SET(DOXYGEN_DOCUMENTATION_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_core/html") 7 | 8 | IF(DOXYGEN_FOUND) 9 | MESSAGE(STATUS "Using Doxygen (${DOXYGEN_EXECUTABLE}) to build reference documentation.") 10 | SET(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/mcl_core.doxyfile) 11 | SET(DOXYFILE ${DOXYGEN_WORKING_DIRECTORY}/mcl_core.doxyfile) 12 | CONFIGURE_FILE(${DOXYFILE_IN} ${DOXYFILE} @ONLY) 13 | 14 | ADD_CUSTOM_TARGET(mcl_core_doc 15 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE} 16 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build/doc 17 | COMMENT "Generating API documentation with Doxygen." 18 | VERBATIM) 19 | 20 | # Install doxygen documents. 21 | INSTALL(DIRECTORY ${DOXYGEN_DOCUMENTATION_DIRECTORY} DESTINATION "${PACKAGE_DESTINATION_DOC}/mcl_core") 22 | 23 | ELSE() 24 | MESSAGE(FATAL_ERROR "Doxygen is required to build the documentation.") 25 | ENDIF() 26 | -------------------------------------------------------------------------------- /mcl_core/examples/callbacks.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file callbacks.h 3 | * @brief Sample callback functions for MCL. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CALLBACKS_H_ 10 | #define CALLBACKS_H_ 11 | 12 | #include "mcl_core/mcl_core.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | mcl_error_t custom_load_function_shared_secret(char **client_id, char **client_secret, char **registration_access_token, char **registration_uri); 20 | mcl_error_t custom_save_function_shared_secret(const char *client_id, const char *client_secret, const char *registration_access_token, const char *registration_uri); 21 | 22 | mcl_error_t custom_load_function_rsa(char **client_id, char **public_key, char **private_key, char **registration_access_token, char **registration_uri); 23 | mcl_error_t custom_save_function_rsa(const char *client_id, const char *public_key, const char *private_key, const char *registration_access_token, const char *registration_uri); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif //CALLBACKS_H_ 30 | -------------------------------------------------------------------------------- /mcl_core/include/mcl_core/mcl_config.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_config.h 3 | * @brief Configuration header of MindConnect Library. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef MCL_CONFIG_H_ 10 | #define MCL_CONFIG_H_ 11 | 12 | #define MCL_LOG_LEVEL_VERBOSE 1 13 | #define MCL_LOG_LEVEL_DEBUG 2 14 | #define MCL_LOG_LEVEL_INFO 3 15 | #define MCL_LOG_LEVEL_WARN 4 16 | #define MCL_LOG_LEVEL_ERROR 5 17 | #define MCL_LOG_LEVEL_FATAL 6 18 | #define MCL_LOG_LEVEL_NONE 0xFF 19 | 20 | /** 21 | * Enable if file system exists. 22 | * It can be overridden by a global preprocessor definition as it is when building with CMake. 23 | */ 24 | #ifndef HAVE_FILE_SYSTEM_ 25 | #ifdef __MBED__ 26 | #define HAVE_FILE_SYSTEM_ 0 27 | #else 28 | #define HAVE_FILE_SYSTEM_ 1 29 | #endif 30 | #endif 31 | 32 | /** 33 | * Select log level for MindConnect Library. 34 | * MCL_LOG_LEVEL_VERBOSE 35 | * MCL_LOG_LEVEL_DEBUG 36 | * MCL_LOG_LEVEL_INFO 37 | * MCL_LOG_LEVEL_WARN 38 | * MCL_LOG_LEVEL_ERROR 39 | * MCL_LOG_LEVEL_FATAL 40 | * MCL_LOG_LEVEL_NONE 41 | * It can be overridden by a global preprocessor definition as it is when building with CMake. 42 | */ 43 | #ifndef MCL_LOG_LEVEL 44 | #define MCL_LOG_LEVEL MCL_LOG_LEVEL_INFO 45 | #endif 46 | 47 | #endif //MCL_CONFIG_H_ 48 | -------------------------------------------------------------------------------- /mcl_core/include/mcl_core/mcl_config_setup.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_config_setup.h 3 | * @brief Configuration setup module interface header file. 4 | * 5 | * Configuration setup header for MCL.\n 6 | * This configuration setup should be used by every module which requires external libraries. 7 | * 8 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 9 | * All rights reserved. 10 | */ 11 | 12 | #ifndef MCL_CONFIG_SETUP_H_ 13 | #define MCL_CONFIG_SETUP_H_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" 17 | { 18 | #endif 19 | 20 | #if (defined(_WIN32) || defined(__WIN32__) || defined(_WIN32_WINNT)) && !defined(WIN32) 21 | #define WIN32 22 | #endif 23 | 24 | #if (defined(_WIN64) || defined(__WIN64__) || defined(_WIN64_WINNT)) && !defined(WIN64) 25 | #define WIN64 26 | #endif 27 | 28 | #ifndef MCL_CORE_EXPORT 29 | #if MCL_STATICLIB 30 | #define MCL_CORE_EXPORT 31 | #elif defined(WIN32) || defined(WIN64) 32 | #if MCL_CORE_BUILD 33 | #define MCL_CORE_EXPORT __declspec(dllexport) 34 | #else 35 | #define MCL_CORE_EXPORT __declspec(dllimport) 36 | #endif 37 | #else 38 | #define MCL_CORE_EXPORT 39 | #endif 40 | #endif 41 | 42 | #ifndef MCL_LOCAL 43 | #if (MCL_STATICLIB || defined(WIN32) || defined(WIN64)) 44 | #define MCL_LOCAL 45 | #else 46 | #define MCL_LOCAL __attribute__ ((visibility ("hidden"))) 47 | #endif 48 | #endif 49 | 50 | #include "mcl_core/mcl_config.h" 51 | #include "mcl_core/mcl_version.h" 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif //MCL_CONFIG_SETUP_H_ 58 | -------------------------------------------------------------------------------- /mcl_core/include/mcl_core/mcl_memory.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_memory.h 3 | * @brief Memory module interface header file. 4 | * 5 | * This module contains functions and macro definitions for memory allocation/deallocation operations. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef MCL_MEMORY_H_ 12 | #define MCL_MEMORY_H_ 13 | 14 | #include "mcl_core/mcl_core_common.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | /** 22 | * This function allocates memory. 23 | * 24 | * @param size Size of the memory to be allocated in bytes. 25 | * @return Pointer to the allocated memory. 26 | */ 27 | extern MCL_CORE_EXPORT void *mcl_memory_malloc(mcl_size_t size); 28 | 29 | /** 30 | * This function allocates memory and sets it to zero. 31 | * 32 | * @param count Number of elements to be allocated. Total memory allocated will be (@p count*@p bytes) 33 | * @param bytes Size of each element in bytes. 34 | * @return Pointer to the allocated memory. 35 | */ 36 | extern MCL_CORE_EXPORT void *mcl_memory_calloc(mcl_size_t count, mcl_size_t bytes); 37 | 38 | /** 39 | * This function reallocates memory. 40 | * 41 | * @param p Pointer to the memory to be reallocated. 42 | * @param bytes Size of the memory to be reallocated in bytes. 43 | * @return Pointer to the reallocated memory. 44 | */ 45 | extern MCL_CORE_EXPORT void *mcl_memory_realloc(void *p, mcl_size_t bytes); 46 | 47 | /** 48 | * This function frees memory. 49 | * 50 | * @param p Pointer to the memory to be freed. 51 | */ 52 | extern MCL_CORE_EXPORT void mcl_memory_free(void *p); 53 | 54 | #define MCL_MALLOC(bytes) mcl_memory_malloc(bytes) 55 | #define MCL_NEW(p) ((p) = MCL_MALLOC((long)sizeof (*p))) 56 | #define MCL_CALLOC(count, bytes) mcl_memory_calloc(count, bytes) 57 | #define MCL_NEW_WITH_ZERO(p) ((p) = MCL_CALLOC(1, (long)sizeof *(p))) 58 | #define MCL_RESIZE(p, bytes) ((p) = mcl_memory_realloc(p, bytes)) 59 | #define MCL_FREE(p) ((void)(mcl_memory_free(p), (p) = NULL)) 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif //MCL_MCL_MEMORY_H_ 66 | -------------------------------------------------------------------------------- /mcl_core/include/mcl_core/mcl_random.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_random.h 3 | * @brief Random module interface header file. 4 | * 5 | * This module includes functions to generate arbitrary size random numbers and GUID. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef MCL_RANDOM_H_ 12 | #define MCL_RANDOM_H_ 13 | 14 | #include "mcl_core/mcl_core_common.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | /** 22 | * This function generates globally unique identifier. 23 | * 24 | * @param [out] guid Random guid. 25 | * @return 26 | * 31 | */ 32 | extern MCL_CORE_EXPORT mcl_error_t mcl_random_generate_guid(char **guid); 33 | 34 | /** 35 | * This function generates random bytes. 36 | * 37 | * @param [out] buffer Array for random bytes. 38 | * @param [in] size Size of array in bytes. 39 | * @return 40 | * 45 | */ 46 | extern MCL_CORE_EXPORT mcl_error_t mcl_random_generate_bytes(unsigned char *buffer, mcl_size_t size); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif //MCL_RANDOM_H_ 53 | -------------------------------------------------------------------------------- /mcl_core/include/mcl_core/mcl_time_util.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_time_util.h 3 | * @brief Time utility module interface header file. 4 | * 5 | * This module provides time utility functions for converting time values 6 | * to ISO 8601 format and validating ISO 8601 formatted timestamps. 7 | * 8 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 9 | * All rights reserved. 10 | */ 11 | 12 | #ifndef MCL_TIME_UTIL_H_ 13 | #define MCL_TIME_UTIL_H_ 14 | 15 | #include "mcl_core/mcl_core_common.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | // yyyy-MM-ddTHH:mm:ss.SSSZ length including null character. 23 | #define MCL_TIMESTAMP_LENGTH 25 24 | 25 | /** 26 | * This function converts time value to ISO 8601 date and time format. 27 | * 28 | * @param [in] time_value Number of seconds passed since reference time. 29 | * @param [in,out] iso8601_formatted_time Time representation in ISO 8601 format, buffer size must be at least MCL_TIMESTAMP_LENGTH. 30 | * @return 31 | * 35 | */ 36 | extern MCL_CORE_EXPORT mcl_error_t mcl_time_util_convert_to_iso_8601_format(const time_t *time_value, char *iso8601_formatted_time); 37 | 38 | /** 39 | * This function validates timestamp in terms of format, length and time value. 40 | * 41 | * @param [in] timestamp Timestamp value to be checked against yyyy-MM-ddTHH:mm:ss.SSSZ format. Ex:2016-04-26T08:06:25.317Z 42 | * @return 43 | * 47 | */ 48 | extern MCL_CORE_EXPORT mcl_bool_t mcl_time_util_validate_timestamp(const char *timestamp); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif //MCL_TIME_UTIL_H_ 55 | -------------------------------------------------------------------------------- /mcl_core/include/mcl_core/mcl_version.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_version.h 3 | * @brief Version header of MindConnect Library. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef MCL_VERSION_H_ 10 | #define MCL_VERSION_H_ 11 | 12 | #define MCL_VERSION_MAJOR 4 13 | #define MCL_VERSION_MINOR 4 14 | #define MCL_VERSION_PATCH 0 15 | 16 | #define MCL_VERSION_NUMBER 0x04040000 17 | #define MCL_VERSION_STRING "4.4.0" 18 | 19 | #endif //MCL_VERSION_H_ 20 | -------------------------------------------------------------------------------- /mcl_core/lib/cJSON/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set sources 2 | ADD_LIBRARY(cJSON OBJECT cJSON.c) 3 | 4 | #PIC option is required in order to build cJSON with shared library target 5 | IF(NOT MCL_STATICLIB) 6 | SET_TARGET_PROPERTIES(cJSON PROPERTIES POSITION_INDEPENDENT_CODE ON FOLDER ${MCL_COMPONENT}) 7 | ENDIF() 8 | -------------------------------------------------------------------------------- /mcl_core/src/core.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file core.h 3 | * @brief Core module header file. 4 | * 5 | * This module implements MCL core interface. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef CORE_H_ 12 | #define CORE_H_ 13 | 14 | #include "core_processor.h" 15 | 16 | /** 17 | * This is the main structure to be used for communication with MindSphere. 18 | */ 19 | typedef struct mcl_core_t 20 | { 21 | core_configuration_t *configuration; //!< Core configuration handle. 22 | core_processor_t *core_processor; //!< Core processor handle. 23 | } core_t; 24 | 25 | #endif //CORE_H_ 26 | -------------------------------------------------------------------------------- /mcl_core/src/core_common.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file core_common.c 3 | * @brief Strings for core error codes. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "core_common.h" 10 | 11 | const char *mcl_core_return_code_strings[MCL_CORE_RETURN_CODE_END] = 12 | { 13 | "MCL_OK", 14 | "MCL_FAIL", 15 | "MCL_TRIGGERED_WITH_NULL", 16 | "MCL_OUT_OF_MEMORY", 17 | "MCL_INVALID_PARAMETER", 18 | "MCL_INVALID_LOG_LEVEL", 19 | "MCL_NO_SERVER_TIME", 20 | "MCL_NO_ACCESS_TOKEN_EXISTS", 21 | "MCL_NO_ACCESS_TOKEN_PROVIDED", 22 | "MCL_NO_FILE_SUPPORT", 23 | "MCL_OPERATION_IS_NOT_SUPPORTED", 24 | "MCL_COULD_NOT_RESOLVE_PROXY", 25 | "MCL_COULD_NOT_RESOLVE_HOST", 26 | "MCL_COULD_NOT_CONNECT", 27 | "MCL_SSL_HANDSHAKE_FAIL", 28 | "MCL_NETWORK_SEND_FAIL", 29 | "MCL_NETWORK_RECEIVE_FAIL", 30 | "MCL_SERVER_CERTIFICATE_NOT_VERIFIED", 31 | "MCL_IMPROPER_CERTIFICATE", 32 | "MCL_REQUEST_TIMEOUT", 33 | "MCL_SERVER_FAIL", 34 | "MCL_CREATED", 35 | "MCL_PARTIAL_CONTENT", 36 | "MCL_BAD_REQUEST", 37 | "MCL_UNAUTHORIZED", 38 | "MCL_FORBIDDEN", 39 | "MCL_NOT_FOUND", 40 | "MCL_CONFLICT", 41 | "MCL_PRECONDITION_FAIL", 42 | "MCL_REQUEST_PAYLOAD_TOO_LARGE", 43 | "MCL_TOO_MANY_REQUESTS", 44 | "MCL_UNEXPECTED_RESULT_CODE", 45 | "MCL_NOT_ONBOARDED", 46 | "MCL_ALREADY_ONBOARDED", 47 | "MCL_EXCHANGE_STREAMING_IS_ACTIVE", 48 | "MCL_CREDENTIALS_UP_TO_DATE", 49 | "MCL_CANNOT_ENTER_CRITICAL_SECTION", 50 | "MCL_BAD_CONTENT_ENCODING", 51 | "MCL_JSON_NON_EXISTING_CHILD", 52 | "MCL_JSON_NAME_DUPLICATION", 53 | "MCL_JSON_TYPE_MISMATCH", 54 | "MCL_SHA256_CALCULATION_FAIL", 55 | "MCL_CREDENTIALS_NOT_SAVED", 56 | "MCL_CREDENTIALS_NOT_LOADED", 57 | "MCL_LIST_IS_EMPTY", 58 | "MCL_LIMIT_EXCEEDED" 59 | }; 60 | -------------------------------------------------------------------------------- /mcl_core/src/core_common.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file core_common.h 3 | * @brief Strings for core error codes. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CORE_COMMON_H_ 10 | #define CORE_COMMON_H_ 11 | 12 | #include "mcl_core/mcl_core_common.h" 13 | 14 | #endif //CORE_COMMON_H_ 15 | -------------------------------------------------------------------------------- /mcl_core/src/crypto/mbedtls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FIND_PATH(MBEDTLS_INCLUDE_PATH "mbedtls/version.h") 2 | FIND_LIBRARY(MBEDTLS_LIBRARY "mbedtls") 3 | FIND_LIBRARY(MBEDCRYPTO_LIBRARY "mbedcrypto") 4 | 5 | MESSAGE(STATUS "mbedTLS Path: ${MBEDTLS_INCLUDE_PATH}") 6 | 7 | #MCL needs just these three to be set in PARENT_SCOPE. 8 | SET(MCL_CRYPTO_INCLUDE_DIRECTORIES ${MBEDTLS_INCLUDE_PATH} PARENT_SCOPE) 9 | SET(MCL_CRYPTO_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDCRYPTO_LIBRARY} PARENT_SCOPE) 10 | SET(MCL_CRYPTO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/security_mbedtls.c" PARENT_SCOPE) -------------------------------------------------------------------------------- /mcl_core/src/crypto/mbedtls/security_mbedtls.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file security_mbedtls.c 3 | * @brief Security module implementation file. 4 | * 5 | * @copyright Copyright (C) 2020 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "mcl_core/mcl_assert.h" 10 | #include "mcl_core/mcl_memory.h" 11 | #include "mbedtls/sha256.h" 12 | #include "mbedtls/entropy.h" 13 | #include "mbedtls/ctr_drbg.h" 14 | 15 | #define SHA256_DIGEST_LENGTH 32 16 | 17 | #define KEY_LENGTH_BITS 3072 18 | 19 | static mbedtls_entropy_context entropy; 20 | static mbedtls_ctr_drbg_context ctr_drbg; 21 | static mcl_bool_t is_initialized = MCL_FALSE; 22 | 23 | #ifdef MBEDTLS_ENTROPY_HARDWARE_ALT 24 | extern int mbedtls_hardware_poll( void *data, unsigned char *output, size_t len, size_t *olen ); 25 | #endif 26 | 27 | mcl_error_t security_initialize(void) 28 | { 29 | MCL_DEBUG_ENTRY("void"); 30 | 31 | if(!is_initialized) 32 | { 33 | mbedtls_entropy_init(&entropy); 34 | #ifdef MBEDTLS_ENTROPY_HARDWARE_ALT 35 | (void) mbedtls_entropy_add_source(&entropy, mbedtls_hardware_poll, (void*)NULL, 1, MBEDTLS_ENTROPY_SOURCE_STRONG); 36 | #endif 37 | (void) mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, MCL_NULL, 0); 38 | is_initialized = MCL_TRUE; 39 | } 40 | 41 | MCL_DEBUG_LEAVE("retVal = <%d>", MCL_OK); 42 | return MCL_OK; 43 | } 44 | 45 | mcl_error_t security_hash_sha256(const mcl_uint8_t *data, mcl_size_t data_size, mcl_uint8_t **hash, mcl_size_t *hash_size) 46 | { 47 | mcl_error_t code = MCL_OK; 48 | 49 | MCL_DEBUG_ENTRY("const mcl_uint8_t *data = <%p>, mcl_size_t data_size = <%u>, mcl_uint8_t **hash = <%p>, mcl_size_t *hash_size = <%p>", data, data_size, hash, hash_size); 50 | 51 | *hash_size = 0; 52 | 53 | // Allocate memory to store SHA256 result. 54 | *hash = MCL_CALLOC(1, SHA256_DIGEST_LENGTH); 55 | 56 | if (MCL_NULL == *hash) 57 | { 58 | code = MCL_OUT_OF_MEMORY; 59 | } 60 | else 61 | { 62 | *hash_size = SHA256_DIGEST_LENGTH; 63 | 64 | // Perform SHA256 calculation. 65 | MCL_DEBUG("Calculating SHA256 with mbedTLS."); 66 | mbedtls_sha256(data, data_size, *hash, 0); 67 | } 68 | 69 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 70 | return code; 71 | } 72 | 73 | mcl_error_t security_rsa_sign(char *rsa_key, char *data, mcl_size_t data_size, mcl_uint8_t **signature, mcl_size_t *signature_size) 74 | { 75 | return MCL_FAIL; 76 | } 77 | 78 | mcl_error_t security_generate_rsa_key(char **public_key, char **private_key) 79 | { 80 | return MCL_FAIL; 81 | } 82 | 83 | mcl_error_t security_rsa_get_modulus_and_exponent(char *public_key, char **modulus, char **exponent) 84 | { 85 | return MCL_FAIL; 86 | } 87 | 88 | mcl_error_t security_generate_random_bytes(unsigned char *buffer, mcl_size_t size) 89 | { 90 | mcl_error_t code = MCL_FAIL; 91 | 92 | if(is_initialized) 93 | { 94 | code = (0 == mbedtls_ctr_drbg_random(&ctr_drbg, buffer, size)) ? MCL_OK : MCL_FAIL; 95 | } 96 | 97 | return code; 98 | } 99 | -------------------------------------------------------------------------------- /mcl_core/src/crypto/openssl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(OPENSSL_VERSION_NUMBER_REQUIRED 3.0.13) 2 | 3 | #Try to find OpenSSL. 4 | FIND_PACKAGE(OpenSSL) 5 | IF(NOT OPENSSL_FOUND) 6 | MESSAGE(FATAL_ERROR "OpenSSL not found") 7 | ENDIF() 8 | 9 | #Verify OpenSSL version 10 | STRING(REGEX MATCH "[0-9]+[.][0-9]+[.][0-9]+" OPENSSL_VERSION_NUMBER ${OPENSSL_VERSION}) 11 | IF((OPENSSL_VERSION_NUMBER VERSION_LESS OPENSSL_VERSION_NUMBER_REQUIRED)) 12 | MESSAGE(FATAL_ERROR "Found OpenSSL version ${OPENSSL_VERSION} but version ${OPENSSL_VERSION_NUMBER_REQUIRED} or later is required.") 13 | ENDIF() 14 | 15 | SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) 16 | CHECK_INCLUDE_FILE("openssl/rsa.h" HAVE_OPENSSL_RSA_H_) 17 | CHECK_INCLUDE_FILE("openssl/md5.h" HAVE_OPENSSL_MD5_H_) 18 | CHECK_INCLUDE_FILE("openssl/sha.h" HAVE_OPENSSL_SHA_H_) 19 | CHECK_INCLUDE_FILE("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H_) 20 | CHECK_INCLUDE_FILE("openssl/rand.h" HAVE_OPENSSL_RAND_H_) 21 | CHECK_INCLUDE_FILE("openssl/bn.h" HAVE_OPENSSL_BN_H_) 22 | CHECK_INCLUDE_FILE("openssl/bio.h" HAVE_OPENSSL_BIO_H_) 23 | CHECK_INCLUDE_FILE("openssl/pem.h" HAVE_OPENSSL_PEM_H_) 24 | 25 | IF(NOT (HAVE_OPENSSL_RSA_H_ AND 26 | HAVE_OPENSSL_MD5_H_ AND 27 | HAVE_OPENSSL_SHA_H_ AND 28 | HAVE_OPENSSL_CRYPTO_H_ AND 29 | HAVE_OPENSSL_RAND_H_ AND 30 | HAVE_OPENSSL_BN_H_ AND 31 | HAVE_OPENSSL_BIO_H_ AND 32 | HAVE_OPENSSL_PEM_H_)) 33 | MESSAGE(FATAL_ERROR "Not found required header file.") 34 | ENDIF() 35 | 36 | #MCL needs just these three to be set in PARENT_SCOPE. 37 | #You may use FIND_PACKAGE like in this case or just manually set. 38 | SET(MCL_CRYPTO_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) 39 | SET(MCL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY} PARENT_SCOPE) 40 | SET(MCL_CRYPTO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/security_libcrypto.c" PARENT_SCOPE) 41 | 42 | IF(WIN32 OR WIN64) 43 | #This is not needed for compiling, you can manually copy dlls when needed. 44 | #Also if you are using static library, there is no need to set MCL_CRYPTO_DLLS. 45 | GET_FILENAME_COMPONENT(OPENSSL_LIBRARY_FOLDER ${OPENSSL_CRYPTO_LIBRARY} DIRECTORY) 46 | GET_FILENAME_COMPONENT(OPENSSL_FOLDER ${OPENSSL_LIBRARY_FOLDER} DIRECTORY) 47 | FILE(GLOB_RECURSE OPENSSL_CRYPTO_DLL ${OPENSSL_FOLDER}/libcrypto*.dll) 48 | SET(MCL_CRYPTO_DLLS ${OPENSSL_CRYPTO_DLL} PARENT_SCOPE) 49 | ENDIF() 50 | -------------------------------------------------------------------------------- /mcl_core/src/crypto/openssl/security_libcrypto.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file security_libcrypto.h 3 | * @brief Security libcrypto module header file. 4 | * 5 | * Libcrypto based implementation of security interface. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef SECURITY_LIBCRYPTO_H_ 12 | #define SECURITY_LIBCRYPTO_H_ 13 | 14 | #include "security.h" 15 | 16 | #endif //SECURITY_LIBCRYPTO_H_ 17 | -------------------------------------------------------------------------------- /mcl_core/src/definitions.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file definitions.h 3 | * @brief Definitions module header file. 4 | * 5 | * General definitions are stored in this header file. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef DEFINITIONS_H_ 12 | #define DEFINITIONS_H_ 13 | 14 | #define NONCE_SIZE 16 15 | 16 | #define DEFAULT_META_TYPE_SIZE 6 17 | #define DEFAULT_PAYLOAD_TYPE_SIZE 20 18 | #define DEFAULT_QUALITY_CODE_SIZE 9 19 | #define DEFAULT_DATE_SIZE 23 20 | #define DEFAULT_TIMESTAMP_SIZE 25 21 | #define DEFAULT_ID_SIZE 37 22 | #define DEFAULT_VALUES_COUNT 5 23 | 24 | #define MAXIMUM_HOST_NAME_LENGTH 256 25 | #define MAXIMUM_PROXY_USER_NAME_LENGTH 32 26 | #define MAXIMUM_PROXY_PASSWORD_LENGTH 32 27 | #define MAXIMUM_PROXY_DOMAIN_LENGTH 256 28 | #define MAXIMUM_USER_AGENT_LENGTH 512 29 | 30 | // 300 seconds is default http request timeout value. 31 | #define DEFAULT_HTTP_REQUEST_TIMEOUT (300) 32 | 33 | // JWT used in authorization header has an expiration time of 24 hours. 34 | #define JWT_EXPIRATION_TIME 86400 35 | 36 | #endif //DEFINITIONS_H_ 37 | -------------------------------------------------------------------------------- /mcl_core/src/file_util/standard/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #MCL needs just these three to be set in PARENT_SCOPE. 3 | SET(MCL_FILE_UTIL_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) 4 | SET(MCL_FILE_UTIL_LIBRARIES "" PARENT_SCOPE) 5 | SET(MCL_FILE_UTIL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/file_util.c" PARENT_SCOPE) 6 | -------------------------------------------------------------------------------- /mcl_core/src/file_util/standard/file_util.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file file_util.h 3 | * @brief File utility module header file. 4 | * 5 | * This utility includes the functions for file handling. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef FILE_UTIL_H_ 12 | #define FILE_UTIL_H_ 13 | 14 | #include "mcl_core/mcl_file_util.h" 15 | 16 | #endif //FILE_UTIL_H_ 17 | -------------------------------------------------------------------------------- /mcl_core/src/hmac.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file hmac.h 3 | * @brief HMAC module header file. 4 | * 5 | * This module defines several hashing functions required by other modules. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef HMAC_H_ 12 | #define HMAC_H_ 13 | 14 | #include "mcl_core/mcl_core_common.h" 15 | 16 | /** 17 | * This function is used for calculating HMAC SHA256 for given data with provided secret @p key. 18 | * If secret @p key exceeds maximum allowed size of 64 bytes it will be reduced to 32 bytes. 19 | * The reduction is done by calculating SHA256 hash of the key, which returns 32 bytes. 20 | * 21 | * @param [in] data Data to calculate HMAC SHA256 for. 22 | * @param [in] data_size Size of @p data. 23 | * @param [in] key Secret key to be used during calculation. 24 | * @param [in] key_size Size of @p key. 25 | * @param [out] hash A newly allocated memory which contains the result of HMAC SHA256. 26 | * @param [out] hash_size Size of @p hash, which should be 32 bytes after SHA256 calculation. 27 | * @return 28 | * 34 | */ 35 | MCL_LOCAL mcl_error_t hmac_sha256(const mcl_uint8_t *data, mcl_size_t data_size, const mcl_uint8_t *key, mcl_size_t key_size, 36 | mcl_uint8_t **hash, mcl_size_t *hash_size); 37 | 38 | #endif //HMAC_H_ 39 | -------------------------------------------------------------------------------- /mcl_core/src/http_client/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | MESSAGE(FATAL_ERROR "MCL implementation can only be used with tls socket implementation.") -------------------------------------------------------------------------------- /mcl_core/src/http_client/basic/http_client_basic.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file http_client_basic.h 3 | * @brief Basic HTTP client module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef HTTP_CLIENT_BASIC_H_ 10 | #define HTTP_CLIENT_BASIC_H_ 11 | 12 | #include "mcl_core/mcl_http_client.h" 13 | #include "mcl_tls_socket.h" 14 | 15 | typedef struct mcl_http_client_t 16 | { 17 | mcl_tls_ca_chain_handle certificate_chain; 18 | const char *user_agent; 19 | mcl_uint16_t port; 20 | mcl_size_t timeout; 21 | } mcl_http_client_t; 22 | 23 | #endif //HTTP_CLIENT_BASIC_H_ 24 | -------------------------------------------------------------------------------- /mcl_core/src/http_client/basic/mbedtls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FIND_PATH(MBEDTLS_INCLUDE_PATH "mbedtls/version.h") 2 | FIND_LIBRARY(MBEDTLS_LIBRARY "mbedtls") 3 | FIND_LIBRARY(MBEDX509_LIBRARY "mbedx509") 4 | 5 | MESSAGE(STATUS "mbedTLS Path: ${MBEDTLS_INCLUDE_PATH}") 6 | 7 | GET_FILENAME_COMPONENT(HTTP_CLIENT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) 8 | 9 | #MCL needs just these three to be set in PARENT_SCOPE. 10 | SET(MCL_HTTP_CLIENT_INCLUDE_DIRECTORIES ${MBEDTLS_INCLUDE_PATH} "${HTTP_CLIENT_DIRECTORY}" PARENT_SCOPE) 11 | SET(MCL_HTTP_CLIENT_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} PARENT_SCOPE) 12 | SET(MCL_HTTP_CLIENT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tls_socket_mbedtls.c" "${HTTP_CLIENT_DIRECTORY}/http_client_basic.c" PARENT_SCOPE) -------------------------------------------------------------------------------- /mcl_core/src/http_client/curl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(CURL_VERSION_REQUIRED 8.6.0) 2 | 3 | #Try to find libcurl. 4 | FIND_PACKAGE(CURL) 5 | IF(CURL_FOUND) 6 | #OpenSSL may be already found. 7 | IF(NOT OPENSSL_FOUND) 8 | FIND_PACKAGE(OpenSSL) 9 | IF(NOT OPENSSL_FOUND) 10 | MESSAGE(FATAL_ERROR "libcurl needs OpenSSL!") 11 | ENDIF() 12 | ENDIF() 13 | ELSE() 14 | MESSAGE(FATAL_ERROR "Not found libcurl!") 15 | ENDIF() 16 | 17 | #Check version 18 | IF(CURL_VERSION_STRING VERSION_LESS CURL_VERSION_REQUIRED) 19 | MESSAGE(FATAL_ERROR "Found libcurl version ${CURL_VERSION_STRING} but version ${CURL_VERSION_REQUIRED} is required.") 20 | ELSE() 21 | MESSAGE(STATUS "Found libcurl version ${CURL_VERSION_STRING}.") 22 | ENDIF() 23 | 24 | SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) 25 | CHECK_INCLUDE_FILE("openssl/ssl.h" HAVE_OPENSSL_SSL_H_) 26 | 27 | IF(NOT HAVE_OPENSSL_SSL_H_) 28 | MESSAGE(FATAL_ERROR "Not found required header file.") 29 | ENDIF() 30 | 31 | #MCL needs just these three to be set in PARENT_SCOPE. 32 | #You may use FIND_PACKAGE like in this case or just manually set. 33 | SET(MCL_HTTP_CLIENT_INCLUDE_DIRECTORIES ${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) 34 | SET(MCL_HTTP_CLIENT_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} PARENT_SCOPE) 35 | SET(MCL_HTTP_CLIENT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/http_client_libcurl.c" PARENT_SCOPE) 36 | 37 | IF(WIN32 OR WIN64) 38 | #This is not needed for compiling, you can manually copy dlls when needed. 39 | #Also if you are using static library, there is no need to set MCL_HTTP_CLIENT_DLLS. 40 | LIST(GET CURL_LIBRARIES 0 CURL_LIBRARY) 41 | GET_FILENAME_COMPONENT(CURL_LIBRARY_FOLDER ${CURL_LIBRARY} DIRECTORY) 42 | GET_FILENAME_COMPONENT(CURL_FOLDER ${CURL_LIBRARY_FOLDER} DIRECTORY) 43 | FILE(GLOB_RECURSE LIBCURL_DLL ${CURL_FOLDER}/libcurl*.dll) 44 | 45 | GET_FILENAME_COMPONENT(OPENSSL_LIBRARY_FOLDER ${OPENSSL_CRYPTO_LIBRARY} DIRECTORY) 46 | GET_FILENAME_COMPONENT(OPENSSL_FOLDER ${OPENSSL_LIBRARY_FOLDER} DIRECTORY) 47 | FILE(GLOB_RECURSE OPENSSL_CRYPTO_DLL ${OPENSSL_FOLDER}/libcrypto*.dll) 48 | FILE(GLOB_RECURSE OPENSSL_SSL_DLL ${OPENSSL_FOLDER}/libssl*.dll) 49 | SET(MCL_HTTP_CLIENT_DLLS ${LIBCURL_DLL} ${OPENSSL_CRYPTO_DLL} ${OPENSSL_SSL_DLL} PARENT_SCOPE) 50 | ENDIF() 51 | -------------------------------------------------------------------------------- /mcl_core/src/http_client/curl/http_client_libcurl.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file http_client_libcurl.h 3 | * @brief HTTP client libcurl module header file. 4 | * 5 | * Implements the functions defined in http_client.h file. This implementation actively uses "libcurl" for HTTP Send/Receive operations. 6 | * For targets in which libcurl cannot be used, another implementation file should be created to implement the http_client.h functions. 7 | * 8 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 9 | * All rights reserved. 10 | */ 11 | 12 | #ifndef HTTP_CLIENT_LIBCURL_H_ 13 | #define HTTP_CLIENT_LIBCURL_H_ 14 | 15 | #include "mcl_core/mcl_http_client.h" 16 | 17 | // If you want to use libcurl as static library, define CURL_STATICLIB before including curl.h otherwise linker won't be able to find __impl_* functions 18 | 19 | #include "curl/curl.h" 20 | 21 | #define SSL_CERTIFICATE_TYPE_PEM "PEM" 22 | 23 | struct mcl_http_client_t 24 | { 25 | CURL *curl; //!< Curl handle. 26 | mcl_list_t *certificates; //!< List of server certificates. 27 | }; 28 | 29 | #endif //HTTP_CLIENT_LIBCURL_H_ 30 | -------------------------------------------------------------------------------- /mcl_core/src/http_definitions.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file http_definitions.c 3 | * @brief HTTP definitions module implementation file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "http_definitions.h" 10 | #include "definitions.h" 11 | 12 | const char *http_header_names[HTTP_HEADER_NAMES_END] = 13 | { 14 | "Authorization", 15 | "Content-Type", 16 | "Content-ID", 17 | "Content-Length", 18 | "Transfer-Encoding", 19 | "Transfer-Encoding: chunked", 20 | "User-Agent", 21 | "Accept", 22 | "Host", 23 | "Content-Disposition", 24 | "Range", 25 | "Content-Range", 26 | "Server-Time", 27 | "If-Match", 28 | "ETag", 29 | "Correlation-ID" 30 | }; 31 | -------------------------------------------------------------------------------- /mcl_core/src/http_definitions.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file http_definitions.h 3 | * @brief HTTP definitions module header file. 4 | * 5 | * This module contains general definitions used for HTTP. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef HTTP_DEFINITIONS_H_ 12 | #define HTTP_DEFINITIONS_H_ 13 | 14 | /** 15 | * @brief Used with http_header_names[E_HTTP_HEADER_NAMES] to get the related string. 16 | * ex: http_header_names[HTTP_HEADER_AUTHORIZATION] returns the string of "Authorization". 17 | */ 18 | typedef enum E_HTTP_HEADER_NAMES 19 | { 20 | HTTP_HEADER_AUTHORIZATION, //!< Http authorization header. 21 | HTTP_HEADER_CONTENT_TYPE, //!< Http content type header. 22 | HTTP_HEADER_CONTENT_ID, //!< Http content id header. 23 | HTTP_HEADER_CONTENT_LENGTH, //!< Length of http content header. 24 | HTTP_HEADER_TRANSFER_ENCODING, //!< Http transfer encoding header. 25 | HTTP_HEADER_TRANSFER_ENCODING_CHUNKED, //!< Http transfer encoding chunked header. 26 | HTTP_HEADER_USER_AGENT, //!< Http user agent header. 27 | HTTP_HEADER_ACCEPT, //!< Http accept header. 28 | HTTP_HEADER_HOST, //!< Http host header. 29 | HTTP_HEADER_RANGE, //!< Http range header. 30 | HTTP_HEADER_CONTENT_RANGE, //!< Http content range header. 31 | HTTP_HEADER_CONTENT_DISPOSITION, //!< Http content disposition header. 32 | HTTP_HEADER_SERVER_TIME, //!< Server-Time header name. 33 | HTTP_HEADER_IF_MATCH, //!< Http If-Match header name. 34 | HTTP_HEADER_ETAG, //!< Http Etag header name. 35 | HTTP_HEADER_CORRELATION_ID, //!< Http Correlation-ID header name. 36 | HTTP_HEADER_NAMES_END //!< End of http header names. 37 | } E_HTTP_HEADER_NAMES; 38 | 39 | extern const char *http_header_names[HTTP_HEADER_NAMES_END]; 40 | 41 | #endif //HTTP_DEFINITIONS_H_ 42 | -------------------------------------------------------------------------------- /mcl_core/src/http_request.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file http_request.h 3 | * @brief HTTP request module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef HTTP_REQUEST_H_ 10 | #define HTTP_REQUEST_H_ 11 | 12 | #include "mcl_core/mcl_http_request.h" 13 | 14 | #endif //HTTP_REQUEST_H_ 15 | -------------------------------------------------------------------------------- /mcl_core/src/http_response.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file http_response.h 3 | * @brief HTTP response module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef HTTP_RESPONSE_H_ 10 | #define HTTP_RESPONSE_H_ 11 | 12 | #include "mcl_core/mcl_http_response.h" 13 | 14 | #endif //HTTP_RESPONSE_H_ 15 | -------------------------------------------------------------------------------- /mcl_core/src/jwt.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file jwt.h 3 | * @brief JWT module header file. 4 | * 5 | * This module is used to generate JWT. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef JWT_H_ 12 | #define JWT_H_ 13 | 14 | #include "security_handler.h" 15 | #include "json_util.h" 16 | 17 | /** 18 | * Handle for JWT. 19 | */ 20 | typedef struct jwt_t 21 | { 22 | mcl_json_t *header; //!< Header of JWT. 23 | mcl_json_t *payload; //!< Payload of JWT. 24 | security_handler_t *security_handler; //!< Security handler. 25 | E_MCL_SECURITY_PROFILE security_profile; //!< Security profile. 26 | mcl_time_t issued_at; //!< Time of issue. 27 | } jwt_t; 28 | 29 | /** 30 | * This function creates and initializes a data struct of #jwt_t. 31 | * @param [in] security_handler Already initialized security handler. All JWT operations will be done using this object. 32 | * @param [in] security_profile Onboarding security profile. 33 | * @param [in] tenant Tenant which will be set in JWT payload. 34 | * @param [out] jwt The newly initialized jwt handle. 35 | * @return 36 | * 41 | */ 42 | MCL_LOCAL mcl_error_t jwt_initialize(security_handler_t *security_handler, E_MCL_SECURITY_PROFILE security_profile, char *tenant, jwt_t **jwt); 43 | 44 | /** 45 | * This function is used to generate the JWT as json string. 46 | * 47 | * @param [in] jwt JWT handle. 48 | * @return Pointer to the JWT of type char or NULL in case of an error. 49 | */ 50 | MCL_LOCAL char *jwt_get_token(jwt_t *jwt); 51 | 52 | /** 53 | * This function destroys #jwt_t data structure. 54 | * 55 | * @param [in] jwt JWT handle which is going to be destroyed. 56 | */ 57 | MCL_LOCAL void jwt_destroy(jwt_t **jwt); 58 | 59 | #endif //JWT_H_ 60 | -------------------------------------------------------------------------------- /mcl_core/src/list.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file list.h 3 | * @brief List module header file. 4 | * 5 | * This module is used for double linked list handling. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef LIST_H_ 12 | #define LIST_H_ 13 | 14 | #include "mcl_core/mcl_list.h" 15 | 16 | #endif //LIST_H_ 17 | -------------------------------------------------------------------------------- /mcl_core/src/log_util.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file log_util.c 3 | * @brief Log utility module implementation file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "log_util.h" 10 | #include "mcl_core/mcl_assert.h" 11 | #include 12 | #include 13 | 14 | #if !MCL_LOG_DISABLED 15 | 16 | static void _mcl_log_util_default_callback(void *user_context, int log_level, const char *file, int line, const char *tag, const char * const format, ...); 17 | static int _mcl_log_level = MCL_LOG_LEVEL; 18 | 19 | mcl_log_util_callback_t mcl_log_util_function = _mcl_log_util_default_callback; 20 | void *mcl_log_util_user_context = NULL; 21 | 22 | static const char *_mcl_level_strings[] = 23 | { 24 | "VERBOSE", 25 | "DEBUG", 26 | "INFO", 27 | "WARN", 28 | "ERROR", 29 | "FATAL" 30 | }; 31 | #endif 32 | 33 | mcl_error_t mcl_log_util_set_output_level(const int log_level) 34 | { 35 | #if !MCL_LOG_DISABLED 36 | if (((MCL_LOG_LEVEL <= log_level) && (log_level <= MCL_LOG_LEVEL_FATAL)) || (MCL_LOG_LEVEL_NONE == log_level)) 37 | { 38 | _mcl_log_level = log_level; 39 | return MCL_OK; 40 | } 41 | #else 42 | if (MCL_LOG_LEVEL_NONE == log_level) 43 | { 44 | return MCL_OK; 45 | } 46 | #endif 47 | 48 | return MCL_INVALID_LOG_LEVEL; 49 | } 50 | 51 | int mcl_log_util_get_output_level(void) 52 | { 53 | #if !MCL_LOG_DISABLED 54 | return _mcl_log_level; 55 | #else 56 | return MCL_LOG_LEVEL_NONE; 57 | #endif 58 | } 59 | 60 | mcl_error_t mcl_log_util_set_callback(mcl_log_util_callback_t callback, void *user_context) 61 | { 62 | #if !MCL_LOG_DISABLED 63 | mcl_error_t code = MCL_OK; 64 | 65 | MCL_DEBUG_ENTRY("mcl_log_util_callback_t callback = <%p>, void *user_context = <%p>", callback, user_context); 66 | 67 | MCL_ASSERT_NOT_NULL(callback, code); 68 | 69 | mcl_log_util_function = callback; 70 | mcl_log_util_user_context = user_context; 71 | 72 | MCL_FUNCTION_LEAVE_LABEL: 73 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 74 | return code; 75 | #else 76 | return MCL_FAIL; 77 | #endif 78 | } 79 | 80 | #if !MCL_LOG_DISABLED 81 | static void _mcl_log_util_default_callback(void *user_context, int log_level, const char *file, int line, const char *tag, const char * const format, ...) 82 | { 83 | va_list args; 84 | va_start(args, format); 85 | 86 | // user_context will not be used. 87 | (void) user_context; 88 | 89 | #if defined(WIN32) || defined(WIN64) 90 | printf_s("MCL | %s | %s | %d | %s | ", _mcl_level_strings[log_level - MCL_LOG_LEVEL_VERBOSE], file, line, tag); 91 | vprintf_s(format, args); 92 | putchar('\r'); 93 | #else 94 | printf("MCL | %s | %s | %d | %s | ", _mcl_level_strings[log_level - MCL_LOG_LEVEL_VERBOSE], file, line, tag); 95 | vprintf(format, args); 96 | #endif 97 | 98 | putchar('\n'); 99 | va_end(args); 100 | } 101 | #endif 102 | -------------------------------------------------------------------------------- /mcl_core/src/log_util.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file log_util.h 3 | * @brief Log utility module header file. 4 | * 5 | * This utility module defines macros and functions for logging purposes. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef LOG_UTIL_H_ 12 | #define LOG_UTIL_H_ 13 | 14 | #include "mcl_core/mcl_log_util.h" 15 | 16 | #endif //LOG_UTIL_H_ 17 | -------------------------------------------------------------------------------- /mcl_core/src/memory/standard/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #MCL needs just these three to be set in PARENT_SCOPE. 3 | SET(MCL_MEMORY_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) 4 | SET(MCL_MEMORY_LIBRARIES "" PARENT_SCOPE) 5 | SET(MCL_MEMORY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/memory.c" PARENT_SCOPE) 6 | -------------------------------------------------------------------------------- /mcl_core/src/memory/standard/memory.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file memory.c 3 | * @brief Memory module implementation file. 4 | * 5 | * This module implements mcl_core/mcl_memory.h interface with standard C library. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #include "memory.h" 12 | #include 13 | 14 | void *mcl_memory_malloc(mcl_size_t size) 15 | { 16 | if (0 == size) 17 | { 18 | return NULL; 19 | } 20 | 21 | return malloc(size); 22 | } 23 | 24 | void *mcl_memory_calloc(mcl_size_t count, mcl_size_t bytes) 25 | { 26 | if ((0 == count) || (0 == bytes)) 27 | { 28 | return NULL; 29 | } 30 | 31 | return calloc(count, bytes); 32 | } 33 | 34 | void *mcl_memory_realloc(void *p, mcl_size_t bytes) 35 | { 36 | if (0 == bytes) 37 | { 38 | free(p); 39 | return NULL; 40 | } 41 | 42 | return realloc(p, bytes); 43 | } 44 | 45 | void mcl_memory_free(void *p) 46 | { 47 | free(p); 48 | } 49 | -------------------------------------------------------------------------------- /mcl_core/src/memory/standard/memory.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file memory.h 3 | * @brief Memory module header file. 4 | * 5 | * This module contains functions for memory allocation/deallocation operations. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef MEMORY_H_ 12 | #define MEMORY_H_ 13 | 14 | #include "mcl_core/mcl_memory.h" 15 | 16 | #endif //MEMORY_H_ 17 | -------------------------------------------------------------------------------- /mcl_core/src/random.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file random.h 3 | * @brief Random module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef RANDOM_H_ 10 | #define RANDOM_H_ 11 | 12 | #include "mcl_core/mcl_core_common.h" 13 | 14 | /** 15 | * This function generates random integer number. 16 | * 17 | * @param [out] random_number Pointer to the random number generated. 18 | * @return 19 | *
    20 | *
  • #MCL_OK in case of success.
  • 21 | *
  • #MCL_FAIL in case of an internal error in random number generation.
  • 22 | *
23 | */ 24 | MCL_LOCAL mcl_error_t random_generate_number(mcl_uint32_t *random_number); 25 | 26 | /** 27 | * This function generates random guid. 28 | * 29 | * @param [out] guid Random guid. 30 | * @return 31 | *
    32 | *
  • #MCL_OK in case of success.
  • 33 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 34 | *
  • #MCL_FAIL in case of an internal error in random number generation.
  • 35 | *
36 | */ 37 | MCL_LOCAL mcl_error_t random_generate_guid(char **guid); 38 | 39 | #endif //RANDOM_H_ 40 | -------------------------------------------------------------------------------- /mcl_core/src/time_util.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file time_util.h 3 | * @brief Time utility module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef TIME_UTIL_H_ 10 | #define TIME_UTIL_H_ 11 | 12 | #include 13 | #include "mcl_core/mcl_core_common.h" 14 | 15 | /** 16 | * This function returns the time elapsed in terms of seconds since Jan 1, 1970 UTC until now. 17 | * 18 | * @param [in] current_time Time value in seconds. 19 | */ 20 | MCL_LOCAL void time_util_get_time(mcl_time_t *current_time); 21 | 22 | #endif //TIME_UTIL_H_ 23 | -------------------------------------------------------------------------------- /mcl_core/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(lib/CMock) 2 | ADD_SUBDIRECTORY(integration) 3 | ADD_SUBDIRECTORY(unit) -------------------------------------------------------------------------------- /mcl_core/test/integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set name of the test framework. 2 | SET(TEST_FRAMEWORK unity_and_cmock) 3 | 4 | #Set paths. 5 | SET(INTEGRATION_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") 6 | SET(TEST_RUNNER_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testrunner") 7 | SET(GENERATE_TEST_RUNNER_SCRIPT_PATH "mcl_core/test/lib/CMock/vendor/unity/auto/generate_test_runner.rb") 8 | 9 | #Set Ruby Command. 10 | SET(RUBY_CMD "ruby") 11 | 12 | #Create test runner directory. 13 | FILE(MAKE_DIRECTORY ${TEST_RUNNER_DIRECTORY}) 14 | 15 | #Loop over each integration test file. 16 | FILE(GLOB INTEGRATION_TEST_FILE_LIST RELATIVE "${INTEGRATION_TEST_DIRECTORY}" "${INTEGRATION_TEST_DIRECTORY}/*.c") 17 | FOREACH(INTEGRATION_TEST_FILE ${INTEGRATION_TEST_FILE_LIST}) 18 | 19 | #Remove file extension from the testcase file 20 | STRING(REPLACE ".c" "" INTEGRATION_TEST_FILE_NAME ${INTEGRATION_TEST_FILE}) 21 | 22 | #Create test runner. 23 | SET(TEST_RUNNER_FILE "${INTEGRATION_TEST_FILE_NAME}_runner.c") 24 | EXECUTE_PROCESS(COMMAND ${RUBY_CMD} ${GENERATE_TEST_RUNNER_SCRIPT_PATH} "${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE}" "${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}" 25 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 26 | RESULT_VARIABLE ruby_result 27 | OUTPUT_VARIABLE ruby_output) 28 | 29 | #Set test source files. 30 | SET(TEST_SOURCES ${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE} ${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}) 31 | 32 | #Set the name of the test executable. 33 | SET(INTEGRATION_TEST_NAME "${INTEGRATION_TEST_FILE_NAME}") 34 | 35 | #Create integration test executable. 36 | ADD_EXECUTABLE(${INTEGRATION_TEST_NAME} ${TEST_SOURCES} ) 37 | 38 | #Link libraries to executable. 39 | TARGET_LINK_LIBRARIES(${INTEGRATION_TEST_NAME} ${MCL_CORE_LIBS} ${PROJECT_LIBRARY_OUTPUT} ${TEST_FRAMEWORK}) 40 | 41 | #Include required directories 42 | TARGET_INCLUDE_DIRECTORIES(${INTEGRATION_TEST_NAME} PUBLIC ${MCL_CORE_INCLUDE_DIRECTORIES}) 43 | 44 | ADD_TEST(${INTEGRATION_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${INTEGRATION_TEST_NAME}) 45 | 46 | SET_TARGET_PROPERTIES(${INTEGRATION_TEST_NAME} PROPERTIES FOLDER "${MCL_COMPONENT}/integration_tests") 47 | 48 | ENDFOREACH(INTEGRATION_TEST_FILE) 49 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(unity_and_cmock STATIC "./src/cmock.c" "./vendor/unity/src/unity.c") 2 | 3 | target_include_directories(unity_and_cmock PUBLIC src vendor/unity/src) -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org/" 2 | 3 | gem "bundler", "~> 1.1.rc.7" 4 | gem "rake", ">= 0.9.2.2" 5 | 6 | gem "minitest" 7 | gem "require_all" 8 | gem "constructor" 9 | gem "diy" 10 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/config/production_environment.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | # Setup our load path: 8 | [ 9 | 'lib', 10 | ].each do |dir| 11 | $LOAD_PATH.unshift( File.join( File.expand_path(File.dirname(__FILE__)) + '/../', dir) ) 12 | end 13 | 14 | 15 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/config/test_environment.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | # Setup our load path: 8 | [ 9 | 'lib', 10 | 'vendor/behaviors/lib', 11 | 'vendor/hardmock/lib', 12 | 'vendor/unity/auto/', 13 | 'test/system/' 14 | ].each do |dir| 15 | $LOAD_PATH.unshift( File.join( File.expand_path(File.dirname(__FILE__) + "/../"), dir) ) 16 | end 17 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | [ "../config/production_environment", 8 | "cmock_header_parser", 9 | "cmock_generator", 10 | "cmock_file_writer", 11 | "cmock_config", 12 | "cmock_plugin_manager", 13 | "cmock_generator_utils", 14 | "cmock_unityhelper_parser"].each {|req| require "#{File.expand_path(File.dirname(__FILE__))}/#{req}"} 15 | 16 | 17 | $QUICK_RUBY_VERSION = RUBY_VERSION.split('.').inject(0){|vv,v| vv * 100 + v.to_i } 18 | 19 | class CMock 20 | 21 | def initialize(options=nil) 22 | cm_config = CMockConfig.new(options) 23 | cm_unityhelper = CMockUnityHelperParser.new(cm_config) 24 | cm_writer = CMockFileWriter.new(cm_config) 25 | cm_gen_utils = CMockGeneratorUtils.new(cm_config, {:unity_helper => cm_unityhelper}) 26 | cm_gen_plugins = CMockPluginManager.new(cm_config, cm_gen_utils) 27 | @cm_parser = CMockHeaderParser.new(cm_config) 28 | @cm_generator = CMockGenerator.new(cm_config, cm_writer, cm_gen_utils, cm_gen_plugins) 29 | @silent = (cm_config.verbosity < 2) 30 | end 31 | 32 | def setup_mocks(files) 33 | [files].flatten.each do |src| 34 | generate_mock src 35 | end 36 | end 37 | 38 | private ############################### 39 | 40 | def generate_mock(src) 41 | name = File.basename(src, '.h') 42 | puts "Creating mock for #{name}..." unless @silent 43 | @cm_generator.create_mock(name, @cm_parser.parse(name, File.read(src))) 44 | end 45 | end 46 | 47 | def option_maker(options, key, val) 48 | options = options || {} 49 | options[key.to_sym] = 50 | if val.chr == ":" 51 | val[1..-1].to_sym 52 | elsif val.include? ";" 53 | val.split(';') 54 | elsif val == 'true' 55 | true 56 | elsif val == 'false' 57 | false 58 | elsif val =~ /^\d+$/ 59 | val.to_i 60 | else 61 | val 62 | end 63 | options 64 | end 65 | 66 | # Command Line Support ############################### 67 | 68 | if ($0 == __FILE__) 69 | usage = "usage: ruby #{__FILE__} (-oOptionsFile) File(s)ToMock" 70 | 71 | if (!ARGV[0]) 72 | puts usage 73 | exit 1 74 | end 75 | 76 | options = {} 77 | filelist = [] 78 | ARGV.each do |arg| 79 | if (arg =~ /^-o\"?([a-zA-Z0-9._\\\/:\s]+)\"?/) 80 | options.merge! CMockConfig.load_config_file_from_yaml( arg.gsub(/^-o/,'') ) 81 | elsif (arg =~ /^--([a-zA-Z0-9._\\\/:\s]+)=\"?([a-zA-Z0-9._\-\\\/:\s\;]+)\"?/) 82 | options = option_maker(options, $1, $2) 83 | else 84 | filelist << arg 85 | end 86 | end 87 | 88 | CMock.new(options).setup_mocks(filelist) 89 | end 90 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_file_writer.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | class CMockFileWriter 8 | 9 | attr_reader :config 10 | 11 | def initialize(config) 12 | @config = config 13 | end 14 | 15 | def create_subdir(subdir) 16 | if !Dir.exists?("#{@config.mock_path}/") 17 | require 'fileutils' 18 | FileUtils.mkdir_p "#{@config.mock_path}/" 19 | end 20 | if subdir && !Dir.exists?("#{@config.mock_path}/#{subdir+'/' if subdir}") 21 | require 'fileutils' 22 | FileUtils.mkdir_p "#{@config.mock_path}/#{subdir+'/' if subdir}" 23 | end 24 | end 25 | 26 | def create_file(filename, subdir) 27 | raise "Where's the block of data to create?" unless block_given? 28 | full_file_name_temp = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}.new" 29 | full_file_name_done = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}" 30 | File.open(full_file_name_temp, 'w') do |file| 31 | yield(file, filename) 32 | end 33 | update_file(full_file_name_done, full_file_name_temp) 34 | end 35 | 36 | private ################################### 37 | 38 | def update_file(dest, src) 39 | require 'fileutils' 40 | FileUtils.rm(dest) if (File.exist?(dest)) 41 | FileUtils.cp(src, dest) 42 | FileUtils.rm(src) 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_generator_plugin_array.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | class CMockGeneratorPluginArray 8 | 9 | attr_reader :priority 10 | attr_accessor :config, :utils, :unity_helper, :ordered 11 | def initialize(config, utils) 12 | @config = config 13 | @ptr_handling = @config.when_ptr 14 | @ordered = @config.enforce_strict_ordering 15 | @utils = utils 16 | @unity_helper = @utils.helpers[:unity_helper] 17 | @priority = 8 18 | end 19 | 20 | def instance_typedefs(function) 21 | function[:args].inject("") do |all, arg| 22 | (arg[:ptr?]) ? all + " int Expected_#{arg[:name]}_Depth;\n" : all 23 | end 24 | end 25 | 26 | def mock_function_declarations(function) 27 | return nil unless function[:contains_ptr?] 28 | args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{m[:name]}"}.join(', ') 29 | args_string = function[:args].map do |m| 30 | const_str = m[:const?] ? 'const ' : '' 31 | m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}" 32 | end.join(', ') 33 | if (function[:return][:void?]) 34 | return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" + 35 | "void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n" 36 | else 37 | return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" + 38 | "void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n" 39 | end 40 | end 41 | 42 | def mock_interfaces(function) 43 | return nil unless function[:contains_ptr?] 44 | lines = [] 45 | func_name = function[:name] 46 | args_string = function[:args].map do |m| 47 | const_str = m[:const?] ? 'const ' : '' 48 | m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}" 49 | end.join(', ') 50 | call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ') 51 | if (function[:return][:void?]) 52 | lines << "void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n" 53 | else 54 | lines << "void #{func_name}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]})\n" 55 | end 56 | lines << "{\n" 57 | lines << @utils.code_add_base_expectation(func_name) 58 | lines << " CMockExpectParameters_#{func_name}(cmock_call_instance, #{call_string});\n" 59 | lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" unless (function[:return][:void?]) 60 | lines << "}\n\n" 61 | end 62 | 63 | end 64 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_generator_plugin_cexception.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | class CMockGeneratorPluginCexception 8 | 9 | attr_reader :priority 10 | attr_reader :config, :utils 11 | 12 | def initialize(config, utils) 13 | @config = config 14 | @utils = utils 15 | @priority = 7 16 | end 17 | 18 | def include_files 19 | return "#include \"CException.h\"\n" 20 | end 21 | 22 | def instance_typedefs(function) 23 | " CEXCEPTION_T ExceptionToThrow;\n" 24 | end 25 | 26 | def mock_function_declarations(function) 27 | if (function[:args_string] == "void") 28 | return "#define #{function[:name]}_ExpectAndThrow(cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n" + 29 | "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n" 30 | else 31 | return "#define #{function[:name]}_ExpectAndThrow(#{function[:args_call]}, cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, #{function[:args_call]}, cmock_to_throw)\n" + 32 | "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, CEXCEPTION_T cmock_to_throw);\n" 33 | end 34 | end 35 | 36 | def mock_implementation(function) 37 | " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" + 38 | " UNITY_CLR_DETAILS();\n" + 39 | " Throw(cmock_call_instance->ExceptionToThrow);\n }\n" 40 | end 41 | 42 | def mock_interfaces(function) 43 | arg_insert = (function[:args_string] == "void") ? "" : "#{function[:args_string]}, " 44 | call_string = function[:args].map{|m| m[:name]}.join(', ') 45 | [ "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{arg_insert}CEXCEPTION_T cmock_to_throw)\n{\n", 46 | @utils.code_add_base_expectation(function[:name]), 47 | @utils.code_call_argument_loader(function), 48 | " cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n", 49 | "}\n\n" ].join 50 | end 51 | 52 | end 53 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_generator_plugin_expect_any_args.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | class CMockGeneratorPluginExpectAnyArgs 8 | 9 | attr_reader :priority 10 | attr_reader :config, :utils 11 | 12 | def initialize(config, utils) 13 | @config = config 14 | @utils = utils 15 | @priority = 3 16 | end 17 | 18 | def instance_structure(function) 19 | if (function[:return][:void?]) || (@config.plugins.include? :ignore) 20 | "" 21 | else 22 | " #{function[:return][:type]} #{function[:name]}_FinalReturn;\n" 23 | end 24 | end 25 | 26 | def instance_typedefs(function) 27 | " CMOCK_ARG_MODE IgnoreMode;\n" 28 | end 29 | 30 | def mock_function_declarations(function) 31 | 32 | if (function[:return][:void?]) 33 | return "#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" + 34 | "void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n" 35 | else 36 | return "#define #{function[:name]}_ExpectAnyArgsAndReturn(cmock_retval) #{function[:name]}_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n" + 37 | "void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n" 38 | end 39 | end 40 | 41 | # def mock_implementation(function) 42 | # lines = " if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n {\n" 43 | # if (function[:return][:void?]) 44 | # lines << " return;\n }\n" 45 | # else 46 | # retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} ) 47 | # lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?]) 48 | # return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '') 49 | # lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n" 50 | # end 51 | # lines 52 | # end 53 | 54 | def mock_interfaces(function) 55 | lines = "" 56 | if (function[:return][:void?]) 57 | lines << "void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n{\n" 58 | else 59 | lines << "void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n" 60 | end 61 | lines << @utils.code_add_base_expectation(function[:name], true) 62 | unless (function[:return][:void?]) 63 | lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" 64 | end 65 | lines << " cmock_call_instance->IgnoreMode = CMOCK_ARG_NONE;\n" 66 | lines << "}\n\n" 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_generator_plugin_ignore.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | class CMockGeneratorPluginIgnore 8 | 9 | attr_reader :priority 10 | attr_reader :config, :utils 11 | 12 | def initialize(config, utils) 13 | @config = config 14 | @utils = utils 15 | @priority = 2 16 | end 17 | 18 | def instance_structure(function) 19 | if (function[:return][:void?]) 20 | " int #{function[:name]}_IgnoreBool;\n" 21 | else 22 | " int #{function[:name]}_IgnoreBool;\n #{function[:return][:type]} #{function[:name]}_FinalReturn;\n" 23 | end 24 | end 25 | 26 | def mock_function_declarations(function) 27 | if (function[:return][:void?]) 28 | return "#define #{function[:name]}_Ignore() #{function[:name]}_CMockIgnore()\n" + 29 | "void #{function[:name]}_CMockIgnore(void);\n" 30 | else 31 | return "#define #{function[:name]}_IgnoreAndReturn(cmock_retval) #{function[:name]}_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n" + 32 | "void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n" 33 | end 34 | end 35 | 36 | def mock_implementation_precheck(function) 37 | lines = " if (Mock.#{function[:name]}_IgnoreBool)\n {\n" 38 | lines << " UNITY_CLR_DETAILS();\n" 39 | if (function[:return][:void?]) 40 | lines << " return;\n }\n" 41 | else 42 | retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} ) 43 | return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '') 44 | lines << " if (cmock_call_instance == NULL)\n return #{return_type}Mock.#{function[:name]}_FinalReturn;\n" 45 | lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?]) 46 | lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n" 47 | end 48 | lines 49 | end 50 | 51 | def mock_interfaces(function) 52 | lines = "" 53 | if (function[:return][:void?]) 54 | lines << "void #{function[:name]}_CMockIgnore(void)\n{\n" 55 | else 56 | lines << "void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n" 57 | end 58 | if (!function[:return][:void?]) 59 | lines << @utils.code_add_base_expectation(function[:name], false) 60 | end 61 | unless (function[:return][:void?]) 62 | lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" 63 | end 64 | lines << " Mock.#{function[:name]}_IgnoreBool = (int)1;\n" 65 | lines << "}\n\n" 66 | end 67 | 68 | def mock_verify(function) 69 | func_name = function[:name] 70 | " if (Mock.#{func_name}_IgnoreBool)\n Mock.#{func_name}_CallInstance = CMOCK_GUTS_NONE;\n" 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_generator_plugin_ignore_arg.rb: -------------------------------------------------------------------------------- 1 | class CMockGeneratorPluginIgnoreArg 2 | attr_reader :priority 3 | attr_accessor :utils 4 | 5 | def initialize(config, utils) 6 | @utils = utils 7 | @priority = 10 8 | end 9 | 10 | def instance_typedefs(function) 11 | lines = "" 12 | function[:args].each do |arg| 13 | lines << " int IgnoreArg_#{arg[:name]};\n" 14 | end 15 | lines 16 | end 17 | 18 | def mock_function_declarations(function) 19 | lines = "" 20 | function[:args].each do |arg| 21 | lines << "#define #{function[:name]}_IgnoreArg_#{arg[:name]}()" 22 | lines << " #{function[:name]}_CMockIgnoreArg_#{arg[:name]}(__LINE__)\n" 23 | lines << "void #{function[:name]}_CMockIgnoreArg_#{arg[:name]}(UNITY_LINE_TYPE cmock_line);\n" 24 | end 25 | lines 26 | end 27 | 28 | def mock_interfaces(function) 29 | lines = [] 30 | func_name = function[:name] 31 | function[:args].each do |arg| 32 | arg_name = arg[:name] 33 | arg_type = arg[:type] 34 | lines << "void #{function[:name]}_CMockIgnoreArg_#{arg[:name]}(UNITY_LINE_TYPE cmock_line)\n" 35 | lines << "{\n" 36 | lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " + 37 | "(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n" 38 | lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" 39 | lines << " cmock_call_instance->IgnoreArg_#{arg_name} = 1;\n" 40 | lines << "}\n\n" 41 | end 42 | lines 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_plugin_manager.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | class CMockPluginManager 8 | 9 | attr_accessor :plugins 10 | 11 | def initialize(config, utils) 12 | @plugins = [] 13 | plugins_to_load = [:expect, config.plugins].flatten.uniq.compact 14 | plugins_to_load.each do |plugin| 15 | plugin_name = plugin.to_s 16 | object_name = "CMockGeneratorPlugin" + camelize(plugin_name) 17 | begin 18 | unless (Object.const_defined? object_name) 19 | require "#{File.expand_path(File.dirname(__FILE__))}/cmock_generator_plugin_#{plugin_name.downcase}.rb" 20 | end 21 | @plugins << eval("#{object_name}.new(config, utils)") 22 | rescue 23 | raise "ERROR: CMock unable to load plugin '#{plugin_name}'" 24 | end 25 | end 26 | @plugins.sort! {|a,b| a.priority <=> b.priority } 27 | end 28 | 29 | def run(method, args=nil) 30 | if args.nil? 31 | return @plugins.collect{ |plugin| plugin.send(method) if plugin.respond_to?(method) }.flatten.join 32 | else 33 | return @plugins.collect{ |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten.join 34 | end 35 | end 36 | 37 | def camelize(lower_case_and_underscored_word) 38 | lower_case_and_underscored_word.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/lib/cmock_unityhelper_parser.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # CMock Project - Automatic Mock Generation for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | class CMockUnityHelperParser 8 | 9 | attr_accessor :c_types 10 | 11 | def initialize(config) 12 | @config = config 13 | @fallback = @config.plugins.include?(:array) ? 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' : 'UNITY_TEST_ASSERT_EQUAL_MEMORY' 14 | @c_types = map_C_types.merge(import_source) 15 | end 16 | 17 | def get_helper(ctype) 18 | lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/,'\1\3\5\6').strip.gsub(/\s+/,'_') 19 | return [@c_types[lookup], ''] if (@c_types[lookup]) 20 | if (lookup =~ /\*$/) 21 | lookup = lookup.gsub(/\*$/,'') 22 | return [@c_types[lookup], '*'] if (@c_types[lookup]) 23 | else 24 | lookup = lookup + '*' 25 | return [@c_types[lookup], '&'] if (@c_types[lookup]) 26 | end 27 | return ['UNITY_TEST_ASSERT_EQUAL_PTR', ''] if (ctype =~ /cmock_\w+_ptr\d+/) 28 | raise("Don't know how to test #{ctype} and memory tests are disabled!") unless @config.memcmp_if_unknown 29 | return (lookup =~ /\*$/) ? [@fallback, '&'] : [@fallback, ''] 30 | end 31 | 32 | private ########################### 33 | 34 | def map_C_types 35 | c_types = {} 36 | @config.treat_as.each_pair do |ctype, expecttype| 37 | c_type = ctype.gsub(/\s+/,'_') 38 | if (expecttype =~ /\*/) 39 | c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype.gsub(/\*/,'')}_ARRAY" 40 | else 41 | c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}" 42 | c_types[c_type+'*'] ||= "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY" 43 | end 44 | end 45 | c_types 46 | end 47 | 48 | def import_source 49 | source = @config.load_unity_helper 50 | return {} if source.nil? 51 | c_types = {} 52 | source = source.gsub(/\/\/.*$/, '') #remove line comments 53 | source = source.gsub(/\/\*.*?\*\//m, '') #remove block comments 54 | 55 | #scan for comparison helpers 56 | match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+))\s*\(' + Array.new(4,'\s*\w+\s*').join(',') + '\)') 57 | pairs = source.scan(match_regex).flatten.compact 58 | (pairs.size/2).times do |i| 59 | expect = pairs[i*2] 60 | ctype = pairs[(i*2)+1] 61 | c_types[ctype] = expect unless expect.include?("_ARRAY") 62 | end 63 | 64 | #scan for array variants of those helpers 65 | match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+_ARRAY))\s*\(' + Array.new(5,'\s*\w+\s*').join(',') + '\)') 66 | pairs = source.scan(match_regex).flatten.compact 67 | (pairs.size/2).times do |i| 68 | expect = pairs[i*2] 69 | ctype = pairs[(i*2)+1] 70 | c_types[ctype.gsub('_ARRAY','*')] = expect 71 | end 72 | 73 | c_types 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/scripts/create_mock.rb: -------------------------------------------------------------------------------- 1 | require "#{ENV['CMOCK_DIR']}/lib/cmock" 2 | 3 | raise "Header file to mock must be specified!" unless ARGV.length >= 1 4 | 5 | mock_out = ENV.fetch('MOCK_OUT', './build/test/mocks') 6 | mock_prefix = ENV.fetch('MOCK_PREFIX', 'mock_') 7 | cmock = CMock.new(plugins: [:ignore, :return_thru_ptr], mock_prefix: mock_prefix, mock_path: mock_out) 8 | cmock.setup_mocks(ARGV[0]) 9 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/scripts/create_runner.rb: -------------------------------------------------------------------------------- 1 | if ($0 == __FILE__) 2 | 3 | #make sure there is at least one parameter left (the input file) 4 | if ARGV.length < 2 5 | puts ["\nusage: ruby #{__FILE__} input_test_file (output)", 6 | "", 7 | " input_test_file - this is the C file you want to create a runner for", 8 | " output - this is the name of the runner file to generate", 9 | " defaults to (input_test_file)_Runner", 10 | ].join("\n") 11 | exit 1 12 | end 13 | 14 | require "#{ENV['UNITY_DIR']}/auto/generate_test_runner" 15 | 16 | test = ARGV[0] 17 | runner = ARGV[1] 18 | generator = UnityTestRunnerGenerator.new.run(test, runner) 19 | 20 | end 21 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/scripts/test_summary.rb: -------------------------------------------------------------------------------- 1 | require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb" 2 | 3 | build_dir = ENV.fetch('BUILD_DIR', './build') 4 | test_build_dir = ENV.fetch('TEST_BUILD_DIR', File.join(build_dir, 'test')) 5 | 6 | results = Dir["#{test_build_dir}/*.result"] 7 | parser = UnityTestSummary.new 8 | parser.set_targets(results) 9 | parser.run 10 | puts parser.report 11 | exit(parser.failures) 12 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/src/cmock.h: -------------------------------------------------------------------------------- 1 | /* ========================================== 2 | CMock Project - Automatic Mock Generation for C 3 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | [Released under MIT License. Please refer to license.txt for details] 5 | ========================================== */ 6 | 7 | #ifndef CMOCK_FRAMEWORK_H 8 | #define CMOCK_FRAMEWORK_H 9 | 10 | #include "cmock_internals.h" 11 | 12 | //should be big enough to index full range of CMOCK_MEM_MAX 13 | #ifndef CMOCK_MEM_INDEX_TYPE 14 | #define CMOCK_MEM_INDEX_TYPE unsigned int 15 | #endif 16 | 17 | #define CMOCK_GUTS_NONE (0) 18 | 19 | #define CMOCK_ARG_MODE CMOCK_MEM_INDEX_TYPE 20 | #define CMOCK_ARG_ALL 0 21 | #define CMOCK_ARG_NONE ((CMOCK_MEM_INDEX_TYPE)(~0)) 22 | 23 | //------------------------------------------------------- 24 | // Memory API 25 | //------------------------------------------------------- 26 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size); 27 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_MEM_INDEX_TYPE obj_index); 28 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index); 29 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index); 30 | 31 | void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index); 32 | 33 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void); 34 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void); 35 | void CMock_Guts_MemFreeAll(void); 36 | void CMock_Guts_MemFreeFinal(void); 37 | 38 | #endif //CMOCK_FRAMEWORK 39 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/src/cmock_internals.h: -------------------------------------------------------------------------------- 1 | /* ========================================== 2 | CMock Project - Automatic Mock Generation for C 3 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | [Released under MIT License. Please refer to license.txt for details] 5 | ========================================== */ 6 | 7 | #ifndef CMOCK_FRAMEWORK_INTERNALS_H 8 | #define CMOCK_FRAMEWORK_INTERNALS_H 9 | 10 | //These are constants that the generated mocks have access to 11 | extern const char* CMockStringOutOfMemory; 12 | extern const char* CMockStringCalledMore; 13 | extern const char* CMockStringCalledLess; 14 | extern const char* CMockStringCalledEarly; 15 | extern const char* CMockStringCalledLate; 16 | extern const char* CMockStringCallOrder; 17 | extern const char* CMockStringIgnPreExp; 18 | extern const char* CMockStringPtrPreExp; 19 | extern const char* CMockStringExpNULL; 20 | extern const char* CMockStringMismatch; 21 | 22 | //define CMOCK_MEM_DYNAMIC to grab memory as needed with malloc 23 | //when you do that, CMOCK_MEM_SIZE is used for incremental size instead of total 24 | #ifdef CMOCK_MEM_STATIC 25 | #undef CMOCK_MEM_DYNAMIC 26 | #endif 27 | 28 | #ifdef CMOCK_MEM_DYNAMIC 29 | #include 30 | #endif 31 | 32 | //this is used internally during pointer arithmetic. make sure this type is the same size as the target's pointer type 33 | #ifndef CMOCK_MEM_PTR_AS_INT 34 | #ifdef UNITY_POINTER_WIDTH 35 | #ifdef UNITY_INT_WIDTH 36 | #if UNITY_POINTER_WIDTH == UNITY_INT_WIDTH 37 | #define CMOCK_MEM_PTR_AS_INT unsigned int 38 | #endif 39 | #endif 40 | #endif 41 | #endif 42 | 43 | #ifndef CMOCK_MEM_PTR_AS_INT 44 | #ifdef UNITY_POINTER_WIDTH 45 | #ifdef UNITY_LONG_WIDTH 46 | #if UNITY_POINTER_WIDTH == UNITY_LONG_WIDTH 47 | #define CMOCK_MEM_PTR_AS_INT unsigned long 48 | #endif 49 | #if UNITY_POINTER_WIDTH > UNITY_LONG_WIDTH 50 | #define CMOCK_MEM_PTR_AS_INT unsigned long long 51 | #endif 52 | #endif 53 | #endif 54 | #endif 55 | 56 | #ifndef CMOCK_MEM_PTR_AS_INT 57 | #define CMOCK_MEM_PTR_AS_INT unsigned long 58 | #endif 59 | 60 | //0 for no alignment, 1 for 16-bit, 2 for 32-bit, 3 for 64-bit 61 | #ifndef CMOCK_MEM_ALIGN 62 | #define CMOCK_MEM_ALIGN (2) 63 | #endif 64 | 65 | //amount of memory to allow cmock to use in its internal heap 66 | #ifndef CMOCK_MEM_SIZE 67 | #define CMOCK_MEM_SIZE (32768) 68 | #endif 69 | 70 | //automatically calculated defs for easier reading 71 | #define CMOCK_MEM_ALIGN_SIZE (CMOCK_MEM_INDEX_TYPE)(1u << CMOCK_MEM_ALIGN) 72 | #define CMOCK_MEM_ALIGN_MASK (CMOCK_MEM_INDEX_TYPE)(CMOCK_MEM_ALIGN_SIZE - 1) 73 | #define CMOCK_MEM_INDEX_SIZE (CMOCK_MEM_INDEX_TYPE)(CMOCK_MEM_PTR_AS_INT)((sizeof(CMOCK_MEM_INDEX_TYPE) > CMOCK_MEM_ALIGN_SIZE) ? sizeof(CMOCK_MEM_INDEX_TYPE) : CMOCK_MEM_ALIGN_SIZE) 74 | 75 | 76 | #endif //CMOCK_FRAMEWORK_INTERNALS 77 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/vendor/unity/auto/colour_reporter.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt" 8 | 9 | $colour_output = true 10 | 11 | def report(message) 12 | if not $colour_output 13 | $stdout.puts(message) 14 | else 15 | message = message.join('\n') if (message.class == Array) 16 | message.each_line do |line| 17 | line.chomp! 18 | colour = case(line) 19 | when /(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i 20 | ($1.to_i == 0) ? :green : :red 21 | when /PASS/ 22 | :green 23 | when /^OK$/ 24 | :green 25 | when /(?:FAIL|ERROR)/ 26 | :red 27 | when /IGNORE/ 28 | :yellow 29 | when /^(?:Creating|Compiling|Linking)/ 30 | :white 31 | else 32 | :silver 33 | end 34 | colour_puts(colour, line) 35 | end 36 | end 37 | $stdout.flush 38 | $stderr.flush 39 | end -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/vendor/unity/auto/generate_config.yml: -------------------------------------------------------------------------------- 1 | #this is a sample configuration file for generate_module 2 | #you would use it by calling generate_module with the -ygenerate_config.yml option 3 | #files like this are useful for customizing generate_module to your environment 4 | :generate_module: 5 | :defaults: 6 | #these defaults are used in place of any missing options at the command line 7 | :path_src: ../src/ 8 | :path_inc: ../src/ 9 | :path_tst: ../test/ 10 | :update_svn: true 11 | :includes: 12 | #use [] for no additional includes, otherwise list the includes on separate lines 13 | :src: 14 | - Defs.h 15 | - Board.h 16 | :inc: [] 17 | :tst: 18 | - Defs.h 19 | - Board.h 20 | - Exception.h 21 | :boilerplates: 22 | #these are inserted at the top of generated files. 23 | #just comment out or remove if not desired. 24 | #use %1$s where you would like the file name to appear (path/extension not included) 25 | :src: | 26 | //------------------------------------------- 27 | // %1$s.c 28 | //------------------------------------------- 29 | :inc: | 30 | //------------------------------------------- 31 | // %1$s.h 32 | //------------------------------------------- 33 | :tst: | 34 | //------------------------------------------- 35 | // Test%1$s.c : Units tests for %1$s.c 36 | //------------------------------------------- 37 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/vendor/unity/auto/test_file_filter.rb: -------------------------------------------------------------------------------- 1 | # ========================================== 2 | # Unity Project - A Test Framework for C 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 | # [Released under MIT License. Please refer to license.txt for details] 5 | # ========================================== 6 | 7 | require'yaml' 8 | 9 | module RakefileHelpers 10 | class TestFileFilter 11 | def initialize(all_files = false) 12 | @all_files = all_files 13 | if not @all_files == true 14 | if File.exist?('test_file_filter.yml') 15 | filters = YAML.load_file( 'test_file_filter.yml' ) 16 | @all_files, @only_files, @exclude_files = 17 | filters[:all_files], filters[:only_files], filters[:exclude_files] 18 | end 19 | end 20 | end 21 | attr_accessor :all_files, :only_files, :exclude_files 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /mcl_core/test/lib/CMock/vendor/unity/auto/type_sanitizer.rb: -------------------------------------------------------------------------------- 1 | module TypeSanitizer 2 | 3 | def self.sanitize_c_identifier(unsanitized) 4 | # convert filename to valid C identifier by replacing invalid chars with '_' 5 | return unsanitized.gsub(/[-\/\\\.\,\s]/, "_") 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /mcl_core/test/unit/cmock.yml.in: -------------------------------------------------------------------------------- 1 | :cmock: 2 | :plugins: [ignore, return_thru_ptr, expect_any_args, ignore_arg] 3 | :includes: ${CMOCK_YML_INCLUDES} 4 | :mock_path: '${CMAKE_CURRENT_BINARY_DIR}/mock' 5 | :mock_prefix: mock_ 6 | :framework: unity 7 | :verbosity: 3 8 | :treat_externs: :include -------------------------------------------------------------------------------- /mcl_core/test/unit/test_memory_standard.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file test_memory_standard.c 3 | * @brief Unit test cases for testing mcl_memory module standard implementation. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "unity.h" 10 | #include "mcl_core/mcl_memory.h" 11 | 12 | void setUp(void) 13 | { 14 | } 15 | 16 | void tearDown(void) 17 | { 18 | } 19 | 20 | /** 21 | * GIVEN : No initial condition. 22 | * WHEN : User requests allocation of a buffer. 23 | * THEN : User expects the buffer is allocated and is not NULL. 24 | */ 25 | void test_malloc_001(void) 26 | { 27 | char test_buffer[] = "This is a test buffer."; 28 | char *allocated_buffer = MCL_MALLOC(sizeof(test_buffer)); 29 | TEST_ASSERT_NOT_NULL_MESSAGE(allocated_buffer, "New memory couldn't be allocated! Buffer is NULL."); 30 | 31 | for (size_t i = 0; i < sizeof(test_buffer); i++) 32 | { 33 | // If allocated buffer is not large enough, there must be crash here. 34 | allocated_buffer[i] = test_buffer[i]; 35 | } 36 | 37 | MCL_FREE(allocated_buffer); 38 | TEST_ASSERT_NULL_MESSAGE(allocated_buffer, "Pointer is NOT NULL after freeing!"); 39 | } 40 | 41 | /** 42 | * GIVEN : No initial condition. 43 | * WHEN : mcl_memory_calloc() is called. 44 | * THEN : User expects the buffer is allocated and content is all zero. 45 | */ 46 | void test_calloc_001(void) 47 | { 48 | size_t test_size = 32; 49 | char *allocated_buffer = mcl_memory_calloc(test_size, 1); 50 | 51 | for (size_t i = 0; i < test_size; i++) 52 | { 53 | TEST_ASSERT_EQUAL(0, allocated_buffer[i]); 54 | } 55 | 56 | MCL_FREE(allocated_buffer); 57 | TEST_ASSERT_NULL_MESSAGE(allocated_buffer, "Pointer is NOT NULL after freeing!"); 58 | } 59 | 60 | /** 61 | * GIVEN : User has an allocated buffer. 62 | * WHEN : mcl_memory_realloc() is called to resize the buffer. 63 | * THEN : User expects the buffer to be resized. 64 | */ 65 | void test_realloc_001(void) 66 | { 67 | char test_buffer[] = "This is a test buffer."; 68 | char *allocated_buffer = MCL_MALLOC(sizeof(test_buffer)); 69 | TEST_ASSERT_NOT_NULL_MESSAGE(allocated_buffer, "New memory couldn't be allocated! Buffer is NULL."); 70 | 71 | for (size_t i = 0; i < sizeof(test_buffer); i++) 72 | { 73 | // If allocated buffer is not large enough, there must be crash here. 74 | allocated_buffer[i] = test_buffer[i]; 75 | } 76 | 77 | allocated_buffer = mcl_memory_realloc(allocated_buffer, 2 * sizeof(test_buffer)); 78 | 79 | for (size_t i = 0; i < sizeof(test_buffer); i++) 80 | { 81 | // Content must remain. 82 | TEST_ASSERT_EQUAL(test_buffer[i], allocated_buffer[i]); 83 | 84 | // If allocated buffer is not large enough, there must be crash here. 85 | allocated_buffer[sizeof(test_buffer) + i] = test_buffer[sizeof(test_buffer) + i]; 86 | } 87 | 88 | MCL_FREE(allocated_buffer); 89 | TEST_ASSERT_NULL_MESSAGE(allocated_buffer, "Pointer is NOT NULL after freeing!"); 90 | } 91 | -------------------------------------------------------------------------------- /mcl_core/test/unit/test_random.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file test_random.c 3 | * @brief This file contains test case functions to test random module. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "unity.h" 10 | #include "mcl_core/mcl_random.h" 11 | #include "random.h" 12 | #include "memory.h" 13 | #include "string_util.h" 14 | #include "mock_security.h" 15 | #include "mcl_core/mcl_log_util.h" 16 | 17 | void setUp(void) 18 | { 19 | } 20 | 21 | void tearDown(void) 22 | { 23 | } 24 | 25 | /** 26 | * GIVEN : No initial condition. 27 | * WHEN : random_generate_number() is called. 28 | * THEN : MCL_OK and random number are returned. 29 | */ 30 | void test_generate_number_001() 31 | { 32 | mcl_uint32_t *random_number = MCL_MALLOC(sizeof(mcl_uint32_t)); 33 | unsigned char expected_buffer[] = { 'M', 'I', 'N', 'D'}; 34 | 35 | security_generate_random_bytes_ExpectAnyArgsAndReturn(MCL_OK); 36 | security_generate_random_bytes_ReturnArrayThruPtr_buffer(expected_buffer, sizeof(expected_buffer)); 37 | 38 | mcl_error_t code = random_generate_number(random_number); 39 | 40 | TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE((mcl_uint8_t *) expected_buffer, (mcl_uint8_t *) random_number, sizeof(expected_buffer), "Random number could not be generated as expected!"); 41 | TEST_ASSERT_EQUAL_MESSAGE(MCL_OK, code, "MCL_OK expected as return code!"); 42 | 43 | MCL_FREE(random_number); 44 | } 45 | 46 | /** 47 | * GIVEN : No initial condition. 48 | * WHEN : mcl_random_generate_guid() is called. 49 | * THEN : MCL_OK and guid are returned. 50 | */ 51 | void test_generate_guid_001() 52 | { 53 | char *guid = MCL_NULL; 54 | char random_buffer[] = {0xe4, 0x4c, 0xea, 0xb5, 0x5b, 0xb8, 0xe2, 0x45, 0x84, 0xff, 0xe2, 0xe6, 0xab, 0x21, 0xc7, 0x9c}; 55 | char expected_guid[] = "b5ea4ce4-b85b-45e2-84ff-e2e6ab21c79c"; 56 | 57 | security_generate_random_bytes_ExpectAnyArgsAndReturn(MCL_OK); 58 | security_generate_random_bytes_ReturnArrayThruPtr_buffer(random_buffer, sizeof(random_buffer)); 59 | 60 | mcl_error_t code = mcl_random_generate_guid(&guid); 61 | 62 | TEST_ASSERT_EQUAL_STRING_MESSAGE(expected_guid, guid, "Guid could not be generated as expected!"); 63 | TEST_ASSERT_EQUAL_MESSAGE(MCL_OK, code, "MCL_OK expected as return code!"); 64 | 65 | MCL_FREE(guid); 66 | } 67 | 68 | /** 69 | * GIVEN : No initial condition. 70 | * WHEN : mcl_random_generate_bytes() is called. 71 | * THEN : MCL_OK and random buffer are returned. 72 | */ 73 | void test_generate_bytes_001() 74 | { 75 | unsigned char expected_buffer[] = { 'M', 'I', 'N', 'D' }; 76 | unsigned char *buffer = MCL_MALLOC(sizeof(expected_buffer)); 77 | 78 | security_generate_random_bytes_ExpectAnyArgsAndReturn(MCL_OK); 79 | security_generate_random_bytes_ReturnArrayThruPtr_buffer(expected_buffer, sizeof(expected_buffer)); 80 | 81 | mcl_error_t code = mcl_random_generate_bytes(buffer, sizeof(expected_buffer)); 82 | 83 | TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE((mcl_uint8_t *) expected_buffer, (mcl_uint8_t *) buffer, sizeof(expected_buffer), "Buffer for random bytes could not be generated as expected!"); 84 | TEST_ASSERT_EQUAL_MESSAGE(MCL_OK, code, "MCL_OK expected as return code!"); 85 | 86 | MCL_FREE(buffer); 87 | } 88 | -------------------------------------------------------------------------------- /mcl_data_lake/.mbedignore: -------------------------------------------------------------------------------- 1 | doc/* 2 | examples/* 3 | test/* -------------------------------------------------------------------------------- /mcl_data_lake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Set component name. 2 | SET(MCL_COMPONENT "data_lake") 3 | 4 | # Set path of MCL Data Lake's root Cmake directory. 5 | SET(MCL_DATA_LAKE_CMAKE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | # Set MCL_DATA_LAKE_SOURCES to collect source files from different locations. 8 | SET(MCL_DATA_LAKE_SOURCES "" CACHE INTERNAL "MCL_DATA_LAKE_SOURCES" FORCE) 9 | SET(MCL_DATA_LAKE_LIBS "" CACHE INTERNAL "MCL_DATA_LAKE_LIBS" FORCE) 10 | SET(MCL_DATA_LAKE_INCLUDE_DIRECTORIES "" CACHE INTERNAL "MCL_DATA_LAKE_INCLUDE_DIRECTORIES" FORCE) 11 | 12 | IF(MCL_DATA_LAKE) 13 | MESSAGE(STATUS "MCL Data Lake build is ${MCL_DATA_LAKE}.") 14 | ADD_DEFINITIONS(-DMCL_DATA_LAKE_BUILD=1) 15 | ENDIF() 16 | 17 | IF(MCL_STATICLIB) 18 | SET(MCL_USER_DEFINED_DYNAMIC_OR_STATIC STATIC) 19 | ADD_DEFINITIONS(-DMCL_STATICLIB=1) 20 | ELSE() 21 | SET(MCL_USER_DEFINED_DYNAMIC_OR_STATIC SHARED) 22 | ADD_DEFINITIONS(-DMCL_STATICLIB=0) 23 | ENDIF() 24 | 25 | MESSAGE(STATUS "MCL Data Lake will be built as ${MCL_USER_DEFINED_DYNAMIC_OR_STATIC} library.") 26 | 27 | # MCL Data Lake sources. 28 | ADD_SUBDIRECTORY(src) 29 | 30 | IF(MCL_TEST AND RUBY_FOUND) 31 | # Turn on CMake testing capabilities. 32 | ENABLE_TESTING() 33 | ADD_SUBDIRECTORY(test) 34 | ENDIF() 35 | 36 | # Doxygen. 37 | IF(MCL_DOC) 38 | ADD_SUBDIRECTORY(doc) 39 | ADD_DEPENDENCIES(mcl_data_lake mcl_data_lake_doc) 40 | MESSAGE(STATUS "Creation of reference documentation is enabled.") 41 | ELSE() 42 | MESSAGE(STATUS "Creation of reference documentation is disabled.") 43 | ENDIF() 44 | 45 | # Get all interface header files of mcl data lake component. 46 | FILE(GLOB MCL_DATA_LAKE_INTERFACE_HEADER_FILES "${MCL_DATA_LAKE_CMAKE_ROOT_DIR}/include/mcl_data_lake/*.h") 47 | 48 | # Install directory for interface header files of mcl data lake component. 49 | INSTALL(FILES ${MCL_DATA_LAKE_INTERFACE_HEADER_FILES} DESTINATION "${PACKAGE_DESTINATION_INCLUDE}/mcl_data_lake") 50 | -------------------------------------------------------------------------------- /mcl_data_lake/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add a target to generate API documentation with Doxygen. 2 | FIND_PACKAGE(Doxygen) 3 | MESSAGE(STATUS "Create and install the HTML based API documentation (requires Doxygen). Doxygen found = " ${DOXYGEN_FOUND}) 4 | 5 | SET(DOXYGEN_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_data_lake") 6 | SET(DOXYGEN_DOCUMENTATION_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_data_lake/html") 7 | 8 | IF(DOXYGEN_FOUND) 9 | MESSAGE(STATUS "Using Doxygen (${DOXYGEN_EXECUTABLE}) to build reference documentation.") 10 | SET(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/mcl_data_lake.doxyfile) 11 | SET(DOXYFILE ${DOXYGEN_WORKING_DIRECTORY}/mcl_data_lake.doxyfile) 12 | CONFIGURE_FILE(${DOXYFILE_IN} ${DOXYFILE} @ONLY) 13 | 14 | ADD_CUSTOM_TARGET(mcl_data_lake_doc 15 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE} 16 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build/doc 17 | COMMENT "Generating API documentation with Doxygen" 18 | VERBATIM) 19 | 20 | # Install doxygen documents. 21 | INSTALL(DIRECTORY ${DOXYGEN_DOCUMENTATION_DIRECTORY} DESTINATION "${PACKAGE_DESTINATION_DOC}/mcl_data_lake") 22 | 23 | ELSE() 24 | MESSAGE(FATAL_ERROR "Doxygen is required to build the documentation.") 25 | ENDIF() 26 | -------------------------------------------------------------------------------- /mcl_data_lake/examples/callbacks.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file callbacks.h 3 | * @brief Sample callback functions for MCL. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CALLBACKS_H_ 10 | #define CALLBACKS_H_ 11 | 12 | #include "mcl_core/mcl_core.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | mcl_error_t custom_load_function_shared_secret(char **client_id, char **client_secret, char **registration_access_token, char **registration_uri); 20 | mcl_error_t custom_save_function_shared_secret(const char *client_id, const char *client_secret, const char *registration_access_token, const char *registration_uri); 21 | 22 | mcl_error_t custom_load_function_rsa(char **client_id, char **public_key, char **private_key, char **registration_access_token, char **registration_uri); 23 | mcl_error_t custom_save_function_rsa(const char *client_id, const char *public_key, const char *private_key, const char *registration_access_token, const char *registration_uri); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif //CALLBACKS_H_ 30 | -------------------------------------------------------------------------------- /mcl_data_lake/include/mcl_data_lake/mcl_data_lake_common.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_data_lake_common.h 3 | * @brief Data lake common module interface header file. 4 | * 5 | * This module contains common type definitions used in various MCL Data Lake modules. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef MCL_DATA_LAKE_COMMON_H_ 12 | #define MCL_DATA_LAKE_COMMON_H_ 13 | 14 | #include "mcl_core/mcl_assert.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | #ifndef MCL_DATA_LAKE_EXPORT 22 | #if MCL_STATICLIB 23 | #define MCL_DATA_LAKE_EXPORT 24 | #elif defined(WIN32) || defined(WIN64) 25 | #if MCL_DATA_LAKE_BUILD 26 | #define MCL_DATA_LAKE_EXPORT __declspec(dllexport) 27 | #else 28 | #define MCL_DATA_LAKE_EXPORT __declspec(dllimport) 29 | #endif 30 | #else 31 | #define MCL_DATA_LAKE_EXPORT 32 | #endif 33 | #endif 34 | 35 | /** 36 | * MCL Data Lake return code definitions. 37 | */ 38 | typedef enum E_MCL_DATA_LAKE_RETURN_CODE 39 | { 40 | MCL_DATA_LAKE_SIGNED_URL_GENERATION_FAIL = MCL_CORE_RETURN_CODE_END, //!< Could not get signed url for all object paths. 41 | MCL_DATA_LAKE_RETURN_CODE_END //!< End of return codes. 42 | } E_MCL_DATA_LAKE_RETURN_CODE; 43 | 44 | extern MCL_DATA_LAKE_EXPORT const char *mcl_data_lake_return_code_strings[MCL_DATA_LAKE_RETURN_CODE_END - MCL_CORE_RETURN_CODE_END]; 45 | 46 | // This function converts the given return code to its string value for data lake module. 47 | #define MCL_DATA_LAKE_CODE_TO_STRING(code) (code >= MCL_CORE_RETURN_CODE_END) ? mcl_data_lake_return_code_strings[code - MCL_CORE_RETURN_CODE_END] : MCL_CORE_CODE_TO_STRING(code) 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif //MCL_DATA_LAKE_COMMON_H_ 54 | -------------------------------------------------------------------------------- /mcl_data_lake/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set sources 2 | FILE(GLOB SOURCES *.c) 3 | LIST(APPEND MCL_DATA_LAKE_SOURCES ${SOURCES}) 4 | 5 | SET(MCL_DATA_LAKE_SOURCES ${MCL_DATA_LAKE_SOURCES} CACHE INTERNAL "MCL_DATA_LAKE_SOURCES" FORCE) 6 | 7 | #Specify library as target 8 | SET(PROJECT_LIBRARY_OUTPUT mcl_data_lake CACHE INTERNAL "PROJECT_LIBRARY_OUTPUT" FORCE) 9 | ADD_LIBRARY(${PROJECT_LIBRARY_OUTPUT} ${MCL_USER_DEFINED_DYNAMIC_OR_STATIC} ${MCL_DATA_LAKE_SOURCES}) 10 | 11 | SET_TARGET_PROPERTIES(${PROJECT_LIBRARY_OUTPUT} PROPERTIES FOLDER ${MCL_COMPONENT}) 12 | SET_TARGET_PROPERTIES(${PROJECT_LIBRARY_OUTPUT} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${PACKAGE_DESTINATION_LIB}) 13 | 14 | ADD_DEPENDENCIES(mcl_data_lake mcl_core) 15 | 16 | #Set include directories 17 | LIST(APPEND MCL_DATA_LAKE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) 18 | LIST(APPEND MCL_DATA_LAKE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) 19 | LIST(APPEND MCL_DATA_LAKE_INCLUDE_DIRECTORIES ${MCL_CMAKE_ROOT_DIR}/mcl_core/include) 20 | LIST(APPEND MCL_DATA_LAKE_INCLUDE_DIRECTORIES ${MCL_DATA_LAKE_CMAKE_ROOT_DIR}/include) 21 | 22 | IF(WIN32 OR WIN64) 23 | LIST(APPEND MCL_DATA_LAKE_LIBS ${MCL_OUTPUT_DIR}/mcl_core.lib) 24 | ELSE() 25 | IF(MCL_STATICLIB) 26 | LIST(APPEND MCL_DATA_LAKE_LIBS ${MCL_OUTPUT_DIR}/libmcl_core.a) 27 | ELSE() 28 | LIST(APPEND MCL_DATA_LAKE_LIBS ${MCL_OUTPUT_DIR}/libmcl_core.so) 29 | ENDIF() 30 | ENDIF() 31 | 32 | LIST(APPEND MCL_DATA_LAKE_LIBS ${MCL_CORE_LIBS}) 33 | 34 | SET(MCL_DATA_LAKE_INCLUDE_DIRECTORIES ${MCL_DATA_LAKE_INCLUDE_DIRECTORIES} CACHE INTERNAL "MCL_DATA_LAKE_INCLUDE_DIRECTORIES" FORCE) 35 | TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY_OUTPUT} PUBLIC ${MCL_DATA_LAKE_INCLUDE_DIRECTORIES}) 36 | 37 | TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY_OUTPUT} ${MCL_DATA_LAKE_LIBS}) 38 | 39 | #Set linker flag -lm for linking against the math lib (pow() floor()) 40 | IF(CMAKE_COMPILER_IS_GNUCC) 41 | TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY_OUTPUT} m) 42 | ENDIF() 43 | 44 | #Set variables for distribution package destination 45 | SET(PACKAGE_DESTINATION_LIB "lib") 46 | 47 | #Install MCL target 48 | INSTALL(TARGETS mcl_data_lake 49 | RUNTIME DESTINATION "${PACKAGE_DESTINATION_LIB}" 50 | LIBRARY DESTINATION "${PACKAGE_DESTINATION_LIB}" 51 | ARCHIVE DESTINATION "${PACKAGE_DESTINATION_LIB}") 52 | -------------------------------------------------------------------------------- /mcl_data_lake/src/data_lake.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_lake.h 3 | * @brief Data lake module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_LAKE_H_ 10 | #define DATA_LAKE_H_ 11 | 12 | #include "mcl_data_lake/mcl_data_lake_configuration.h" 13 | #include "data_lake_processor.h" 14 | 15 | /** 16 | * Handle for data lake. 17 | */ 18 | typedef struct mcl_data_lake_t 19 | { 20 | mcl_data_lake_configuration_t *configuration; //!< Data structure holding the data lake configuration. 21 | data_lake_processor_t processor; //!< Data lake processor handle. 22 | } data_lake_t; 23 | 24 | #endif //DATA_LAKE_H_ 25 | -------------------------------------------------------------------------------- /mcl_data_lake/src/data_lake_common.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_lake_common.c 3 | * @brief Strings for data lake error codes. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "data_lake_common.h" 10 | 11 | const char *mcl_data_lake_return_code_strings[MCL_DATA_LAKE_RETURN_CODE_END - MCL_CORE_RETURN_CODE_END] = 12 | { 13 | "MCL_DATA_LAKE_SIGNED_URL_GENERATION_FAIL" 14 | }; 15 | -------------------------------------------------------------------------------- /mcl_data_lake/src/data_lake_common.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_lake_common.h 3 | * @brief Strings for data lake error codes. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_LAKE_COMMON_H_ 10 | #define DATA_LAKE_COMMON_H_ 11 | 12 | #include "mcl_data_lake/mcl_data_lake_common.h" 13 | 14 | #endif //DATA_LAKE_COMMON_H_ 15 | -------------------------------------------------------------------------------- /mcl_data_lake/src/data_lake_configuration.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_lake_configuration.h 3 | * @brief Data lake configuration module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_LAKE_CONFIGURATION_H_ 10 | #define DATA_LAKE_CONFIGURATION_H_ 11 | 12 | #include "mcl_core/mcl_core.h" 13 | 14 | /** 15 | * Data lake configuration struct. 16 | */ 17 | typedef struct mcl_data_lake_configuration_t 18 | { 19 | mcl_core_t *core; 20 | char *upload_url_generation_url; 21 | char *certificate; 22 | mcl_bool_t certificate_is_file; 23 | } data_lake_configuration_t; 24 | 25 | /** 26 | * This function checks whether all mandatory parameters of a data lake configuration are set or not. 27 | * 28 | * @param [in] configuration Data lake configuration to validate. 29 | * @return 30 | *
    31 | *
  • #MCL_OK in case of success.
  • 32 | *
  • #MCL_INVALID_PARAMETER in case data lake configuration has one or more missing mandatory parameters.
  • 33 | *
34 | */ 35 | MCL_LOCAL mcl_error_t data_lake_configuration_validate(data_lake_configuration_t *configuration); 36 | 37 | #endif //DATA_LAKE_CONFIGURATION_H_ 38 | -------------------------------------------------------------------------------- /mcl_data_lake/src/data_lake_json.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_lake_json.h 3 | * @brief Data lake json module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_LAKE_JSON_H_ 10 | #define DATA_LAKE_JSON_H_ 11 | 12 | #include "data_lake_object.h" 13 | 14 | /** 15 | * This function generates a json string from an array of datalake objects. 16 | * 17 | * @param [in] object_array Array of data lake objects. 18 | * @param [in] array_size Size of array. 19 | * @param [in] client_id Client ID. 20 | * @param [in] subtenant_id Subtenant ID. 21 | * @param [out] json Json body for the request which is needed to generate upload urls. 22 | * @return 23 | *
    24 | *
  • #MCL_OK in case of success.
  • 25 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 26 | *
  • #MCL_INVALID_PARAMETER in case there is no path to generate upload url.
  • 27 | *
  • #MCL_FAIL in case of an internal error in MCL.
  • 28 | *
29 | */ 30 | mcl_error_t data_lake_json_from_objects(data_lake_object_t **object_array, mcl_size_t array_size, const char *client_id, const char *subtenant_id, char **json); 31 | 32 | /** 33 | * This function is used to match signed urls with objects. 34 | * 35 | * @param [in] object_array Array of data lake objects. 36 | * @param [in] array_size Size of array. 37 | * @param [in] json Json string to parse, does not need to be NULL terminated. 38 | * @param [in] json_size Size of json string. 39 | * @param [in] client_id_length Length of Client ID. 40 | * @return 41 | *
    42 | *
  • #MCL_OK in case of success.
  • 43 | *
  • #MCL_DATA_LAKE_SIGNED_URL_GENERATION_FAIL if signed URL could not be retrieved for all data lake objects with non-NULL paths.
  • 44 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 45 | *
  • #MCL_FAIL in case of an internal error in MCL.
  • 46 | *
47 | */ 48 | mcl_error_t data_lake_json_match_signed_urls_with_objects(data_lake_object_t **object_array, mcl_size_t array_size, char *json, 49 | mcl_size_t json_size, mcl_size_t client_id_length); 50 | 51 | #endif //DATA_LAKE_JSON_H_ 52 | -------------------------------------------------------------------------------- /mcl_data_lake/src/data_lake_object.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file data_lake_object.h 3 | * @brief Data lake object module header file. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DATA_LAKE_OBJECT_H_ 10 | #define DATA_LAKE_OBJECT_H_ 11 | 12 | #include "mcl_data_lake/mcl_data_lake_object.h" 13 | 14 | /** 15 | * Handle for data lake object. 16 | */ 17 | typedef struct mcl_data_lake_object_t 18 | { 19 | mcl_data_lake_upload_callback upload_callback; //!< Callback used by http client to copy object data to http request. 20 | void *user_context; //!< Context which will be passed to the callback. 21 | char *path; //!< Object path in Mindsphere. 22 | char *signed_url; //!< Signed URL for the object. 23 | mcl_size_t size; //!< Size of the object. 24 | } data_lake_object_t; 25 | 26 | /** 27 | * Internal parameters for data lake object. 28 | */ 29 | typedef enum E_DATA_LAKE_OBJECT_INTERNAL_PARAMETER 30 | { 31 | DATA_LAKE_OBJECT_INTERNAL_PARAMETER_SIGNED_URL = MCL_DATA_LAKE_OBJECT_PARAMETER_END, //!< Signed url parameter as char *. 32 | DATA_LAKE_OBJECT_INTERNAL_PARAMETER_END 33 | } E_DATA_LAKE_OBJECT_INTERNAL_PARAMETER; 34 | 35 | /** 36 | * This function is used to set an internal parameter of a data lake object. 37 | * 38 | * @param [in] object Data lake object to set its parameter. 39 | * @param [in] parameter One of the parameters listed in #E_DATA_LAKE_OBJECT_INTERNAL_PARAMETER. 40 | * @param [in] value New value of the @p parameter. 41 | * @return 42 | *
    43 | *
  • #MCL_OK in case of success.
  • 44 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 45 | *
  • #MCL_INVALID_PARAMETER if provided @p parameter is invalid.
  • 46 | *
47 | */ 48 | MCL_LOCAL mcl_error_t data_lake_object_set_internal_parameter(mcl_data_lake_object_t *object, 49 | E_DATA_LAKE_OBJECT_INTERNAL_PARAMETER parameter, const void *value); 50 | 51 | /** 52 | * This function checks whether all mandatory parameters of a data lake object are set or not. 53 | * 54 | * @param [in] object Data lake object to validate. 55 | * @return 56 | *
    57 | *
  • #MCL_OK in case of success.
  • 58 | *
  • #MCL_INVALID_PARAMETER in case data lake object has one or more missing mandatory parameters.
  • 59 | *
60 | */ 61 | MCL_LOCAL mcl_error_t data_lake_object_validate(data_lake_object_t *object); 62 | 63 | #endif //DATA_LAKE_OBJECT_H_ 64 | -------------------------------------------------------------------------------- /mcl_data_lake/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(integration) 2 | ADD_SUBDIRECTORY(unit) -------------------------------------------------------------------------------- /mcl_data_lake/test/integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set name of the test framework. 2 | SET(TEST_FRAMEWORK unity_and_cmock) 3 | 4 | #Set paths. 5 | SET(INTEGRATION_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") 6 | SET(TEST_RUNNER_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testrunner") 7 | SET(GENERATE_TEST_RUNNER_SCRIPT_PATH "mcl_core/test/lib/CMock/vendor/unity/auto/generate_test_runner.rb") 8 | 9 | #Set Ruby Command. 10 | SET(RUBY_CMD "ruby") 11 | 12 | #Create test runner directory. 13 | FILE(MAKE_DIRECTORY ${TEST_RUNNER_DIRECTORY}) 14 | 15 | #Loop over each integration test file. 16 | FILE(GLOB INTEGRATION_TEST_FILE_LIST RELATIVE "${INTEGRATION_TEST_DIRECTORY}" "${INTEGRATION_TEST_DIRECTORY}/*.c") 17 | FOREACH(INTEGRATION_TEST_FILE ${INTEGRATION_TEST_FILE_LIST}) 18 | 19 | #Remove file extension from the testcase file 20 | STRING(REPLACE ".c" "" INTEGRATION_TEST_FILE_NAME ${INTEGRATION_TEST_FILE}) 21 | 22 | #Create test runner. 23 | SET(TEST_RUNNER_FILE "${INTEGRATION_TEST_FILE_NAME}_runner.c") 24 | EXECUTE_PROCESS(COMMAND ${RUBY_CMD} ${GENERATE_TEST_RUNNER_SCRIPT_PATH} "${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE}" "${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}" 25 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 26 | RESULT_VARIABLE ruby_result 27 | OUTPUT_VARIABLE ruby_output) 28 | 29 | #Set test source files. 30 | SET(TEST_SOURCES ${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE} ${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}) 31 | 32 | #Set the name of the test executable. 33 | SET(INTEGRATION_TEST_NAME "${INTEGRATION_TEST_FILE_NAME}") 34 | 35 | #Create integration test executable. 36 | ADD_EXECUTABLE(${INTEGRATION_TEST_NAME} $ ${TEST_SOURCES}) 37 | 38 | #Link libraries to executable. 39 | TARGET_LINK_LIBRARIES(${INTEGRATION_TEST_NAME} ${MCL_DATA_LAKE_LIBS} ${PROJECT_LIBRARY_OUTPUT} ${TEST_FRAMEWORK}) 40 | 41 | #Include required directories 42 | TARGET_INCLUDE_DIRECTORIES(${INTEGRATION_TEST_NAME} PUBLIC ${MCL_DATA_LAKE_INCLUDE_DIRECTORIES}) 43 | 44 | ADD_TEST(${INTEGRATION_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${INTEGRATION_TEST_NAME}) 45 | 46 | SET_TARGET_PROPERTIES(${INTEGRATION_TEST_NAME} PROPERTIES FOLDER "${MCL_COMPONENT}/integration_tests") 47 | 48 | ENDFOREACH(INTEGRATION_TEST_FILE) 49 | -------------------------------------------------------------------------------- /mcl_data_lake/test/unit/cmock.yml.in: -------------------------------------------------------------------------------- 1 | :cmock: 2 | :plugins: [ignore, return_thru_ptr, expect_any_args, ignore_arg] 3 | :includes: ${CMOCK_YML_INCLUDES} 4 | :mock_path: '${CMAKE_CURRENT_BINARY_DIR}/mock' 5 | :mock_prefix: mock_ 6 | :framework: unity 7 | :verbosity: 3 8 | :treat_externs: :include -------------------------------------------------------------------------------- /mcl_deployment/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Set component name. 2 | SET(MCL_COMPONENT "deployment") 3 | 4 | # Set path of MCL Deployment Component's root Cmake directory. 5 | SET(MCL_DEPLOYMENT_CMAKE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | # Set MCL_DEPLOYMENT_SOURCES to collect source files from different locations. 8 | SET(MCL_DEPLOYMENT_SOURCES "" CACHE INTERNAL "MCL_DEPLOYMENT_SOURCES" FORCE) 9 | SET(MCL_DEPLOYMENT_LIBS "" CACHE INTERNAL "MCL_DEPLOYMENT_LIBS" FORCE) 10 | SET(MCL_DEPLOYMENT_INCLUDE_DIRECTORIES "" CACHE INTERNAL "MCL_DEPLOYMENT_INCLUDE_DIRECTORIES" FORCE) 11 | 12 | IF(MCL_DEPLOYMENT) 13 | MESSAGE(STATUS "MCL Deployment build is ${MCL_DEPLOYMENT}.") 14 | ADD_DEFINITIONS(-DMCL_DEPLOYMENT_BUILD=1) 15 | ENDIF() 16 | 17 | IF(MCL_STATICLIB) 18 | SET(MCL_USER_DEFINED_DYNAMIC_OR_STATIC STATIC) 19 | ADD_DEFINITIONS(-DMCL_STATICLIB=1) 20 | ELSE() 21 | SET(MCL_USER_DEFINED_DYNAMIC_OR_STATIC SHARED) 22 | ADD_DEFINITIONS(-DMCL_STATICLIB=0) 23 | ENDIF() 24 | 25 | MESSAGE(STATUS "MCL Deployment will be built as ${MCL_USER_DEFINED_DYNAMIC_OR_STATIC} library.") 26 | 27 | # MCL DEPLOYMENT sources. 28 | ADD_SUBDIRECTORY(src) 29 | 30 | IF(MCL_TEST AND RUBY_FOUND) 31 | # Turn on CMake testing capabilities. 32 | ENABLE_TESTING() 33 | ADD_SUBDIRECTORY(test) 34 | ENDIF() 35 | 36 | # Doxygen. 37 | IF(MCL_DOC) 38 | ADD_SUBDIRECTORY(doc) 39 | ADD_DEPENDENCIES(mcl_deployment mcl_deployment_doc) 40 | MESSAGE(STATUS "Creation of reference documentation is enabled.") 41 | ELSE() 42 | MESSAGE(STATUS "Creation of reference documentation is disabled.") 43 | ENDIF() 44 | 45 | # Get all interface header files of mcl deployment component. 46 | FILE(GLOB MCL_DEPLOYMENT_INTERFACE_HEADER_FILES "${MCL_DEPLOYMENT_CMAKE_ROOT_DIR}/include/mcl_deployment/*.h") 47 | 48 | # Install directory for interface header files of mcl deployment component. 49 | INSTALL(FILES ${MCL_DEPLOYMENT_INTERFACE_HEADER_FILES} DESTINATION "${PACKAGE_DESTINATION_INCLUDE}/mcl_deployment") 50 | -------------------------------------------------------------------------------- /mcl_deployment/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add a target to generate API documentation with Doxygen. 2 | FIND_PACKAGE(Doxygen) 3 | MESSAGE(STATUS "Create and install the HTML based API documentation (requires Doxygen). Doxygen found = " ${DOXYGEN_FOUND}) 4 | 5 | SET(DOXYGEN_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_deployment") 6 | SET(DOXYGEN_DOCUMENTATION_DIRECTORY "${CMAKE_BINARY_DIR}/build/doc/mcl_deployment/html") 7 | 8 | IF(DOXYGEN_FOUND) 9 | MESSAGE(STATUS "Using Doxygen (${DOXYGEN_EXECUTABLE}) to build reference documentation.") 10 | SET(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/mcl_deployment.doxyfile) 11 | SET(DOXYFILE ${DOXYGEN_WORKING_DIRECTORY}/mcl_deployment.doxyfile) 12 | CONFIGURE_FILE(${DOXYFILE_IN} ${DOXYFILE} @ONLY) 13 | 14 | ADD_CUSTOM_TARGET(mcl_deployment_doc 15 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE} 16 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build/doc 17 | COMMENT "Generating API documentation with Doxygen" 18 | VERBATIM) 19 | 20 | # Install doxygen documents. 21 | INSTALL(DIRECTORY ${DOXYGEN_DOCUMENTATION_DIRECTORY} DESTINATION "${PACKAGE_DESTINATION_DOC}/mcl_deployment") 22 | 23 | ELSE() 24 | MESSAGE(FATAL_ERROR "Doxygen is required to build the documentation.") 25 | ENDIF() 26 | -------------------------------------------------------------------------------- /mcl_deployment/examples/callbacks.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file callbacks.h 3 | * @brief Sample callback functions for MCL. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef CALLBACKS_H_ 10 | #define CALLBACKS_H_ 11 | 12 | #include "mcl_core/mcl_core.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | mcl_error_t custom_load_function_shared_secret(char **client_id, char **client_secret, char **registration_access_token, char **registration_uri); 20 | mcl_error_t custom_save_function_shared_secret(const char *client_id, const char *client_secret, const char *registration_access_token, const char *registration_uri); 21 | 22 | mcl_error_t custom_load_function_rsa(char **client_id, char **public_key, char **private_key, char **registration_access_token, char **registration_uri); 23 | mcl_error_t custom_save_function_rsa(const char *client_id, const char *public_key, const char *private_key, const char *registration_access_token, const char *registration_uri); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif //CALLBACKS_H_ 30 | -------------------------------------------------------------------------------- /mcl_deployment/include/mcl_deployment/mcl_deployment_common.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_deployment_common.h 3 | * @brief Header for component commons. 4 | * 5 | * This module contains common type definitions used in various MCL Deployment component modules. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef MCL_DEPLOYMENT_COMMON_H_ 12 | #define MCL_DEPLOYMENT_COMMON_H_ 13 | 14 | #include "mcl_core/mcl_assert.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | #ifndef MCL_DEPLOYMENT_EXPORT 22 | #if MCL_STATICLIB 23 | #define MCL_DEPLOYMENT_EXPORT 24 | #elif defined(WIN32) || defined(WIN64) 25 | #if MCL_DEPLOYMENT_BUILD 26 | #define MCL_DEPLOYMENT_EXPORT __declspec(dllexport) 27 | #else 28 | #define MCL_DEPLOYMENT_EXPORT __declspec(dllimport) 29 | #endif 30 | #else 31 | #define MCL_DEPLOYMENT_EXPORT 32 | #endif 33 | #endif 34 | 35 | /** 36 | * MCL Deployment component functions' return code definitions. 37 | */ 38 | typedef enum E_MCL_DEPLOYMENT_RETURN_CODE 39 | { 40 | MCL_DEPLOYMENT_FAIL = MCL_CORE_RETURN_CODE_END, //!< General fail code for MCL Deployment component. 41 | MCL_DEPLOYMENT_RETURN_CODE_END //!< End of return codes. 42 | } E_MCL_DEPLOYMENT_RETURN_CODE; 43 | 44 | extern MCL_DEPLOYMENT_EXPORT const char *mcl_deployment_return_code_strings[MCL_DEPLOYMENT_RETURN_CODE_END - MCL_CORE_RETURN_CODE_END]; 45 | 46 | // This function converts the given return code to its string value for this component. 47 | #define MCL_DEPLOYMENT_CODE_TO_STRING(code) (code >= MCL_CORE_RETURN_CODE_END) ? mcl_deployment_return_code_strings[code - MCL_CORE_RETURN_CODE_END] : MCL_CORE_CODE_TO_STRING(code) 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif //MCL_DEPLOYMENT_COMMON_H_ 54 | -------------------------------------------------------------------------------- /mcl_deployment/include/mcl_deployment/mcl_deployment_configuration.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_deployment_configuration.h 3 | * @brief Header for component configuration. 4 | * 5 | * This interface introduces configuration data structure for #mcl_deployment module 6 | * and functions to initialize and set parameters of this configuration. 7 | * 8 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 9 | * All rights reserved. 10 | */ 11 | 12 | #ifndef MCL_DEPLOYMENT_CONFIGURATION_H_ 13 | #define MCL_DEPLOYMENT_CONFIGURATION_H_ 14 | 15 | #include "mcl_deployment/mcl_deployment_common.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | /** 23 | * Handle for deployment configuration. 24 | */ 25 | typedef struct mcl_deployment_configuration_t mcl_deployment_configuration_t; 26 | 27 | /** 28 | * Parameters for deployment configuration. 29 | */ 30 | typedef enum E_MCL_DEPLOYMENT_CONFIGURATION_PARAMETER 31 | { 32 | MCL_DEPLOYMENT_CONFIGURATION_PARAMETER_CORE = 0, //!< Handle of the core component (mcl_core_t *). 33 | MCL_DEPLOYMENT_CONFIGURATION_PARAMETER_END 34 | } E_MCL_DEPLOYMENT_CONFIGURATION_PARAMETER; 35 | 36 | /** 37 | * This function creates and initializes a data struct of #mcl_deployment_configuration_t. 38 | * 39 | * @param [out] configuration Data structure holding the configuration parameters. 40 | * @return 41 | *
    42 | *
  • #MCL_OK in case of success.
  • 43 | *
  • #MCL_TRIGGERED_WITH_NULL if provided @p configuration is NULL.
  • 44 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 45 | *
46 | */ 47 | extern MCL_DEPLOYMENT_EXPORT mcl_error_t mcl_deployment_configuration_initialize(mcl_deployment_configuration_t **configuration); 48 | 49 | /** 50 | * This function is used to set a parameter of the configuration. 51 | * 52 | * @param [in] configuration Configuration to set its parameter. 53 | * @param [in] parameter One of the parameters listed in #E_MCL_DEPLOYMENT_CONFIGURATION_PARAMETER. 54 | * @param [in] value New value of the @p parameter. 55 | * @return 56 | *
    57 | *
  • #MCL_OK in case of success.
  • 58 | *
  • #MCL_TRIGGERED_WITH_NULL if provided @p configuration or @p value is NULL.
  • 59 | *
  • #MCL_INVALID_PARAMETER if provided @p parameter is invalid.
  • 60 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 61 | *
62 | */ 63 | extern MCL_DEPLOYMENT_EXPORT mcl_error_t mcl_deployment_configuration_set_parameter(mcl_deployment_configuration_t *configuration, E_MCL_DEPLOYMENT_CONFIGURATION_PARAMETER parameter, const void *value); 64 | 65 | /** 66 | * This function destroys #mcl_deployment_configuration_t data structure. 67 | * 68 | * @param [in] configuration Configuration handle which is going to be destroyed. 69 | */ 70 | extern MCL_DEPLOYMENT_EXPORT void mcl_deployment_configuration_destroy(mcl_deployment_configuration_t **configuration); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif //MCL_DEPLOYMENT_CONFIGURATION_H_ 77 | -------------------------------------------------------------------------------- /mcl_deployment/include/mcl_deployment/mcl_deployment_workflow.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_deployment_workflow.h 3 | * @brief Header for deployment workflow. 4 | * 5 | * This module defines the deployment workflow structure. 6 | * 7 | * Use #mcl_deployment_workflow_get_parameter function to get any paramater of the workflow returned 8 | * in the response from MindSphere. 9 | * 10 | * See #mcl_deployment module to get the deployment workflow from MindSphere. 11 | * 12 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 13 | * All rights reserved. 14 | */ 15 | 16 | #ifndef MCL_DEPLOYMENT_WORKFLOW_H_ 17 | #define MCL_DEPLOYMENT_WORKFLOW_H_ 18 | 19 | #include "mcl_deployment/mcl_deployment_common.h" 20 | #include "mcl_deployment/mcl_deployment_workflow_state.h" 21 | #include "mcl_deployment/mcl_deployment_workflow_model.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | /** 29 | * Handle for deployment workflow. 30 | */ 31 | typedef struct mcl_deployment_workflow_t mcl_deployment_workflow_t; 32 | 33 | /** 34 | * Parameters of deployment workflow. 35 | */ 36 | typedef enum E_MCL_DEPLOYMENT_WORKFLOW_PARAMETER 37 | { 38 | MCL_DEPLOYMENT_WORKFLOW_PARAMETER_ID, //!< Workflow id as char*. 39 | MCL_DEPLOYMENT_WORKFLOW_PARAMETER_DEVICE_ID, //!< Device id as char*. 40 | MCL_DEPLOYMENT_WORKFLOW_PARAMETER_CREATED_AT, //!< Time when the workflow is created as char*. 41 | MCL_DEPLOYMENT_WORKFLOW_PARAMETER_CURRENT_STATE, //!< Current state of the workflow as mcl_deployment_workflow_state_t*. 42 | MCL_DEPLOYMENT_WORKFLOW_PARAMETER_HISTORY, //!< History of workflow states as mcl_list_t* of mcl_deployment_workflow_state_t*. 43 | MCL_DEPLOYMENT_WORKFLOW_PARAMETER_MODEL, //!< Model of the workflow as mcl_deployment_workflow_model_t*. 44 | MCL_DEPLOYMENT_WORKFLOW_PARAMETER_DATA //!< User defined data of the workflow as mcl_json_t*. 45 | } E_MCL_DEPLOYMENT_WORKFLOW_PARAMETER; 46 | 47 | /** 48 | * This function is used to get the value of a parameter of the deployment workflow. 49 | * Reference to the parameter is returned and no new memory allocation is performed. 50 | * Hence, there is no need to free any memory for the returned values. 51 | * 52 | * @param [in] workflow Deployment workflow instance. 53 | * @param [in] parameter One of the parameters listed in #E_MCL_DEPLOYMENT_WORKFLOW_PARAMETER. 54 | * @param [out] value Value of the @p parameter. 55 | * @return 56 | *
    57 | *
  • #MCL_OK in case of success.
  • 58 | *
  • #MCL_TRIGGERED_WITH_NULL if provided @p workflow is NULL.
  • 59 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 60 | *
  • #MCL_INVALID_PARAMETER if provided @p parameter or @ value is invalid.
  • 61 | *
62 | */ 63 | extern MCL_DEPLOYMENT_EXPORT mcl_error_t mcl_deployment_workflow_get_parameter(mcl_deployment_workflow_t *workflow, E_MCL_DEPLOYMENT_WORKFLOW_PARAMETER parameter, void **value); 64 | 65 | /** 66 | * This function destroys deployment workflow instance. 67 | * 68 | * @param [in] workflow Deployment workflow instance to destroy. 69 | */ 70 | extern MCL_DEPLOYMENT_EXPORT void mcl_deployment_workflow_destroy(mcl_deployment_workflow_t **workflow); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif //MCL_DEPLOYMENT_WORKFLOW_H_ 77 | -------------------------------------------------------------------------------- /mcl_deployment/include/mcl_deployment/mcl_deployment_workflow_model.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_deployment_workflow_model.h 3 | * @brief Header for deployment workflow model. 4 | * 5 | * This module defines the workflow model. 6 | * 7 | * Use #mcl_deployment_workflow_model_get_parameter function to get any parameter of the workflow model. 8 | * 9 | * See #mcl_deployment_workflow module to get the model of the workflow. 10 | * 11 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 12 | * All rights reserved. 13 | */ 14 | 15 | #ifndef MCL_DEPLOYMENT_WORKFLOW_MODEL_H_ 16 | #define MCL_DEPLOYMENT_WORKFLOW_MODEL_H_ 17 | 18 | #include "mcl_deployment/mcl_deployment_common.h" 19 | #include "mcl_deployment/mcl_deployment_workflow_model_state.h" 20 | #include "mcl_deployment/mcl_deployment_workflow_model_transition.h" 21 | #include "mcl_deployment/mcl_deployment_workflow_model_state_group.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | /** 29 | * Handle for deployment workflow model. 30 | */ 31 | typedef struct mcl_deployment_workflow_model_t mcl_deployment_workflow_model_t; 32 | 33 | /** 34 | * Parameters of deployment workflow model. 35 | */ 36 | typedef enum E_MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER 37 | { 38 | MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_KEY, //!< Key of the workflow model (char*). 39 | MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_STATES, //!< List of states in workflow model (mcl_list_t* of mcl_deployment_workflow_model_state*). 40 | MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_TRANSITIONS, //!< List of transitions in workflow model (mcl_list_t* of mcl_deployment_workflow_model_transition*). 41 | MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_STATE_GROUPS //!< List of state groups in workflow model (mcl_list_t* of mcl_deployment_workflow_model_state_group*). 42 | } E_MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER; 43 | 44 | /** 45 | * This function is used to get the value of a parameter of the deployment workflow model. 46 | * Reference to the parameter is returned and no new memory allocation is performed. 47 | * Hence, there is no need to free any memory for the returned values. 48 | * 49 | * @param [in] model Deployment workflow model. 50 | * @param [in] parameter One of the parameters listed in #E_MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER. 51 | * @param [out] value Value of the @p parameter. 52 | * @return 53 | *
    54 | *
  • #MCL_OK in case of success.
  • 55 | *
  • #MCL_TRIGGERED_WITH_NULL if the function is called with an unexpected NULL parameter.
  • 56 | *
  • #MCL_INVALID_PARAMETER if provided @p parameter is invalid.
  • 57 | *
58 | */ 59 | extern MCL_DEPLOYMENT_EXPORT mcl_error_t mcl_deployment_workflow_model_get_parameter(mcl_deployment_workflow_model_t *model, E_MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER parameter, void **value); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif //MCL_DEPLOYMENT_WORKFLOW_MODEL_H_ 66 | -------------------------------------------------------------------------------- /mcl_deployment/include/mcl_deployment/mcl_deployment_workflow_model_state.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_deployment_workflow_model_state.h 3 | * @brief Header for deployment workflow model state. 4 | * 5 | * This module defines a state in a workflow model. 6 | * 7 | * Use #mcl_deployment_workflow_model_state_get_parameter function to get 8 | * any parameter of the state in the workflow model. 9 | * 10 | * See #mcl_deployment_workflow_model module to get the state of the workflow model. 11 | * 12 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 13 | * All rights reserved. 14 | */ 15 | 16 | #ifndef MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_H_ 17 | #define MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_H_ 18 | 19 | #include "mcl_deployment/mcl_deployment_common.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | /** 27 | * Handle for deployment workflow model state. 28 | */ 29 | typedef struct mcl_deployment_workflow_model_state_t mcl_deployment_workflow_model_state_t; 30 | 31 | /** 32 | * Parameters of deployment workflow model state. 33 | */ 34 | typedef enum E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER 35 | { 36 | MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_NAME, //!< Name of workflow model state (char*). 37 | MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_DESCRIPTION, //!< Description of workflow model state (char*). 38 | MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_INITIAL, //!< Boolean flag to show if the state is the initial state (mcl_bool_t). 39 | MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_FINAL, //!< Boolean flag to show if the state is the final state (mcl_bool_t). 40 | MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_CANCEL //!< Boolean flag to show if the state can be cancelled (mcl_bool_t). 41 | } E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER; 42 | 43 | /** 44 | * This function is used to get the value of a parameter of the deployment workflow model state. 45 | * Reference to the parameter is returned and no new memory allocation is performed. 46 | * Hence, there is no need to free any memory for the returned values. 47 | * 48 | * @param [in] state Deployment workflow model state. 49 | * @param [in] parameter One of the parameters listed in #E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER. 50 | * @param [out] value Value of the @p parameter. 51 | * @return 52 | *
    53 | *
  • #MCL_OK in case of success.
  • 54 | *
  • #MCL_TRIGGERED_WITH_NULL if the function is called with an unexpected NULL parameter.
  • 55 | *
  • #MCL_INVALID_PARAMETER if provided @p parameter is invalid.
  • 56 | *
57 | */ 58 | extern MCL_DEPLOYMENT_EXPORT mcl_error_t mcl_deployment_workflow_model_state_get_parameter(mcl_deployment_workflow_model_state_t *state, E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER parameter, void **value); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif //MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_H_ 65 | -------------------------------------------------------------------------------- /mcl_deployment/include/mcl_deployment/mcl_deployment_workflow_model_state_group.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_deployment_workflow_model_state_group.h 3 | * @brief Header for deployment workflow model state group. 4 | * 5 | * This module defines a state group in a workflow model. 6 | * 7 | * Use #mcl_deployment_workflow_model_state_group_get_parameter function to get 8 | * any parameter of the state group in the workflow model. 9 | * 10 | * See #mcl_deployment_workflow_model module to get the state groups of the workflow model. 11 | * 12 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 13 | * All rights reserved. 14 | */ 15 | 16 | #ifndef MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_H_ 17 | #define MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_H_ 18 | 19 | #include "mcl_deployment/mcl_deployment_common.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | /** 27 | * Handle for deployment workflow model state group. 28 | */ 29 | typedef struct mcl_deployment_workflow_model_state_group_t mcl_deployment_workflow_model_state_group_t; 30 | 31 | /** 32 | * Parameters of deployment workflow model state group. 33 | */ 34 | typedef enum E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER 35 | { 36 | MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER_NAME, //!< Name of workflow model state group (char*). 37 | MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER_STATES //!< List of state names in the state group (mcl_list_t of char*). 38 | } E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER; 39 | 40 | /** 41 | * This function is used to get the value of a parameter of the deployment workflow model state group. 42 | * Reference to the parameter is returned and no new memory allocation is performed. 43 | * Hence, there is no need to free any memory for the returned values. 44 | * 45 | * @param [in] state_group Deployment workflow model state group. 46 | * @param [in] parameter One of the parameters listed in #E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER. 47 | * @param [out] value Value of the @p parameter. 48 | * @return 49 | *
    50 | *
  • #MCL_OK in case of success.
  • 51 | *
  • #MCL_TRIGGERED_WITH_NULL if the function is called with an unexpected NULL parameter.
  • 52 | *
  • #MCL_INVALID_PARAMETER if provided @p parameter is invalid.
  • 53 | *
54 | */ 55 | extern MCL_DEPLOYMENT_EXPORT mcl_error_t mcl_deployment_workflow_model_state_group_get_parameter(mcl_deployment_workflow_model_state_group_t *state_group, E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER parameter, void **value); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif //MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_H_ 62 | -------------------------------------------------------------------------------- /mcl_deployment/include/mcl_deployment/mcl_deployment_workflow_model_transition.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file mcl_deployment_workflow_model_transition.h 3 | * @brief Header for deployment workflow model transition. 4 | * 5 | * This module defines a transition in a workflow model. 6 | * 7 | * Use #mcl_deployment_workflow_model_transition_get_parameter function to get 8 | * any parameter of the transition in the workflow model. 9 | * 10 | * See #mcl_deployment_workflow_model module to get the transition of the workflow model. 11 | * 12 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 13 | * All rights reserved. 14 | */ 15 | 16 | #ifndef MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_H_ 17 | #define MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_H_ 18 | 19 | #include "mcl_deployment/mcl_deployment_common.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | /** 27 | * Handle for deployment workflow model transition. 28 | */ 29 | typedef struct mcl_deployment_workflow_model_transition_t mcl_deployment_workflow_model_transition_t; 30 | 31 | /** 32 | * Parameters of deployment workflow model transition. 33 | */ 34 | typedef enum E_MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER 35 | { 36 | MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_FROM, //!< State the transition is from (char*). 37 | MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_TO, //!< State the transition is to (char*). 38 | MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_TYPE, //!< Type of the transition (char*). 39 | MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_DETAILS //!< Details about the transition (mcl_json_t). 40 | } E_MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER; 41 | 42 | /** 43 | * This function is used to get the value of a parameter of the deployment workflow model transition. 44 | * Reference to the parameter is returned and no new memory allocation is performed. 45 | * Hence, there is no need to free any memory for the returned values. 46 | * 47 | * @param [in] transition Deployment workflow model transition. 48 | * @param [in] parameter One of the parameters listed in #E_MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER. 49 | * @param [out] value Value of the @p parameter. 50 | * @return 51 | *
    52 | *
  • #MCL_OK in case of success.
  • 53 | *
  • #MCL_TRIGGERED_WITH_NULL if the function is called with an unexpected NULL parameter.
  • 54 | *
  • #MCL_INVALID_PARAMETER if provided @p parameter is invalid.
  • 55 | *
56 | */ 57 | extern MCL_DEPLOYMENT_EXPORT mcl_error_t mcl_deployment_workflow_model_transition_get_parameter(mcl_deployment_workflow_model_transition_t *transition, E_MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER parameter, void **value); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif //MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_H_ 64 | -------------------------------------------------------------------------------- /mcl_deployment/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set sources 2 | FILE(GLOB SOURCES *.c) 3 | LIST(APPEND MCL_DEPLOYMENT_SOURCES ${SOURCES}) 4 | 5 | SET(MCL_DEPLOYMENT_SOURCES ${MCL_DEPLOYMENT_SOURCES} CACHE INTERNAL "MCL_DEPLOYMENT_SOURCES" FORCE) 6 | 7 | #Specify library as target 8 | SET(PROJECT_LIBRARY_OUTPUT mcl_deployment CACHE INTERNAL "PROJECT_LIBRARY_OUTPUT" FORCE) 9 | ADD_LIBRARY(${PROJECT_LIBRARY_OUTPUT} ${MCL_USER_DEFINED_DYNAMIC_OR_STATIC} $ ${MCL_DEPLOYMENT_SOURCES}) 10 | 11 | SET_TARGET_PROPERTIES(${PROJECT_LIBRARY_OUTPUT} PROPERTIES FOLDER ${MCL_COMPONENT}) 12 | SET_TARGET_PROPERTIES(${PROJECT_LIBRARY_OUTPUT} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${PACKAGE_DESTINATION_LIB}) 13 | 14 | ADD_DEPENDENCIES(mcl_deployment mcl_core) 15 | 16 | #Set include directories 17 | LIST(APPEND MCL_DEPLOYMENT_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) 18 | LIST(APPEND MCL_DEPLOYMENT_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) 19 | LIST(APPEND MCL_DEPLOYMENT_INCLUDE_DIRECTORIES ${MCL_CMAKE_ROOT_DIR}/mcl_core/include) 20 | LIST(APPEND MCL_DEPLOYMENT_INCLUDE_DIRECTORIES ${MCL_DEPLOYMENT_CMAKE_ROOT_DIR}/include) 21 | 22 | IF(WIN32 OR WIN64) 23 | LIST(APPEND MCL_DEPLOYMENT_LIBS ${MCL_OUTPUT_DIR}/mcl_core.lib) 24 | ELSE() 25 | IF(MCL_STATICLIB) 26 | LIST(APPEND MCL_DEPLOYMENT_LIBS ${MCL_OUTPUT_DIR}/libmcl_core.a) 27 | ELSE() 28 | LIST(APPEND MCL_DEPLOYMENT_LIBS ${MCL_OUTPUT_DIR}/libmcl_core.so) 29 | ENDIF() 30 | ENDIF() 31 | 32 | LIST(APPEND MCL_DEPLOYMENT_LIBS ${MCL_CORE_LIBS}) 33 | 34 | SET(MCL_DEPLOYMENT_INCLUDE_DIRECTORIES ${MCL_DEPLOYMENT_INCLUDE_DIRECTORIES} CACHE INTERNAL "MCL_DEPLOYMENT_INCLUDE_DIRECTORIES" FORCE) 35 | TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY_OUTPUT} PUBLIC ${MCL_DEPLOYMENT_INCLUDE_DIRECTORIES}) 36 | 37 | TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY_OUTPUT} ${MCL_DEPLOYMENT_LIBS}) 38 | 39 | #Install MCL target 40 | INSTALL(TARGETS mcl_deployment 41 | RUNTIME DESTINATION "${PACKAGE_DESTINATION_LIB}" 42 | LIBRARY DESTINATION "${PACKAGE_DESTINATION_LIB}" 43 | ARCHIVE DESTINATION "${PACKAGE_DESTINATION_LIB}") 44 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment.h 3 | * @brief Internal header for the component functionality. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_H_ 10 | #define DEPLOYMENT_H_ 11 | 12 | #include "deployment_configuration.h" 13 | #include "deployment_processor.h" 14 | 15 | /** 16 | * This is the main handle for deployment component. 17 | */ 18 | typedef struct mcl_deployment_t 19 | { 20 | deployment_configuration_t *configuration; 21 | deployment_processor_t processor; 22 | } deployment_t; 23 | 24 | #endif //DEPLOYMENT_H_ 25 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_common.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_common.c 3 | * @brief Implementation of component commons. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "deployment_common.h" 10 | 11 | const char *mcl_deployment_return_code_strings[MCL_DEPLOYMENT_RETURN_CODE_END - MCL_CORE_RETURN_CODE_END] = 12 | { 13 | "MCL_DEPLOYMENT_FAIL" 14 | }; 15 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_common.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_common.h 3 | * @brief Internal header for component commons. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_COMMON_H_ 10 | #define DEPLOYMENT_COMMON_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | 14 | #endif //DEPLOYMENT_COMMON_H_ 15 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_configuration.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_configuration.h 3 | * @brief Internal header for component configuration. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_CONFIGURATION_H_ 10 | #define DEPLOYMENT_CONFIGURATION_H_ 11 | 12 | #include "mcl_core/mcl_core.h" 13 | 14 | /** 15 | * Handle for the component configuration. 16 | */ 17 | typedef struct mcl_deployment_configuration_t 18 | { 19 | mcl_core_t *core; 20 | char *workflow_instances_url; 21 | } deployment_configuration_t; 22 | 23 | /** 24 | * This function checks whether all mandatory parameters of a component configuration are set or not. 25 | * 26 | * @param [in] configuration Component configuration to validate. 27 | * @return 28 | *
    29 | *
  • #MCL_OK in case of success.
  • 30 | *
  • #MCL_INVALID_PARAMETER in case component configuration has one or more missing mandatory parameters.
  • 31 | *
32 | */ 33 | MCL_LOCAL mcl_error_t deployment_configuration_validate(deployment_configuration_t *configuration); 34 | 35 | #endif //DEPLOYMENT_CONFIGURATION_H_ 36 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_json.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_json.h 3 | * @brief Header for json operations of MCL deployment component. 4 | * 5 | * This module provides the functions for json operations of MCL deployment component. 6 | * 7 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 8 | * All rights reserved. 9 | */ 10 | 11 | #ifndef DEPLOYMENT_JSON_H_ 12 | #define DEPLOYMENT_JSON_H_ 13 | 14 | #include "mcl_deployment/mcl_deployment_common.h" 15 | #include "mcl_core/mcl_list.h" 16 | #include "deployment_workflow.h" 17 | 18 | /** 19 | * This function parses a given json string into a list of deployment workflow objects. 20 | * 21 | * @param [in] json_string Json string. 22 | * @param [in] string_length Length of json string. 23 | * @param [out] workflows List of deployment workflows. 24 | * @return 25 | *
    26 | *
  • #MCL_OK in case of success.
  • 27 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 28 | *
  • #MCL_JSON_NON_EXISTING_CHILD in case there is a missing mandatory field.
  • 29 | *
30 | */ 31 | MCL_LOCAL mcl_error_t deployment_json_parse_workflows(const char *json_string, mcl_size_t string_length, mcl_list_t **workflows); 32 | 33 | /** 34 | * This function parses a given json string into a deployment workflow object. 35 | * 36 | * @param [in] json_string Json string. 37 | * @param [in] string_length Length of json string. 38 | * @param [out] workflow Deployment workflow. 39 | * @return 40 | *
    41 | *
  • #MCL_OK in case of success.
  • 42 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 43 | *
  • #MCL_JSON_NON_EXISTING_CHILD in case there is a missing mandatory field.
  • 44 | *
45 | */ 46 | MCL_LOCAL mcl_error_t deployment_json_parse_workflow(const char* json_string, mcl_size_t string_length, deployment_workflow_t **workflow); 47 | 48 | /** 49 | * This function converts a deployment workflow state to a json string. 50 | * 51 | * @param [in] workflow_state Workflow state. 52 | * @param [out] json_string Json string. 53 | * @return 54 | *
    55 | *
  • #MCL_OK in case of success.
  • 56 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 57 | *
  • #MCL_JSON_NON_EXISTING_CHILD in case there is a missing mandatory field.
  • 58 | *
59 | */ 60 | MCL_LOCAL mcl_error_t deployment_json_from_workflow_state(deployment_workflow_state_t *workflow_state, char **json_string); 61 | 62 | #endif //DEPLOYMENT_JSON_H_ 63 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow.h 3 | * @brief Internal header for deployment workflow. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_WORKFLOW_H_ 10 | #define DEPLOYMENT_WORKFLOW_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | #include "deployment_workflow_state.h" 14 | #include "deployment_workflow_model.h" 15 | #include "mcl_core/mcl_list.h" 16 | 17 | /** 18 | * Handle for deployment workflow. 19 | */ 20 | typedef struct mcl_deployment_workflow_t 21 | { 22 | char *id; 23 | char *device_id; 24 | char *created_at; 25 | deployment_workflow_state_t *current_state; 26 | mcl_list_t *history; 27 | deployment_workflow_model_t *model; 28 | mcl_json_t *data; 29 | } deployment_workflow_t; 30 | 31 | /** 32 | * This function initializes a deployment workflow instance. 33 | * 34 | * @param [out] workflow Deployment workflow instance. 35 | * @return 36 | *
    37 | *
  • #MCL_OK in case of success.
  • 38 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 39 | *
  • #MCL_TRIGGERED_WITH_NULL in case @p workflow is null.
  • 40 | *
41 | */ 42 | MCL_LOCAL mcl_error_t deployment_workflow_initialize(deployment_workflow_t **workflow); 43 | 44 | #endif //DEPLOYMENT_WORKFLOW_H_ 45 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_filter.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_filter.h 3 | * @brief Internal header for deployment workflow filter. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_WORKFLOW_FILTER_H_ 10 | #define DEPLOYMENT_WORKFLOW_FILTER_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | 14 | /** 15 | * Handle for deployment workflow filter. 16 | */ 17 | typedef struct mcl_deployment_workflow_filter_t 18 | { 19 | mcl_bool_t model; 20 | mcl_bool_t history; 21 | char *current_state; 22 | char *group; 23 | char *device_id; 24 | char *model_key; 25 | } deployment_workflow_filter_t; 26 | 27 | #endif //DEPLOYMENT_WORKFLOW_FILTER_H_ 28 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model.c 3 | * @brief Implementation of deployment workflow model. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "mcl_deployment/mcl_deployment_workflow_model.h" 10 | #include "deployment_workflow_model.h" 11 | #include "mcl_core/mcl_memory.h" 12 | 13 | mcl_error_t deployment_workflow_model_initialize(deployment_workflow_model_t **model) 14 | { 15 | mcl_error_t code = MCL_OK; 16 | 17 | MCL_DEBUG_ENTRY("deployment_workflow_model_t **model = <%p>", model); 18 | 19 | if (MCL_NULL != MCL_NEW(*model)) 20 | { 21 | (*model)->key = MCL_NULL; 22 | (*model)->states = MCL_NULL; 23 | (*model)->transitions = MCL_NULL; 24 | (*model)->state_groups = MCL_NULL; 25 | } 26 | else 27 | { 28 | code = MCL_OUT_OF_MEMORY; 29 | } 30 | 31 | // Error check. 32 | if (MCL_OK != code) 33 | { 34 | deployment_workflow_model_destroy(model); 35 | } 36 | 37 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 38 | return code; 39 | } 40 | 41 | mcl_error_t mcl_deployment_workflow_model_get_parameter(mcl_deployment_workflow_model_t *model, 42 | E_MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER parameter, void **value) 43 | { 44 | mcl_error_t code = MCL_OK; 45 | 46 | MCL_DEBUG_ENTRY("mcl_deployment_workflow_model_t *model = <%p>, E_MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER parameter = <%d>, void **value = <%p>", 47 | model, parameter, value); 48 | 49 | MCL_ASSERT_NOT_NULL(model, code); 50 | MCL_ASSERT_NOT_NULL(value, code); 51 | 52 | switch (parameter) 53 | { 54 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_KEY: 55 | *value = model->key; 56 | break; 57 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_STATES: 58 | *value = model->states; 59 | break; 60 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_TRANSITIONS: 61 | *value = model->transitions; 62 | break; 63 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_PARAMETER_STATE_GROUPS: 64 | *value = model->state_groups; 65 | break; 66 | default: 67 | *value = MCL_NULL; 68 | code = MCL_INVALID_PARAMETER; 69 | break; 70 | } 71 | 72 | MCL_FUNCTION_LEAVE_LABEL: 73 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 74 | return code; 75 | } 76 | 77 | void deployment_workflow_model_destroy(deployment_workflow_model_t **model) 78 | { 79 | MCL_DEBUG_ENTRY("deployment_workflow_model_t **model = <%p>", model); 80 | 81 | if ((MCL_NULL != model) && (MCL_NULL != *model)) 82 | { 83 | MCL_FREE((*model)->key); 84 | mcl_list_destroy_with_content(&(*model)->states, (mcl_list_item_destroy_callback) deployment_workflow_model_state_destroy); 85 | mcl_list_destroy_with_content(&(*model)->transitions, (mcl_list_item_destroy_callback) deployment_workflow_model_transition_destroy); 86 | mcl_list_destroy_with_content(&(*model)->state_groups, (mcl_list_item_destroy_callback) deployment_workflow_model_state_group_destroy); 87 | MCL_FREE(*model); 88 | } 89 | 90 | MCL_DEBUG_LEAVE("retVal = void"); 91 | } 92 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model.h 3 | * @brief Internal header for deployment workflow model. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_WORKFLOW_MODEL_H_ 10 | #define DEPLOYMENT_WORKFLOW_MODEL_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | #include "deployment_workflow_model_state.h" 14 | #include "deployment_workflow_model_transition.h" 15 | #include "deployment_workflow_model_state_group.h" 16 | #include "mcl_core/mcl_list.h" 17 | 18 | /** 19 | * Handle for deployment workflow model. 20 | */ 21 | typedef struct mcl_deployment_workflow_model_t 22 | { 23 | char *key; 24 | mcl_list_t *states; 25 | mcl_list_t *transitions; 26 | mcl_list_t *state_groups; 27 | } deployment_workflow_model_t; 28 | 29 | /** 30 | * This function initializes a deployment workflow model. 31 | * 32 | * @param [out] model Deployment workflow model. 33 | * @return 34 | *
    35 | *
  • #MCL_OK in case of success.
  • 36 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 37 | *
38 | */ 39 | MCL_LOCAL mcl_error_t deployment_workflow_model_initialize(deployment_workflow_model_t **model); 40 | 41 | /** 42 | * This function destroys deployment workflow model. 43 | * 44 | * @param [in] model Deployment workflow model to destroy. 45 | */ 46 | MCL_LOCAL void deployment_workflow_model_destroy(deployment_workflow_model_t **model); 47 | 48 | #endif //DEPLOYMENT_WORKFLOW_MODEL_H_ 49 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model_state.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model_state.c 3 | * @brief Implementation of deployment workflow model state. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "mcl_deployment/mcl_deployment_workflow_model_state.h" 10 | #include "deployment_workflow_model_state.h" 11 | #include "mcl_core/mcl_memory.h" 12 | #include "mcl_core/mcl_string_util.h" 13 | 14 | mcl_error_t deployment_workflow_model_state_initialize(deployment_workflow_model_state_t **state) 15 | { 16 | mcl_error_t code = MCL_OK; 17 | 18 | MCL_DEBUG_ENTRY("deployment_workflow_model_state_t **state = <%p>", state); 19 | 20 | if (MCL_NULL != MCL_NEW(*state)) 21 | { 22 | (*state)->name = MCL_NULL; 23 | (*state)->description = MCL_NULL; 24 | (*state)->initial = MCL_FALSE; 25 | (*state)->final = MCL_FALSE; 26 | (*state)->cancel = MCL_FALSE; 27 | } 28 | else 29 | { 30 | code = MCL_OUT_OF_MEMORY; 31 | } 32 | 33 | // Error check. 34 | if (MCL_OK != code) 35 | { 36 | deployment_workflow_model_state_destroy(state); 37 | } 38 | 39 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 40 | return code; 41 | } 42 | 43 | mcl_error_t mcl_deployment_workflow_model_state_get_parameter(mcl_deployment_workflow_model_state_t *state, 44 | E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER parameter, void **value) 45 | { 46 | mcl_error_t code = MCL_OK; 47 | 48 | MCL_DEBUG_ENTRY("mcl_deployment_workflow_model_state_t *state = <%p>, E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER parameter = <%d>, "\ 49 | "void **value = <%p>", state, parameter, value); 50 | 51 | MCL_ASSERT_NOT_NULL(state, code); 52 | MCL_ASSERT_NOT_NULL(value, code); 53 | 54 | switch (parameter) 55 | { 56 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_NAME: 57 | *value = state->name; 58 | break; 59 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_DESCRIPTION: 60 | *value = state->description; 61 | break; 62 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_INITIAL: 63 | *value = &state->initial; 64 | break; 65 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_FINAL: 66 | *value = &state->final; 67 | break; 68 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_PARAMETER_CANCEL: 69 | *value = &state->cancel; 70 | break; 71 | default: 72 | *value = MCL_NULL; 73 | code = MCL_INVALID_PARAMETER; 74 | break; 75 | } 76 | 77 | MCL_FUNCTION_LEAVE_LABEL: 78 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 79 | return code; 80 | } 81 | 82 | void deployment_workflow_model_state_destroy(deployment_workflow_model_state_t **state) 83 | { 84 | MCL_DEBUG_ENTRY("deployment_workflow_model_state_t **state = <%p>", state); 85 | 86 | if ((MCL_NULL != state) && (MCL_NULL != *state)) 87 | { 88 | MCL_FREE((*state)->name); 89 | MCL_FREE((*state)->description); 90 | MCL_FREE(*state); 91 | } 92 | 93 | MCL_DEBUG_LEAVE("retVal = void"); 94 | } 95 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model_state.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model_state.h 3 | * @brief Internal header for deployment workflow model state. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_WORKFLOW_MODEL_STATE_H_ 10 | #define DEPLOYMENT_WORKFLOW_MODEL_STATE_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | 14 | /** 15 | * Handle for deployment workflow model state. 16 | */ 17 | typedef struct mcl_deployment_workflow_model_state_t 18 | { 19 | char *name; 20 | char *description; 21 | mcl_bool_t initial; 22 | mcl_bool_t final; 23 | mcl_bool_t cancel; 24 | } deployment_workflow_model_state_t; 25 | 26 | /** 27 | * This function initializes a deployment workflow model state. 28 | * 29 | * @param [out] state Deployment workflow model state. 30 | * @return 31 | *
    32 | *
  • #MCL_OK in case of success.
  • 33 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 34 | *
35 | */ 36 | MCL_LOCAL mcl_error_t deployment_workflow_model_state_initialize(deployment_workflow_model_state_t **state); 37 | 38 | /** 39 | * This function destroys deployment workflow model state. 40 | * 41 | * @param [in] state Deployment workflow model state to destroy. 42 | */ 43 | MCL_LOCAL void deployment_workflow_model_state_destroy(deployment_workflow_model_state_t **state); 44 | 45 | #endif //DEPLOYMENT_WORKFLOW_MODEL_STATE_H_ 46 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model_state_group.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model_state_group.c 3 | * @brief Implementation of deployment workflow model state group. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "mcl_deployment/mcl_deployment_workflow_model_state_group.h" 10 | #include "deployment_workflow_model_state_group.h" 11 | #include "mcl_core/mcl_memory.h" 12 | 13 | static void _destroy_string(char **str); 14 | 15 | mcl_error_t deployment_workflow_model_state_group_initialize(deployment_workflow_model_state_group_t **state_group) 16 | { 17 | mcl_error_t code = MCL_OK; 18 | 19 | MCL_DEBUG_ENTRY("deployment_workflow_model_state_group_t **state_group = <%p>", state_group); 20 | 21 | if (MCL_NULL != MCL_NEW(*state_group)) 22 | { 23 | (*state_group)->name = MCL_NULL; 24 | (*state_group)->states = MCL_NULL; 25 | } 26 | else 27 | { 28 | code = MCL_OUT_OF_MEMORY; 29 | } 30 | 31 | // Error check. 32 | if (MCL_OK != code) 33 | { 34 | deployment_workflow_model_state_group_destroy(state_group); 35 | } 36 | 37 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 38 | return code; 39 | } 40 | 41 | mcl_error_t mcl_deployment_workflow_model_state_group_get_parameter(mcl_deployment_workflow_model_state_group_t *state_group, 42 | E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER parameter, void **value) 43 | { 44 | mcl_error_t code = MCL_OK; 45 | 46 | MCL_DEBUG_ENTRY("mcl_deployment_workflow_model_state_group_t *state_group = <%p>, "\ 47 | "E_MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER parameter = <%d>, void **value = <%p>", state_group, parameter, value); 48 | 49 | MCL_ASSERT_NOT_NULL(state_group, code); 50 | MCL_ASSERT_NOT_NULL(value, code); 51 | 52 | switch (parameter) 53 | { 54 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER_NAME: 55 | *value = state_group->name; 56 | break; 57 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_PARAMETER_STATES: 58 | *value = state_group->states; 59 | break; 60 | default: 61 | *value = MCL_NULL; 62 | code = MCL_INVALID_PARAMETER; 63 | break; 64 | } 65 | 66 | MCL_FUNCTION_LEAVE_LABEL: 67 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 68 | return code; 69 | } 70 | 71 | void deployment_workflow_model_state_group_destroy(deployment_workflow_model_state_group_t **state_group) 72 | { 73 | MCL_DEBUG_ENTRY("deployment_workflow_model_state_group_t **state_group = <%p>", state_group); 74 | 75 | if ((MCL_NULL != state_group) && (MCL_NULL != *state_group)) 76 | { 77 | MCL_FREE((*state_group)->name); 78 | mcl_list_destroy_with_content(&(*state_group)->states, (mcl_list_item_destroy_callback) _destroy_string); 79 | MCL_FREE(*state_group); 80 | } 81 | 82 | MCL_DEBUG_LEAVE("retVal = void"); 83 | } 84 | 85 | static void _destroy_string(char **str) 86 | { 87 | MCL_FREE(*str); 88 | } 89 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model_state_group.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model_state_group.h 3 | * @brief Internal header for deployment workflow model. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_H_ 10 | #define DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | #include "mcl_core/mcl_list.h" 14 | 15 | /** 16 | * Handle for deployment workflow model state group. 17 | */ 18 | typedef struct mcl_deployment_workflow_model_state_group_t 19 | { 20 | char *name; 21 | mcl_list_t *states; 22 | } deployment_workflow_model_state_group_t; 23 | 24 | /** 25 | * This function initializes a deployment workflow model state group. 26 | * 27 | * @param [out] state_group Deployment workflow model state group. 28 | * @return 29 | *
    30 | *
  • #MCL_OK in case of success.
  • 31 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 32 | *
33 | */ 34 | MCL_LOCAL mcl_error_t deployment_workflow_model_state_group_initialize(deployment_workflow_model_state_group_t **state_group); 35 | 36 | /** 37 | * This function destroys deployment workflow model state group. 38 | * 39 | * @param [in] state_group Deployment workflow model state group to destroy. 40 | */ 41 | MCL_LOCAL void deployment_workflow_model_state_group_destroy(deployment_workflow_model_state_group_t **state_group); 42 | 43 | #endif //DEPLOYMENT_WORKFLOW_MODEL_STATE_GROUP_H_ 44 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model_transition.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model_transition.c 3 | * @brief Implementation of deployment workflow model transition. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #include "mcl_deployment/mcl_deployment_workflow_model_transition.h" 10 | #include "deployment_workflow_model_transition.h" 11 | #include "mcl_core/mcl_memory.h" 12 | 13 | mcl_error_t deployment_workflow_model_transition_initialize(deployment_workflow_model_transition_t **transition) 14 | { 15 | mcl_error_t code = MCL_OK; 16 | 17 | MCL_DEBUG_ENTRY("deployment_workflow_model_transition_t **transition = <%p>", transition); 18 | 19 | if (MCL_NULL != MCL_NEW(*transition)) 20 | { 21 | (*transition)->from = MCL_NULL; 22 | (*transition)->to = MCL_NULL; 23 | (*transition)->type = MCL_NULL; 24 | (*transition)->details = MCL_NULL; 25 | } 26 | else 27 | { 28 | code = MCL_OUT_OF_MEMORY; 29 | } 30 | 31 | // Error check. 32 | if (MCL_OK != code) 33 | { 34 | deployment_workflow_model_transition_destroy(transition); 35 | } 36 | 37 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 38 | return code; 39 | } 40 | 41 | mcl_error_t mcl_deployment_workflow_model_transition_get_parameter(mcl_deployment_workflow_model_transition_t *transition, 42 | E_MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER parameter, void **value) 43 | { 44 | mcl_error_t code = MCL_OK; 45 | 46 | MCL_DEBUG_ENTRY("mcl_deployment_workflow_model_transition_t *transition = <%p>, E_MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER parameter = <%d>, "\ 47 | "void **value = <%p>", transition, parameter, value); 48 | 49 | MCL_ASSERT_NOT_NULL(transition, code); 50 | MCL_ASSERT_NOT_NULL(value, code); 51 | 52 | switch (parameter) 53 | { 54 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_FROM: 55 | *value = transition->from; 56 | break; 57 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_TO: 58 | *value = transition->to; 59 | break; 60 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_TYPE: 61 | *value = transition->type; 62 | break; 63 | case MCL_DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_PARAMETER_DETAILS: 64 | *value = transition->details; 65 | break; 66 | default: 67 | *value = MCL_NULL; 68 | code = MCL_INVALID_PARAMETER; 69 | break; 70 | } 71 | 72 | MCL_FUNCTION_LEAVE_LABEL: 73 | MCL_DEBUG_LEAVE("retVal = <%d>", code); 74 | return code; 75 | } 76 | 77 | void deployment_workflow_model_transition_destroy(deployment_workflow_model_transition_t **transition) 78 | { 79 | MCL_DEBUG_ENTRY("deployment_workflow_model_transition_t **transition = <%p>", transition); 80 | 81 | if ((MCL_NULL != transition) && (MCL_NULL != *transition)) 82 | { 83 | MCL_FREE((*transition)->from); 84 | MCL_FREE((*transition)->to); 85 | MCL_FREE((*transition)->type); 86 | mcl_json_util_destroy(&((*transition)->details)); 87 | MCL_FREE(*transition); 88 | } 89 | 90 | MCL_DEBUG_LEAVE("retVal = void"); 91 | } 92 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_model_transition.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_model_transition.h 3 | * @brief Internal header for deployment workflow model transition. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_H_ 10 | #define DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | #include "mcl_core/mcl_json_util.h" 14 | 15 | /** 16 | * Handle for deployment workflow model transition. 17 | */ 18 | typedef struct mcl_deployment_workflow_model_transition_t 19 | { 20 | char *from; 21 | char *to; 22 | char *type; 23 | mcl_json_t *details; 24 | } deployment_workflow_model_transition_t; 25 | 26 | /** 27 | * This function initializes a deployment workflow model transition. 28 | * 29 | * @param [out] transition Deployment workflow model transition. 30 | * @return 31 | *
    32 | *
  • #MCL_OK in case of success.
  • 33 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 34 | *
35 | */ 36 | MCL_LOCAL mcl_error_t deployment_workflow_model_transition_initialize(deployment_workflow_model_transition_t **transition); 37 | 38 | /** 39 | * This function destroys deployment workflow model transition. 40 | * 41 | * @param [in] transition Deployment workflow model transition to destroy. 42 | */ 43 | MCL_LOCAL void deployment_workflow_model_transition_destroy(deployment_workflow_model_transition_t **transition); 44 | 45 | #endif //DEPLOYMENT_WORKFLOW_MODEL_TRANSITION_H_ 46 | -------------------------------------------------------------------------------- /mcl_deployment/src/deployment_workflow_state.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file deployment_workflow_state.h 3 | * @brief Internal header for deployment workflow state. 4 | * 5 | * @copyright Copyright (C) 2019 Siemens Aktiengesellschaft.\n 6 | * All rights reserved. 7 | */ 8 | 9 | #ifndef DEPLOYMENT_WORKFLOW_STATE_H_ 10 | #define DEPLOYMENT_WORKFLOW_STATE_H_ 11 | 12 | #include "mcl_deployment/mcl_deployment_common.h" 13 | #include "mcl_core/mcl_json_util.h" 14 | 15 | /** 16 | * Handle for deployment workflow state. 17 | */ 18 | typedef struct mcl_deployment_workflow_state_t 19 | { 20 | char *state; 21 | double progress; 22 | char *entered; 23 | char *updated; 24 | char *message; 25 | mcl_json_t *details; 26 | } deployment_workflow_state_t; 27 | 28 | /** 29 | * This function initializes a deployment workflow state instance. 30 | * 31 | * @param [out] workflow_state Deployment workflow state instance. 32 | * @return 33 | *
    34 | *
  • #MCL_OK in case of success.
  • 35 | *
  • #MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • 36 | *
37 | */ 38 | MCL_LOCAL mcl_error_t deployment_workflow_state_initialize(deployment_workflow_state_t **workflow_state); 39 | 40 | /** 41 | * This function validates a deployment workflow state. 42 | * 43 | * @param [in] workflow_state Deployment workflow state instance. 44 | * @return 45 | *
    46 | *
  • #MCL_OK in case validity.
  • 47 | *
  • #MCL_INVALID_PARAMETER in case of an invalid or missing parameter.
  • 48 | *
49 | */ 50 | MCL_LOCAL mcl_error_t deployment_workflow_state_validate(deployment_workflow_state_t *workflow_state); 51 | 52 | #endif //DEPLOYMENT_WORKFLOW_STATE_H_ 53 | -------------------------------------------------------------------------------- /mcl_deployment/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(integration) 2 | ADD_SUBDIRECTORY(unit) -------------------------------------------------------------------------------- /mcl_deployment/test/integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Set name of the test framework. 2 | SET(TEST_FRAMEWORK unity_and_cmock) 3 | 4 | #Set paths. 5 | SET(INTEGRATION_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") 6 | SET(TEST_RUNNER_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testrunner") 7 | SET(GENERATE_TEST_RUNNER_SCRIPT_PATH "mcl_core/test/lib/CMock/vendor/unity/auto/generate_test_runner.rb") 8 | 9 | #Set Ruby Command. 10 | SET(RUBY_CMD "ruby") 11 | 12 | #Create test runner directory. 13 | FILE(MAKE_DIRECTORY ${TEST_RUNNER_DIRECTORY}) 14 | 15 | #Loop over each integration test file. 16 | FILE(GLOB INTEGRATION_TEST_FILE_LIST RELATIVE "${INTEGRATION_TEST_DIRECTORY}" "${INTEGRATION_TEST_DIRECTORY}/*.c") 17 | FOREACH(INTEGRATION_TEST_FILE ${INTEGRATION_TEST_FILE_LIST}) 18 | 19 | #Remove file extension from the testcase file 20 | STRING(REPLACE ".c" "" INTEGRATION_TEST_FILE_NAME ${INTEGRATION_TEST_FILE}) 21 | 22 | #Create test runner. 23 | SET(TEST_RUNNER_FILE "${INTEGRATION_TEST_FILE_NAME}_runner.c") 24 | EXECUTE_PROCESS(COMMAND ${RUBY_CMD} ${GENERATE_TEST_RUNNER_SCRIPT_PATH} "${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE}" "${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}" 25 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 26 | RESULT_VARIABLE ruby_result 27 | OUTPUT_VARIABLE ruby_output) 28 | 29 | #Set test source files. 30 | SET(TEST_SOURCES ${INTEGRATION_TEST_DIRECTORY}/${INTEGRATION_TEST_FILE} ${TEST_RUNNER_DIRECTORY}/${TEST_RUNNER_FILE}) 31 | 32 | #Set the name of the test executable. 33 | SET(INTEGRATION_TEST_NAME "${INTEGRATION_TEST_FILE_NAME}") 34 | 35 | #Create integration test executable. 36 | ADD_EXECUTABLE(${INTEGRATION_TEST_NAME} $ ${TEST_SOURCES}) 37 | 38 | #Link libraries to executable. 39 | TARGET_LINK_LIBRARIES(${INTEGRATION_TEST_NAME} ${MCL_DEPLOYMENT_LIBS} ${PROJECT_LIBRARY_OUTPUT} ${TEST_FRAMEWORK}) 40 | 41 | #Include required directories 42 | TARGET_INCLUDE_DIRECTORIES(${INTEGRATION_TEST_NAME} PUBLIC ${MCL_DEPLOYMENT_INCLUDE_DIRECTORIES}) 43 | 44 | ADD_TEST(${INTEGRATION_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${INTEGRATION_TEST_NAME}) 45 | 46 | SET_TARGET_PROPERTIES(${INTEGRATION_TEST_NAME} PROPERTIES FOLDER "${MCL_COMPONENT}/integration_tests") 47 | 48 | ENDFOREACH(INTEGRATION_TEST_FILE) 49 | -------------------------------------------------------------------------------- /mcl_deployment/test/unit/cmock.yml.in: -------------------------------------------------------------------------------- 1 | :cmock: 2 | :plugins: [ignore, return_thru_ptr, expect_any_args] 3 | :includes: ${CMOCK_YML_INCLUDES} 4 | :mock_path: '${CMAKE_CURRENT_BINARY_DIR}/mock' 5 | :mock_prefix: mock_ 6 | :framework: unity 7 | :verbosity: 3 8 | :treat_externs: :include --------------------------------------------------------------------------------