Skip to content

Commit

Permalink
Changes to InvokeResponseMessage to reflect 1.3 spec (#30639)
Browse files Browse the repository at this point in the history
  • Loading branch information
tehampson authored Nov 29, 2023
1 parent b3ef405 commit 2937f3a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/app/MessageDef/InvokeResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ CHIP_ERROR InvokeResponseMessage::Parser::PrettyPrint() const
ReturnErrorOnFailure(invokeResponses.PrettyPrint());
PRETTY_PRINT_DECDEPTH();
}
break;
case to_underlying(Tag::kMoreChunkedMessages):
#if CHIP_DETAIL_LOGGING
{
bool moreChunkedMessages;
ReturnErrorOnFailure(reader.Get(moreChunkedMessages));
PRETTY_PRINT("\tmoreChunkedMessages = %s, ", moreChunkedMessages ? "true" : "false");
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
Expand Down Expand Up @@ -98,6 +107,11 @@ CHIP_ERROR InvokeResponseMessage::Parser::GetInvokeResponses(InvokeResponseIBs::
return apStatus->Init(reader);
}

CHIP_ERROR InvokeResponseMessage::Parser::GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const
{
return GetSimpleValue(to_underlying(Tag::kMoreChunkedMessages), TLV::kTLVType_Boolean, apMoreChunkedMessages);
}

InvokeResponseMessage::Builder & InvokeResponseMessage::Builder::SuppressResponse(const bool aSuppressResponse)
{
if (mError == CHIP_NO_ERROR)
Expand All @@ -116,6 +130,16 @@ InvokeResponseIBs::Builder & InvokeResponseMessage::Builder::CreateInvokeRespons
return mInvokeResponses;
}

InvokeResponseMessage::Builder & InvokeResponseMessage::Builder::MoreChunkedMessages(const bool aMoreChunkedMessages)
{
// skip if error has already been set
if (mError == CHIP_NO_ERROR)
{
mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kMoreChunkedMessages), aMoreChunkedMessages);
}
return *this;
}

CHIP_ERROR InvokeResponseMessage::Builder::EndOfInvokeResponseMessage()
{
if (mError == CHIP_NO_ERROR)
Expand Down
22 changes: 20 additions & 2 deletions src/app/MessageDef/InvokeResponseMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ namespace app {
namespace InvokeResponseMessage {
enum class Tag : uint8_t
{
kSuppressResponse = 0,
kInvokeResponses = 1,
kSuppressResponse = 0,
kInvokeResponses = 1,
kMoreChunkedMessages = 2,
};

class Parser : public MessageParser
Expand All @@ -61,6 +62,16 @@ class Parser : public MessageParser
* #CHIP_END_OF_TLV if there is no such element
*/
CHIP_ERROR GetInvokeResponses(InvokeResponseIBs::Parser * const apInvokeResponses) const;

/**
* @brief Get MoreChunkedMessages boolean
*
* @param [out] apMoreChunkedMessages A pointer to bool for storing more chunked messages value.
*
* @return #CHIP_NO_ERROR on success
* #CHIP_END_OF_TLV if there is no such element
*/
CHIP_ERROR GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const;
};

class Builder : public MessageBuilder
Expand All @@ -86,6 +97,13 @@ class Builder : public MessageBuilder
*/
InvokeResponseIBs::Builder & GetInvokeResponses() { return mInvokeResponses; }

/**
* @brief Set True if the set of InvokeResponseIB have to be sent across multiple packets in a single transaction
* @param [in] aMoreChunkedMessages true if more chunked messages are needed
* @return A reference to *this
*/
InvokeResponseMessage::Builder & MoreChunkedMessages(const bool aMoreChunkedMessages);

/**
* @brief Mark the end of this InvokeResponseMessage
*
Expand Down
12 changes: 11 additions & 1 deletion src/app/tests/TestMessageDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,9 @@ void BuildInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aW

BuildInvokeResponses(apSuite, invokeResponsesBuilder);

invokeResponseMessageBuilder.MoreChunkedMessages(true);
NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR);

invokeResponseMessageBuilder.EndOfInvokeResponseMessage();
NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR);
}
Expand All @@ -966,8 +969,15 @@ void ParseInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aR
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

bool suppressResponse = false;
invokeResponseMessageParser.GetSuppressResponse(&suppressResponse);
err = invokeResponseMessageParser.GetSuppressResponse(&suppressResponse);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(apSuite, suppressResponse == true);

bool moreChunkedMessages = true;
err = invokeResponseMessageParser.GetMoreChunkedMessages(&suppressResponse);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(apSuite, moreChunkedMessages == true);

#if CHIP_CONFIG_IM_PRETTY_PRINT
invokeResponseMessageParser.PrettyPrint();
#endif
Expand Down

0 comments on commit 2937f3a

Please sign in to comment.