Skip to content

Commit

Permalink
Fix the various MessageDef EndOf* functions to return CHIP_ERROR. (#2…
Browse files Browse the repository at this point in the history
…6910)

Simplifies consumers and makes it clearer you're not supposed to use the object
any more after the EndOf... call.

Fixes #8309
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 14, 2023
1 parent 072923d commit 9475052
Show file tree
Hide file tree
Showing 84 changed files with 224 additions and 254 deletions.
6 changes: 3 additions & 3 deletions src/app/AttributeAccessInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ CHIP_ERROR AttributeReportBuilder::PrepareAttribute(AttributeReportIBs::Builder
attributePathIBBuilder.ListIndex(DataModel::Nullable<ListIndex>());
}

ReturnErrorOnFailure(attributePathIBBuilder.EndOfAttributePathIB().GetError());
ReturnErrorOnFailure(attributePathIBBuilder.EndOfAttributePathIB());

return attributeDataIBBuilder.GetError();
}

CHIP_ERROR AttributeReportBuilder::FinishAttribute(AttributeReportIBs::Builder & aAttributeReportIBsBuilder)
{
ReturnErrorOnFailure(aAttributeReportIBsBuilder.GetAttributeReport().GetAttributeData().EndOfAttributeDataIB().GetError());
return aAttributeReportIBsBuilder.GetAttributeReport().EndOfAttributeReportIB().GetError();
ReturnErrorOnFailure(aAttributeReportIBsBuilder.GetAttributeReport().GetAttributeData().EndOfAttributeDataIB());
return aAttributeReportIBsBuilder.GetAttributeReport().EndOfAttributeReportIB();
}

namespace {
Expand Down
5 changes: 2 additions & 3 deletions src/app/ClusterStateCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,8 @@ CHIP_ERROR ClusterStateCache::OnUpdateDataVersionFilterList(DataVersionFilterIBs
SuccessOrExit(err = aDataVersionFilterIBsBuilder.GetError());
ClusterPathIB::Builder & filterPath = filterIB.CreatePath();
SuccessOrExit(err = filterIB.GetError());
SuccessOrExit(
err = filterPath.Endpoint(filter.first.mEndpointId).Cluster(filter.first.mClusterId).EndOfClusterPathIB().GetError());
SuccessOrExit(err = filterIB.DataVersion(filter.first.mDataVersion.Value()).EndOfDataVersionFilterIB().GetError());
SuccessOrExit(err = filterPath.Endpoint(filter.first.mEndpointId).Cluster(filter.first.mClusterId).EndOfClusterPathIB());
SuccessOrExit(err = filterIB.DataVersion(filter.first.mDataVersion.Value()).EndOfDataVersionFilterIB());
ChipLogProgress(DataManagement, "Update DataVersionFilter: Endpoint=%u Cluster=" ChipLogFormatMEI " Version=%" PRIu32,
filter.first.mEndpointId, ChipLogValueMEI(filter.first.mClusterId), filter.first.mDataVersion.Value());

Expand Down
17 changes: 8 additions & 9 deletions src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,10 @@ CHIP_ERROR CommandHandler::FinishCommand(bool aStartDataStruct)
{
ReturnErrorOnFailure(commandData.GetWriter()->EndContainer(mDataElementContainerType));
}
ReturnErrorOnFailure(commandData.EndOfCommandDataIB().GetError());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().EndOfInvokeResponseIB().GetError());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().EndOfInvokeResponses().GetError());
ReturnErrorOnFailure(mInvokeResponseBuilder.EndOfInvokeResponseMessage().GetError());
ReturnErrorOnFailure(commandData.EndOfCommandDataIB());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().EndOfInvokeResponseIB());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().EndOfInvokeResponses());
ReturnErrorOnFailure(mInvokeResponseBuilder.EndOfInvokeResponseMessage());
MoveToState(State::AddedCommand);
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -547,11 +547,10 @@ CHIP_ERROR CommandHandler::PrepareStatus(const ConcreteCommandPath & aCommandPat
CHIP_ERROR CommandHandler::FinishStatus()
{
VerifyOrReturnError(mState == State::AddingCommand, CHIP_ERROR_INCORRECT_STATE);
ReturnErrorOnFailure(
mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetStatus().EndOfCommandStatusIB().GetError());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().EndOfInvokeResponseIB().GetError());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().EndOfInvokeResponses().GetError());
ReturnErrorOnFailure(mInvokeResponseBuilder.EndOfInvokeResponseMessage().GetError());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetStatus().EndOfCommandStatusIB());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().EndOfInvokeResponseIB());
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().EndOfInvokeResponses());
ReturnErrorOnFailure(mInvokeResponseBuilder.EndOfInvokeResponseMessage());
MoveToState(State::AddedCommand);
return CHIP_NO_ERROR;
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ CHIP_ERROR CommandSender::FinishCommand(bool aEndDataStruct)
ReturnErrorOnFailure(commandData.GetWriter()->EndContainer(mDataElementContainerType));
}

