From 444afbcbe62a47ba23bd286c26f22b40f997c620 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Tue, 19 Dec 2023 09:26:06 +1000 Subject: [PATCH] Added "packet id" report for selected operations. --- client/lib/include/cc_mqtt5_client/common.h | 3 ++ client/lib/src/op/SendOp.cpp | 29 +++++++++++---- client/lib/src/op/SendOp.h | 1 + client/lib/src/op/SubscribeOp.cpp | 9 ++++- client/lib/src/op/SubscribeOp.h | 1 + client/lib/src/op/UnsubscribeOp.cpp | 10 ++++- client/lib/src/op/UnsubscribeOp.h | 1 + client/lib/templ/client.cpp.templ | 27 ++++++++++++++ client/lib/templ/client.h.templ | 39 ++++++++++++++++++++ client/lib/test/unit/UnitTestBmBase.cpp | 3 ++ client/lib/test/unit/UnitTestCommonBase.cpp | 18 +++++++++ client/lib/test/unit/UnitTestCommonBase.h | 6 +++ client/lib/test/unit/UnitTestDefaultBase.cpp | 3 ++ 13 files changed, 140 insertions(+), 10 deletions(-) diff --git a/client/lib/include/cc_mqtt5_client/common.h b/client/lib/include/cc_mqtt5_client/common.h index 8040ed3..ce70ddd 100644 --- a/client/lib/include/cc_mqtt5_client/common.h +++ b/client/lib/include/cc_mqtt5_client/common.h @@ -390,6 +390,7 @@ typedef struct const char* m_reasonStr; ///< "Reason String" property, can be NULL const CC_Mqtt5UserProp* m_userProps; ///< Pointer to "User Properties" array, can be NULL unsigned m_userPropsCount; ///< Amount of elements in the "User Properties" array. + unsigned m_packetId; ///< "Packet Identifier" of the "subscribe" operation. } CC_Mqtt5SubscribeResponse; /// @brief Topic filter configuration structure of the "unsubscribe" operation. @@ -409,6 +410,7 @@ typedef struct const char* m_reasonStr; ///< "Reason String" property, can be NULL const CC_Mqtt5UserProp* m_userProps; ///< Pointer to "User Properties" array, can be NULL unsigned m_userPropsCount; ///< Amount of elements in the "User Properties" array. + unsigned m_packetId; ///< "Packet Identifier" of the "unsubscribe" operation. } CC_Mqtt5UnsubscribeResponse; /// @brief Received message information @@ -466,6 +468,7 @@ typedef struct const char* m_reasonStr; ///< "Reason String" property, can be NULL. const CC_Mqtt5UserProp* m_userProps; ///< Pointer to array of "User Properties", can be NULL unsigned m_userPropsCount; ///< Number of elements in "User Properties" array. + unsigned m_packetId; ///< "Packet Identifier" of the "publish" operation. } CC_Mqtt5PublishResponse; /// @brief Callback used to request time measurement. diff --git a/client/lib/src/op/SendOp.cpp b/client/lib/src/op/SendOp.cpp index 0a7e18c..b50cd35 100644 --- a/client/lib/src/op/SendOp.cpp +++ b/client/lib/src/op/SendOp.cpp @@ -40,7 +40,8 @@ SendOp::~SendOp() void SendOp::handle(PubackMsg& msg) { - if (m_pubMsg.field_packetId().field().value() != msg.field_packetId().value()) { + auto packetId = msg.field_packetId().value(); + if (m_pubMsg.field_packetId().field().value() != packetId) { return; } @@ -58,6 +59,8 @@ void SendOp::handle(PubackMsg& msg) UserPropsList userProps; // Will be referenced in response auto response = CC_Mqtt5PublishResponse(); + response.m_packetId = packetId; + auto completeOpOnExit = comms::util::makeScopeGuard( [this, &status, &response]() @@ -123,7 +126,8 @@ void SendOp::handle(PubackMsg& msg) void SendOp::handle(PubrecMsg& msg) { - if (m_pubMsg.field_packetId().field().value() != msg.field_packetId().value()) { + auto packetId = msg.field_packetId().value(); + if (m_pubMsg.field_packetId().field().value() != packetId) { return; } @@ -141,6 +145,8 @@ void SendOp::handle(PubrecMsg& msg) UserPropsList userProps; // Will be referenced in response auto response = CC_Mqtt5PublishResponse(); + response.m_packetId = packetId; + auto completeOpOnExit = comms::util::makeScopeGuard( [this, &status, &response]() @@ -230,7 +236,8 @@ void SendOp::handle(PubrecMsg& msg) void SendOp::handle(PubcompMsg& msg) { - if (m_pubMsg.field_packetId().field().value() != msg.field_packetId().value()) { + auto packetId = msg.field_packetId().value(); + if (m_pubMsg.field_packetId().field().value() != packetId) { return; } @@ -248,6 +255,8 @@ void SendOp::handle(PubcompMsg& msg) UserPropsList userProps; // Will be referenced in response auto response = CC_Mqtt5PublishResponse(); + response.m_packetId = packetId; + auto completeOpOnExit = comms::util::makeScopeGuard( [this, &status, &response]() @@ -408,6 +417,10 @@ CC_Mqtt5ErrorCode SendOp::configBasic(const CC_Mqtt5PublishBasicConfig& config) m_pubMsg.transportField_flags().field_retain().setBitValue_bit(config.m_retain); m_pubMsg.transportField_flags().field_qos().setValue(config.m_qos); + + if (config.m_qos > CC_Mqtt5QoS_AtMostOnceDelivery) { + m_pubMsg.field_packetId().field().setValue(allocPacketId()); + } if (mustAssignTopic) { auto& topicStr = m_pubMsg.field_topic().value(); @@ -596,11 +609,6 @@ CC_Mqtt5ErrorCode SendOp::send(CC_Mqtt5PublishCompleteCb cb, void* cbData) m_cb = cb; m_cbData = cbData; - using Qos = PublishMsg::TransportField_flags::Field_qos::ValueType; - if (m_pubMsg.transportField_flags().field_qos().value() > Qos::AtMostOnceDelivery) { - m_pubMsg.field_packetId().field().setValue(allocPacketId()); - } - m_pubMsg.doRefresh(); // Update packetId presence m_sendAttempts = 0U; @@ -628,6 +636,11 @@ CC_Mqtt5ErrorCode SendOp::cancel() return CC_Mqtt5ErrorCode_Success; } +unsigned SendOp::getPacketId() const +{ + return m_pubMsg.field_packetId().field().getValue(); +} + Op::Type SendOp::typeImpl() const { return Type_Send; diff --git a/client/lib/src/op/SendOp.h b/client/lib/src/op/SendOp.h index 30f88ef..3cfa0f1 100644 --- a/client/lib/src/op/SendOp.h +++ b/client/lib/src/op/SendOp.h @@ -44,6 +44,7 @@ class SendOp final : public Op unsigned getResendAttempts() const; CC_Mqtt5ErrorCode send(CC_Mqtt5PublishCompleteCb cb, void* cbData); CC_Mqtt5ErrorCode cancel(); + unsigned getPacketId() const; protected: virtual Type typeImpl() const override; diff --git a/client/lib/src/op/SubscribeOp.cpp b/client/lib/src/op/SubscribeOp.cpp index 5238e0f..374d853 100644 --- a/client/lib/src/op/SubscribeOp.cpp +++ b/client/lib/src/op/SubscribeOp.cpp @@ -48,6 +48,7 @@ SubscribeOp::SubscribeOp(ClientImpl& client) : Base(client), m_timer(client.timerMgr().allocTimer()) { + m_subMsg.field_packetId().setValue(allocPacketId()); } SubscribeOp::~SubscribeOp() @@ -163,7 +164,6 @@ CC_Mqtt5ErrorCode SubscribeOp::send(CC_Mqtt5SubscribeCompleteCb cb, void* cbData m_cb = cb; m_cbData = cbData; - m_subMsg.field_packetId().setValue(allocPacketId()); auto result = client().sendMessage(m_subMsg); if (result != CC_Mqtt5ErrorCode_Success) { return result; @@ -181,6 +181,11 @@ CC_Mqtt5ErrorCode SubscribeOp::cancel() return CC_Mqtt5ErrorCode_Success; } +unsigned SubscribeOp::getPacketId() const +{ + return m_subMsg.field_packetId().getValue(); +} + void SubscribeOp::handle(SubackMsg& msg) { auto packetId = msg.field_packetId().value(); @@ -196,6 +201,8 @@ void SubscribeOp::handle(SubackMsg& msg) UserPropsList userProps; // Will be referenced in response auto response = CC_Mqtt5SubscribeResponse(); + response.m_packetId = packetId; + auto terminationReason = DisconnectReason::ProtocolError; auto terminateOnExit = comms::util::makeScopeGuard( diff --git a/client/lib/src/op/SubscribeOp.h b/client/lib/src/op/SubscribeOp.h index 8555839..7d61d32 100644 --- a/client/lib/src/op/SubscribeOp.h +++ b/client/lib/src/op/SubscribeOp.h @@ -29,6 +29,7 @@ class SubscribeOp final : public Op CC_Mqtt5ErrorCode addUserProp(const CC_Mqtt5UserProp& prop); CC_Mqtt5ErrorCode send(CC_Mqtt5SubscribeCompleteCb cb, void* cbData); CC_Mqtt5ErrorCode cancel(); + unsigned getPacketId() const; using Base::handle; virtual void handle(SubackMsg& msg) override; diff --git a/client/lib/src/op/UnsubscribeOp.cpp b/client/lib/src/op/UnsubscribeOp.cpp index b72fc29..2d9bbf8 100644 --- a/client/lib/src/op/UnsubscribeOp.cpp +++ b/client/lib/src/op/UnsubscribeOp.cpp @@ -48,6 +48,7 @@ UnsubscribeOp::UnsubscribeOp(ClientImpl& client) : Base(client), m_timer(client.timerMgr().allocTimer()) { + m_unsubMsg.field_packetId().setValue(allocPacketId()); } UnsubscribeOp::~UnsubscribeOp() @@ -137,7 +138,6 @@ CC_Mqtt5ErrorCode UnsubscribeOp::send(CC_Mqtt5UnsubscribeCompleteCb cb, void* cb m_cb = cb; m_cbData = cbData; - m_unsubMsg.field_packetId().setValue(allocPacketId()); auto result = client().sendMessage(m_unsubMsg); if (result != CC_Mqtt5ErrorCode_Success) { return result; @@ -155,8 +155,14 @@ CC_Mqtt5ErrorCode UnsubscribeOp::cancel() return CC_Mqtt5ErrorCode_Success; } +unsigned UnsubscribeOp::getPacketId() const +{ + return m_unsubMsg.field_packetId().getValue(); +} + void UnsubscribeOp::handle(UnsubackMsg& msg) { + auto packetId = msg.field_packetId().value(); if (msg.field_packetId().value() != m_unsubMsg.field_packetId().value()) { return; } @@ -169,6 +175,8 @@ void UnsubscribeOp::handle(UnsubackMsg& msg) UserPropsList userProps; // Will be referenced in response auto response = CC_Mqtt5UnsubscribeResponse(); + response.m_packetId = packetId; + auto terminationReason = DisconnectReason::ProtocolError; auto terminateOnExit = comms::util::makeScopeGuard( diff --git a/client/lib/src/op/UnsubscribeOp.h b/client/lib/src/op/UnsubscribeOp.h index be84988..69f05fc 100644 --- a/client/lib/src/op/UnsubscribeOp.h +++ b/client/lib/src/op/UnsubscribeOp.h @@ -28,6 +28,7 @@ class UnsubscribeOp final : public Op CC_Mqtt5ErrorCode addUserProp(const CC_Mqtt5UserProp& prop); CC_Mqtt5ErrorCode send(CC_Mqtt5UnsubscribeCompleteCb cb, void* cbData); CC_Mqtt5ErrorCode cancel(); + unsigned getPacketId() const; using Base::handle; virtual void handle(UnsubackMsg& msg) override; diff --git a/client/lib/templ/client.cpp.templ b/client/lib/templ/client.cpp.templ index 458b9cc..b8856e4 100644 --- a/client/lib/templ/client.cpp.templ +++ b/client/lib/templ/client.cpp.templ @@ -576,6 +576,15 @@ CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_subscribe_cancel(CC_Mqtt5SubscribeHand return subscribeOpFromHandle(handle)->cancel(); } +unsigned cc_mqtt5_##NAME##client_subscribe_get_packet_id(CC_Mqtt5SubscribeHandle handle) +{ + if (handle == nullptr) { + return 0U; + } + + return subscribeOpFromHandle(handle)->getPacketId(); +} + CC_Mqtt5UnsubscribeHandle cc_mqtt5_##NAME##client_unsubscribe_prepare(CC_Mqtt5ClientHandle handle, CC_Mqtt5ErrorCode* ec) { if (handle == nullptr) { @@ -648,6 +657,15 @@ CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_unsubscribe_cancel(CC_Mqtt5Unsubscribe return unsubscribeOpFromHandle(handle)->cancel(); } +unsigned cc_mqtt5_##NAME##client_unsubscribe_get_packet_id(CC_Mqtt5UnsubscribeHandle handle) +{ + if (handle == nullptr) { + return CC_Mqtt5ErrorCode_BadParam; + } + + return unsubscribeOpFromHandle(handle)->getPacketId(); +} + CC_Mqtt5PublishHandle cc_mqtt5_##NAME##client_publish_prepare(CC_Mqtt5ClientHandle handle, CC_Mqtt5ErrorCode* ec) { if (handle == nullptr) { @@ -752,6 +770,15 @@ CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_publish_cancel(CC_Mqtt5PublishHandle h return sendOpFromHandle(handle)->cancel(); } +unsigned cc_mqtt5_##NAME##client_publish_get_packet_id(CC_Mqtt5PublishHandle handle) +{ + if (handle == nullptr) { + return 0U; + } + + return sendOpFromHandle(handle)->getPacketId(); +} + CC_Mqtt5ReauthHandle cc_mqtt5_##NAME##client_reauth_prepare(CC_Mqtt5ClientHandle handle, CC_Mqtt5ErrorCode* ec) { if (handle == nullptr) { diff --git a/client/lib/templ/client.h.templ b/client/lib/templ/client.h.templ index 762f267..32e3905 100644 --- a/client/lib/templ/client.h.templ +++ b/client/lib/templ/client.h.templ @@ -305,6 +305,7 @@ CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_connect_send(CC_Mqtt5ConnectHandle han /// @ingroup connect CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_connect_cancel(CC_Mqtt5ConnectHandle handle); + /// @brief Check the inner state of the library of whether it's connected to the broker. /// @param[in] handle Handle returned by @ref cc_mqtt5_##NAME##client_alloc() function. /// @ingroup connect @@ -431,6 +432,16 @@ CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_subscribe_send(CC_Mqtt5SubscribeHandle /// @ingroup subscribe CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_subscribe_cancel(CC_Mqtt5SubscribeHandle handle); +/// @brief Retrieve "Packet Identifier" of the "subscribe" operation. +/// @details The retrieved value can be used to differentiate between the "subscribe" operations +/// in case they use the same callback when calling the +/// @ref cc_mqtt5_##NAME##client_subscribe_send() function. +/// @param[in] handle Handle returned by @ref cc_mqtt5_##NAME##client_subscribe_prepare() function. +/// @pre The function can be called while the handle is valid, i.e. until the callback +/// of the operation completion is called or until the operation is cancelled. +/// @return "Packet Identifier" value +unsigned cc_mqtt5_##NAME##client_subscribe_get_packet_id(CC_Mqtt5SubscribeHandle handle); + /// @brief Prepare "unsubscribe" operation. /// @param[in] handle Handle returned by @ref cc_mqtt5_##NAME##client_alloc() function. /// @param[out] ec Error code reporting result of the operation. Can be NULL. @@ -494,6 +505,16 @@ CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_unsubscribe_send(CC_Mqtt5UnsubscribeHa /// @ingroup unsubscribe CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_unsubscribe_cancel(CC_Mqtt5UnsubscribeHandle handle); +/// @brief Retrieve "Packet Identifier" of the "unsubscribe" operation. +/// @details The retrieved value can be used to differentiate between the "unsubscribe" operations +/// in case they use the same callback when calling the +/// @ref cc_mqtt5_##NAME##client_unsubscribe_send() function. +/// @param[in] handle Handle returned by @ref cc_mqtt5_##NAME##client_unsubscribe_prepare() function. +/// @pre The function can be called while the handle is valid, i.e. until the callback +/// of the operation completion is called or until the operation is cancelled. +/// @return "Packet Identifier" value +unsigned cc_mqtt5_##NAME##client_unsubscribe_get_packet_id(CC_Mqtt5UnsubscribeHandle handle); + /// @brief Prepare "publish" operation. /// @param[in] handle Handle returned by @ref cc_mqtt5_##NAME##client_alloc() function. /// @param[out] ec Error code reporting result of the operation. Can be NULL. @@ -586,6 +607,24 @@ CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_publish_send(CC_Mqtt5PublishHandle han /// @ingroup publish CC_Mqtt5ErrorCode cc_mqtt5_##NAME##client_publish_cancel(CC_Mqtt5PublishHandle handle); +/// @brief Retrieve "Packet Identifier" of the "publish" operation. +/// @details The retrieved value can be used to differentiate between the "publish" operations +/// in case they use the same callback when calling the +/// @ref cc_mqtt5_##NAME##client_publish_send() function. +/// @param[in] handle Handle returned by @ref cc_mqtt5_##NAME##client_publish_prepare() function. +/// @pre The function is expected to be called after the @ref cc_mqtt5_##NAME##client_publish_config_basic() +/// which sets the QoS value. In case the QoS value is @ref CC_Mqtt5QoS_AtMostOnceDelivery the +/// "Packet Identifier" is not allocated and @b 0 is returned +/// @pre The function can be called while the handle is valid, i.e. until the callback +/// of the operation completion is called or until the operation is cancelled. +/// @note When QoS is @b 0 (@ref CC_Mqtt5QoS_AtMostOnceDelivery), the callback function is +//// invoked immediately from within the @ref cc_mqtt5_##NAME##client_publish_send() +/// invocation immediatelly invalidating the handle, i.e. in such case the +/// @ref cc_mqtt5_##NAME##client_publish_get_packet_id() cannot be called after the +/// @ref cc_mqtt5_##NAME##client_publish_send(). +/// @return "Packet Identifier" value when allocated, @b 0 otherwise. +unsigned cc_mqtt5_##NAME##client_publish_get_packet_id(CC_Mqtt5PublishHandle handle); + /// @brief Prepare "reauth" operation. /// @param[in] handle Handle returned by @ref cc_mqtt5_##NAME##client_alloc() function. /// @param[out] ec Error code reporting result of the operation. Can be NULL. diff --git a/client/lib/test/unit/UnitTestBmBase.cpp b/client/lib/test/unit/UnitTestBmBase.cpp index c12489d..56b29f5 100644 --- a/client/lib/test/unit/UnitTestBmBase.cpp +++ b/client/lib/test/unit/UnitTestBmBase.cpp @@ -59,6 +59,7 @@ const UnitTestBmBase::LibFuncs& UnitTestBmBase::getFuncs() funcs.m_subscribe_add_user_prop = &cc_mqtt5_bm_client_subscribe_add_user_prop; funcs.m_subscribe_send = &cc_mqtt5_bm_client_subscribe_send; funcs.m_subscribe_cancel = &cc_mqtt5_bm_client_subscribe_cancel; + funcs.m_subscribe_get_packet_id = &cc_mqtt5_bm_client_subscribe_get_packet_id; funcs.m_unsubscribe_prepare = &cc_mqtt5_bm_client_unsubscribe_prepare; funcs.m_unsubscribe_set_response_timeout = &cc_mqtt5_bm_client_unsubscribe_set_response_timeout; funcs.m_unsubscribe_get_response_timeout = &cc_mqtt5_bm_client_unsubscribe_get_response_timeout; @@ -67,6 +68,7 @@ const UnitTestBmBase::LibFuncs& UnitTestBmBase::getFuncs() funcs.m_unsubscribe_add_user_prop = &cc_mqtt5_bm_client_unsubscribe_add_user_prop; funcs.m_unsubscribe_send = &cc_mqtt5_bm_client_unsubscribe_send; funcs.m_unsubscribe_cancel = &cc_mqtt5_bm_client_unsubscribe_cancel; + funcs.m_unsubscribe_get_packet_id = &cc_mqtt5_bm_client_unsubscribe_get_packet_id; funcs.m_publish_prepare = &cc_mqtt5_bm_client_publish_prepare; funcs.m_publish_init_config_basic = &cc_mqtt5_bm_client_publish_init_config_basic; funcs.m_publish_init_config_extra = &cc_mqtt5_bm_client_publish_init_config_extra; @@ -79,6 +81,7 @@ const UnitTestBmBase::LibFuncs& UnitTestBmBase::getFuncs() funcs.m_publish_add_user_prop = &cc_mqtt5_bm_client_publish_add_user_prop; funcs.m_publish_send = &cc_mqtt5_bm_client_publish_send; funcs.m_publish_cancel = &cc_mqtt5_bm_client_publish_cancel; + funcs.m_publish_get_packet_id = &cc_mqtt5_bm_client_publish_get_packet_id; funcs.m_reauth_prepare = &cc_mqtt5_bm_client_reauth_prepare; funcs.m_reauth_init_config_auth = &cc_mqtt5_bm_client_reauth_init_config_auth; funcs.m_reauth_set_response_timeout = &cc_mqtt5_bm_client_reauth_set_response_timeout; diff --git a/client/lib/test/unit/UnitTestCommonBase.cpp b/client/lib/test/unit/UnitTestCommonBase.cpp index 968238b..57886d1 100644 --- a/client/lib/test/unit/UnitTestCommonBase.cpp +++ b/client/lib/test/unit/UnitTestCommonBase.cpp @@ -93,6 +93,7 @@ UnitTestCommonBase::UnitTestCommonBase(const LibFuncs& funcs) : test_assert(m_funcs.m_subscribe_add_user_prop != nullptr); test_assert(m_funcs.m_subscribe_send != nullptr); test_assert(m_funcs.m_subscribe_cancel != nullptr); + test_assert(m_funcs.m_subscribe_get_packet_id != nullptr); test_assert(m_funcs.m_unsubscribe_prepare != nullptr); test_assert(m_funcs.m_unsubscribe_set_response_timeout != nullptr); test_assert(m_funcs.m_unsubscribe_get_response_timeout != nullptr); @@ -101,6 +102,7 @@ UnitTestCommonBase::UnitTestCommonBase(const LibFuncs& funcs) : test_assert(m_funcs.m_unsubscribe_add_user_prop != nullptr); test_assert(m_funcs.m_unsubscribe_send != nullptr); test_assert(m_funcs.m_unsubscribe_cancel != nullptr); + test_assert(m_funcs.m_unsubscribe_get_packet_id != nullptr); test_assert(m_funcs.m_publish_prepare != nullptr); test_assert(m_funcs.m_publish_init_config_basic != nullptr); test_assert(m_funcs.m_publish_init_config_extra != nullptr); @@ -113,6 +115,7 @@ UnitTestCommonBase::UnitTestCommonBase(const LibFuncs& funcs) : test_assert(m_funcs.m_publish_add_user_prop != nullptr); test_assert(m_funcs.m_publish_send != nullptr); test_assert(m_funcs.m_publish_cancel != nullptr); + test_assert(m_funcs.m_publish_get_packet_id != nullptr); test_assert(m_funcs.m_reauth_prepare != nullptr); test_assert(m_funcs.m_reauth_init_config_auth != nullptr); test_assert(m_funcs.m_reauth_set_response_timeout != nullptr); @@ -1101,6 +1104,11 @@ CC_Mqtt5ErrorCode UnitTestCommonBase::unitTestSubscribeAddUserProp(CC_Mqtt5Subsc return m_funcs.m_subscribe_add_user_prop(handle, prop); } +unsigned UnitTestCommonBase::unitTestSubscribeGetPacktId(CC_Mqtt5SubscribeHandle handle) +{ + return m_funcs.m_subscribe_get_packet_id(handle); +} + CC_Mqtt5UnsubscribeHandle UnitTestCommonBase::unitTestUnsubscribePrepare(CC_Mqtt5Client* client, CC_Mqtt5ErrorCode* ec) { return m_funcs.m_unsubscribe_prepare(client, ec); @@ -1126,6 +1134,11 @@ CC_Mqtt5ErrorCode UnitTestCommonBase::unitTestUnsubscribeAddUserProp(CC_Mqtt5Uns return m_funcs.m_unsubscribe_add_user_prop(handle, prop); } +unsigned UnitTestCommonBase::unitTestUnsubscribeGetPacktId(CC_Mqtt5UnsubscribeHandle handle) +{ + return m_funcs.m_unsubscribe_get_packet_id(handle); +} + CC_Mqtt5PublishHandle UnitTestCommonBase::unitTestPublishPrepare(CC_Mqtt5Client* client, CC_Mqtt5ErrorCode* ec) { return m_funcs.m_publish_prepare(client, ec); @@ -1161,6 +1174,11 @@ CC_Mqtt5ErrorCode UnitTestCommonBase::unitTestPublishAddUserProp(CC_Mqtt5Publish return m_funcs.m_publish_add_user_prop(handle, prop); } +unsigned UnitTestCommonBase::unitTestPublishGetPacktId(CC_Mqtt5PublishHandle handle) +{ + return m_funcs.m_publish_get_packet_id(handle); +} + CC_Mqtt5ReauthHandle UnitTestCommonBase::unitTestReauthPrepare(CC_Mqtt5Client* client, CC_Mqtt5ErrorCode* ec) { return m_funcs.m_reauth_prepare(client, ec); diff --git a/client/lib/test/unit/UnitTestCommonBase.h b/client/lib/test/unit/UnitTestCommonBase.h index 9d8d2f9..d1c775e 100644 --- a/client/lib/test/unit/UnitTestCommonBase.h +++ b/client/lib/test/unit/UnitTestCommonBase.h @@ -72,6 +72,7 @@ class UnitTestCommonBase CC_Mqtt5ErrorCode (*m_subscribe_add_user_prop)(CC_Mqtt5SubscribeHandle, const CC_Mqtt5UserProp*) = nullptr; CC_Mqtt5ErrorCode (*m_subscribe_send)(CC_Mqtt5SubscribeHandle, CC_Mqtt5SubscribeCompleteCb, void*) = nullptr; CC_Mqtt5ErrorCode (*m_subscribe_cancel)(CC_Mqtt5SubscribeHandle) = nullptr; + unsigned (*m_subscribe_get_packet_id)(CC_Mqtt5SubscribeHandle) = nullptr; CC_Mqtt5UnsubscribeHandle (*m_unsubscribe_prepare)(CC_Mqtt5ClientHandle, CC_Mqtt5ErrorCode*) = nullptr; CC_Mqtt5ErrorCode (*m_unsubscribe_set_response_timeout)(CC_Mqtt5UnsubscribeHandle, unsigned) = nullptr; unsigned (*m_unsubscribe_get_response_timeout)(CC_Mqtt5UnsubscribeHandle) = nullptr; @@ -80,6 +81,7 @@ class UnitTestCommonBase CC_Mqtt5ErrorCode (*m_unsubscribe_add_user_prop)(CC_Mqtt5UnsubscribeHandle, const CC_Mqtt5UserProp*) = nullptr; CC_Mqtt5ErrorCode (*m_unsubscribe_send)(CC_Mqtt5UnsubscribeHandle, CC_Mqtt5UnsubscribeCompleteCb, void*) = nullptr; CC_Mqtt5ErrorCode (*m_unsubscribe_cancel)(CC_Mqtt5UnsubscribeHandle) = nullptr; + unsigned (*m_unsubscribe_get_packet_id)(CC_Mqtt5UnsubscribeHandle) = nullptr; CC_Mqtt5PublishHandle (*m_publish_prepare)(CC_Mqtt5ClientHandle, CC_Mqtt5ErrorCode*) = nullptr; void (*m_publish_init_config_basic)(CC_Mqtt5PublishBasicConfig*) = nullptr; void (*m_publish_init_config_extra)(CC_Mqtt5PublishExtraConfig*) = nullptr; @@ -92,6 +94,7 @@ class UnitTestCommonBase CC_Mqtt5ErrorCode (*m_publish_add_user_prop)(CC_Mqtt5PublishHandle, const CC_Mqtt5UserProp*) = nullptr; CC_Mqtt5ErrorCode (*m_publish_send)(CC_Mqtt5PublishHandle, CC_Mqtt5PublishCompleteCb, void*) = nullptr; CC_Mqtt5ErrorCode (*m_publish_cancel)(CC_Mqtt5PublishHandle) = nullptr; + unsigned (*m_publish_get_packet_id)(CC_Mqtt5PublishHandle) = nullptr; CC_Mqtt5ReauthHandle (*m_reauth_prepare)(CC_Mqtt5ClientHandle, CC_Mqtt5ErrorCode*) = nullptr; void (*m_reauth_init_config_auth)(CC_Mqtt5AuthConfig*) = nullptr; CC_Mqtt5ErrorCode (*m_reauth_set_response_timeout)(CC_Mqtt5ReauthHandle, unsigned) = nullptr; @@ -460,11 +463,13 @@ class UnitTestCommonBase CC_Mqtt5ErrorCode unitTestSubscribeConfigTopic(CC_Mqtt5SubscribeHandle handle, const CC_Mqtt5SubscribeTopicConfig* config); CC_Mqtt5ErrorCode unitTestSubscribeConfigExtra(CC_Mqtt5SubscribeHandle handle, const CC_Mqtt5SubscribeExtraConfig* config); CC_Mqtt5ErrorCode unitTestSubscribeAddUserProp(CC_Mqtt5SubscribeHandle handle, const CC_Mqtt5UserProp* prop); + unsigned unitTestSubscribeGetPacktId(CC_Mqtt5SubscribeHandle handle); CC_Mqtt5UnsubscribeHandle unitTestUnsubscribePrepare(CC_Mqtt5Client* client, CC_Mqtt5ErrorCode* ec); CC_Mqtt5ErrorCode unitTestUnsubscribeSetResponseTimeout(CC_Mqtt5UnsubscribeHandle handle, unsigned ms); void unitTestUnsubscribeInitConfigTopic(CC_Mqtt5UnsubscribeTopicConfig* config); CC_Mqtt5ErrorCode unitTestUnsubscribeConfigTopic(CC_Mqtt5UnsubscribeHandle handle, const CC_Mqtt5UnsubscribeTopicConfig* config); CC_Mqtt5ErrorCode unitTestUnsubscribeAddUserProp(CC_Mqtt5UnsubscribeHandle handle, const CC_Mqtt5UserProp* prop); + unsigned unitTestUnsubscribeGetPacktId(CC_Mqtt5UnsubscribeHandle handle); CC_Mqtt5PublishHandle unitTestPublishPrepare(CC_Mqtt5Client* client, CC_Mqtt5ErrorCode* ec); void unitTestPublishInitConfigBasic(CC_Mqtt5PublishBasicConfig* config); void unitTestPublishInitConfigExtra(CC_Mqtt5PublishExtraConfig* config); @@ -472,6 +477,7 @@ class UnitTestCommonBase CC_Mqtt5ErrorCode unitTestPublishConfigBasic(CC_Mqtt5PublishHandle handle, const CC_Mqtt5PublishBasicConfig* config); CC_Mqtt5ErrorCode unitTestPublishConfigExtra(CC_Mqtt5PublishHandle handle, const CC_Mqtt5PublishExtraConfig* config); CC_Mqtt5ErrorCode unitTestPublishAddUserProp(CC_Mqtt5PublishHandle handle, const CC_Mqtt5UserProp* prop); + unsigned unitTestPublishGetPacktId(CC_Mqtt5PublishHandle handle); CC_Mqtt5ReauthHandle unitTestReauthPrepare(CC_Mqtt5Client* client, CC_Mqtt5ErrorCode* ec); void unitTestReauthInitConfigAuth(CC_Mqtt5AuthConfig* config); CC_Mqtt5ErrorCode unitTestReauthAddUserProp(CC_Mqtt5ReauthHandle handle, const CC_Mqtt5UserProp* prop); diff --git a/client/lib/test/unit/UnitTestDefaultBase.cpp b/client/lib/test/unit/UnitTestDefaultBase.cpp index 7f0d5a9..2c0394e 100644 --- a/client/lib/test/unit/UnitTestDefaultBase.cpp +++ b/client/lib/test/unit/UnitTestDefaultBase.cpp @@ -59,6 +59,7 @@ const UnitTestDefaultBase::LibFuncs& UnitTestDefaultBase::getFuncs() funcs.m_subscribe_add_user_prop = &cc_mqtt5_client_subscribe_add_user_prop; funcs.m_subscribe_send = &cc_mqtt5_client_subscribe_send; funcs.m_subscribe_cancel = &cc_mqtt5_client_subscribe_cancel; + funcs.m_subscribe_get_packet_id = &cc_mqtt5_client_subscribe_get_packet_id; funcs.m_unsubscribe_prepare = &cc_mqtt5_client_unsubscribe_prepare; funcs.m_unsubscribe_set_response_timeout = &cc_mqtt5_client_unsubscribe_set_response_timeout; funcs.m_unsubscribe_get_response_timeout = &cc_mqtt5_client_unsubscribe_get_response_timeout; @@ -67,6 +68,7 @@ const UnitTestDefaultBase::LibFuncs& UnitTestDefaultBase::getFuncs() funcs.m_unsubscribe_add_user_prop = &cc_mqtt5_client_unsubscribe_add_user_prop; funcs.m_unsubscribe_send = &cc_mqtt5_client_unsubscribe_send; funcs.m_unsubscribe_cancel = &cc_mqtt5_client_unsubscribe_cancel; + funcs.m_unsubscribe_get_packet_id = &cc_mqtt5_client_unsubscribe_get_packet_id; funcs.m_publish_prepare = &cc_mqtt5_client_publish_prepare; funcs.m_publish_init_config_basic = &cc_mqtt5_client_publish_init_config_basic; funcs.m_publish_init_config_extra = &cc_mqtt5_client_publish_init_config_extra; @@ -79,6 +81,7 @@ const UnitTestDefaultBase::LibFuncs& UnitTestDefaultBase::getFuncs() funcs.m_publish_add_user_prop = &cc_mqtt5_client_publish_add_user_prop; funcs.m_publish_send = &cc_mqtt5_client_publish_send; funcs.m_publish_cancel = &cc_mqtt5_client_publish_cancel; + funcs.m_publish_get_packet_id = &cc_mqtt5_client_publish_get_packet_id; funcs.m_reauth_prepare = &cc_mqtt5_client_reauth_prepare; funcs.m_reauth_init_config_auth = &cc_mqtt5_client_reauth_init_config_auth; funcs.m_reauth_set_response_timeout = &cc_mqtt5_client_reauth_set_response_timeout;