diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index d4cda3aaba227f..35ad1b6a57247c 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -62,16 +62,18 @@ static_library("app") { "MessageDef/CommandDataIB.cpp", "MessageDef/CommandPathIB.cpp", "MessageDef/CommandStatusIB.cpp", - "MessageDef/EventDataElement.cpp", - "MessageDef/EventDataElement.h", + "MessageDef/EventDataIB.cpp", + "MessageDef/EventDataIB.h", "MessageDef/EventFilterIB.cpp", "MessageDef/EventFilters.cpp", - "MessageDef/EventList.cpp", - "MessageDef/EventList.h", "MessageDef/EventPathIB.cpp", "MessageDef/EventPathIB.h", "MessageDef/EventPaths.cpp", "MessageDef/EventPaths.h", + "MessageDef/EventReportIB.cpp", + "MessageDef/EventReportIB.h", + "MessageDef/EventReports.cpp", + "MessageDef/EventReports.h", "MessageDef/EventStatusIB.cpp", "MessageDef/EventStatusIB.h", "MessageDef/InvokeRequestMessage.cpp", diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp index 5fa2eaeb1db386..201a1ac2398e21 100644 --- a/src/app/EventManagement.cpp +++ b/src/app/EventManagement.cpp @@ -85,7 +85,7 @@ struct EventEnvelopeContext { EventEnvelopeContext() {} - uint16_t mFieldsToRead = 0; + int mFieldsToRead = 0; /* PriorityLevel and DeltaSystemTimestamp are there if that is not first event when putting events in report*/ Timestamp mDeltaSystemTime = Timestamp::System(System::Clock::kZero); Timestamp mDeltaUtc = Timestamp::UTC(0); @@ -173,8 +173,7 @@ CHIP_ERROR EventManagement::CopyToNextBuffer(CircularEventBuffer * apEventBuffer err = writer.Finalize(); SuccessOrExit(err); - ChipLogProgress(EventLogging, "Copy Event to next buffer with priority %u", - static_cast(nextBuffer->GetPriorityLevel())); + ChipLogProgress(EventLogging, "Copy Event to next buffer with priority %u", static_cast(nextBuffer->GetPriority())); exit: if (err != CHIP_NO_ERROR) { @@ -302,8 +301,12 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even CHIP_ERROR err = CHIP_NO_ERROR; TLVWriter checkpoint = apContext->mWriter; TLV::TLVType dataContainerType; - EventDataElement::Builder eventDataElementBuilder; + EventReportIB::Builder eventReportBuilder; + EventDataIB::Builder eventDataIBBuilder; EventPathIB::Builder eventPathBuilder; + EventStatusIB::Builder eventStatusIBBuilder; + StatusIB::Builder statusIBBuilder; + StatusIB status; uint64_t deltatime = 0; VerifyOrExit(apContext->mCurrentEventNumber >= apContext->mStartingEventNumber, @@ -312,9 +315,32 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even VerifyOrExit(apOptions != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(apOptions->mTimestamp.mType != Timestamp::Type::kInvalid, err = CHIP_ERROR_INVALID_ARGUMENT); - eventDataElementBuilder.Init(&(apContext->mWriter)); - eventPathBuilder = eventDataElementBuilder.CreateEventPath(); - err = eventPathBuilder.GetError(); + eventReportBuilder.Init(&(apContext->mWriter)); + // TODO: Update IsUrgent, issue 11386 + // TODO: Update statusIB, issue 11388 + eventStatusIBBuilder = eventReportBuilder.CreateEventStatus(); + eventPathBuilder = eventStatusIBBuilder.CreatePath(); + err = eventStatusIBBuilder.GetError(); + SuccessOrExit(err); + eventPathBuilder.Node(apOptions->mpEventSchema->mNodeId) + .Endpoint(apOptions->mpEventSchema->mEndpointId) + .Cluster(apOptions->mpEventSchema->mClusterId) + .Event(apOptions->mpEventSchema->mEventId) + .IsUrgent(false) + .EndOfEventPathIB(); + err = eventPathBuilder.GetError(); + SuccessOrExit(err); + statusIBBuilder = eventStatusIBBuilder.CreateErrorStatus(); + err = eventStatusIBBuilder.GetError(); + SuccessOrExit(err); + statusIBBuilder.EncodeStatusIB(status); + eventStatusIBBuilder.EndOfEventStatusIB(); + err = statusIBBuilder.GetError(); + SuccessOrExit(err); + + eventDataIBBuilder = eventReportBuilder.CreateEventData(); + eventPathBuilder = eventDataIBBuilder.CreatePath(); + err = eventDataIBBuilder.GetError(); SuccessOrExit(err); // TODO: Revisit NodeId since the the encoding spec and the IM seem to disagree on how this stuff works @@ -327,15 +353,16 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even err = eventPathBuilder.GetError(); SuccessOrExit(err); - eventDataElementBuilder.PriorityLevel(static_cast(apContext->mPriority)); + eventDataIBBuilder.Priority(chip::to_underlying(apContext->mPriority)); // TODO: need to add utc and systen system check here deltatime = apOptions->mTimestamp.mValue - apContext->mCurrentSystemTime.mValue; - eventDataElementBuilder.DeltaSystemTimestamp(deltatime); - err = eventDataElementBuilder.GetError(); + eventDataIBBuilder.DeltaSystemTimestamp(deltatime); + err = eventDataIBBuilder.GetError(); SuccessOrExit(err); - err = apContext->mWriter.StartContainer(ContextTag(EventDataElement::kCsTag_Data), TLV::kTLVType_Structure, dataContainerType); + err = apContext->mWriter.StartContainer(ContextTag(chip::to_underlying(EventDataIB::Tag::kData)), TLV::kTLVType_Structure, + dataContainerType); SuccessOrExit(err); // Callback to write the EventData err = apDelegate->WriteEvent(apContext->mWriter); @@ -344,8 +371,10 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even err = apContext->mWriter.EndContainer(dataContainerType); SuccessOrExit(err); - eventDataElementBuilder.EndOfEventDataElement(); - SuccessOrExit(err = eventDataElementBuilder.GetError()); + eventDataIBBuilder.EndOfEventDataIB(); + SuccessOrExit(err = eventDataIBBuilder.GetError()); + eventReportBuilder.EndOfEventReportIB(); + SuccessOrExit(err = eventReportBuilder.GetError()); err = apContext->mWriter.Finalize(); SuccessOrExit(err); @@ -438,16 +467,16 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si TLVReader reader(aReader); // TODO: Add UTC timestamp support - if (aReader.GetTag() == TLV::ContextTag(EventDataElement::kCsTag_DeltaSystemTimestamp)) + if (aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp))) { if (ctx->mpContext->mFirst) // First event gets a timestamp, subsequent ones get a delta T { - err = ctx->mpWriter->Put(TLV::ContextTag(EventDataElement::kCsTag_SystemTimestamp), + err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp)), ctx->mpContext->mCurrentSystemTime.mValue); } else { - err = ctx->mpWriter->Put(TLV::ContextTag(EventDataElement::kCsTag_DeltaSystemTimestamp), + err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)), ctx->mpContext->mCurrentSystemTime.mValue - ctx->mpContext->mPreviousSystemTime.mValue); } } @@ -458,11 +487,12 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si // First event in the sequence gets a event number neatly packaged // right after the priority to keep tags ordered - if (aReader.GetTag() == TLV::ContextTag(EventDataElement::kCsTag_PriorityLevel)) + if (aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kPriority))) { if (ctx->mpContext->mFirst) { - err = ctx->mpWriter->Put(TLV::ContextTag(EventDataElement::kCsTag_Number), ctx->mpContext->mCurrentEventNumber); + err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kEventNumber)), + ctx->mpContext->mCurrentEventNumber); } } @@ -583,31 +613,45 @@ CHIP_ERROR EventManagement::CopyEvent(const TLVReader & aReader, TLVWriter & aWr { TLVReader reader; TLVType containerType; + TLVType containerType1; CopyAndAdjustDeltaTimeContext context(&aWriter, apContext); CHIP_ERROR err = CHIP_NO_ERROR; reader.Init(aReader); - err = reader.EnterContainer(containerType); - SuccessOrExit(err); - - err = aWriter.StartContainer(AnonymousTag, kTLVType_Structure, containerType); - SuccessOrExit(err); + ReturnErrorOnFailure(reader.EnterContainer(containerType)); + ReturnErrorOnFailure(aWriter.StartContainer(AnonymousTag, kTLVType_Structure, containerType)); + + ReturnErrorOnFailure(reader.Next()); + ReturnErrorOnFailure(reader.EnterContainer(containerType1)); + ReturnErrorOnFailure(aWriter.StartContainer(TLV::ContextTag(to_underlying(EventReportIB::Tag::kEventStatus)), + kTLVType_Structure, containerType1)); + ReturnErrorOnFailure(reader.Next()); + do + { + ReturnErrorOnFailure(aWriter.CopyElement(reader)); + } while (CHIP_NO_ERROR == (err = reader.Next())); + if (err == CHIP_END_OF_TLV) + { + err = CHIP_NO_ERROR; + } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(containerType1)); + ReturnErrorOnFailure(aWriter.EndContainer(containerType1)); + ReturnErrorOnFailure(reader.Next()); + ReturnErrorOnFailure(reader.EnterContainer(containerType1)); + ReturnErrorOnFailure( + aWriter.StartContainer(TLV::ContextTag(to_underlying(EventReportIB::Tag::kEventData)), kTLVType_Structure, containerType1)); err = TLV::Utilities::Iterate(reader, CopyAndAdjustDeltaTime, &context, false /*recurse*/); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; } - SuccessOrExit(err); - - err = aWriter.EndContainer(containerType); - SuccessOrExit(err); - - err = aWriter.Finalize(); - SuccessOrExit(err); - -exit: - return err; + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(aWriter.EndContainer(containerType1)); + ReturnErrorOnFailure(aWriter.EndContainer(containerType)); + ReturnErrorOnFailure(aWriter.Finalize()); + return CHIP_NO_ERROR; } static bool IsInterestedEventPaths(EventLoadOutContext * eventLoadOutContext, const EventEnvelopeContext & event) @@ -634,11 +678,15 @@ CHIP_ERROR EventManagement::EventIterator(const TLVReader & aReader, size_t aDep CHIP_ERROR err = CHIP_NO_ERROR; TLVReader innerReader; TLVType tlvType; + TLVType tlvType1; EventEnvelopeContext event; innerReader.Init(aReader); ReturnErrorOnFailure(innerReader.EnterContainer(tlvType)); - + ReturnErrorOnFailure(innerReader.Next()); + // Skip EventStatus Element + ReturnErrorOnFailure(innerReader.Next()); + ReturnErrorOnFailure(innerReader.EnterContainer(tlvType1)); err = TLV::Utilities::Iterate(innerReader, FetchEventParameters, &event, false /*recurse*/); if (event.mFieldsToRead != kRequiredEventField) { @@ -659,7 +707,6 @@ CHIP_ERROR EventManagement::EventIterator(const TLVReader & aReader, size_t aDep return CHIP_EVENT_ID_FOUND; } } - return CHIP_NO_ERROR; } @@ -750,7 +797,7 @@ CHIP_ERROR EventManagement::FetchEventParameters(const TLVReader & aReader, size TLVReader reader; reader.Init(aReader); - if (reader.GetTag() == TLV::ContextTag(EventDataElement::kCsTag_EventPath)) + if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kPath))) { EventPathIB::Parser path; ReturnErrorOnFailure(path.Init(aReader)); @@ -758,22 +805,22 @@ CHIP_ERROR EventManagement::FetchEventParameters(const TLVReader & aReader, size ReturnErrorOnFailure(path.GetEndpoint(&(envelope->mEndpointId))); ReturnErrorOnFailure(path.GetCluster(&(envelope->mClusterId))); ReturnErrorOnFailure(path.GetEvent(&(envelope->mEventId))); - envelope->mFieldsToRead |= 1 << EventDataElement::kCsTag_EventPath; + envelope->mFieldsToRead |= 1 << to_underlying(EventDataIB::Tag::kPath); } - if (reader.GetTag() == TLV::ContextTag(EventDataElement::kCsTag_PriorityLevel)) + if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kPriority))) { uint16_t extPriority; // Note: the type here matches the type case in EventManagement::LogEvent, priority section ReturnErrorOnFailure(reader.Get(extPriority)); envelope->mPriority = static_cast(extPriority); - envelope->mFieldsToRead |= 1 << EventDataElement::kCsTag_PriorityLevel; + envelope->mFieldsToRead |= 1 << to_underlying(EventDataIB::Tag::kPriority); } - if (reader.GetTag() == TLV::ContextTag(EventDataElement::kCsTag_DeltaSystemTimestamp)) + if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp))) { ReturnErrorOnFailure(reader.Get(envelope->mDeltaSystemTime.mValue)); - envelope->mFieldsToRead |= 1 << EventDataElement::kCsTag_DeltaSystemTimestamp; + envelope->mFieldsToRead |= 1 << to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp); } return CHIP_NO_ERROR; @@ -785,8 +832,12 @@ CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void * ReturnErrorOnFailure(aReader.Next()); TLVType containerType; + TLVType containerType1; ReturnErrorOnFailure(aReader.EnterContainer(containerType)); - + ReturnErrorOnFailure(aReader.Next()); + // Skip EventStatus + ReturnErrorOnFailure(aReader.Next()); + ReturnErrorOnFailure(aReader.EnterContainer(containerType1)); EventEnvelopeContext context; constexpr bool recurse = false; CHIP_ERROR err = TLV::Utilities::Iterate(aReader, FetchEventParameters, &context, recurse); @@ -796,8 +847,8 @@ CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void * } ReturnErrorOnFailure(err); + ReturnErrorOnFailure(aReader.ExitContainer(containerType1)); ReturnErrorOnFailure(aReader.ExitContainer(containerType)); - const PriorityLevel imp = static_cast(context.mPriority); ReclaimEventCtx * const ctx = static_cast(apAppData); @@ -812,7 +863,7 @@ CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void * EventLogging, "Dropped events from buffer with priority %u due to overflow: { event priority_level: %u, count: 0x" ChipLogFormatX64 " };", - static_cast(eventBuffer->GetPriorityLevel()), static_cast(imp), ChipLogValueX64(numEventsToDrop)); + static_cast(eventBuffer->GetPriority()), static_cast(imp), ChipLogValueX64(numEventsToDrop)); ctx->mSpaceNeededForMovedEvent = 0; return CHIP_NO_ERROR; } @@ -838,9 +889,9 @@ void EventManagement::SetScheduledEventEndpoint(EventNumber * apEventEndpoints) while (eventBuffer != nullptr) { - if (eventBuffer->GetPriorityLevel() >= PriorityLevel::First && (eventBuffer->GetPriorityLevel() <= PriorityLevel::Last)) + if (eventBuffer->GetPriority() >= PriorityLevel::First && (eventBuffer->GetPriority() <= PriorityLevel::Last)) { - apEventEndpoints[static_cast(eventBuffer->GetPriorityLevel())] = eventBuffer->GetLastEventNumber(); + apEventEndpoints[static_cast(eventBuffer->GetPriority())] = eventBuffer->GetLastEventNumber(); } eventBuffer = eventBuffer->GetNextCircularEventBuffer(); } diff --git a/src/app/EventManagement.h b/src/app/EventManagement.h index c2cb9c0c17fce2..cc695130c3c9d8 100644 --- a/src/app/EventManagement.h +++ b/src/app/EventManagement.h @@ -29,7 +29,7 @@ #include "EventLoggingDelegate.h" #include "EventLoggingTypes.h" #include -#include +#include #include #include #include @@ -41,8 +41,8 @@ namespace chip { namespace app { constexpr size_t kMaxEventSizeReserve = 512; -constexpr uint16_t kRequiredEventField = (1 << EventDataElement::kCsTag_PriorityLevel) | - (1 << EventDataElement::kCsTag_DeltaSystemTimestamp) | (1 << EventDataElement::kCsTag_EventPath); +constexpr uint16_t kRequiredEventField = (1 << to_underlying(EventDataIB::Tag::kPriority)) | + (1 << to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)) | (1 << to_underlying(EventDataIB::Tag::kPath)); /** * @brief @@ -126,7 +126,7 @@ class CircularEventBuffer : public TLV::CHIPCircularTLVBuffer mFirstEventNumber = mpEventNumberCounter->GetValue(); } - PriorityLevel GetPriorityLevel() { return mPriority; } + PriorityLevel GetPriority() { return mPriority; } CircularEventBuffer * GetPreviousCircularEventBuffer() { return mpPrev; } CircularEventBuffer * GetNextCircularEventBuffer() { return mpNext; } diff --git a/src/app/MessageDef/AttributeStatusList.cpp b/src/app/MessageDef/AttributeStatusList.cpp index 34873704c6a04d..e9d231edaa42d7 100644 --- a/src/app/MessageDef/AttributeStatusList.cpp +++ b/src/app/MessageDef/AttributeStatusList.cpp @@ -64,7 +64,7 @@ CHIP_ERROR AttributeStatusList::Parser::CheckSchemaValidity() const PRETTY_PRINT("AttributeStatusList ="); PRETTY_PRINT("["); - // make a copy of the EventList reader + // make a copy of the EventReports reader reader.Init(mReader); while (CHIP_NO_ERROR == (err = reader.Next())) diff --git a/src/app/MessageDef/EventDataElement.cpp b/src/app/MessageDef/EventDataElement.cpp deleted file mode 100644 index 2e5ac2c99ddd58..00000000000000 --- a/src/app/MessageDef/EventDataElement.cpp +++ /dev/null @@ -1,542 +0,0 @@ -/** - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2018 Google LLC. - * Copyright (c) 2016-2017 Nest Labs, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * This file defines EventDataElement parser and builder in CHIP interaction model - * - */ - -#include "EventDataElement.h" - -#include "MessageDefHelper.h" - -#include -#include -#include - -#include - -using namespace chip; -using namespace chip::TLV; - -namespace chip { -namespace app { -CHIP_ERROR EventDataElement::Parser::Init(const chip::TLV::TLVReader & aReader) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // make a copy of the reader here - mReader.Init(aReader); - - VerifyOrExit(chip::TLV::kTLVType_Structure == mReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = mReader.EnterContainer(mOuterContainerType); - -exit: - - return err; -} - -CHIP_ERROR -EventDataElement::Parser::ParseData(chip::TLV::TLVReader & aReader, int aDepth) const -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - if (aDepth == 0) - { - PRETTY_PRINT("EventData = "); - } - else - { - if (chip::TLV::IsContextTag(aReader.GetTag())) - { - PRETTY_PRINT("0x%" PRIx32 " = ", chip::TLV::TagNumFromTag(aReader.GetTag())); - } - else if (chip::TLV::IsProfileTag(aReader.GetTag())) - { - PRETTY_PRINT("0x%" PRIx32 "::0x%" PRIx32 " = ", chip::TLV::ProfileIdFromTag(aReader.GetTag()), - chip::TLV::TagNumFromTag(aReader.GetTag())); - } - else - { - // Anonymous tag, don't print anything - } - } - - switch (aReader.GetType()) - { - case chip::TLV::kTLVType_Structure: - PRETTY_PRINT("{"); - break; - - case chip::TLV::kTLVType_Array: - PRETTY_PRINT_SAMELINE("["); - PRETTY_PRINT("\t\t"); - break; - - case chip::TLV::kTLVType_SignedInteger: { - int64_t value_s64; - - err = aReader.Get(value_s64); - SuccessOrExit(err); - - PRETTY_PRINT_SAMELINE("%" PRId64 ", ", value_s64); - break; - } - - case chip::TLV::kTLVType_UnsignedInteger: { - uint64_t value_u64; - - err = aReader.Get(value_u64); - SuccessOrExit(err); - - PRETTY_PRINT_SAMELINE("%" PRIu64 ", ", value_u64); - break; - } - - case chip::TLV::kTLVType_Boolean: { - bool value_b; - - err = aReader.Get(value_b); - SuccessOrExit(err); - - PRETTY_PRINT_SAMELINE("%s, ", value_b ? "true" : "false"); - break; - } - - case chip::TLV::kTLVType_UTF8String: { - char value_s[256]; - - err = aReader.GetString(value_s, sizeof(value_s)); - VerifyOrExit(err == CHIP_NO_ERROR || err == CHIP_ERROR_BUFFER_TOO_SMALL, ); - - if (err == CHIP_ERROR_BUFFER_TOO_SMALL) - { - PRETTY_PRINT_SAMELINE("... (byte string too long) ..."); - err = CHIP_NO_ERROR; - } - else - { - PRETTY_PRINT_SAMELINE("\"%s\", ", value_s); - } - break; - } - - case chip::TLV::kTLVType_ByteString: { - uint8_t value_b[256]; - uint32_t len, readerLen; - - readerLen = aReader.GetLength(); - - err = aReader.GetBytes(value_b, sizeof(value_b)); - VerifyOrExit(err == CHIP_NO_ERROR || err == CHIP_ERROR_BUFFER_TOO_SMALL, ); - - PRETTY_PRINT_SAMELINE("["); - PRETTY_PRINT("\t\t"); - - if (readerLen < sizeof(value_b)) - { - len = readerLen; - } - else - { - len = sizeof(value_b); - } - - if (err == CHIP_ERROR_BUFFER_TOO_SMALL) - { - PRETTY_PRINT_SAMELINE("... (byte string too long) ..."); - } - else - { - for (size_t i = 0; i < len; i++) - { - PRETTY_PRINT_SAMELINE("0x%" PRIx8 ", ", value_b[i]); - } - } - - err = CHIP_NO_ERROR; - PRETTY_PRINT("\t\t]"); - break; - } - - case chip::TLV::kTLVType_Null: - PRETTY_PRINT_SAMELINE("NULL"); - break; - - default: - PRETTY_PRINT_SAMELINE("--"); - break; - } - - if (aReader.GetType() == chip::TLV::kTLVType_Structure || aReader.GetType() == chip::TLV::kTLVType_Array) - { - const char terminating_char = (aReader.GetType() == chip::TLV::kTLVType_Structure) ? '}' : ']'; - chip::TLV::TLVType type; - - IgnoreUnusedVariable(terminating_char); - - err = aReader.EnterContainer(type); - SuccessOrExit(err); - - while ((err = aReader.Next()) == CHIP_NO_ERROR) - { - PRETTY_PRINT_INCDEPTH(); - - err = ParseData(aReader, aDepth + 1); - SuccessOrExit(err); - - PRETTY_PRINT_DECDEPTH(); - } - - PRETTY_PRINT("%c,", terminating_char); - - err = aReader.ExitContainer(type); - SuccessOrExit(err); - } - -exit: - return err; -} - -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR EventDataElement::Parser::CheckSchemaValidity() const -{ - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t TagPresenceMask = 0; - chip::TLV::TLVReader reader; - - PRETTY_PRINT("EventDataElement ="); - PRETTY_PRINT("{"); - - // make a copy of the Path reader - reader.Init(mReader); - - while (CHIP_NO_ERROR == (err = reader.Next())) - { - VerifyOrExit(chip::TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG); - switch (chip::TLV::TagNumFromTag(reader.GetTag())) - { - case kCsTag_EventPath: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_EventPath)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EventPath); - - VerifyOrExit(chip::TLV::kTLVType_List == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - EventPathIB::Parser path; - err = path.Init(reader); - SuccessOrExit(err); - - PRETTY_PRINT_INCDEPTH(); - err = path.CheckSchemaValidity(); - SuccessOrExit(err); - PRETTY_PRINT_DECDEPTH(); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_PriorityLevel: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_PriorityLevel)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_PriorityLevel); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - uint64_t value; - err = reader.Get(value); - SuccessOrExit(err); - - PRETTY_PRINT("\tPriorityLevel = 0x%" PRIx64 ",", value); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_Number: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_Number)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_Number); - - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - uint64_t value; - err = reader.Get(value); - SuccessOrExit(err); - - PRETTY_PRINT("\tNumber = 0x%" PRIx64 ",", value); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_UTCTimestamp: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_UTCTimestamp)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_UTCTimestamp); - - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - uint64_t value; - err = reader.Get(value); - SuccessOrExit(err); - - PRETTY_PRINT("\tUTCTimestamp = 0x%" PRIx64 ",", value); - } -#endif // CHIP_DETAIL_LOGGING - break; - - case kCsTag_SystemTimestamp: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_SystemTimestamp)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_SystemTimestamp); - - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - uint64_t value; - err = reader.Get(value); - SuccessOrExit(err); - - PRETTY_PRINT("\tSystemTimestamp = 0x%" PRIx64 ",", value); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_DeltaUTCTimestamp: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_DeltaUTCTimestamp)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_DeltaUTCTimestamp); - - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - uint64_t value; - err = reader.Get(value); - SuccessOrExit(err); - - PRETTY_PRINT("\tDeltaUTCTimestampstamp= 0x%" PRIx64 ",", value); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_DeltaSystemTimestamp: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_DeltaSystemTimestamp)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_DeltaSystemTimestamp); - - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - uint64_t value; - err = reader.Get(value); - SuccessOrExit(err); - - PRETTY_PRINT("\tDeltaSystemTimestamp = 0x%" PRIx64 ",", value); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_Data: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_Data)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_Data); - - PRETTY_PRINT_INCDEPTH(); - err = ParseData(reader, 0); - SuccessOrExit(err); - PRETTY_PRINT_DECDEPTH(); - break; - default: - ExitNow(err = CHIP_ERROR_INVALID_TLV_TAG); - } - } - PRETTY_PRINT("},"); - PRETTY_PRINT(""); - - // if we have exhausted this container - if (CHIP_END_OF_TLV == err) - { - // check for required fields: - const uint16_t RequiredFields = (1 << kCsTag_EventPath) | (1 << kCsTag_PriorityLevel) | (1 << kCsTag_Data); - - if ((TagPresenceMask & RequiredFields) == RequiredFields) - { - err = CHIP_NO_ERROR; - } - else - { - err = CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT; - } - } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - - return err; -} -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - -CHIP_ERROR EventDataElement::Parser::GetEventPath(EventPathIB::Parser * const apEventPath) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_EventPath), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_List == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apEventPath->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; -} - -CHIP_ERROR EventDataElement::Parser::GetPriorityLevel(uint8_t * const apPriorityLevel) -{ - return GetUnsignedInteger(kCsTag_PriorityLevel, apPriorityLevel); -} - -CHIP_ERROR EventDataElement::Parser::GetNumber(uint64_t * const apNumber) -{ - return GetUnsignedInteger(kCsTag_Number, apNumber); -} - -CHIP_ERROR EventDataElement::Parser::GetUTCTimestamp(uint64_t * const apUTCTimestamp) -{ - return GetUnsignedInteger(kCsTag_UTCTimestamp, apUTCTimestamp); -} - -CHIP_ERROR EventDataElement::Parser::GetSystemTimestamp(uint64_t * const apSystemTimestamp) -{ - return GetUnsignedInteger(kCsTag_SystemTimestamp, apSystemTimestamp); -} - -CHIP_ERROR EventDataElement::Parser::GetDeltaUTCTimestamp(uint64_t * const apDeltaUTCTimestampstamp) -{ - return GetUnsignedInteger(kCsTag_DeltaUTCTimestamp, apDeltaUTCTimestampstamp); -} - -CHIP_ERROR EventDataElement::Parser::GetDeltaSystemTimestamp(uint64_t * const apDeltaSystemTimestamp) -{ - return GetUnsignedInteger(kCsTag_DeltaSystemTimestamp, apDeltaSystemTimestamp); -} - -CHIP_ERROR EventDataElement::Parser::GetData(chip::TLV::TLVReader * const apReader) const -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_Data), *apReader); - - return err; -} - -CHIP_ERROR EventDataElement::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - -EventPathIB::Builder & EventDataElement::Builder::CreateEventPath() -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mEventPathBuilder.Init(mpWriter, kCsTag_EventPath); - } - else - { - mEventPathBuilder.ResetError(mError); - } - return mEventPathBuilder; -} - -EventDataElement::Builder EventDataElement::Builder::PriorityLevel(const uint8_t aPriorityLevel) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_PriorityLevel), aPriorityLevel); - } - return *this; -} - -EventDataElement::Builder EventDataElement::Builder::Number(const uint64_t aNumber) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_Number), aNumber); - } - return *this; -} - -EventDataElement::Builder EventDataElement::Builder::UTCTimestamp(const uint64_t aUTCTimestamp) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_UTCTimestamp), aUTCTimestamp); - } - return *this; -} - -EventDataElement::Builder EventDataElement::Builder::SystemTimestamp(const uint64_t aSystemTimestamp) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_SystemTimestamp), aSystemTimestamp); - } - return *this; -} - -EventDataElement::Builder EventDataElement::Builder::DeltaUTCTimestamp(const uint64_t aDeltaUTCTimestamp) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_DeltaUTCTimestamp), aDeltaUTCTimestamp); - } - return *this; -} - -EventDataElement::Builder EventDataElement::Builder::DeltaSystemTimestamp(const uint64_t aDeltaSystemTimestamp) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_DeltaSystemTimestamp), aDeltaSystemTimestamp); - } - return *this; -} - -// Mark the end of this element and recover the type for outer container -EventDataElement::Builder & EventDataElement::Builder::EndOfEventDataElement() -{ - EndOfContainer(); - return *this; -} -}; // namespace app -}; // namespace chip diff --git a/src/app/MessageDef/EventDataIB.cpp b/src/app/MessageDef/EventDataIB.cpp new file mode 100644 index 00000000000000..108bf25bbbb46a --- /dev/null +++ b/src/app/MessageDef/EventDataIB.cpp @@ -0,0 +1,460 @@ +/** + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018 Google LLC. + * Copyright (c) 2016-2017 Nest Labs, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * This file defines EventDataIB parser and builder in CHIP interaction model + * + */ + +#include "EventDataIB.h" + +#include "MessageDefHelper.h" + +#include +#include +#include + +#include + +namespace chip { +namespace app { +CHIP_ERROR +EventDataIB::Parser::ParseData(TLV::TLVReader & aReader, int aDepth) const +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + if (aDepth == 0) + { + PRETTY_PRINT("EventData = "); + } + else + { + if (TLV::IsContextTag(aReader.GetTag())) + { + PRETTY_PRINT("0x%" PRIx32 " = ", TLV::TagNumFromTag(aReader.GetTag())); + } + else if (TLV::IsProfileTag(aReader.GetTag())) + { + PRETTY_PRINT("0x%" PRIx32 "::0x%" PRIx32 " = ", TLV::ProfileIdFromTag(aReader.GetTag()), + TLV::TagNumFromTag(aReader.GetTag())); + } + else + { + // Anonymous tag, don't print anything + } + } + + switch (aReader.GetType()) + { + case TLV::kTLVType_Structure: + PRETTY_PRINT("{"); + break; + + case TLV::kTLVType_Array: + PRETTY_PRINT_SAMELINE("["); + PRETTY_PRINT("\t\t"); + break; + + case TLV::kTLVType_SignedInteger: { + int64_t value_s64; + ReturnErrorOnFailure(aReader.Get(value_s64)); + PRETTY_PRINT_SAMELINE("%" PRId64 ", ", value_s64); + break; + } + + case TLV::kTLVType_UnsignedInteger: { + uint64_t value_u64; + ReturnErrorOnFailure(aReader.Get(value_u64)); + PRETTY_PRINT_SAMELINE("%" PRIu64 ", ", value_u64); + break; + } + + case TLV::kTLVType_Boolean: { + bool value_b; + ReturnErrorOnFailure(aReader.Get(value_b)); + PRETTY_PRINT_SAMELINE("%s, ", value_b ? "true" : "false"); + break; + } + + case TLV::kTLVType_UTF8String: { + char value_s[256]; + + err = aReader.GetString(value_s, sizeof(value_s)); + VerifyOrReturnError(err == CHIP_NO_ERROR || err == CHIP_ERROR_BUFFER_TOO_SMALL, err); + + if (err == CHIP_ERROR_BUFFER_TOO_SMALL) + { + PRETTY_PRINT_SAMELINE("... (byte string too long) ..."); + err = CHIP_NO_ERROR; + } + else + { + PRETTY_PRINT_SAMELINE("\"%s\", ", value_s); + } + break; + } + + case TLV::kTLVType_ByteString: { + uint8_t value_b[256]; + uint32_t len, readerLen; + + readerLen = aReader.GetLength(); + + err = aReader.GetBytes(value_b, sizeof(value_b)); + VerifyOrReturnError(err == CHIP_NO_ERROR || err == CHIP_ERROR_BUFFER_TOO_SMALL, err); + + PRETTY_PRINT_SAMELINE("["); + PRETTY_PRINT("\t\t"); + + if (readerLen < sizeof(value_b)) + { + len = readerLen; + } + else + { + len = sizeof(value_b); + } + + if (err == CHIP_ERROR_BUFFER_TOO_SMALL) + { + PRETTY_PRINT_SAMELINE("... (byte string too long) ..."); + } + else + { + for (size_t i = 0; i < len; i++) + { + PRETTY_PRINT_SAMELINE("0x%" PRIx8 ", ", value_b[i]); + } + } + + err = CHIP_NO_ERROR; + PRETTY_PRINT("\t\t]"); + break; + } + + case TLV::kTLVType_Null: + PRETTY_PRINT_SAMELINE("NULL"); + break; + + default: + PRETTY_PRINT_SAMELINE("--"); + break; + } + + if (aReader.GetType() == TLV::kTLVType_Structure || aReader.GetType() == TLV::kTLVType_Array) + { + const char terminating_char = (aReader.GetType() == TLV::kTLVType_Structure) ? '}' : ']'; + TLV::TLVType type; + + IgnoreUnusedVariable(terminating_char); + + ReturnErrorOnFailure(aReader.EnterContainer(type)); + + while ((err = aReader.Next()) == CHIP_NO_ERROR) + { + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(ParseData(aReader, aDepth + 1)); + PRETTY_PRINT_DECDEPTH(); + } + + PRETTY_PRINT("%c,", terminating_char); + ReturnErrorOnFailure(aReader.ExitContainer(type)); + } + return CHIP_NO_ERROR; +} + +#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; + + PRETTY_PRINT("EventDataIB ="); + PRETTY_PRINT("{"); + + // make a copy of the Path reader + reader.Init(mReader); + + while (CHIP_NO_ERROR == (err = reader.Next())) + { + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) + { + case to_underlying(Tag::kPath): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kPath)); + { + EventPathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventNumber): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEventNumber))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEventNumber)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + EventNumber number; + ReturnErrorOnFailure(reader.Get(number)); + PRETTY_PRINT("\tEventNumber = 0x%" PRIx64 ",", number); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kPriority): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kPriority))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kPriority)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + uint64_t value; + ReturnErrorOnFailure(reader.Get(value)); + PRETTY_PRINT("\tPriorityLevel = 0x%" PRIx64 ",", value); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kEpochTimestamp): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEpochTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEpochTimestamp)); + + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + uint64_t value; + ReturnErrorOnFailure(reader.Get(value)); + PRETTY_PRINT("\tEpochTimestamp = 0x%" PRIx64 ",", value); + } +#endif // CHIP_DETAIL_LOGGING + break; + + case to_underlying(Tag::kSystemTimestamp): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kSystemTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kSystemTimestamp)); + + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + uint64_t value; + ReturnErrorOnFailure(reader.Get(value)); + PRETTY_PRINT("\tSystemTimestamp = 0x%" PRIx64 ",", value); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kDeltaEpochTimestamp): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kDeltaEpochTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kDeltaEpochTimestamp)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + uint64_t value; + ReturnErrorOnFailure(reader.Get(value)); + PRETTY_PRINT("\tDeltaEpochTimestampstamp= 0x%" PRIx64 ",", value); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kDeltaSystemTimestamp): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kDeltaSystemTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kDeltaSystemTimestamp)); + + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + uint64_t value; + ReturnErrorOnFailure(reader.Get(value)); + PRETTY_PRINT("\tDeltaSystemTimestamp = 0x%" PRIx64 ",", value); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kData): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kData))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kData)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(ParseData(reader, 0)); + PRETTY_PRINT_DECDEPTH(); + break; + default: + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; + } + } + PRETTY_PRINT("},"); + PRETTY_PRINT(""); + + // if we have exhausted this container + if (CHIP_END_OF_TLV == err) + { + // check for required fields: + const int RequiredFields = + (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kPriority)) | (1 << to_underlying(Tag::kData)); + + if ((TagPresenceMask & RequiredFields) == RequiredFields) + { + err = CHIP_NO_ERROR; + } + else + { + err = CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT; + } + } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; +} +#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK + +CHIP_ERROR EventDataIB::Parser::GetPath(EventPathIB::Parser * const apPath) +{ + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kPath)), reader)); + ReturnErrorOnFailure(apPath->Init(reader)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR EventDataIB::Parser::GetPriority(uint8_t * const apPriority) +{ + return GetUnsignedInteger(to_underlying(Tag::kPriority), apPriority); +} + +CHIP_ERROR EventDataIB::Parser::GetEventNumber(EventNumber * const apEventNumber) +{ + return GetUnsignedInteger(to_underlying(Tag::kEventNumber), apEventNumber); +} + +CHIP_ERROR EventDataIB::Parser::GetEpochTimestamp(uint64_t * const apEpochTimestamp) +{ + return GetUnsignedInteger(to_underlying(Tag::kEpochTimestamp), apEpochTimestamp); +} + +CHIP_ERROR EventDataIB::Parser::GetSystemTimestamp(uint64_t * const apSystemTimestamp) +{ + return GetUnsignedInteger(to_underlying(Tag::kSystemTimestamp), apSystemTimestamp); +} + +CHIP_ERROR EventDataIB::Parser::GetDeltaEpochTimestamp(uint64_t * const apDeltaEpochTimestampstamp) +{ + return GetUnsignedInteger(to_underlying(Tag::kDeltaEpochTimestamp), apDeltaEpochTimestampstamp); +} + +CHIP_ERROR EventDataIB::Parser::GetDeltaSystemTimestamp(uint64_t * const apDeltaSystemTimestamp) +{ + return GetUnsignedInteger(to_underlying(Tag::kDeltaSystemTimestamp), apDeltaSystemTimestamp); +} + +CHIP_ERROR EventDataIB::Parser::GetData(TLV::TLVReader * const apReader) const +{ + return mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kData)), *apReader); +} + +EventPathIB::Builder & EventDataIB::Builder::CreatePath() +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mPath.Init(mpWriter, to_underlying(Tag::kPath)); + } + return mPath; +} + +EventDataIB::Builder EventDataIB::Builder::Priority(const uint8_t aPriority) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kPriority)), aPriority); + } + return *this; +} + +EventDataIB::Builder EventDataIB::Builder::EventNumber(const uint64_t aEventNumber) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kEventNumber)), aEventNumber); + } + return *this; +} + +EventDataIB::Builder EventDataIB::Builder::EpochTimestamp(const uint64_t aEpochTimestamp) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kEpochTimestamp)), aEpochTimestamp); + } + return *this; +} + +EventDataIB::Builder EventDataIB::Builder::SystemTimestamp(const uint64_t aSystemTimestamp) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kSystemTimestamp)), aSystemTimestamp); + } + return *this; +} + +EventDataIB::Builder EventDataIB::Builder::DeltaEpochTimestamp(const uint64_t aDeltaEpochTimestamp) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kDeltaEpochTimestamp)), aDeltaEpochTimestamp); + } + return *this; +} + +EventDataIB::Builder EventDataIB::Builder::DeltaSystemTimestamp(const uint64_t aDeltaSystemTimestamp) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kDeltaSystemTimestamp)), aDeltaSystemTimestamp); + } + return *this; +} + +// Mark the end of this element and recover the type for outer container +EventDataIB::Builder & EventDataIB::Builder::EndOfEventDataIB() +{ + EndOfContainer(); + return *this; +} +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/EventDataElement.h b/src/app/MessageDef/EventDataIB.h similarity index 63% rename from src/app/MessageDef/EventDataElement.h rename to src/app/MessageDef/EventDataIB.h index fcaf100141e6e4..3e63b7eb5f8db4 100644 --- a/src/app/MessageDef/EventDataElement.h +++ b/src/app/MessageDef/EventDataIB.h @@ -17,18 +17,17 @@ */ /** * @file - * This file defines EventDataElement parser and builder in CHIP interaction model + * This file defines EventDataIB parser and builder in CHIP interaction model * */ #pragma once -#include "Builder.h" #include "EventPathIB.h" - -#include "Parser.h" - +#include "StructBuilder.h" +#include "StructParser.h" #include +#include #include #include #include @@ -37,31 +36,22 @@ namespace chip { namespace app { -namespace EventDataElement { -enum +namespace EventDataIB { +enum class Tag : uint8_t { - kCsTag_EventPath = 0, - kCsTag_PriorityLevel = 1, - kCsTag_Number = 2, - kCsTag_UTCTimestamp = 3, - kCsTag_SystemTimestamp = 4, - kCsTag_DeltaUTCTimestamp = 5, - kCsTag_DeltaSystemTimestamp = 6, - kCsTag_Data = 7, + kPath = 0, + kEventNumber = 1, + kPriority = 2, + kEpochTimestamp = 3, + kSystemTimestamp = 4, + kDeltaEpochTimestamp = 5, + kDeltaSystemTimestamp = 6, + kData = 7, }; -class Parser : public chip::app::Parser +class Parser : public StructParser { public: - /** - * @brief Initialize the parser object with TLVReader - * - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this EventDataElement - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(const chip::TLV::TLVReader & aReader); - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed @@ -82,46 +72,46 @@ class Parser : public chip::app::Parser /** * @brief Get a TLVReader for the EventPath. Next() must be called before accessing them. * - * @param [in] apEventPath A pointer to apEventPath + * @param [in] apPath A pointer to apPath * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Path * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetEventPath(EventPathIB::Parser * const apEventPath); + CHIP_ERROR GetPath(EventPathIB::Parser * const apPath); /** - * @brief Get a TLVReader for the Number. Next() must be called before accessing them. + * @brief Get a TLVReader for the EventNumber. Next() must be called before accessing them. * - * @param [in] apPriorityLevel A pointer to apPriorityLevel + * @param [in] apEventNumber A pointer to apEventNumber * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetPriorityLevel(uint8_t * const apPriorityLevel); + CHIP_ERROR GetEventNumber(uint64_t * const apEventNumber); /** * @brief Get a TLVReader for the Number. Next() must be called before accessing them. * - * @param [in] apNumber A pointer to apNumber + * @param [in] apPriority A pointer to apPriorityLevel * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetNumber(uint64_t * const apNumber); + CHIP_ERROR GetPriority(uint8_t * const apPriority); /** - * @brief Get a TLVReader for the UTCTimestamp. Next() must be called before accessing them. + * @brief Get a TLVReader for the EpochTimestamp. Next() must be called before accessing them. * - * @param [in] apUTCTimestamp A pointer to apUTCTimestamp + * @param [in] apEpochTimestamp A pointer to apEpochTimestamp * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetUTCTimestamp(uint64_t * const apUTCTimestamp); + CHIP_ERROR GetEpochTimestamp(uint64_t * const apEpochTimestamp); /** * @brief Get a TLVReader for the SystemTimestamp. Next() must be called before accessing them. @@ -135,15 +125,15 @@ class Parser : public chip::app::Parser CHIP_ERROR GetSystemTimestamp(uint64_t * const apSystemTimestamp); /** - * @brief Get a TLVReader for the DeltaUTCTimestamp. Next() must be called before accessing them. + * @brief Get a TLVReader for the DeltaEpochTimestamp. Next() must be called before accessing them. * - * @param [in] apDeltaUTCTimestamp A pointer to apDeltaUTCTimestamp + * @param [in] apDeltaEpochTimestamp A pointer to apDeltaEpochTimestamp * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetDeltaUTCTimestamp(uint64_t * const apDeltaUTCTimestamp); + CHIP_ERROR GetDeltaEpochTimestamp(uint64_t * const apDeltaEpochTimestamp); /** * @brief Get a TLVReader for the DeltaSystemTimestamp. Next() must be called before accessing them. @@ -164,31 +154,22 @@ class Parser : public chip::app::Parser * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetData(chip::TLV::TLVReader * const apReader) const; + CHIP_ERROR GetData(TLV::TLVReader * const apReader) const; protected: // A recursively callable function to parse a data element and pretty-print it. - CHIP_ERROR ParseData(chip::TLV::TLVReader & aReader, int aDepth) const; + CHIP_ERROR ParseData(TLV::TLVReader & aReader, int aDepth) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: - /** - * @brief Initialize a EventDataElement::Builder for writing into a TLV stream - * - * @param [in] apWriter A pointer to TLVWriter - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); - /** * @brief Initialize a EventPathIB::Builder for writing into the TLV stream * * @return A reference to EventPathIB::Builder */ - EventPathIB::Builder & CreateEventPath(); + EventPathIB::Builder & CreatePath(); /** * @brief Inject PriorityLevel into the TLV stream to indicate the priority level associated with @@ -198,49 +179,49 @@ class Builder : public chip::app::Builder * * @return A reference to *this */ - EventDataElement::Builder PriorityLevel(const uint8_t aPriorityLevel); + EventDataIB::Builder Priority(const uint8_t aPriority); /** * @brief Inject Number into the TLV stream to indicate the number associated with * the cluster that is referenced by the path. The event number is a monotonically increasing number that * uniquely identifies each emitted event. This number is scoped to the PriorityLevel. * - * @param [in] aNumber The uint64_t variable to reflectt the event number + * @param [in] aEventNumber The uint64_t variable to reflect the event number * * @return A reference to *this */ - EventDataElement::Builder Number(const uint64_t aNumber); + EventDataIB::Builder EventNumber(const EventNumber aEventNumber); /** - * @brief Inject UTCTimestamp into the TLV stream. + * @brief Inject EpochTimestamp into the TLV stream. * This is encoded as a 64-bit millisecond number since UNIX epoch (Jan 1 1970 00:00:00 GMT). * - * @param [in] aUTCTimestamp The uint64_t variable to reflect the UTC timestamp of the Event. + * @param [in] aEpochTimestamp The uint64_t variable to reflect the Epoch timestamp of the Event. * * @return A reference to *this */ - EventDataElement::Builder UTCTimestamp(const uint64_t aUTCTimestamp); + EventDataIB::Builder EpochTimestamp(const uint64_t aEpochTimestamp); /** - * @brief Inject SystemTimestamp into the TLV stream. If UTC time is not available, time since boot + * @brief Inject SystemTimestamp into the TLV stream. If Epoch time is not available, time since boot * SHALL be encoded in this field as 64-bit, milliseconds. * * @param [in] aSystemTimestamp The uint64_t variable to reflect system time * * @return A reference to *this */ - EventDataElement::Builder SystemTimestamp(const uint64_t aSystemTimestamp); + EventDataIB::Builder SystemTimestamp(const uint64_t aSystemTimestamp); /** - * @brief Inject DeltaUTCTimestamp into the TLV stream. - * This field is present if delta encoding of the UTC timestamp relative to a prior event is desired for compression - * reasons. When this field is present, the UTC Timestamp field SHALL be omitted. + * @brief Inject DeltaEpochTimestamp into the TLV stream. + * This field is present if delta encoding of the Epoch timestamp relative to a prior event is desired for compression + * reasons. When this field is present, the Epoch Timestamp field SHALL be omitted. * - * @param [in] aDeltaUTCTimestamp The uint64_t variable to reflect DeltaUTCTimestamp + * @param [in] aDeltaEpochTimestamp The uint64_t variable to reflect DeltaEpochTimestamp * * @return A reference to *this */ - EventDataElement::Builder DeltaUTCTimestamp(const uint64_t aDeltaUTCTimestamp); + EventDataIB::Builder DeltaEpochTimestamp(const uint64_t aDeltaEpochTimestamp); /** * @brief Inject DeltaSystemTimestamp into the TLV stream. @@ -251,18 +232,18 @@ class Builder : public chip::app::Builder * * @return A reference to *this */ - EventDataElement::Builder DeltaSystemTimestamp(const uint64_t aDeltaSystemTimestamp); + EventDataIB::Builder DeltaSystemTimestamp(const uint64_t aDeltaSystemTimestamp); /** - * @brief Mark the end of this EventDataElement + * @brief Mark the end of this EventDataIB * * @return A reference to *this */ - EventDataElement::Builder & EndOfEventDataElement(); + EventDataIB::Builder & EndOfEventDataIB(); private: - EventPathIB::Builder mEventPathBuilder; + EventPathIB::Builder mPath; }; -}; // namespace EventDataElement -}; // namespace app -}; // namespace chip +} // namespace EventDataIB +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/EventList.cpp b/src/app/MessageDef/EventList.cpp deleted file mode 100644 index 65a2e97c462d41..00000000000000 --- a/src/app/MessageDef/EventList.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/** - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2018 Google LLC. - * Copyright (c) 2016-2017 Nest Labs, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * This file defines EventList parser and builder in CHIP interaction model - * - */ - -#include "EventList.h" - -#include "MessageDefHelper.h" - -#include -#include -#include - -#include - -using namespace chip; -using namespace chip::TLV; - -namespace chip { -namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR EventList::Parser::CheckSchemaValidity() const -{ - CHIP_ERROR err = CHIP_NO_ERROR; - size_t NumDataElement = 0; - chip::TLV::TLVReader reader; - - PRETTY_PRINT("EventList ="); - PRETTY_PRINT("["); - - // make a copy of the EventList reader - reader.Init(mReader); - - while (CHIP_NO_ERROR == (err = reader.Next())) - { - VerifyOrExit(chip::TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); - VerifyOrExit(chip::TLV::kTLVType_Structure == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - { - EventDataElement::Parser event; - err = event.Init(reader); - SuccessOrExit(err); - - PRETTY_PRINT_INCDEPTH(); - err = event.CheckSchemaValidity(); - SuccessOrExit(err); - PRETTY_PRINT_DECDEPTH(); - } - - ++NumDataElement; - } - - PRETTY_PRINT("],"); - PRETTY_PRINT(""); - - // if we have exhausted this container - if (CHIP_END_OF_TLV == err) - { - // if we have at least one data element - if (NumDataElement > 0) - { - err = CHIP_NO_ERROR; - } - // NOTE: temporarily disable this check, to allow test to continue - else - { - ChipLogError(DataManagement, "PROTOCOL ERROR: Empty event list"); - err = CHIP_NO_ERROR; - } - } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - - return err; -} -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - -EventDataElement::Builder & EventList::Builder::CreateEventBuilder() -{ - // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mEventDataElementBuilder.ResetError(mError)); - - mError = mEventDataElementBuilder.Init(mpWriter); - -exit: - // on error, mEventDataElementBuilder would be un-/partial initialized and cannot be used to write anything - return mEventDataElementBuilder; -} - -EventList::Builder & EventList::Builder::EndOfEventList() -{ - EndOfContainer(); - return *this; -} -}; // namespace app -}; // namespace chip diff --git a/src/app/MessageDef/EventPaths.cpp b/src/app/MessageDef/EventPaths.cpp index 134e3cc75ae0f3..08bb866f1b678f 100644 --- a/src/app/MessageDef/EventPaths.cpp +++ b/src/app/MessageDef/EventPaths.cpp @@ -77,7 +77,7 @@ CHIP_ERROR EventPaths::Parser::CheckSchemaValidity() const } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -EventPathIB::Builder & EventPaths::Builder::CreateEventPath() +EventPathIB::Builder & EventPaths::Builder::CreatePath() { if (mError == CHIP_NO_ERROR) { diff --git a/src/app/MessageDef/EventPaths.h b/src/app/MessageDef/EventPaths.h index 454a73c7c0023b..632a8525b77218 100644 --- a/src/app/MessageDef/EventPaths.h +++ b/src/app/MessageDef/EventPaths.h @@ -67,7 +67,7 @@ class Builder : public ArrayBuilder * * @return A reference to EventPathIB::Builder */ - EventPathIB::Builder & CreateEventPath(); + EventPathIB::Builder & CreatePath(); /** * @brief Mark the end of this EventPaths diff --git a/src/app/MessageDef/EventReportIB.cpp b/src/app/MessageDef/EventReportIB.cpp new file mode 100644 index 00000000000000..a64d3e1fbbf916 --- /dev/null +++ b/src/app/MessageDef/EventReportIB.cpp @@ -0,0 +1,141 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "EventReportIB.h" +#include "EventDataIB.h" +#include "MessageDefHelper.h" +#include "StructBuilder.h" +#include "StructParser.h" + +#include +#include +#include + +#include + +namespace chip { +namespace app { +#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +CHIP_ERROR EventReportIB::Parser::CheckSchemaValidity() const +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; + + PRETTY_PRINT("EventReportIB ="); + PRETTY_PRINT("{"); + + // make a copy of the reader + reader.Init(mReader); + + while (CHIP_NO_ERROR == (err = reader.Next())) + { + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) + { + case to_underlying(Tag::kEventStatus): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEventStatus))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEventStatus)); + { + EventStatusIB::Parser eventStatus; + ReturnErrorOnFailure(eventStatus.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventStatus.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventData): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEventData))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEventData)); + { + EventDataIB::Parser eventData; + ReturnErrorOnFailure(eventData.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventData.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + default: + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; + } + } + + PRETTY_PRINT("},"); + PRETTY_PRINT(""); + + if (CHIP_END_OF_TLV == err) + { + const int RequiredFields = (1 << to_underlying(Tag::kEventData)) | (1 << to_underlying(Tag::kEventStatus)); + + if ((TagPresenceMask & RequiredFields) == RequiredFields) + { + err = CHIP_NO_ERROR; + } + } + + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; +} +#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK + +CHIP_ERROR EventReportIB::Parser::GetEventStatus(EventStatusIB::Parser * const apEventStatus) const +{ + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventStatus)), reader)); + ReturnErrorOnFailure(apEventStatus->Init(reader)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR EventReportIB::Parser::GetEventData(EventDataIB::Parser * const apEventData) const +{ + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventData)), reader)); + ReturnErrorOnFailure(apEventData->Init(reader)); + return CHIP_NO_ERROR; +} + +EventStatusIB::Builder & EventReportIB::Builder::CreateEventStatus() +{ + if (mError == CHIP_NO_ERROR) + { + mError = mEventStatus.Init(mpWriter, to_underlying(Tag::kEventStatus)); + } + return mEventStatus; +} + +EventDataIB::Builder & EventReportIB::Builder::CreateEventData() +{ + if (mError == CHIP_NO_ERROR) + { + mError = mEventData.Init(mpWriter, to_underlying(Tag::kEventData)); + } + return mEventData; +} + +EventReportIB::Builder & EventReportIB::Builder::EndOfEventReportIB() +{ + EndOfContainer(); + return *this; +} +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/EventReportIB.h b/src/app/MessageDef/EventReportIB.h new file mode 100644 index 00000000000000..69f02af6241910 --- /dev/null +++ b/src/app/MessageDef/EventReportIB.h @@ -0,0 +1,114 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "EventDataIB.h" +#include "EventStatusIB.h" +#include "StructBuilder.h" +#include "StructParser.h" + +#include +#include +#include +#include +#include +#include + +namespace chip { +namespace app { +namespace EventReportIB { +enum class Tag : uint8_t +{ + kEventStatus = 0, + kEventData = 1, +}; + +class Parser : public StructParser +{ +public: +#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK + /** + * @brief Roughly verify the message is correctly formed + * 1) all mandatory tags are present + * 2) all elements have expected data type + * 3) any tag can only appear once + * 4) At the top level of the structure, unknown tags are ignored for forward compatibility + * @note The main use of this function is to print out what we're + * receiving during protocol development and debugging. + * The encoding rule has changed in IM encoding spec so this + * check is only "roughly" conformant now. + * + * @return #CHIP_NO_ERROR on success + */ + CHIP_ERROR CheckSchemaValidity() const; +#endif + + /** + * @brief Get a TLVReader for the StatusIB. Next() must be called before accessing them. + * + * @param [in] apEventStatus A pointer to apEventStatus + * + * @return #CHIP_NO_ERROR on success + * # CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a structure + * #CHIP_END_OF_TLV if there is no such element + */ + CHIP_ERROR GetEventStatus(EventStatusIB::Parser * const apEventStatus) const; + + /** + * @brief Get a TLVReader for the EventDataIB. Next() must be called before accessing them. + * + * @param [in] apEventData A pointer to apEventData + * + * @return #CHIP_NO_ERROR on success + * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a EventData + * #CHIP_END_OF_TLV if there is no such element + */ + CHIP_ERROR GetEventData(EventDataIB::Parser * const apEventData) const; +}; + +class Builder : public StructBuilder +{ +public: + /** + * @brief Initialize a EventDataIB::Builder for writing into the TLV stream + * + * @return A reference to EventDataIB::Builder + */ + EventDataIB::Builder & CreateEventData(); + + /** + * @brief Initialize a StatusIB::Builder for writing into the TLV stream + * + * @return A reference to StatusIB::Builder + */ + EventStatusIB::Builder & CreateEventStatus(); + + /** + * @brief Mark the end of this EventReportIB + * + * @return A reference to *this + */ + EventReportIB::Builder & EndOfEventReportIB(); + +private: + EventStatusIB::Builder mEventStatus; + EventDataIB::Builder mEventData; +}; +} // namespace EventReportIB +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/EventReports.cpp b/src/app/MessageDef/EventReports.cpp new file mode 100644 index 00000000000000..379834a0640d9e --- /dev/null +++ b/src/app/MessageDef/EventReports.cpp @@ -0,0 +1,100 @@ +/** + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018 Google LLC. + * Copyright (c) 2016-2017 Nest Labs, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * This file defines EventReports parser and builder in CHIP interaction model + * + */ + +#include "EventReports.h" +#include "MessageDefHelper.h" + +#include +#include +#include + +#include + +namespace chip { +namespace app { +#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +CHIP_ERROR EventReports::Parser::CheckSchemaValidity() const +{ + CHIP_ERROR err = CHIP_NO_ERROR; + size_t numEventReports = 0; + TLV::TLVReader reader; + + PRETTY_PRINT("EventReports ="); + PRETTY_PRINT("["); + + // make a copy of the reader + reader.Init(mReader); + + while (CHIP_NO_ERROR == (err = reader.Next())) + { + VerifyOrReturnError(TLV::AnonymousTag == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG); + { + EventReportIB::Parser eventReport; + ReturnErrorOnFailure(eventReport.Init(reader)); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventReport.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + + ++numEventReports; + } + + PRETTY_PRINT("],"); + PRETTY_PRINT(""); + + // if we have exhausted this container + if (CHIP_END_OF_TLV == err) + { + // if we have at least one event report + if (numEventReports > 0) + { + err = CHIP_NO_ERROR; + } + else + { + ChipLogError(DataManagement, "PROTOCOL ERROR: Empty event reports"); + err = CHIP_NO_ERROR; + } + } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; +} +#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK + +EventReportIB::Builder & EventReports::Builder::CreateEventReport() +{ + if (mError == CHIP_NO_ERROR) + { + mError = mEventReport.Init(mpWriter); + } + return mEventReport; +} + +EventReports::Builder & EventReports::Builder::EndOfEventReports() +{ + EndOfContainer(); + return *this; +} +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/EventList.h b/src/app/MessageDef/EventReports.h similarity index 77% rename from src/app/MessageDef/EventList.h rename to src/app/MessageDef/EventReports.h index c3550a24d5a276..3e9e241dcf5b90 100644 --- a/src/app/MessageDef/EventList.h +++ b/src/app/MessageDef/EventReports.h @@ -17,7 +17,7 @@ */ /** * @file - * This file defines EventList parser and builder in CHIP interaction model + * This file defines EventReports parser and builder in CHIP interaction model * */ @@ -25,7 +25,7 @@ #include "ArrayBuilder.h" #include "ArrayParser.h" -#include "EventDataElement.h" +#include "EventReportIB.h" #include #include @@ -36,7 +36,7 @@ namespace chip { namespace app { -namespace EventList { +namespace EventReports { class Parser : public ArrayParser { public: @@ -62,23 +62,22 @@ class Builder : public ArrayBuilder { public: /** - * @brief Initialize a EventDataElement::Builder for writing into the TLV stream + * @brief Initialize a EventReportIB::Builder for writing into the TLV stream * - * @return A reference to EventDataElement::Builder + * @return A reference to EventReportIB::Builder */ - EventDataElement::Builder & CreateEventBuilder(); + EventReportIB::Builder & CreateEventReport(); /** - * @brief Mark the end of this EventList + * @brief Mark the end of this EventReports * * @return A reference to *this */ - EventList::Builder & EndOfEventList(); + EventReports::Builder & EndOfEventReports(); private: - EventDataElement::Builder mEventDataElementBuilder; + EventReportIB::Builder mEventReport; }; -}; // namespace EventList - -}; // namespace app -}; // namespace chip +} // namespace EventReports +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/ReportDataMessage.cpp b/src/app/MessageDef/ReportDataMessage.cpp index 0e50621a37ffad..db97c589287076 100644 --- a/src/app/MessageDef/ReportDataMessage.cpp +++ b/src/app/MessageDef/ReportDataMessage.cpp @@ -36,22 +36,6 @@ using namespace chip::TLV; namespace chip { namespace app { -CHIP_ERROR ReportDataMessage::Parser::Init(const chip::TLV::TLVReader & aReader) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // make a copy of the reader here - mReader.Init(aReader); - - VerifyOrExit(chip::TLV::kTLVType_Structure == mReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = mReader.EnterContainer(mOuterContainerType); - -exit: - - return err; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const { @@ -59,7 +43,7 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const uint16_t TagPresenceMask = 0; chip::TLV::TLVReader reader; AttributeDataList::Parser attributeDataList; - EventList::Parser eventList; + EventReports::Parser EventReports; PRETTY_PRINT("ReportDataMessage ="); PRETTY_PRINT("{"); @@ -115,17 +99,17 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const } #endif // CHIP_DETAIL_LOGGING break; - case kCsTag_EventDataList: + case kCsTag_EventReports: // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_EventDataList)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EventDataList); + VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_EventReports)), err = CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << kCsTag_EventReports); VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { - eventList.Init(reader); + EventReports.Init(reader); PRETTY_PRINT_INCDEPTH(); - err = eventList.CheckSchemaValidity(); + err = EventReports.CheckSchemaValidity(); SuccessOrExit(err); PRETTY_PRINT_DECDEPTH(); } @@ -194,17 +178,17 @@ CHIP_ERROR ReportDataMessage::Parser::GetAttributeDataList(AttributeDataList::Pa return err; } -CHIP_ERROR ReportDataMessage::Parser::GetEventDataList(EventList::Parser * const apEventDataList) const +CHIP_ERROR ReportDataMessage::Parser::GetEventReports(EventReports::Parser * const apEventReports) const { CHIP_ERROR err = CHIP_NO_ERROR; chip::TLV::TLVReader reader; - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_EventDataList), reader); + err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_EventReports), reader); SuccessOrExit(err); VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - err = apEventDataList->Init(reader); + err = apEventReports->Init(reader); SuccessOrExit(err); exit: @@ -218,11 +202,6 @@ CHIP_ERROR ReportDataMessage::Parser::GetMoreChunkedMessages(bool * const apMore return GetSimpleValue(kCsTag_MoreChunkedMessages, chip::TLV::kTLVType_Boolean, apMoreChunkedMessages); } -CHIP_ERROR ReportDataMessage::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - ReportDataMessage::Builder & ReportDataMessage::Builder::SuppressResponse(const bool aSuppressResponse) { // skip if error has already been set @@ -257,18 +236,18 @@ AttributeDataList::Builder & ReportDataMessage::Builder::CreateAttributeDataList return mAttributeDataListBuilder; } -EventList::Builder & ReportDataMessage::Builder::CreateEventDataListBuilder() +EventReports::Builder & ReportDataMessage::Builder::CreateEventReportsBuilder() { // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mEventDataListBuilder.Init(mpWriter, kCsTag_EventDataList); + mError = mEventReportsBuilder.Init(mpWriter, kCsTag_EventReports); } else { mAttributeDataListBuilder.ResetError(mError); } - return mEventDataListBuilder; + return mEventReportsBuilder; } ReportDataMessage::Builder & ReportDataMessage::Builder::MoreChunkedMessages(const bool aMoreChunkedMessages) diff --git a/src/app/MessageDef/ReportDataMessage.h b/src/app/MessageDef/ReportDataMessage.h index 078a7f128f2484..a8050a266043fa 100644 --- a/src/app/MessageDef/ReportDataMessage.h +++ b/src/app/MessageDef/ReportDataMessage.h @@ -31,9 +31,9 @@ #include #include "AttributeDataList.h" -#include "Builder.h" -#include "EventList.h" -#include "Parser.h" +#include "EventReports.h" +#include "StructBuilder.h" +#include "StructParser.h" namespace chip { namespace app { @@ -43,22 +43,13 @@ enum kCsTag_SuppressResponse = 0, kCsTag_SubscriptionId = 1, kCsTag_AttributeDataList = 2, - kCsTag_EventDataList = 3, + kCsTag_EventReports = 3, kCsTag_MoreChunkedMessages = 4, }; -class Parser : public chip::app::Parser +class Parser : public StructParser { public: - /** - * @brief Initialize the parser object with TLVReader - * - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this ReportDataMessage - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(const chip::TLV::TLVReader & aReader); - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed @@ -109,15 +100,15 @@ class Parser : public chip::app::Parser CHIP_ERROR GetAttributeDataList(AttributeDataList::Parser * const apAttributeDataList) const; /** - * @brief Get a TLVReader for the EventDataList. Next() must be called before accessing them. + * @brief Get a TLVReader for the EventReports. Next() must be called before accessing them. * - * @param [in] apEventDataList A pointer to apEventDataList + * @param [in] apEventReports A pointer to apEventReports * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Array * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetEventDataList(EventList::Parser * const apEventDataList) const; + CHIP_ERROR GetEventReports(EventReports::Parser * const apEventReports) const; /** * @brief Check whether there are more chunked messages in a transaction. Next() must be called before accessing them. @@ -130,18 +121,9 @@ class Parser : public chip::app::Parser CHIP_ERROR GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: - /** - * @brief Initialize a ReportDataMessage::Builder for writing into a TLV stream - * - * @param [in] apWriter A pointer to TLVWriter - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); - /** * @brief Inject SuppressResponse into the TLV stream to indicate whether a response (a StatusResponseMessage specifically) * is to be sent back to the request. @@ -173,11 +155,11 @@ class Builder : public chip::app::Builder AttributeDataList::Builder & CreateAttributeDataListBuilder(); /** - * @brief Initialize a EventList::Builder for writing into the TLV stream + * @brief Initialize a EventReports::Builder for writing into the TLV stream * - * @return A reference to EventList::Builder + * @return A reference to EventReports::Builder */ - EventList::Builder & CreateEventDataListBuilder(); + EventReports::Builder & CreateEventReportsBuilder(); /** * @brief This flag is set to ‘true’ when there are more chunked messages in a transaction. @@ -195,7 +177,7 @@ class Builder : public chip::app::Builder private: AttributeDataList::Builder mAttributeDataListBuilder; - EventList::Builder mEventDataListBuilder; + EventReports::Builder mEventReportsBuilder; }; }; // namespace ReportDataMessage diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index d3516d1aabe796..e72563973b65c5 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -234,7 +234,7 @@ CHIP_ERROR ReadClient::GenerateEventPaths(EventPaths::Builder & aEventPathsBuild for (size_t eventIndex = 0; eventIndex < aEventPathParamsListSize; ++eventIndex) { - EventPathIB::Builder eventPathBuilder = aEventPathsBuilder.CreateEventPath(); + EventPathIB::Builder eventPathBuilder = aEventPathsBuilder.CreatePath(); EventPathParams eventPath = apEventPathParamsList[eventIndex]; eventPathBuilder.Node(eventPath.mNodeId) .Event(eventPath.mEventId) @@ -343,12 +343,12 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload) CHIP_ERROR err = CHIP_NO_ERROR; ReportDataMessage::Parser report; - bool isEventListPresent = false; + bool isEventReportsPresent = false; bool isAttributeDataListPresent = false; bool suppressResponse = false; bool moreChunkedMessages = false; uint64_t subscriptionId = 0; - EventList::Parser eventList; + EventReports::Parser EventReports; AttributeDataList::Parser attributeDataList; System::PacketBufferTLVReader reader; @@ -402,19 +402,20 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload) } SuccessOrExit(err); - err = report.GetEventDataList(&eventList); - isEventListPresent = (err == CHIP_NO_ERROR); + err = report.GetEventReports(&EventReports); + isEventReportsPresent = (err == CHIP_NO_ERROR); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; } SuccessOrExit(err); - if (isEventListPresent && nullptr != mpCallback) + if (isEventReportsPresent && nullptr != mpCallback) { - chip::TLV::TLVReader eventListReader; - eventList.GetReader(&eventListReader); - mpCallback->OnEventData(this, eventListReader); + chip::TLV::TLVReader EventReportsReader; + EventReports.GetReader(&EventReportsReader); + ChipLogProgress(DataManagement, "on event data is called!!!!!!!!!!!!!"); + mpCallback->OnEventData(this, EventReportsReader); } err = report.GetAttributeDataList(&attributeDataList); diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index f019fcf762497b..86508c425c3ada 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -64,12 +64,12 @@ class ReadClient : public Messaging::ExchangeDelegate * The ReadClient object MUST continue to exist after this call is completed. * * @param[in] apReadClient The read client which initialized the read transaction. - * @param[in] apEventListReader TLV reader positioned at the list that contains the events. The + * @param[in] apEventReportsReader TLV reader positioned at the list that contains the events. The * implementation of EventStreamReceived is expected to call Next() on the reader to * advance it to the first element of the list, then process the elements from beginning to * the end. The callee is expected to consume all events. */ - virtual void OnEventData(const ReadClient * apReadClient, TLV::TLVReader & aEventList) {} + virtual void OnEventData(const ReadClient * apReadClient, TLV::TLVReader & aEventReports) {} /** * OnResponse will be called when a report data response has been received and processed for the given path. diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 54bc91aac4c2af..7c839dd5aa4d9c 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -154,7 +154,7 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeDataList(ReportDataMessage::Bui return err; } -CHIP_ERROR Engine::BuildSingleReportDataEventList(ReportDataMessage::Builder & aReportDataBuilder, ReadHandler * apReadHandler) +CHIP_ERROR Engine::BuildSingleReportDataEventReports(ReportDataMessage::Builder & aReportDataBuilder, ReadHandler * apReadHandler) { CHIP_ERROR err = CHIP_NO_ERROR; size_t eventCount = 0; @@ -164,15 +164,15 @@ CHIP_ERROR Engine::BuildSingleReportDataEventList(ReportDataMessage::Builder & a ClusterInfo * clusterInfoList = apReadHandler->GetEventClusterInfolist(); EventNumber * eventNumberList = apReadHandler->GetVendedEventNumberList(); EventManagement & eventManager = EventManagement::GetInstance(); - EventList::Builder eventList; + EventReports::Builder EventReports; aReportDataBuilder.Checkpoint(backup); VerifyOrExit(clusterInfoList != nullptr, ); VerifyOrExit(apReadHandler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); - eventList = aReportDataBuilder.CreateEventDataListBuilder(); - SuccessOrExit(err = eventList.GetError()); + EventReports = aReportDataBuilder.CreateEventReportsBuilder(); + SuccessOrExit(err = EventReports.GetError()); memcpy(initialEvents, eventNumberList, sizeof(initialEvents)); // If the eventManager is not valid or has not been initialized, @@ -199,7 +199,7 @@ CHIP_ERROR Engine::BuildSingleReportDataEventList(ReportDataMessage::Builder & a while (apReadHandler->GetCurrentPriority() != PriorityLevel::Invalid) { uint8_t priorityIndex = static_cast(apReadHandler->GetCurrentPriority()); - err = eventManager.FetchEventsSince(*(eventList.GetWriter()), clusterInfoList, apReadHandler->GetCurrentPriority(), + err = eventManager.FetchEventsSince(*(EventReports.GetWriter()), clusterInfoList, apReadHandler->GetCurrentPriority(), eventNumberList[priorityIndex], eventCount); if ((err == CHIP_END_OF_TLV) || (err == CHIP_ERROR_TLV_UNDERRUN) || (err == CHIP_NO_ERROR)) @@ -244,8 +244,8 @@ CHIP_ERROR Engine::BuildSingleReportDataEventList(ReportDataMessage::Builder & a } } - eventList.EndOfEventList(); - SuccessOrExit(err = eventList.GetError()); + EventReports.EndOfEventReports(); + SuccessOrExit(err = EventReports.GetError()); ChipLogDetail(DataManagement, "Fetched %zu events", eventCount); @@ -282,7 +282,7 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler) err = BuildSingleReportDataAttributeDataList(reportDataBuilder, apReadHandler); SuccessOrExit(err); - err = BuildSingleReportDataEventList(reportDataBuilder, apReadHandler); + err = BuildSingleReportDataEventReports(reportDataBuilder, apReadHandler); SuccessOrExit(err); // TODO: Add mechanism to set mSuppressResponse to handle status reports for multiple reports diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index 69ec6d7e04249d..02e513b707d027 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -93,7 +93,7 @@ class Engine CHIP_ERROR BuildAndSendSingleReportData(ReadHandler * apReadHandler); CHIP_ERROR BuildSingleReportDataAttributeDataList(ReportDataMessage::Builder & reportDataBuilder, ReadHandler * apReadHandler); - CHIP_ERROR BuildSingleReportDataEventList(ReportDataMessage::Builder & reportDataBuilder, ReadHandler * apReadHandler); + CHIP_ERROR BuildSingleReportDataEventReports(ReportDataMessage::Builder & reportDataBuilder, ReadHandler * apReadHandler); CHIP_ERROR RetrieveClusterData(FabricIndex aAccessingFabricIndex, AttributeDataList::Builder & aAttributeDataList, ClusterInfo & aClusterInfo); EventNumber CountEvents(ReadHandler * apReadHandler, EventNumber * apInitialEvents); diff --git a/src/app/tests/TestEventLogging.cpp b/src/app/tests/TestEventLogging.cpp index 0511a183f56d1b..68bc9956c3a5fd 100644 --- a/src/app/tests/TestEventLogging.cpp +++ b/src/app/tests/TestEventLogging.cpp @@ -50,9 +50,9 @@ static const uint32_t kLivenessChangeEvent = 1; static const chip::EndpointId kTestEndpointId = 2; static const chip::TLV::Tag kLivenessDeviceStatus = chip::TLV::ContextTag(1); -static uint8_t gDebugEventBuffer[128]; -static uint8_t gInfoEventBuffer[128]; -static uint8_t gCritEventBuffer[128]; +static uint8_t gDebugEventBuffer[256]; +static uint8_t gInfoEventBuffer[256]; +static uint8_t gCritEventBuffer[256]; static chip::app::CircularEventBuffer gCircularEventBuffer[3]; class TestContext : public chip::Test::AppContext diff --git a/src/app/tests/TestMessageDef.cpp b/src/app/tests/TestMessageDef.cpp index 0200590b14c776..574ac8206ef314 100644 --- a/src/app/tests/TestMessageDef.cpp +++ b/src/app/tests/TestMessageDef.cpp @@ -73,6 +73,33 @@ CHIP_ERROR DebugPrettyPrint(const chip::System::PacketBufferHandle & aMsgBuf) return err; } +void BuildStatusIB(nlTestSuite * apSuite, StatusIB::Builder & aStatusIBBuilder) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + StatusIB statusIB; + statusIB.mStatus = chip::Protocols::InteractionModel::Status::InvalidSubscription; + aStatusIBBuilder.EncodeStatusIB(statusIB); + err = aStatusIBBuilder.GetError(); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); +} + +void ParseStatusIB(nlTestSuite * apSuite, StatusIB::Parser & aStatusIBParser) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + StatusIB::Parser StatusIBParser; + StatusIB statusIB; + +#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK + err = aStatusIBParser.CheckSchemaValidity(); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); +#endif + err = aStatusIBParser.DecodeStatusIB(statusIB); + NL_TEST_ASSERT(apSuite, + err == CHIP_NO_ERROR && statusIB.mStatus == chip::Protocols::InteractionModel::Status::InvalidSubscription && + !statusIB.mClusterStatus.HasValue()); +} + void BuildEventFilterIB(nlTestSuite * apSuite, EventFilterIB::Builder & aEventFilterIBBuilder) { aEventFilterIBBuilder.Node(1).EventMin(2).EndOfEventFilterIB(); @@ -227,7 +254,7 @@ void ParseEventPath(nlTestSuite * apSuite, EventPathIB::Parser & aEventPathParse void BuildEventPaths(nlTestSuite * apSuite, EventPaths::Builder & aEventPathsBuilder) { - EventPathIB::Builder eventPathBuilder = aEventPathsBuilder.CreateEventPath(); + EventPathIB::Builder eventPathBuilder = aEventPathsBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); BuildEventPath(apSuite, eventPathBuilder); @@ -279,28 +306,24 @@ void ParseCommandPath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && commandId == 4); } -void BuildEventDataElement(nlTestSuite * apSuite, EventDataElement::Builder & aEventDataElementBuilder) +void BuildEventDataIB(nlTestSuite * apSuite, EventDataIB::Builder & aEventDataIBBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; - EventPathIB::Builder eventPathBuilder = aEventDataElementBuilder.CreateEventPath(); + EventPathIB::Builder eventPathBuilder = aEventDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); BuildEventPath(apSuite, eventPathBuilder); - aEventDataElementBuilder.PriorityLevel(2) - .Number(3) - .UTCTimestamp(4) - .SystemTimestamp(5) - .DeltaUTCTimestamp(6) - .DeltaSystemTimestamp(7); - err = aEventDataElementBuilder.GetError(); + aEventDataIBBuilder.Priority(2).EventNumber(3).EpochTimestamp(4).SystemTimestamp(5).DeltaEpochTimestamp(6).DeltaSystemTimestamp( + 7); + err = aEventDataIBBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); // Construct test event data { - chip::TLV::TLVWriter * pWriter = aEventDataElementBuilder.GetWriter(); + chip::TLV::TLVWriter * pWriter = aEventDataIBBuilder.GetWriter(); chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; - err = - pWriter->StartContainer(chip::TLV::ContextTag(EventDataElement::kCsTag_Data), chip::TLV::kTLVType_Structure, dummyType); + err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(EventDataIB::Tag::kData)), + chip::TLV::kTLVType_Structure, dummyType); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); @@ -310,47 +333,47 @@ void BuildEventDataElement(nlTestSuite * apSuite, EventDataElement::Builder & aE NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } - aEventDataElementBuilder.EndOfEventDataElement(); + aEventDataIBBuilder.EndOfEventDataIB(); } -void ParseEventDataElement(nlTestSuite * apSuite, EventDataElement::Parser & aEventDataElementParser) +void ParseEventDataIB(nlTestSuite * apSuite, EventDataIB::Parser & aEventDataIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; - uint8_t importanceLevel = 0; - uint64_t number = 0; - uint64_t uTCTimestamp = 0; + uint8_t priorityLevel = 0; + chip::EventNumber number = 0; + uint64_t EpochTimestamp = 0; uint64_t systemTimestamp = 0; uint64_t deltaUTCTimestamp = 0; uint64_t deltaSystemTimestamp = 0; #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - err = aEventDataElementParser.CheckSchemaValidity(); + err = aEventDataIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif { { EventPathIB::Parser eventPath; - err = aEventDataElementParser.GetEventPath(&eventPath); + err = aEventDataIBParser.GetPath(&eventPath); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } - err = aEventDataElementParser.GetPriorityLevel(&importanceLevel); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && importanceLevel == 2); - err = aEventDataElementParser.GetNumber(&number); + err = aEventDataIBParser.GetPriority(&priorityLevel); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && priorityLevel == 2); + err = aEventDataIBParser.GetEventNumber(&number); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && number == 3); - err = aEventDataElementParser.GetUTCTimestamp(&uTCTimestamp); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && uTCTimestamp == 4); - err = aEventDataElementParser.GetSystemTimestamp(&systemTimestamp); + err = aEventDataIBParser.GetEpochTimestamp(&EpochTimestamp); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && EpochTimestamp == 4); + err = aEventDataIBParser.GetSystemTimestamp(&systemTimestamp); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && systemTimestamp == 5); - err = aEventDataElementParser.GetDeltaUTCTimestamp(&deltaUTCTimestamp); + err = aEventDataIBParser.GetDeltaEpochTimestamp(&deltaUTCTimestamp); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaUTCTimestamp == 6); - err = aEventDataElementParser.GetDeltaSystemTimestamp(&deltaSystemTimestamp); + err = aEventDataIBParser.GetDeltaSystemTimestamp(&deltaSystemTimestamp); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaSystemTimestamp == 7); { chip::TLV::TLVReader reader; bool val = false; chip::TLV::TLVType container; - aEventDataElementParser.GetData(&reader); + aEventDataIBParser.GetData(&reader); err = reader.EnterContainer(container); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -366,84 +389,87 @@ void ParseEventDataElement(nlTestSuite * apSuite, EventDataElement::Parser & aEv } } -void BuildEventList(nlTestSuite * apSuite, EventList::Builder & aEventListBuilder) +void BuildEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Builder & aEventStatusIBBuilder) { - EventDataElement::Builder eventDataElementBuilder = aEventListBuilder.CreateEventBuilder(); - NL_TEST_ASSERT(apSuite, eventDataElementBuilder.GetError() == CHIP_NO_ERROR); - BuildEventDataElement(apSuite, eventDataElementBuilder); + EventPathIB::Builder eventPathBuilder = aEventStatusIBBuilder.CreatePath(); + NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); + BuildEventPath(apSuite, eventPathBuilder); - aEventListBuilder.EndOfEventList(); - NL_TEST_ASSERT(apSuite, aEventListBuilder.GetError() == CHIP_NO_ERROR); + StatusIB::Builder statusIBBuilder = aEventStatusIBBuilder.CreateErrorStatus(); + NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); + BuildStatusIB(apSuite, statusIBBuilder); + + aEventStatusIBBuilder.EndOfEventStatusIB(); + NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); } -void ParseEventList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Parser & aEventStatusIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; - EventList::Parser eventListParser; - - err = eventListParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EventPathIB::Parser eventPathParser; + StatusIB::Parser statusParser; #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - err = eventListParser.CheckSchemaValidity(); + err = aEventStatusIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif + err = aEventStatusIBParser.GetPath(&eventPathParser); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + + err = aEventStatusIBParser.GetErrorStatus(&statusParser); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } -void BuildStatusIB(nlTestSuite * apSuite, StatusIB::Builder & aStatusIBBuilder) +void BuildEventReportIB(nlTestSuite * apSuite, EventReportIB::Builder & aEventReportIBBuilder) { - CHIP_ERROR err = CHIP_NO_ERROR; + EventStatusIB::Builder eventStatusIBBuilder = aEventReportIBBuilder.CreateEventStatus(); + NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); + BuildEventStatusIB(apSuite, eventStatusIBBuilder); - StatusIB statusIB; - statusIB.mStatus = chip::Protocols::InteractionModel::Status::InvalidSubscription; - aStatusIBBuilder.EncodeStatusIB(statusIB); - err = aStatusIBBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EventDataIB::Builder eventDataIBBuilder = aEventReportIBBuilder.CreateEventData(); + NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); + BuildEventDataIB(apSuite, eventDataIBBuilder); + + aEventReportIBBuilder.EndOfEventReportIB(); + NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); } -void ParseStatusIB(nlTestSuite * apSuite, StatusIB::Parser & aStatusIBParser) +void ParseEventReportIB(nlTestSuite * apSuite, EventReportIB::Parser & aEventReportIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; - StatusIB::Parser StatusIBParser; - StatusIB statusIB; + EventStatusIB::Parser eventStatusParser; + EventDataIB::Parser eventDataParser; #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - err = aStatusIBParser.CheckSchemaValidity(); + err = aEventReportIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = aStatusIBParser.DecodeStatusIB(statusIB); - NL_TEST_ASSERT(apSuite, - err == CHIP_NO_ERROR && statusIB.mStatus == chip::Protocols::InteractionModel::Status::InvalidSubscription && - !statusIB.mClusterStatus.HasValue()); + err = aEventReportIBParser.GetEventStatus(&eventStatusParser); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + err = aEventReportIBParser.GetEventData(&eventDataParser); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } -void BuildEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Builder & aEventStatusIBBuilder) +void BuildEventReports(nlTestSuite * apSuite, EventReports::Builder & aEventReportsBuilder) { - EventPathIB::Builder eventPathBuilder = aEventStatusIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); - BuildEventPath(apSuite, eventPathBuilder); + EventReportIB::Builder eventReportIBBuilder = aEventReportsBuilder.CreateEventReport(); + NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR); + BuildEventReportIB(apSuite, eventReportIBBuilder); - StatusIB::Builder statusIBBuilder = aEventStatusIBBuilder.CreateErrorStatus(); - NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); - BuildStatusIB(apSuite, statusIBBuilder); - - aEventStatusIBBuilder.EndOfEventStatusIB(); - NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); + aEventReportsBuilder.EndOfEventReports(); + NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR); } -void ParseEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Parser & aEventStatusIBParser) +void ParseEventReports(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; - EventPathIB::Parser eventPathParser; - StatusIB::Parser statusParser; + EventReports::Parser eventReportsParser; + + err = eventReportsParser.Init(aReader); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - err = aEventStatusIBParser.CheckSchemaValidity(); + err = eventReportsParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = aEventStatusIBParser.GetPath(&eventPathParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - - err = aEventStatusIBParser.GetErrorStatus(&statusParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } void BuildAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Builder & aAttributeStatusIBBuilder) @@ -904,9 +930,9 @@ void BuildReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWrite NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); BuildAttributeDataList(apSuite, attributeDataList); - EventList::Builder eventList = reportDataBuilder.CreateEventDataListBuilder(); + EventReports::Builder EventReports = reportDataBuilder.CreateEventReportsBuilder(); NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); - BuildEventList(apSuite, eventList); + BuildEventReports(apSuite, EventReports); reportDataBuilder.MoreChunkedMessages(true); NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); @@ -923,7 +949,7 @@ void ParseReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReade bool suppressResponse = false; uint64_t subscriptionId = 0; AttributeDataList::Parser attributeDataListParser; - EventList::Parser eventListParser; + EventReports::Parser EventReportsParser; bool moreChunkedMessages = false; reportDataParser.Init(aReader); @@ -940,7 +966,7 @@ void ParseReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReade err = reportDataParser.GetAttributeDataList(&attributeDataListParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = reportDataParser.GetEventDataList(&eventListParser); + err = reportDataParser.GetEventReports(&EventReportsParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); err = reportDataParser.GetMoreChunkedMessages(&moreChunkedMessages); @@ -1416,16 +1442,40 @@ void CommandPathIBTest(nlTestSuite * apSuite, void * apContext) ParseCommandPath(apSuite, reader); } -void EventDataElementTest(nlTestSuite * apSuite, void * apContext) +void EventDataIBTest(nlTestSuite * apSuite, void * apContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + EventDataIB::Builder eventDataIBBuilder; + EventDataIB::Parser eventDataIBParser; + chip::System::PacketBufferTLVWriter writer; + chip::System::PacketBufferTLVReader reader; + writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); + eventDataIBBuilder.Init(&writer); + BuildEventDataIB(apSuite, eventDataIBBuilder); + chip::System::PacketBufferHandle buf; + err = writer.Finalize(&buf); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + + DebugPrettyPrint(buf); + + reader.Init(std::move(buf)); + err = reader.Next(); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + + eventDataIBParser.Init(reader); + ParseEventDataIB(apSuite, eventDataIBParser); +} + +void EventReportIBTest(nlTestSuite * apSuite, void * apContext) { CHIP_ERROR err = CHIP_NO_ERROR; - EventDataElement::Builder eventDataElementBuilder; - EventDataElement::Parser eventDataElementParser; + EventReportIB::Builder eventReportIBBuilder; + EventReportIB::Parser eventReportIBParser; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - eventDataElementBuilder.Init(&writer); - BuildEventDataElement(apSuite, eventDataElementBuilder); + eventReportIBBuilder.Init(&writer); + BuildEventReportIB(apSuite, eventReportIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1436,19 +1486,19 @@ void EventDataElementTest(nlTestSuite * apSuite, void * apContext) err = reader.Next(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - eventDataElementParser.Init(reader); - ParseEventDataElement(apSuite, eventDataElementParser); + eventReportIBParser.Init(reader); + ParseEventReportIB(apSuite, eventReportIBParser); } -void EventListTest(nlTestSuite * apSuite, void * apContext) +void EventReportsTest(nlTestSuite * apSuite, void * apContext) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; - EventList::Builder eventListBuilder; + EventReports::Builder eventReportsBuilder; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - eventListBuilder.Init(&writer); - BuildEventList(apSuite, eventListBuilder); + eventReportsBuilder.Init(&writer); + BuildEventReports(apSuite, eventReportsBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1458,7 +1508,7 @@ void EventListTest(nlTestSuite * apSuite, void * apContext) reader.Init(std::move(buf)); err = reader.Next(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseEventList(apSuite, reader); + ParseEventReports(apSuite, reader); } void StatusIBTest(nlTestSuite * apSuite, void * apContext) @@ -2020,8 +2070,9 @@ const nlTest sTests[] = NL_TEST_DEF("AttributePathListTest", AttributePathListTest), NL_TEST_DEF("EventPathTest", EventPathTest), NL_TEST_DEF("EventPathsTest", EventPathsTest), - NL_TEST_DEF("EventDataElementTest", EventDataElementTest), - NL_TEST_DEF("EventListTest", EventListTest), + NL_TEST_DEF("EventDataIBTest", EventDataIBTest), + NL_TEST_DEF("EventReportIBTest", EventReportIBTest), + NL_TEST_DEF("EventReportsTest", EventReportsTest), NL_TEST_DEF("StatusIBTest", StatusIBTest), NL_TEST_DEF("EventStatusIBTest", EventStatusIBTest), NL_TEST_DEF("AttributeStatusIBTest", AttributeStatusIBTest), diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index f5db2d8e039437..b1cae917314721 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -156,25 +156,27 @@ void GenerateSubscribeResponse(nlTestSuite * apSuite, void * apContext, chip::Sy class MockInteractionModelApp : public chip::app::ReadClient::Callback, public chip::app::InteractionModelDelegate { public: - void OnEventData(const chip::app::ReadClient * apReadClient, chip::TLV::TLVReader & apEventListReader) override + void OnEventData(const chip::app::ReadClient * apReadClient, chip::TLV::TLVReader & apEventReportsReader) override { CHIP_ERROR err = CHIP_NO_ERROR; chip::TLV::TLVReader reader; int numDataElementIndex = 0; - reader.Init(apEventListReader); + reader.Init(apEventReportsReader); while (CHIP_NO_ERROR == (err = reader.Next())) { uint8_t priorityLevel = 0; - chip::app::EventDataElement::Parser event; - VerifyOrReturn(event.Init(reader) == CHIP_NO_ERROR); - VerifyOrReturn(event.GetPriorityLevel(&priorityLevel) == CHIP_NO_ERROR); + chip::app::EventReportIB::Parser eventReport; + chip::app::EventDataIB::Parser eventData; + VerifyOrReturn(eventReport.Init(reader) == CHIP_NO_ERROR); + VerifyOrReturn(eventReport.GetEventData(&eventData) == CHIP_NO_ERROR); + VerifyOrReturn(eventData.GetPriority(&priorityLevel) == CHIP_NO_ERROR); if (numDataElementIndex == 0) { - VerifyOrReturn(priorityLevel == static_cast(chip::app::PriorityLevel::Critical)); + VerifyOrReturn(priorityLevel == chip::to_underlying(chip::app::PriorityLevel::Critical)); } else if (numDataElementIndex == 1) { - VerifyOrReturn(priorityLevel == static_cast(chip::app::PriorityLevel::Info)); + VerifyOrReturn(priorityLevel == chip::to_underlying(chip::app::PriorityLevel::Info)); } ++numDataElementIndex; } diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index 2bf9bc9ecb8bf8..7f07735ab9caec 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -132,7 +132,7 @@ class MockInteractionModelApp : public chip::app::InteractionModelDelegate, public ::chip::app::ReadClient::Callback { public: - void OnEventData(const chip::app::ReadClient * apReadClient, chip::TLV::TLVReader & apEventListReader) override {} + void OnEventData(const chip::app::ReadClient * apReadClient, chip::TLV::TLVReader & apEventReportsReader) override {} void OnSubscriptionEstablished(const chip::app::ReadClient * apReadClient) override { if (apReadClient->IsSubscriptionType())