ReturnErrorOnFailure(commandData.EndOfCommandDataIB().GetError());
ReturnErrorOnFailure(mInvokeRequestBuilder.GetInvokeRequests().EndOfInvokeRequests().GetError());
ReturnErrorOnFailure(mInvokeRequestBuilder.EndOfInvokeRequestMessage().GetError());
ReturnErrorOnFailure(commandData.EndOfCommandDataIB());
ReturnErrorOnFailure(mInvokeRequestBuilder.GetInvokeRequests().EndOfInvokeRequests());
ReturnErrorOnFailure(mInvokeRequestBuilder.EndOfInvokeRequestMessage());

MoveToState(State::AddedCommand);

Expand Down
16 changes: 7 additions & 9 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even
EventPathIB::Builder & eventPathBuilder = eventDataIBBuilder.CreatePath();
ReturnErrorOnFailure(eventDataIBBuilder.GetError());

eventPathBuilder.Endpoint(apOptions->mPath.mEndpointId)
.Cluster(apOptions->mPath.mClusterId)
.Event(apOptions->mPath.mEventId)
.EndOfEventPathIB();
ReturnErrorOnFailure(eventPathBuilder.GetError());
CHIP_ERROR err = eventPathBuilder.Endpoint(apOptions->mPath.mEndpointId)
.Cluster(apOptions->mPath.mClusterId)
.Event(apOptions->mPath.mEventId)
.EndOfEventPathIB();
ReturnErrorOnFailure(err);
eventDataIBBuilder.EventNumber(apContext->mCurrentEventNumber).Priority(chip::to_underlying(apContext->mPriority));
ReturnErrorOnFailure(eventDataIBBuilder.GetError());

Expand All @@ -330,10 +330,8 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even
{
apContext->mWriter.Put(TLV::ProfileTag(kEventManagementProfile, kFabricIndexTag), apOptions->mFabricIndex);
}
eventDataIBBuilder.EndOfEventDataIB();
ReturnErrorOnFailure(eventDataIBBuilder.GetError());
eventReportBuilder.EndOfEventReportIB();
ReturnErrorOnFailure(eventReportBuilder.GetError());
ReturnErrorOnFailure(eventDataIBBuilder.EndOfEventDataIB());
ReturnErrorOnFailure(eventReportBuilder.EndOfEventReportIB());
ReturnErrorOnFailure(apContext->mWriter.Finalize());
apContext->mFirst = false;
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ AttributeDataIB::Builder & AttributeDataIB::Builder::DataVersion(const chip::Dat
return *this;
}

AttributeDataIB::Builder & AttributeDataIB::Builder::EndOfAttributeDataIB()
CHIP_ERROR AttributeDataIB::Builder::EndOfAttributeDataIB()
{
EndOfContainer();
return *this;
return GetError();
}
} // namespace app
} // namespace chip
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeDataIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class Builder : public StructBuilder
/**
* @brief Mark the end of this AttributeDataIB
*
* @return A reference to *this
* @return Our The builder's final status.
*/
AttributeDataIB::Builder & EndOfAttributeDataIB();
CHIP_ERROR EndOfAttributeDataIB();

private:
AttributePathIB::Builder mPath;
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeDataIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ AttributeDataIB::Builder & AttributeDataIBs::Builder::GetAttributeDataIBBuilder(
return mAttributeDataIBBuilder;
}

AttributeDataIBs::Builder & AttributeDataIBs::Builder::EndOfAttributeDataIBs()
CHIP_ERROR AttributeDataIBs::Builder::EndOfAttributeDataIBs()
{
EndOfContainer();

return *this;
return GetError();
}

}; // namespace app
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeDataIBs.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Builder : public ArrayBuilder
/**
* @brief Mark the end of this AttributeDataIBs
*
* @return A reference to *this
* @return The builder's final status.
*/
AttributeDataIBs::Builder & EndOfAttributeDataIBs();
CHIP_ERROR EndOfAttributeDataIBs();

