Skip to content

Commit

Permalink
Merge 527cd7d into 5623978
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored Nov 15, 2021
2 parents 5623978 + 527cd7d commit 3864357
Show file tree
Hide file tree
Showing 16 changed files with 407 additions and 80 deletions.
10 changes: 10 additions & 0 deletions src/app/ClusterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

#include <app/ConcreteAttributePath.h>
#include <app/util/basic-types.h>
#include <assert.h>
#include <lib/core/Optional.h>
Expand Down Expand Up @@ -57,6 +58,15 @@ struct ClusterInfo
return true;
}

bool IsPathIncluded(const ConcreteAttributePath & other) const
{
VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
VerifyOrReturnError(HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false);

return true;
}

bool HasWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); }

/**
Expand Down
25 changes: 14 additions & 11 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,20 @@ CHIP_ERROR ReadClient::SendStatusResponse(CHIP_ERROR aError)
{
if (IsAwaitingInitialReport())
{
MoveToState(ClientState::AwaitingSubscribeResponse);
if (!mPendingMoreChunks)
{
MoveToState(ClientState::AwaitingSubscribeResponse);
}
}
else
{
RefreshLivenessCheckTimer();
}
}
ReturnLogErrorOnFailure(
mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::StatusResponse, std::move(msgBuf),
Messaging::SendFlags(IsAwaitingSubscribeResponse() ? Messaging::SendMessageFlags::kExpectResponse
: Messaging::SendMessageFlags::kNone)));
ReturnLogErrorOnFailure(mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::StatusResponse, std::move(msgBuf),
Messaging::SendFlags((IsAwaitingSubscribeResponse() || mPendingMoreChunks)
? Messaging::SendMessageFlags::kExpectResponse
: Messaging::SendMessageFlags::kNone)));
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -293,7 +296,7 @@ CHIP_ERROR ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchange
}

exit:
if (!IsSubscriptionType() || err != CHIP_NO_ERROR)
if ((!IsSubscriptionType() && !mPendingMoreChunks) || err != CHIP_NO_ERROR)
{
ShutdownInternal(err);
}
Expand Down Expand Up @@ -332,7 +335,6 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload)
bool isEventReportsPresent = false;
bool isAttributeReportIBsPresent = false;
bool suppressResponse = false;
bool moreChunkedMessages = false;
uint64_t subscriptionId = 0;
EventReports::Parser EventReports;
AttributeReportIBs::Parser attributeReportIBs;
Expand Down Expand Up @@ -381,10 +383,11 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload)
}
SuccessOrExit(err);

err = report.GetMoreChunkedMessages(&moreChunkedMessages);
err = report.GetMoreChunkedMessages(&mPendingMoreChunks);
if (CHIP_END_OF_TLV == err)
{
err = CHIP_NO_ERROR;
mPendingMoreChunks = false;
err = CHIP_NO_ERROR;
}
SuccessOrExit(err);

Expand All @@ -410,7 +413,7 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload)
err = CHIP_NO_ERROR;
}
SuccessOrExit(err);
if (isAttributeReportIBsPresent && nullptr != mpCallback && !moreChunkedMessages)
if (isAttributeReportIBsPresent && nullptr != mpCallback)
{
TLV::TLVReader attributeReportIBsReader;
attributeReportIBs.GetReader(&attributeReportIBsReader);
Expand All @@ -426,7 +429,7 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload)

exit:
SendStatusResponse(err);
if (!mInitialReport)
if (!mInitialReport && !mPendingMoreChunks)
{
mpExchangeCtx = nullptr;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class ReadClient : public Messaging::ExchangeDelegate
Callback * mpCallback = nullptr;
ClientState mState = ClientState::Uninitialized;
bool mInitialReport = true;
bool mPendingMoreChunks = false;
uint16_t mMinIntervalFloorSeconds = 0;
uint16_t mMaxIntervalCeilingSeconds = 0;
uint64_t mSubscriptionId = 0;
Expand Down
24 changes: 20 additions & 4 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange
VerifyOrExit((statusCode == Protocols::InteractionModel::Status::Success), err = CHIP_ERROR_INVALID_ARGUMENT);
switch (mState)
{
case HandlerState::AwaitingChunkingResponse:
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
MoveToState(HandlerState::GeneratingReports);
if (mpExchangeCtx)
{
mpExchangeCtx->WillSendMessage();
}
SuccessOrExit(err = InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun());
break;
case HandlerState::AwaitingReportResponse:
if (IsSubscriptionType())
{
Expand Down Expand Up @@ -192,7 +201,7 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange
return err;
}

CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload)
CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, bool aMoreChunks)
{
VerifyOrReturnLogError(IsReportable(), CHIP_ERROR_INCORRECT_STATE);
if (IsInitialReport())
Expand All @@ -206,7 +215,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload)
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);
}
VerifyOrReturnLogError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE);
MoveToState(HandlerState::AwaitingReportResponse);
MoveToState(aMoreChunks ? HandlerState::AwaitingChunkingResponse : HandlerState::AwaitingReportResponse);
CHIP_ERROR err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::ReportData, std::move(aPayload),
Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse));
if (err == CHIP_NO_ERROR)
Expand All @@ -216,7 +225,10 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload)
err = RefreshSubscribeSyncTimer();
}
}
ClearDirty();
if (!aMoreChunks)
{
ClearDirty();
}
return err;
}

Expand Down Expand Up @@ -380,7 +392,8 @@ CHIP_ERROR ReadHandler::ProcessAttributePathList(AttributePathIBs::Parser & aAtt
// if we have exhausted this container
if (CHIP_END_OF_TLV == err)
{
err = CHIP_NO_ERROR;
mAttributePathExpandIterator = AttributePathExpandIterator(mpAttributeClusterInfoList);
err = CHIP_NO_ERROR;
}

exit:
Expand Down Expand Up @@ -441,6 +454,9 @@ const char * ReadHandler::GetStateStr() const
case HandlerState::GeneratingReports:
return "GeneratingReports";

case HandlerState::AwaitingChunkingResponse:
return "AwaitingChunkingResponse";

case HandlerState::AwaitingReportResponse:
return "AwaitingReportResponse";
}
Expand Down
33 changes: 21 additions & 12 deletions src/app/ReadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#pragma once

#include <app/AttributePathExpandIterator.h>
#include <app/ClusterInfo.h>
#include <app/EventManagement.h>
#include <app/InteractionModelDelegate.h>
Expand Down Expand Up @@ -97,12 +98,13 @@ class ReadHandler : public Messaging::ExchangeDelegate
* Send ReportData to initiator
*
* @param[in] aPayload A payload that has read request data
* @param[in] aMoreChunks A flags indicating there will be more chunks for this read request
*
* @retval #Others If fails to send report data
* @retval #CHIP_NO_ERROR On success.
*
*/
CHIP_ERROR SendReportData(System::PacketBufferHandle && aPayload);
CHIP_ERROR SendReportData(System::PacketBufferHandle && aPayload, bool mMoreChunks);

