From 18d01d3e8c77862e2ce602caace5d401e6a2dc21 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Sun, 28 Apr 2024 09:47:10 +1000 Subject: [PATCH 01/10] Updating next release version to be 0.5.1 --- client/lib/include/cc_mqtt5_client/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/include/cc_mqtt5_client/common.h b/client/lib/include/cc_mqtt5_client/common.h index e264544..215233a 100644 --- a/client/lib/include/cc_mqtt5_client/common.h +++ b/client/lib/include/cc_mqtt5_client/common.h @@ -25,7 +25,7 @@ extern "C" { /// @brief Patch level of the library /// @ingroup global -#define CC_MQTT5_CLIENT_PATCH_VERSION 0U +#define CC_MQTT5_CLIENT_PATCH_VERSION 1U /// @brief Macro to create numeric version as single unsigned number /// @ingroup global From 3abb19d12ca2b2ddc89084efb3bd74198d30fc41 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Sat, 25 May 2024 10:51:29 +1000 Subject: [PATCH 02/10] Some more unittests. --- client/lib/test/unit/UnitTestPublish.th | 106 ++++++++++++++++++++++++ client/lib/test/unit/UnitTestReceive.th | 84 +++++++++++++++++++ 2 files changed, 190 insertions(+) diff --git a/client/lib/test/unit/UnitTestPublish.th b/client/lib/test/unit/UnitTestPublish.th index f471b68..58ebe27 100644 --- a/client/lib/test/unit/UnitTestPublish.th +++ b/client/lib/test/unit/UnitTestPublish.th @@ -55,6 +55,7 @@ public: void test46(); void test47(); void test48(); + void test49(); private: virtual void setUp() override @@ -4396,4 +4397,109 @@ void UnitTestPublish::test48() auto& pubrespInfo2 = unitTestPublishResponseInfo(); TS_ASSERT_EQUALS(pubrespInfo2.m_status, CC_Mqtt5AsyncOpStatus_Complete); unitTestPopPublishResponseInfo(); +} + +void UnitTestPublish::test49() +{ + // Testing reception of multiple PUBACK in the single message. + + auto clientPtr = apiAllocClient(); + auto* client = clientPtr.get(); + + unitTestPerformBasicConnect(client, __FUNCTION__); + TS_ASSERT(apiIsConnected(client)); + + const std::string Topic("some/topic"); + const UnitTestData Data = { 0x1, 0x2, 0x3, 0x4, 0x5}; + + auto config = CC_Mqtt5PublishBasicConfig(); + apiPublishInitConfigBasic(&config); + + config.m_topic = Topic.c_str(); + config.m_data = &Data[0]; + config.m_dataLen = static_cast(Data.size()); + config.m_qos = CC_Mqtt5QoS_AtLeastOnceDelivery; + + auto* publish1 = apiPublishPrepare(client, nullptr); + TS_ASSERT_DIFFERS(publish1, nullptr); + + auto ec = apiPublishConfigBasic(publish1, &config); + TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); + + ec = unitTestSendPublish(publish1); + TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); + + auto sentMsg = unitTestGetSentMessage(); + TS_ASSERT(sentMsg); + TS_ASSERT_EQUALS(sentMsg->getId(), cc_mqtt5::MsgId_Publish); + auto* publishMsg1 = dynamic_cast(sentMsg.get()); + TS_ASSERT_DIFFERS(publishMsg1, nullptr); + TS_ASSERT(publishMsg1->field_packetId().doesExist()); + auto packetId1 = publishMsg1->field_packetId().field().value(); + + auto* publish2 = apiPublishPrepare(client, nullptr); + TS_ASSERT_DIFFERS(publish2, nullptr); + + ec = apiPublishConfigBasic(publish2, &config); + TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); + + ec = unitTestSendPublish(publish2); + TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); + + sentMsg = unitTestGetSentMessage(); + TS_ASSERT(sentMsg); + TS_ASSERT_EQUALS(sentMsg->getId(), cc_mqtt5::MsgId_Publish); + auto* publishMsg2 = dynamic_cast(sentMsg.get()); + TS_ASSERT_DIFFERS(publishMsg2, nullptr); + TS_ASSERT(publishMsg2->field_packetId().doesExist()); + auto packetId2 = publishMsg2->field_packetId().field().value(); + + auto* publish3 = apiPublishPrepare(client, nullptr); + TS_ASSERT_DIFFERS(publish3, nullptr); + + ec = apiPublishConfigBasic(publish3, &config); + TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); + + ec = unitTestSendPublish(publish3); + TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); + + sentMsg = unitTestGetSentMessage(); + TS_ASSERT(sentMsg); + TS_ASSERT_EQUALS(sentMsg->getId(), cc_mqtt5::MsgId_Publish); + auto* publishMsg3 = dynamic_cast(sentMsg.get()); + TS_ASSERT_DIFFERS(publishMsg3, nullptr); + TS_ASSERT(publishMsg3->field_packetId().doesExist()); + auto packetId3 = publishMsg3->field_packetId().field().value(); + + unitTestTick(client, 1000); + UnitTestPubackMsg pubackMsg1; + pubackMsg1.field_packetId().setValue(packetId1); + unitTestReceiveMessage(client, pubackMsg1, false); + TS_ASSERT(!unitTestIsPublishComplete()); // The data hasn't been sent yet + + UnitTestPubackMsg pubackMsg2; + pubackMsg2.field_packetId().setValue(packetId2); + unitTestReceiveMessage(client, pubackMsg2, false); + TS_ASSERT(!unitTestIsPublishComplete()); // The data hasn't been sent yet + + UnitTestPubackMsg pubackMsg3; + pubackMsg3.field_packetId().setValue(packetId3); + unitTestReceiveMessage(client, pubackMsg3); // All PABACK messages in the single data chunk + + TS_ASSERT(unitTestIsPublishComplete()); + auto& pubrespInfo1 = unitTestPublishResponseInfo(); + TS_ASSERT_EQUALS(pubrespInfo1.m_status, CC_Mqtt5AsyncOpStatus_Complete); + unitTestPopPublishResponseInfo(); + + TS_ASSERT(unitTestIsPublishComplete()); + auto& pubrespInfo2 = unitTestPublishResponseInfo(); + TS_ASSERT_EQUALS(pubrespInfo2.m_status, CC_Mqtt5AsyncOpStatus_Complete); + unitTestPopPublishResponseInfo(); + + TS_ASSERT(unitTestIsPublishComplete()); + auto& pubrespInfo3 = unitTestPublishResponseInfo(); + TS_ASSERT_EQUALS(pubrespInfo3.m_status, CC_Mqtt5AsyncOpStatus_Complete); + unitTestPopPublishResponseInfo(); + + TS_ASSERT(!unitTestIsPublishComplete()); } \ No newline at end of file diff --git a/client/lib/test/unit/UnitTestReceive.th b/client/lib/test/unit/UnitTestReceive.th index 833f6cb..5fea6d8 100644 --- a/client/lib/test/unit/UnitTestReceive.th +++ b/client/lib/test/unit/UnitTestReceive.th @@ -33,6 +33,8 @@ public: void test24(); void test25(); void test26(); + void test27(); + void test28(); private: virtual void setUp() override @@ -1858,4 +1860,86 @@ void UnitTestReceive::test26() TS_ASSERT_EQUALS(msgInfo.m_data, Data); unitTestPopReceivedMessageInfo(); TS_ASSERT(!unitTestHasMessageRecieved()); +} + +void UnitTestReceive::test27() +{ + // Receiving message together with PINGRESP + auto clientPtr = apiAllocClient(); + auto* client = clientPtr.get(); + + unitTestPerformBasicConnect(client, __FUNCTION__); + TS_ASSERT(apiIsConnected(client)); + + unitTestPerformBasicSubscribe(client, "#"); + + unitTestTick(client); + auto sentMsg = unitTestGetSentMessage(); + TS_ASSERT(sentMsg); + TS_ASSERT_EQUALS(sentMsg->getId(), cc_mqtt5::MsgId_Pingreq); + + unitTestTick(client, 100); + + const std::string Topic = "some/topic"; + const UnitTestData Data = {'h', 'e', 'l', 'l', 'o'}; + + UnitTestPublishMsg publishMsg; + publishMsg.field_topic().value() = Topic; + publishMsg.field_payload().value() = Data; + unitTestReceiveMessage(client, publishMsg, false); + + UnitTestPingrespMsg pingrespMsg; + unitTestReceiveMessage(client, pingrespMsg); + + TS_ASSERT(unitTestHasMessageRecieved()); + auto& msgInfo = unitTestReceivedMessageInfo(); + TS_ASSERT_EQUALS(msgInfo.m_topic, Topic); + TS_ASSERT_EQUALS(msgInfo.m_data, Data); + unitTestPopReceivedMessageInfo(); + + unitTestTick(client); + sentMsg = unitTestGetSentMessage(); + TS_ASSERT(sentMsg); + TS_ASSERT_EQUALS(sentMsg->getId(), cc_mqtt5::MsgId_Pingreq); +} + +void UnitTestReceive::test28() +{ + // Receiving message together with PINGRESP + auto clientPtr = apiAllocClient(); + auto* client = clientPtr.get(); + + unitTestPerformBasicConnect(client, __FUNCTION__); + TS_ASSERT(apiIsConnected(client)); + + unitTestPerformBasicSubscribe(client, "#"); + + unitTestTick(client); + auto sentMsg = unitTestGetSentMessage(); + TS_ASSERT(sentMsg); + TS_ASSERT_EQUALS(sentMsg->getId(), cc_mqtt5::MsgId_Pingreq); + + unitTestTick(client, 100); + + const std::string Topic = "some/topic"; + const UnitTestData Data = {'h', 'e', 'l', 'l', 'o'}; + + UnitTestPingrespMsg pingrespMsg; + unitTestReceiveMessage(client, pingrespMsg, false); + + UnitTestPublishMsg publishMsg; + publishMsg.field_topic().value() = Topic; + publishMsg.field_payload().value() = Data; + unitTestReceiveMessage(client, publishMsg); + + TS_ASSERT(unitTestHasMessageRecieved()); + auto& msgInfo = unitTestReceivedMessageInfo(); + TS_ASSERT_EQUALS(msgInfo.m_topic, Topic); + TS_ASSERT_EQUALS(msgInfo.m_data, Data); + unitTestPopReceivedMessageInfo(); + + unitTestTick(client); + sentMsg = unitTestGetSentMessage(); + TS_ASSERT(sentMsg); + TS_ASSERT_EQUALS(sentMsg->getId(), cc_mqtt5::MsgId_Pingreq); } \ No newline at end of file From e6191ff6c52a747b999cab914413333f52f63c30 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Mon, 10 Jun 2024 16:14:40 +1000 Subject: [PATCH 03/10] Cosmetic updates. --- client/app/common/TcpSession.h | 5 +---- client/lib/doxygen/main.dox | 2 +- client/lib/test/unit/UnitTestCommonBase.h | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/client/app/common/TcpSession.h b/client/app/common/TcpSession.h index 5bcf61b..3ed88d6 100644 --- a/client/app/common/TcpSession.h +++ b/client/app/common/TcpSession.h @@ -28,21 +28,18 @@ class TcpSession final : public Session private: using Socket = boost::asio::ip::tcp::socket; - using Timer = boost::asio::steady_timer; using InDataBuf = std::array; using DataBuf = std::vector; TcpSession(boost::asio::io_context& io, const ProgramOptions& opts) : Base(io, opts), - m_socket(io), - m_readTimer(io) + m_socket(io) { } void doRead(); Socket m_socket; - Timer m_readTimer; InDataBuf m_inData; DataBuf m_buf; }; diff --git a/client/lib/doxygen/main.dox b/client/lib/doxygen/main.dox index f9c4ad2..9f6c302 100644 --- a/client/lib/doxygen/main.dox +++ b/client/lib/doxygen/main.dox @@ -550,7 +550,7 @@ /// called before the @b cc_mqtt5_client_connect_cancel(), the operation is /// cancelled @b without callback invocation. /// -/// @subsection doc_cc_mqtt5_client_connect_simplify Simplifying the "Connect" Operation Preparation. +/// @subsection doc_cc_mqtt5_client_connect_simplify Simplifying the "Connect" Operation Preparation /// In many use cases the "connect" operation can be quite simple with a lot of defaults. /// To simplify the sequence of the operation preparation and handling of errors, /// the library provides several wrapper functions that can be used: diff --git a/client/lib/test/unit/UnitTestCommonBase.h b/client/lib/test/unit/UnitTestCommonBase.h index 2e8b458..7f2b1df 100644 --- a/client/lib/test/unit/UnitTestCommonBase.h +++ b/client/lib/test/unit/UnitTestCommonBase.h @@ -21,7 +21,6 @@ class UnitTestCommonBase { CC_Mqtt5ClientHandle (*m_alloc)() = nullptr; void (*m_free)(CC_Mqtt5ClientHandle) = nullptr; - CC_Mqtt5ErrorCode (*m_init)(CC_Mqtt5ClientHandle) = nullptr; void (*m_tick)(CC_Mqtt5ClientHandle, unsigned) = nullptr; unsigned (*m_process_data)(CC_Mqtt5ClientHandle, const unsigned char*, unsigned) = nullptr; void (*m_notify_network_disconnected)(CC_Mqtt5ClientHandle) = nullptr; From 8ef3534bbf4eab379c8623807ccae98b76d617cf Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Fri, 28 Jun 2024 08:59:16 +1000 Subject: [PATCH 04/10] Fixing cc.mqtt5.generated version comparison. --- client/lib/src/ProtocolDefs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/src/ProtocolDefs.h b/client/lib/src/ProtocolDefs.h index 31d63ae..3afce46 100644 --- a/client/lib/src/ProtocolDefs.h +++ b/client/lib/src/ProtocolDefs.h @@ -20,7 +20,7 @@ #include -static_assert(CC_MQTT5_VERSION <= COMMS_MAKE_VERSION(2, 7, 0), +static_assert(COMMS_MAKE_VERSION(2, 7, 0) <= CC_MQTT5_VERSION, "The version of the cc_mqtt5 library is too low."); namespace cc_mqtt5_client From 983ed21b84ef1fb6fb66ada77d3e8f33e9001cd0 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Fri, 28 Jun 2024 09:02:29 +1000 Subject: [PATCH 05/10] Requiring cc.mqtt5.generated (v2.8) --- .github/workflows/actions_build.yml | 4 ++-- client/lib/src/ProtocolDefs.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actions_build.yml b/.github/workflows/actions_build.yml index c5a1462..9bd03e2 100644 --- a/.github/workflows/actions_build.yml +++ b/.github/workflows/actions_build.yml @@ -3,8 +3,8 @@ name: Github Actions Build on: [push] env: - COMMS_TAG: v5.2.3 - CC_MQTT5_TAG: v2.7 + COMMS_TAG: v5.2.5 + CC_MQTT5_TAG: v2.8 jobs: build_gcc_ubuntu_22_04: diff --git a/client/lib/src/ProtocolDefs.h b/client/lib/src/ProtocolDefs.h index 3afce46..741a9dd 100644 --- a/client/lib/src/ProtocolDefs.h +++ b/client/lib/src/ProtocolDefs.h @@ -20,7 +20,7 @@ #include -static_assert(COMMS_MAKE_VERSION(2, 7, 0) <= CC_MQTT5_VERSION, +static_assert(COMMS_MAKE_VERSION(2, 8, 0) <= CC_MQTT5_VERSION, "The version of the cc_mqtt5 library is too low."); namespace cc_mqtt5_client From 2d8e3cf6b435a17ab55f1dfe04c76470afd16d35 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Fri, 28 Jun 2024 09:03:34 +1000 Subject: [PATCH 06/10] Updating next release to be v1.0 --- client/lib/include/cc_mqtt5_client/common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/lib/include/cc_mqtt5_client/common.h b/client/lib/include/cc_mqtt5_client/common.h index 215233a..e672252 100644 --- a/client/lib/include/cc_mqtt5_client/common.h +++ b/client/lib/include/cc_mqtt5_client/common.h @@ -17,15 +17,15 @@ extern "C" { /// @brief Major verion of the library /// @ingroup global -#define CC_MQTT5_CLIENT_MAJOR_VERSION 0U +#define CC_MQTT5_CLIENT_MAJOR_VERSION 1U /// @brief Minor verion of the library /// @ingroup global -#define CC_MQTT5_CLIENT_MINOR_VERSION 5U +#define CC_MQTT5_CLIENT_MINOR_VERSION 0U /// @brief Patch level of the library /// @ingroup global -#define CC_MQTT5_CLIENT_PATCH_VERSION 1U +#define CC_MQTT5_CLIENT_PATCH_VERSION 0U /// @brief Macro to create numeric version as single unsigned number /// @ingroup global From ce5ec46a590d0372f40693b41d656ecaaf171ced Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Fri, 28 Jun 2024 09:04:07 +1000 Subject: [PATCH 07/10] Removed appveyor configuration. --- .appveyor.yml | 62 ------------------------------------- script/appveyor_install.bat | 49 ----------------------------- 2 files changed, 111 deletions(-) delete mode 100644 .appveyor.yml delete mode 100644 script/appveyor_install.bat diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 9a31dde..0000000 --- a/.appveyor.yml +++ /dev/null @@ -1,62 +0,0 @@ -image: - - Visual Studio 2017 - - Visual Studio 2022 - - Visual Studio 2019 - - -init: - - git config --global core.autocrlf input - -clone_folder: c:\projects\cc_tutorial -shallow_clone: true - -platform: - - x64 - - x86 - -configuration: - - Debug - - Release - -environment: - COMMS_BRANCH: v5.2.3 - CC_MQTT5_BRANCH: v2.7 - matrix: - - CPP_STD: 17 - - CPP_STD: 20 - -matrix: - fast_finish: false - exclude: - - image: Visual Studio 2017 - CPP_STD: 20 - -install: - - call script\appveyor_install.bat - - set BUILD_DIR=%APPVEYOR_BUILD_FOLDER%\build.%PLATFORM%.%CONFIGURATION%.%TOOLCHAIN% - - if exist %BUILD_DIR% rmdir /S /Q %BUILD_DIR% - - set COMMS_TAG=%COMMS_BRANCH% - - set CC_MQTT5_TAG=%CC_MQTT5_BRANCH% - - set COMMON_INSTALL_DIR=%BUILD_DIR%\install - - set COMMON_BUILD_TYPE=%CONFIGURATION% - - set COMMON_CXX_STANDARD=%CPP_STD% - - set GENERATOR="%CMAKE_GENERATOR%" - - set PLATFORM="%CMAKE_PLATFORM%" - - call script\prepare_externals.bat - -build_script: - - echo ------------------------- Building Project ------------------------- - - cd %BUILD_DIR% - - if NOT [%PLATFORM%] == [] set PLATFORM_PARAM=-A %PLATFORM% - - cmake .. -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G "%CMAKE_GENERATOR%" %PLATFORM_PARAM% -DBOOST_ROOT="%BOOST_DIR%" ^ - -DBoost_USE_STATIC_LIBS=ON -DCMAKE_CXX_STANDARD=%CPP_STD% -DCMAKE_INSTALL_PREFIX=install ^ - -DCMAKE_PREFIX_PATH="%COMMON_INSTALL_DIR%" -DCC_MQTT5_BUILD_UNIT_TESTS=ON -DCC_MQTT5_CLIENT_AFL_FUZZ=ON ^ - -DCC_MQTT5_CUSTOM_CLIENT_CONFIG_FILES=%APPVEYOR_BUILD_FOLDER%/client/lib/script/BareMetalTestConfig.cmake - - cmake --build . --config %CONFIGURATION% --target install --parallel %NUMBER_OF_PROCESSORS% - - -test_script: - - echo ------------------------- Testing ------------------------- - - ctest -V - - diff --git a/script/appveyor_install.bat b/script/appveyor_install.bat deleted file mode 100644 index 2482070..0000000 --- a/script/appveyor_install.bat +++ /dev/null @@ -1,49 +0,0 @@ -IF "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( - set TOOLCHAIN=msvc15 - set BOOST_VER=1_69_0 - set CMAKE_GENERATOR=NMake Makefiles - - IF "%PLATFORM%"=="x86" ( - echo Performing x86 build in VS2017 - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat" - - ) ELSE ( - echo Performing amd64 build in VS2017 - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" - ) - -) ELSE IF "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" ( - set TOOLCHAIN=msvc16 - set BOOST_VER=1_77_0 - set CMAKE_GENERATOR=Visual Studio 16 2019 - - IF "%PLATFORM%"=="x86" ( - echo Performing x86 build in VS2019 - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" - set CMAKE_PLATFORM=Win32 - ) ELSE ( - echo Performing amd64 build in VS2019 - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" - set CMAKE_PLATFORM=x64 - ) - -) ELSE IF "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2022" ( - set TOOLCHAIN=msvc17 - set BOOST_VER=1_83_0 - set CMAKE_GENERATOR=Visual Studio 17 2022 - - IF "%PLATFORM%"=="x86" ( - echo Performing x86 build in VS2022 - call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat" - set CMAKE_PLATFORM=Win32 - ) ELSE ( - echo Performing amd64 build in VS2022 - call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" - set CMAKE_PLATFORM=x64 - ) -) ELSE ( - echo Toolchain %TOOLCHAIN% is not supported - exit -1 -) - -set BOOST_DIR=C:\Libraries\boost_%BOOST_VER% From b0e5ce08698cbf46d207e1ec277452fbc4a3b476 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Fri, 28 Jun 2024 09:07:13 +1000 Subject: [PATCH 08/10] Allow custom ccache executable. --- CMakeLists.txt | 1 + cmake/Compile.cmake | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f2a076..a0e0230 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ option (BUILD_SHARED_LIBS "Build as shared library" OFF) # Extra Configuration Variables # CC_MQTT5_CUSTOM_CLIENT_CONFIG_FILES - List of custom client configuration files +# CC_MQTT5_CCACHE_EXECUTABLE - Custom ccache executable # Other variables set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard to use") diff --git a/cmake/Compile.cmake b/cmake/Compile.cmake index b2bd913..7933d47 100644 --- a/cmake/Compile.cmake +++ b/cmake/Compile.cmake @@ -2,6 +2,9 @@ macro (cc_mqtt5_compile) set (compile_opts) if (CC_MQTT5_USE_CCACHE) list (APPEND compile_opts USE_CCACHE) + if (NOT "${CC_MQTT5_CCACHE_EXECUTABLE}" STREQUAL "") + list (APPEND compile_opts CCACHE_EXECUTABLE "${CC_MQTT5_CCACHE_EXECUTABLE}") + endif () endif () if (CC_MQTT5_WARN_AS_ERR) From c3970c31873523a9903695a5f22c96050e247638 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Fri, 28 Jun 2024 09:15:52 +1000 Subject: [PATCH 09/10] Added "client.c" to check external C compilation. --- client/lib/CMakeLists.txt | 1 + client/lib/include/cc_mqtt5_client/common.h | 15 ++++++++------- client/lib/src/client.c | 9 +++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 client/lib/src/client.c diff --git a/client/lib/CMakeLists.txt b/client/lib/CMakeLists.txt index ca13e11..1c18559 100644 --- a/client/lib/CMakeLists.txt +++ b/client/lib/CMakeLists.txt @@ -149,6 +149,7 @@ function (gen_lib_mqtt5_client config_file) src/op/SendOp.cpp src/op/SubscribeOp.cpp src/op/UnsubscribeOp.cpp + src/client.c src/ClientImpl.cpp src/TimerMgr.cpp ) diff --git a/client/lib/include/cc_mqtt5_client/common.h b/client/lib/include/cc_mqtt5_client/common.h index e672252..ec991ff 100644 --- a/client/lib/include/cc_mqtt5_client/common.h +++ b/client/lib/include/cc_mqtt5_client/common.h @@ -12,6 +12,7 @@ #ifdef __cplusplus extern "C" { +#else // #ifdef __cplusplus #include #endif // #ifdef __cplusplus @@ -215,7 +216,7 @@ struct CC_Mqtt5Client; /// @brief Handle used to access client specific data structures. /// @details Returned by cc_mqtt5_client_alloc() function. /// @ingroup client -typedef CC_Mqtt5Client* CC_Mqtt5ClientHandle; +typedef struct CC_Mqtt5Client* CC_Mqtt5ClientHandle; /// @brief Declaration of the hidden structure used to define @ref CC_Mqtt5ConnectHandle /// @ingroup connect @@ -224,7 +225,7 @@ struct CC_Mqtt5Connect; /// @brief Handle for "connect" operation. /// @details Returned by cc_mqtt5_client_connect_prepare() function. /// @ingroup connect -typedef CC_Mqtt5Connect* CC_Mqtt5ConnectHandle; +typedef struct CC_Mqtt5Connect* CC_Mqtt5ConnectHandle; /// @brief Declaration of the hidden structure used to define @ref CC_Mqtt5DisconnectHandle /// @ingroup disconnect @@ -233,7 +234,7 @@ struct CC_Mqtt5Disconnect; /// @brief Handle for "disconnect" operation. /// @details Returned by cc_mqtt5_client_disconnect_prepare() function. /// @ingroup disconnect -typedef CC_Mqtt5Disconnect* CC_Mqtt5DisconnectHandle; +typedef struct CC_Mqtt5Disconnect* CC_Mqtt5DisconnectHandle; /// @brief Declaration of the hidden structure used to define @ref CC_Mqtt5SubscribeHandle /// @ingroup subscribe @@ -242,7 +243,7 @@ struct CC_Mqtt5Subscribe; /// @brief Handle for "subscribe" operation. /// @details Returned by cc_mqtt5_client_subscribe_prepare() function. /// @ingroup subscribe -typedef CC_Mqtt5Subscribe* CC_Mqtt5SubscribeHandle; +typedef struct CC_Mqtt5Subscribe* CC_Mqtt5SubscribeHandle; /// @brief Declaration of the hidden structure used to define @ref CC_Mqtt5UnsubscribeHandle /// @ingroup unsubscribe @@ -251,7 +252,7 @@ struct CC_Mqtt5Unsubscribe; /// @brief Handle for "unsubscribe" operation. /// @details Returned by cc_mqtt5_client_unsubscribe_prepare() function. /// @ingroup unsubscribe -typedef CC_Mqtt5Unsubscribe* CC_Mqtt5UnsubscribeHandle; +typedef struct CC_Mqtt5Unsubscribe* CC_Mqtt5UnsubscribeHandle; /// @brief Declaration of the hidden structure used to define @ref CC_Mqtt5PublishHandle /// @ingroup publish @@ -260,7 +261,7 @@ struct CC_Mqtt5Publish; /// @brief Handle for "publish" operation. /// @details Returned by cc_mqtt5_client_publish_prepare() function. /// @ingroup publish -typedef CC_Mqtt5Publish* CC_Mqtt5PublishHandle; +typedef struct CC_Mqtt5Publish* CC_Mqtt5PublishHandle; /// @brief Declaration of the hidden structure used to define @ref CC_Mqtt5ReauthHandle /// @ingroup reauth @@ -269,7 +270,7 @@ struct CC_Mqtt5Reauth; /// @brief Handle for "reauth" operation. /// @details Returned by cc_mqtt5_client_reauth_prepare() function. /// @ingroup reauth -typedef CC_Mqtt5Reauth* CC_Mqtt5ReauthHandle; +typedef struct CC_Mqtt5Reauth* CC_Mqtt5ReauthHandle; /// @brief Wraping structre of the single "User Property". /// @see @b cc_mqtt5_client_init_user_prop() diff --git a/client/lib/src/client.c b/client/lib/src/client.c new file mode 100644 index 0000000..26b7510 --- /dev/null +++ b/client/lib/src/client.c @@ -0,0 +1,9 @@ +// +// Copyright 2023 - 2024 (C). Alex Robenko. All rights reserved. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +// Just check "C" compilation +#include "cc_mqtt5_client/client.h" \ No newline at end of file From aefdfe4e1200bdaab9dc0ad3a42a1e0a590e7121 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Fri, 28 Jun 2024 18:23:58 +1000 Subject: [PATCH 10/10] Fixing build. --- client/lib/CMakeLists.txt | 30 +++++++++++++++++-- .../{src/client.c => templ/client.c.templ} | 6 ++-- 2 files changed, 30 insertions(+), 6 deletions(-) rename client/lib/{src/client.c => templ/client.c.templ} (59%) diff --git a/client/lib/CMakeLists.txt b/client/lib/CMakeLists.txt index 1c18559..abb0949 100644 --- a/client/lib/CMakeLists.txt +++ b/client/lib/CMakeLists.txt @@ -8,6 +8,7 @@ endif () set (HEADER_TEMPL ${CMAKE_CURRENT_SOURCE_DIR}/templ/client.h.templ) set (SRC_TEMPL ${CMAKE_CURRENT_SOURCE_DIR}/templ/client.cpp.templ) +set (C_TEMPL ${CMAKE_CURRENT_SOURCE_DIR}/templ/client.c.templ) set (CONFIG_TEMPL ${CMAKE_CURRENT_SOURCE_DIR}/templ/Config.h.templ) set (PROT_OPTS_TEMPL ${CMAKE_CURRENT_SOURCE_DIR}/templ/ProtocolOptions.h.templ) set (TEMPL_PROCESS_SCRIPT ${PROJECT_SOURCE_DIR}/cmake/ProcessTemplate.cmake) @@ -39,6 +40,7 @@ function (gen_lib_mqtt5_client config_file) set (header_output ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${name}client.h) set (src_output ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${name}client.cpp) + set (c_output ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${name}client.c) set (config_output ${CMAKE_CURRENT_BINARY_DIR}/${dir}/Config.h) set (prot_opts_output ${CMAKE_CURRENT_BINARY_DIR}/${dir}/ProtocolOptions.h) @@ -90,6 +92,29 @@ function (gen_lib_mqtt5_client config_file) # --------------------------------- + add_custom_command( + OUTPUT "${c_output}" + COMMAND ${CMAKE_COMMAND} + -DIN_FILE="${C_TEMPL}" + -DOUT_FILE="${c_output}" + -DNAME="${name}" + -P ${TEMPL_PROCESS_SCRIPT} + DEPENDS ${C_TEMPL} ${TEMPL_PROCESS_SCRIPT} + ) + + set_source_files_properties( + ${c_output} + PROPERTIES GENERATED TRUE + ) + + set (c_tgt_name "${name}client.c.tgt") + add_custom_target( + ${c_tgt_name} + DEPENDS "${c_output}" ${C_TEMPL} ${TEMPL_PROCESS_SCRIPT} + ) + + # --------------------------------- + add_custom_command( OUTPUT "${config_output}" COMMAND ${CMAKE_COMMAND} @@ -149,11 +174,10 @@ function (gen_lib_mqtt5_client config_file) src/op/SendOp.cpp src/op/SubscribeOp.cpp src/op/UnsubscribeOp.cpp - src/client.c src/ClientImpl.cpp src/TimerMgr.cpp ) - add_library (${lib_name} ${src} ${src_output}) + add_library (${lib_name} ${src} ${src_output} ${c_output}) add_library (cc::${lib_name} ALIAS ${lib_name}) target_link_libraries(${lib_name} PRIVATE cc::cc_mqtt5 cc::comms) target_include_directories( @@ -169,7 +193,7 @@ function (gen_lib_mqtt5_client config_file) ${lib_name} PROPERTIES INTERFACE_LINK_LIBRARIES "" ) - add_dependencies(${lib_name} ${header_tgt_name} ${src_tgt_name} ${config_tgt_name} ${prot_opts_tgt_name}) + add_dependencies(${lib_name} ${header_tgt_name} ${src_tgt_name} ${c_tgt_name} ${config_tgt_name} ${prot_opts_tgt_name}) if (CC_MQTT5_CLIENT_LIB_FORCE_PIC) set_property(TARGET ${lib_name} PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/client/lib/src/client.c b/client/lib/templ/client.c.templ similarity index 59% rename from client/lib/src/client.c rename to client/lib/templ/client.c.templ index 26b7510..def484f 100644 --- a/client/lib/src/client.c +++ b/client/lib/templ/client.c.templ @@ -1,9 +1,9 @@ // -// Copyright 2023 - 2024 (C). Alex Robenko. All rights reserved. +// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -// Just check "C" compilation -#include "cc_mqtt5_client/client.h" \ No newline at end of file +// Just check C compilation when header is included. +#include "##NAME##client.h"