private:
AttributeDataIB::Builder mAttributeDataIBBuilder;
Expand Down
10 changes: 4 additions & 6 deletions src/app/MessageDef/AttributePathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ AttributePathIB::Builder & AttributePathIB::Builder::ListIndex(const chip::ListI
return *this;
}

AttributePathIB::Builder & AttributePathIB::Builder::EndOfAttributePathIB()
CHIP_ERROR AttributePathIB::Builder::EndOfAttributePathIB()
{
EndOfContainer();
return *this;
return GetError();
}

CHIP_ERROR AttributePathIB::Builder::Encode(const AttributePathParams & aAttributePathParams)
Expand All @@ -364,8 +364,7 @@ CHIP_ERROR AttributePathIB::Builder::Encode(const AttributePathParams & aAttribu
ListIndex(aAttributePathParams.mListIndex);
}

EndOfAttributePathIB();
return GetError();
return EndOfAttributePathIB();
}

CHIP_ERROR AttributePathIB::Builder::Encode(const ConcreteDataAttributePath & aAttributePath)
Expand All @@ -388,8 +387,7 @@ CHIP_ERROR AttributePathIB::Builder::Encode(const ConcreteDataAttributePath & aA
return CHIP_ERROR_INVALID_ARGUMENT;
}

EndOfAttributePathIB();
return GetError();
return EndOfAttributePathIB();
}

} // namespace app
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributePathIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ class Builder : public ListBuilder
/**
* @brief Mark the end of this AttributePathIB
*
* @return A reference to *this
* @return The builder's final status.
*/
AttributePathIB::Builder & EndOfAttributePathIB();
CHIP_ERROR EndOfAttributePathIB();

CHIP_ERROR Encode(const AttributePathParams & aAttributePathParams);
CHIP_ERROR Encode(const ConcreteDataAttributePath & aAttributePathParams);
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributePathIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ AttributePathIB::Builder & AttributePathIBs::Builder::CreatePath()
}

// Mark the end of this array and recover the type for outer container
AttributePathIBs::Builder & AttributePathIBs::Builder::EndOfAttributePathIBs()
CHIP_ERROR AttributePathIBs::Builder::EndOfAttributePathIBs()
{
EndOfContainer();
return *this;
return GetError();
}
} // namespace app
} // namespace chip
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributePathIBs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class Builder : public ArrayBuilder
/**
* @brief Mark the end of this AttributePathIB
*
* @return A reference to *this
* @return The builder's final status.
*/
AttributePathIBs::Builder & EndOfAttributePathIBs();
CHIP_ERROR EndOfAttributePathIBs();

private:
AttributePathIB::Builder mAttributePath;
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeReportIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ AttributeDataIB::Builder & AttributeReportIB::Builder::CreateAttributeData()
return mAttributeData;
}

AttributeReportIB::Builder & AttributeReportIB::Builder::EndOfAttributeReportIB()
CHIP_ERROR AttributeReportIB::Builder::EndOfAttributeReportIB()
{
EndOfContainer();
return *this;
return GetError();
}
} // namespace app
} // namespace chip
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeReportIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class Builder : public StructBuilder
/**
* @brief Mark the end of this AttributeReportIB
*
* @return A reference to *this
* @return The builder's final status.
*/
AttributeReportIB::Builder & EndOfAttributeReportIB();
CHIP_ERROR EndOfAttributeReportIB();

private:
AttributeStatusIB::Builder mAttributeStatus;
Expand Down
8 changes: 4 additions & 4 deletions src/app/MessageDef/AttributeReportIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ AttributeReportIB::Builder & AttributeReportIBs::Builder::CreateAttributeReport(
return mAttributeReport;
}

AttributeReportIBs::Builder & AttributeReportIBs::Builder::EndOfAttributeReportIBs()
CHIP_ERROR AttributeReportIBs::Builder::EndOfAttributeReportIBs()
{
EndOfContainer();
return *this;
return GetError();
}

