Skip to content

Commit 9e4dac0

Browse files
committed
ReadHandler changes for large payloads
When sending reports, if the session established with the peer supports large payloads, the ReadHandler will allocate a large buffer to, potentially, fit more attribute and event data.
1 parent 5ee4ef6 commit 9e4dac0

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/app/InteractionModelEngine.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,11 @@ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest
853853
return Status::ResourceExhausted;
854854
}
855855

856+
if (apExchangeContext->GetSessionHandle()->AllowsLargePayload())
857+
{
858+
handler->UseLargePayloadBuffer();
859+
}
860+
856861
handler->OnInitialRequest(std::move(aPayload));
857862

858863
return Status::Success;

src/app/ReadHandler.h

+6
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ class ReadHandler : public Messaging::ExchangeDelegate
491491
/// @param aFlag Flag to clear
492492
void ClearStateFlag(ReadHandlerFlags aFlag);
493493

494+
495+
void UseLargePayloadBuffer() { mUseLargePayloadBuffer = true; }
496+
bool ShouldUseLargePayloadBuffer() { return mUseLargePayloadBuffer; }
497+
494498
AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr);
495499

496500
// The current generation of the reporting engine dirty set the last time we were notified that a path we're interested in was
@@ -572,6 +576,8 @@ class ReadHandler : public Messaging::ExchangeDelegate
572576

573577
// TODO (#27675): Merge all observers into one and that one will dispatch the callbacks to the right place.
574578
Observer * mObserver = nullptr;
579+
580+
bool mUseLargePayloadBuffer = false;
575581
};
576582
} // namespace app
577583
} // namespace chip

src/app/StatusResponse.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace chip {
2828
namespace app {
2929
static constexpr size_t kMaxSecureSduLengthBytes = kMaxAppMessageLen + kMaxTagLen;
30+
static constexpr size_t kMaxLargeSecureSduLengthBytes = kMaxLargeAppMessageLen + kMaxTagLen;
3031

3132
class StatusResponse
3233
{

src/app/reporting/Engine.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,11 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
492492
CHIP_ERROR err = CHIP_NO_ERROR;
493493
chip::System::PacketBufferTLVWriter reportDataWriter;
494494
ReportDataMessage::Builder reportDataBuilder;
495-
chip::System::PacketBufferHandle bufHandle = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes);
496-
uint16_t reservedSize = 0;
497-
bool hasMoreChunks = false;
498-
bool needCloseReadHandler = false;
495+
size_t maxSduSize = chip::app::kMaxSecureSduLengthBytes;
496+
chip::System::PacketBufferHandle bufHandle = nullptr;
497+
uint16_t reservedSize = 0;
498+
bool hasMoreChunks = false;
499+
bool needCloseReadHandler = false;
499500

500501
// Reserved size for the MoreChunks boolean flag, which takes up 1 byte for the control tag and 1 byte for the context tag.
501502
const uint32_t kReservedSizeForMoreChunksFlag = 1 + 1;
@@ -512,11 +513,18 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
512513

513514
VerifyOrExit(apReadHandler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
514515
VerifyOrExit(apReadHandler->GetSession() != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
516+
517+
if (apReadHandler->ShouldUseLargePayloadBuffer())
518+
{
519+
maxSduSize = chip::app::kMaxLargeSecureSduLengthBytes;
520+
}
521+
522+
bufHandle = System::PacketBufferHandle::New(maxSduSize);
515523
VerifyOrExit(!bufHandle.IsNull(), err = CHIP_ERROR_NO_MEMORY);
516524

517-
if (bufHandle->AvailableDataLength() > kMaxSecureSduLengthBytes)
525+
if (bufHandle->AvailableDataLength() > maxSduSize)
518526
{
519-
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - kMaxSecureSduLengthBytes);
527+
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - maxSduSize);
520528
}
521529

522530
reportDataWriter.Init(std::move(bufHandle));

0 commit comments

Comments
 (0)