Skip to content

Commit

Permalink
use DataVersion instead of optional<DataVersion>
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed Jan 31, 2022
1 parent 07462f0 commit 9f5be31
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 51 deletions.
4 changes: 2 additions & 2 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac
virtual void OnEventSubscription(){};

/////////// ReadClient Callback Interface /////////
void OnAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::Optional<chip::DataVersion> & aVersion,
chip::TLV::TLVReader * data, const chip::app::StatusIB & status) override
void OnAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::DataVersion aVersion, chip::TLV::TLVReader * data,
const chip::app::StatusIB & status) override
{
CHIP_ERROR error = status.ToChipError();
if (CHIP_NO_ERROR != error)
Expand Down
4 changes: 2 additions & 2 deletions src/app/AttributeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void AttributeCache::OnReportEnd()
mCallback.OnReportEnd();
}

void AttributeCache::OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion,
TLV::TLVReader * apData, const StatusIB & aStatus)
void AttributeCache::OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus)
{
//
// Since the cache itself is a ReadClient::Callback, it may be incorrectly passed in directly when registering with the
Expand Down
2 changes: 1 addition & 1 deletion src/app/AttributeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class AttributeCache : protected ReadClient::Callback
//
void OnReportBegin() override;
void OnReportEnd() override;
void OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion, TLV::TLVReader * apData,
void OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus) override;
void OnError(CHIP_ERROR aError) override { return mCallback.OnError(aError); }

Expand Down
5 changes: 2 additions & 3 deletions src/app/BufferedReadCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,11 @@ CHIP_ERROR BufferedReadCallback::DispatchBufferedData(const ConcreteAttributePat
//
mBufferedList.clear();
mBufferedPath = ConcreteDataAttributePath();
mDataVersion.ClearValue();
return CHIP_NO_ERROR;
}

void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion,
TLV::TLVReader * apData, const StatusIB & aStatus)
void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus)
{
CHIP_ERROR err;

Expand Down
4 changes: 2 additions & 2 deletions src/app/BufferedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BufferedReadCallback : public ReadClient::Callback
//
void OnReportBegin() override;
void OnReportEnd() override;
void OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion, TLV::TLVReader * apData,
void OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus) override;
void OnError(CHIP_ERROR aError) override { return mCallback.OnError(aError); }
void OnEventData(const EventHeader & aEventHeader, TLV::TLVReader * apData, const StatusIB * apStatus) override
Expand All @@ -89,7 +89,7 @@ class BufferedReadCallback : public ReadClient::Callback
*
*/
CHIP_ERROR BufferListItem(TLV::TLVReader & reader);
Optional<DataVersion> mDataVersion;
DataVersion mDataVersion;
ConcreteDataAttributePath mBufferedPath;
std::vector<System::PacketBufferHandle> mBufferedList;
Callback & mCallback;
Expand Down
20 changes: 5 additions & 15 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,33 +502,23 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo
TLV::TLVReader reader = aAttributeReportIBsReader;
ReturnErrorOnFailure(report.Init(reader));

Optional<DataVersion> dataVersion;
err = report.GetAttributeStatus(&status);
DataVersion version = 0;
err = report.GetAttributeStatus(&status);
if (CHIP_NO_ERROR == err)
{
StatusIB::Parser errorStatus;
ReturnErrorOnFailure(status.GetPath(&path));
ReturnErrorOnFailure(ProcessAttributePath(path, attributePath));
ReturnErrorOnFailure(status.GetErrorStatus(&errorStatus));
ReturnErrorOnFailure(errorStatus.DecodeStatusIB(statusIB));
mpCallback.OnAttributeData(attributePath, dataVersion, nullptr, statusIB);
mpCallback.OnAttributeData(attributePath, version, nullptr, statusIB);
}
else if (CHIP_END_OF_TLV == err)
{
ReturnErrorOnFailure(report.GetAttributeData(&data));
ReturnErrorOnFailure(data.GetPath(&path));
ReturnErrorOnFailure(ProcessAttributePath(path, attributePath));
DataVersion version = 0;
err = data.GetDataVersion(&version);
if (err == CHIP_NO_ERROR)
{
dataVersion.SetValue(version);
}
else if (err == CHIP_END_OF_TLV)
{
err = CHIP_NO_ERROR;
}
ReturnErrorOnFailure(err);
ReturnErrorOnFailure(data.GetDataVersion(&version));
ReturnErrorOnFailure(data.GetData(&dataReader));

// The element in an array may be another array -- so we should only set the list operation when we are handling the
Expand All @@ -538,7 +528,7 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo
attributePath.mListOp = ConcreteDataAttributePath::ListOperation::ReplaceAll;
}

mpCallback.OnAttributeData(attributePath, dataVersion, &dataReader, statusIB);
mpCallback.OnAttributeData(attributePath, version, &dataReader, statusIB);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ class ReadClient : public Messaging::ExchangeDelegate
* receives an OnDone call to destroy the object.
*
* @param[in] aPath The attribute path field in report response.
* @param[in] aVersion The data version for cluster in report response. The version could be omitted when
* EnableTagCompression in the Path field is true.
* @param[in] aVersion The data version for cluster in report response.
* @param[in] apData The attribute data of the given path, will be a nullptr if status is not Success.
* @param[in] aStatus Attribute-specific status, containing an InteractionModel::Status code as well as an
* optional cluster-specific status code.
*/
virtual void OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion,
TLV::TLVReader * apData, const StatusIB & aStatus)
virtual void OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus)
{}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestAttributeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void DataSeriesGenerator::Generate()
System::PacketBufferTLVReader reader;
ReadClient::Callback * callback = mReadCallback;
StatusIB status;
Optional<DataVersion> version;
DataVersion version = 0;
callback->OnReportBegin();