CHIP_ERROR AttributeReportIBs::Builder::EncodeAttributeStatus(const ConcreteReadAttributePath & aPath, const StatusIB & aStatus)
Expand All @@ -103,8 +103,8 @@ CHIP_ERROR AttributeReportIBs::Builder::EncodeAttributeStatus(const ConcreteRead
statusIBBuilder.EncodeStatusIB(aStatus);
ReturnErrorOnFailure(statusIBBuilder.GetError());

ReturnErrorOnFailure(attributeStatusIBBuilder.EndOfAttributeStatusIB().GetError());
return attributeReport.EndOfAttributeReportIB().GetError();
ReturnErrorOnFailure(attributeStatusIBBuilder.EndOfAttributeStatusIB());
return attributeReport.EndOfAttributeReportIB();
}

} // namespace app
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeReportIBs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Builder : public ArrayBuilder
/**
* @brief Mark the end of this AttributeReportIBs
*
* @return A reference to *this
* @return The builder's final status.
*/
AttributeReportIBs::Builder & EndOfAttributeReportIBs();
CHIP_ERROR EndOfAttributeReportIBs();

/**
* Encode an AttributeReportIB containing an AttributeStatus.
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeStatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ StatusIB::Builder & AttributeStatusIB::Builder::CreateErrorStatus()
return mErrorStatus;
}

AttributeStatusIB::Builder & AttributeStatusIB::Builder::EndOfAttributeStatusIB()
CHIP_ERROR AttributeStatusIB::Builder::EndOfAttributeStatusIB()
{
EndOfContainer();
return *this;
return GetError();
}
} // namespace app
} // namespace chip
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeStatusIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class Builder : public StructBuilder
/**
* @brief Mark the end of this AttributeStatusIB
*
* @return A reference to *this
* @return The builder's final status.
*/
AttributeStatusIB::Builder & EndOfAttributeStatusIB();
CHIP_ERROR EndOfAttributeStatusIB();

private:
AttributePathIB::Builder mPath;
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeStatusIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ AttributeStatusIB::Builder & AttributeStatusIBs::Builder::CreateAttributeStatus(
return mAttributeStatus;
}

AttributeStatusIBs::Builder & AttributeStatusIBs::Builder::EndOfAttributeStatuses()
CHIP_ERROR AttributeStatusIBs::Builder::EndOfAttributeStatuses()
{
EndOfContainer();
return *this;
return GetError();
}

#if CHIP_CONFIG_IM_PRETTY_PRINT
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeStatusIBs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class Builder : public ArrayBuilder
/**
* @brief Mark the end of this AttributeStatusIBs
*
* @return A reference to *this
* @return The builder's final status.
*/
AttributeStatusIBs::Builder & EndOfAttributeStatuses();
CHIP_ERROR EndOfAttributeStatuses();

private:
AttributeStatusIB::Builder mAttributeStatus;
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/ClusterPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ ClusterPathIB::Builder & ClusterPathIB::Builder::Cluster(const ClusterId aCluste
return *this;
}

ClusterPathIB::Builder & ClusterPathIB::Builder::EndOfClusterPathIB()
CHIP_ERROR ClusterPathIB::Builder::EndOfClusterPathIB()
{
EndOfContainer();
return *this;
return GetError();
}
} // namespace app
} // namespace chip
4 changes: 2 additions & 2 deletions src/app/MessageDef/ClusterPathIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class Builder : public ListBuilder
/**
* @brief Mark the end of this ClusterPathIB
*
* @return A reference to *this
* @return The builder's final status.
*/
ClusterPathIB::Builder & EndOfClusterPathIB();
CHIP_ERROR EndOfClusterPathIB();
};
} // namespace ClusterPathIB
} // namespace app
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/CommandDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ CommandPathIB::Builder & CommandDataIB::Builder::CreatePath()
return mPath;
}

CommandDataIB::Builder & CommandDataIB::Builder::EndOfCommandDataIB()
CHIP_ERROR CommandDataIB::Builder::EndOfCommandDataIB()
{
EndOfContainer();
return *this;
return GetError();
}
} // namespace app
} // namespace chip
4 changes: 2 additions & 2 deletions src/app/MessageDef/CommandDataIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class Builder : public StructBuilder
/**
* @brief Mark the end of this CommandDataIB
*
* @return A reference to *this
* @return The builder's final status.
*/
CommandDataIB::Builder & EndOfCommandDataIB();
CHIP_ERROR EndOfCommandDataIB();

private:
CommandPathIB::Builder mPath;
Expand Down
Loading

0 comments on commit 9475052

Please sign in to comment.