From 8dda88a26dc31431ae19d0810a4defd6109e5d32 Mon Sep 17 00:00:00 2001 From: Yunhan Wang Date: Tue, 16 Nov 2021 13:55:34 -0800 Subject: [PATCH] address comments --- src/app/EventLoggingTypes.h | 10 ++++------ src/app/EventManagement.cpp | 1 - src/app/MessageDef/EventDataIB.cpp | 4 +++- src/app/ReadClient.h | 8 +++++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/app/EventLoggingTypes.h b/src/app/EventLoggingTypes.h index 3871fb70402f5d..d852e015d5f760 100644 --- a/src/app/EventLoggingTypes.h +++ b/src/app/EventLoggingTypes.h @@ -110,8 +110,7 @@ struct Timestamp { enum class Type { - kInvalid = 0, - kSystem, + kSystem = 0, kEpoch }; Timestamp() {} @@ -129,11 +128,10 @@ struct Timestamp return timestamp; } - bool IsValid() { return mType != Type::kInvalid; } bool IsSystem() { return mType == Type::kSystem; } bool IsEpoch() { return mType == Type::kEpoch; } - Type mType = Type::kInvalid; + Type mType = Type::kSystem; uint64_t mValue = 0; }; @@ -148,9 +146,9 @@ class EventOptions kUrgent = 0, kNotUrgent, }; - EventOptions(void) : mTimestamp(Timestamp::Type::kInvalid), mpEventSchema(nullptr), mUrgent(Type::kNotUrgent) {} + EventOptions(void) : mTimestamp(Timestamp::Type::kSystem), mpEventSchema(nullptr), mUrgent(Type::kNotUrgent) {} - EventOptions(Type aType) : mTimestamp(Timestamp::Type::kInvalid), mpEventSchema(nullptr), mUrgent(aType) {} + EventOptions(Type aType) : mTimestamp(Timestamp::Type::kSystem), mpEventSchema(nullptr), mUrgent(aType) {} EventOptions(Timestamp aTimestamp) : mTimestamp(aTimestamp), mpEventSchema(nullptr), mUrgent(Type::kNotUrgent) {} diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp index 6ca331deefd2a1..a66bc37b01d31d 100644 --- a/src/app/EventManagement.cpp +++ b/src/app/EventManagement.cpp @@ -310,7 +310,6 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even /* no-op: don't write event, but advance current event Number */); VerifyOrExit(apOptions != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(apOptions->mTimestamp.mType != Timestamp::Type::kInvalid, err = CHIP_ERROR_INVALID_ARGUMENT); eventReportBuilder.Init(&(apContext->mWriter)); // TODO: Update IsUrgent, issue 11386 diff --git a/src/app/MessageDef/EventDataIB.cpp b/src/app/MessageDef/EventDataIB.cpp index acad4eebf92191..9d7931450865d9 100644 --- a/src/app/MessageDef/EventDataIB.cpp +++ b/src/app/MessageDef/EventDataIB.cpp @@ -404,7 +404,8 @@ CHIP_ERROR EventDataIB::Parser::ProcessEventTimestamp(EventHeader & aEventHeader bool hasEpochTimestamp = false; bool hasDeltaSystemTimestamp = false; bool hasDeltaEpochTimestamp = false; - err = GetDeltaSystemTimestamp(&timeStampVal); + + err = GetDeltaSystemTimestamp(&timeStampVal); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; @@ -424,6 +425,7 @@ CHIP_ERROR EventDataIB::Parser::ProcessEventTimestamp(EventHeader & aEventHeader } else if (err == CHIP_NO_ERROR) { + VerifyOrReturnError(aEventHeader.mTimestamp.IsEpoch(), CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT); aEventHeader.mTimestamp.mValue += timeStampVal; hasDeltaEpochTimestamp = true; } diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index 86ff3f1c414803..210feb87e9e855 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -68,7 +68,8 @@ class ReadClient : public Messaging::ExchangeDelegate * * @param[in] apReadClient: The read client object that initiated the read or subscribe transaction. * @param[in] aEventHeader: The event header in report response. - * @param[in] apData: The event data of the given path, will be a nullptr if status is not Success. + * @param[in] apData: A TLVReader positioned right on the payload of the event. This will be set to null if the apStatus is + * not null. * @param[in] apStatus: Event-specific status, containing an InteractionModel::Status code as well as an optional * cluster-specific status code. */ @@ -269,12 +270,13 @@ class ReadClient : public Messaging::ExchangeDelegate * @param [in] aEvent The event data. */ template - CHIP_ERROR CheckEventHeaderWithClusterObject(const EventHeader & aEventHeader, const EventDataT & aEvent) + CHIP_ERROR CheckEventHeaderWithClusterObject(const EventHeader & aEventHeader, const EventDataT & aEvent, + TLV::TLVReader & aReader) { VerifyOrReturnError((aEventHeader.mPath.mEventId == aEvent.GetEventId()) && (aEventHeader.mPath.mClusterId == aEvent.GetClusterId()), CHIP_ERROR_INVALID_ARGUMENT); - return CHIP_NO_ERROR; + return DataModel::Decode(aReader, aEvent); } /**