bool IsFree() const { return mState == HandlerState::Uninitialized; }
bool IsReportable() const { return mState == HandlerState::GeneratingReports && !mHoldReport; }
Expand Down Expand Up @@ -130,7 +132,12 @@ class ReadHandler : public Messaging::ExchangeDelegate
bool IsActiveSubscription() const { return mActiveSubscription; }
CHIP_ERROR OnSubscribeRequest(Messaging::ExchangeContext * apExchangeContext, System::PacketBufferHandle && aPayload);
void GetSubscriptionId(uint64_t & aSubscriptionId) { aSubscriptionId = mSubscriptionId; }
void SetDirty() { mDirty = true; }
AttributePathExpandIterator * GetAttributePathExpandIterator() { return &mAttributePathExpandIterator; }
void SetDirty()
{
mDirty = true;
mAttributePathExpandIterator = AttributePathExpandIterator(mpAttributeClusterInfoList);
}
void ClearDirty() { mDirty = false; }
bool IsDirty() { return mDirty; }
NodeId GetInitiatorNodeId() const { return mInitiatorNodeId; }
Expand All @@ -140,11 +147,12 @@ class ReadHandler : public Messaging::ExchangeDelegate
friend class TestReadInteraction;
enum class HandlerState
{
Uninitialized = 0, ///< The handler has not been initialized
Initialized, ///< The handler has been initialized and is ready
GeneratingReports, ///< The handler has received either a Read or Subscribe request and is the process of generating a
///< report.
AwaitingReportResponse, ///< The handler has sent the report to the client and is awaiting a status response.
Uninitialized = 0, ///< The handler has not been initialized
Initialized, ///< The handler has been initialized and is ready
GeneratingReports, ///< The handler has received either a Read or Subscribe request and is the process of generating a
///< report.
AwaitingChunkingResponse, ///< The handler just sent a report chunk and is waiting a status response.
AwaitingReportResponse, ///< The handler has sent the last report chunk to the client and is awaiting a status response.
};

static void OnRefreshSubscribeTimerSyncCallback(System::Layer * apSystemLayer, void * apAppState);
Expand Down Expand Up @@ -189,11 +197,12 @@ class ReadHandler : public Messaging::ExchangeDelegate
uint16_t mMinIntervalFloorSeconds = 0;
uint16_t mMaxIntervalCeilingSeconds = 0;
Optional<SessionHandle> mSessionHandle;
bool mHoldReport = false;
bool mDirty = false;
bool mActiveSubscription = false;
NodeId mInitiatorNodeId = kUndefinedNodeId;
FabricIndex mFabricIndex = 0;
bool mHoldReport = false;
bool mDirty = false;
bool mActiveSubscription = false;
NodeId mInitiatorNodeId = kUndefinedNodeId;
FabricIndex mFabricIndex = 0;
AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr);
};
} // namespace app
} // namespace chip
Loading

0 comments on commit 3864357

Please sign in to comment.