uint8_t index = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/app/tests/TestBufferedReadCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DataSeriesValidator : public BufferedReadCallback::Callback

void OnReportBegin() override;
void OnReportEnd() override;
void OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion, TLV::TLVReader * apData,
void OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus) override;
void OnDone() override {}

Expand All @@ -95,8 +95,8 @@ void DataSeriesValidator::OnReportBegin()

void DataSeriesValidator::OnReportEnd() {}

void DataSeriesValidator::OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion,
TLV::TLVReader * apData, const StatusIB & aStatus)
void DataSeriesValidator::OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus)
{
uint32_t expectedListLength;

Expand Down Expand Up @@ -302,7 +302,7 @@ void DataSeriesGenerator::Generate()
ReadClient::Callback * callback = &mReadCallback;
StatusIB status;
bool hasData;
Optional<DataVersion> version;
DataVersion version = 0;

callback->OnReportBegin();

Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class MockInteractionModelApp : public chip::app::ReadClient::Callback
mGotEventResponse = true;
}

void OnAttributeData(const chip::app::ConcreteDataAttributePath & aPath, chip::Optional<chip::DataVersion> & aVersion,
void OnAttributeData(const chip::app::ConcreteDataAttributePath & aPath, chip::DataVersion aVersion,
chip::TLV::TLVReader * apData, const chip::app::StatusIB & status) override
{
if (status.mStatus == chip::Protocols::InteractionModel::Status::Success)
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class MockInteractionModelApp : public chip::app::InteractionModelDelegate,
}
}
}
void OnAttributeData(const chip::app::ConcreteDataAttributePath & aPath, chip::Optional<chip::DataVersion> & aVersion,
void OnAttributeData(const chip::app::ConcreteDataAttributePath & aPath, chip::DataVersion aVersion,
chip::TLV::TLVReader * aData, const chip::app::StatusIB & status) override
{}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/TypedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class TypedReadAttributeCallback final : public app::ReadClient::Callback
void AdoptReadClient(Platform::UniquePtr<app::ReadClient> aReadClient) { mReadClient = std::move(aReadClient); }

private:
void OnAttributeData(const app::ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion, TLV::TLVReader * apData,
void OnAttributeData(const app::ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const app::StatusIB & aStatus) override
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
9 changes: 2 additions & 7 deletions src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ReadClientCallback : public ReadClient::Callback

app::BufferedReadCallback * GetBufferedReadCallback() { return &mBufferedReadCallback; }

void OnAttributeData(const ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion, TLV::TLVReader * apData,
void OnAttributeData(const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const StatusIB & aStatus) override
{
//
Expand All @@ -89,7 +89,6 @@ class ReadClientCallback : public ReadClient::Callback
size_t bufferLen = (apData == nullptr ? 0 : apData->GetRemainingLength() + apData->GetLengthRead());
std::unique_ptr<uint8_t[]> buffer = std::unique_ptr<uint8_t[]>(apData == nullptr ? nullptr : new uint8_t[bufferLen]);
uint32_t size = 0;
DataVersion version = 0;
// When the apData is nullptr, means we did not receive a valid attribute data from server, status will be some error
// status.
if (apData != nullptr)
Expand All @@ -106,13 +105,9 @@ class ReadClientCallback : public ReadClient::Callback
return;
}
size = writer.GetLengthWritten();
if (aVersion.HasValue())
{
version = aVersion.Value();
}
}

gOnReadAttributeDataCallback(mAppContext, version, aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId,
gOnReadAttributeDataCallback(mAppContext, aVersion, aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId,
to_underlying(aStatus.mStatus), buffer.get(), size);
}

Expand Down
6 changes: 3 additions & 3 deletions src/controller/tests/TestReadChunking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TestReadCallback : public app::ReadClient::Callback
{
public:
TestReadCallback() : mBufferedCallback(*this) {}
void OnAttributeData(const app::ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion, TLV::TLVReader * apData,
void OnAttributeData(const app::ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const app::StatusIB & aStatus) override;

void OnDone() override;
Expand All @@ -108,8 +108,8 @@ class TestReadCallback : public app::ReadClient::Callback
app::BufferedReadCallback mBufferedCallback;
};

void TestReadCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPath, Optional<DataVersion> & aVersion,
TLV::TLVReader * apData, const app::StatusIB & aStatus)
void TestReadCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData,
const app::StatusIB & aStatus)
{
if (aPath.mAttributeId != kTestListAttribute)
{
Expand Down
8 changes: 4 additions & 4 deletions src/darwin/Framework/CHIP/CHIPDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ - (instancetype)initWithDevice:(chip::DeviceProxy *)device

void OnReportEnd() override;

void OnAttributeData(const ConcreteDataAttributePath & aPath, chip::Optional<chip::DataVersion> & aVersion,
TLV::TLVReader * apData, const StatusIB & aStatus) override;
void OnAttributeData(
const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData, const StatusIB & aStatus) override;

void OnError(CHIP_ERROR aError) override;

Expand Down Expand Up @@ -214,8 +214,8 @@ - (instancetype)initWithPath:(const ConcreteDataAttributePath &)path value:(null
// Else we have a pending error already.
}

void SubscriptionCallback::OnAttributeData(const ConcreteDataAttributePath & aPath, chip::Optional<chip::DataVersion> & aVersion,
TLV::TLVReader * apData, const StatusIB & aStatus)
void SubscriptionCallback::OnAttributeData(
const ConcreteDataAttributePath & aPath, DataVersion aVersion, TLV::TLVReader * apData, const StatusIB & aStatus)
{
if (aPath.IsListItemOperation()) {
ReportError(CHIP_ERROR_INCORRECT_STATE);
Expand Down

0 comments on commit 9f5be31

Please sign in to comment.