From 479a30fad2e60aa3d52134b9466197a734f031fa Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Wed, 15 Dec 2021 13:33:05 -0800 Subject: [PATCH] Shift event number from priority-based to global-based (#13021) --- src/app/EventLoggingTypes.h | 4 +- src/app/EventManagement.cpp | 306 +++++++----------- src/app/EventManagement.h | 116 ++----- src/app/ReadClient.cpp | 21 +- src/app/ReadClient.h | 1 + src/app/ReadHandler.cpp | 150 ++++----- src/app/ReadHandler.h | 16 +- src/app/reporting/Engine.cpp | 81 ++--- src/app/reporting/Engine.h | 1 - src/app/server/Server.cpp | 21 +- src/app/tests/TestEventLogging.cpp | 47 +-- src/app/tests/TestReadInteraction.cpp | 25 +- .../tests/integration/chip_im_responder.cpp | 8 +- src/include/platform/CHIPDeviceConfig.h | 28 +- src/platform/EFR32/CHIPDevicePlatformConfig.h | 5 +- src/platform/cc13x2_26x2/CHIPPlatformConfig.h | 5 +- .../nxp/k32w/k32w0/CHIPDevicePlatformConfig.h | 4 +- src/platform/qpg/CHIPDevicePlatformConfig.h | 4 +- 18 files changed, 312 insertions(+), 531 deletions(-) diff --git a/src/app/EventLoggingTypes.h b/src/app/EventLoggingTypes.h index 742c2c71892117..8ef91c418bba8c 100644 --- a/src/app/EventLoggingTypes.h +++ b/src/app/EventLoggingTypes.h @@ -149,8 +149,7 @@ class EventOptions struct EventLoadOutContext { EventLoadOutContext(TLV::TLVWriter & aWriter, PriorityLevel aPriority, EventNumber aStartingEventNumber) : - mWriter(aWriter), mPriority(aPriority), mStartingEventNumber(aStartingEventNumber), mCurrentEventNumber(0), mFirst(true), - mSamePriorityEvent(false) + mWriter(aWriter), mPriority(aPriority), mStartingEventNumber(aStartingEventNumber), mCurrentEventNumber(0), mFirst(true) {} TLV::TLVWriter & mWriter; @@ -162,7 +161,6 @@ struct EventLoadOutContext size_t mEventCount = 0; ClusterInfo * mpInterestedEventPaths = nullptr; bool mFirst = true; - bool mSamePriorityEvent = false; }; } // namespace app } // namespace chip diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp index 0f522832e94dea..10f7c289c651b6 100644 --- a/src/app/EventManagement.cpp +++ b/src/app/EventManagement.cpp @@ -88,18 +88,43 @@ struct EventEnvelopeContext int mFieldsToRead = 0; /* PriorityLevel and DeltaTime are there if that is not first event when putting events in report*/ #if CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS & CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME - Timestamp mDeltaTime = Timestamp::System(System::Clock::kZero); + Timestamp mCurrentTime = Timestamp::System(System::Clock::kZero); #else - Timestamp mDeltaTime = Timestamp::Epoch(System::Clock::kZero); + Timestamp mCurrentTime = Timestamp::Epoch(System::Clock::kZero); #endif - PriorityLevel mPriority = PriorityLevel::First; - ClusterId mClusterId = 0; - EndpointId mEndpointId = 0; - EventId mEventId = 0; + PriorityLevel mPriority = PriorityLevel::First; + ClusterId mClusterId = 0; + EndpointId mEndpointId = 0; + EventId mEventId = 0; + EventNumber mEventNumber = 0; }; +void EventManagement::InitializeCounter(Platform::PersistedStorage::Key * apCounterKey, uint32_t aCounterEpoch, + PersistedCounter * apPersistedCounter) +{ + PersistedCounter * eventNumberCounter = nullptr; + if (apPersistedCounter != nullptr && apCounterKey != nullptr && aCounterEpoch != 0) + { + eventNumberCounter = + (apPersistedCounter->Init(*apCounterKey, aCounterEpoch) == CHIP_NO_ERROR) ? apPersistedCounter : nullptr; + } + + if (eventNumberCounter == nullptr) + { + mNonPersistedCounter.Init(0); + mpEventNumberCounter = &(mNonPersistedCounter); + } + else + { + mpEventNumberCounter = eventNumberCounter; + } + mLastEventNumber = mpEventNumberCounter->GetValue(); +} + void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, - CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources) + CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources, + Platform::PersistedStorage::Key * apCounterKey, uint32_t aCounterEpoch, + PersistedCounter * apPersistedCounter) { CircularEventBuffer * current = nullptr; CircularEventBuffer * prev = nullptr; @@ -130,9 +155,10 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3 current->mProcessEvictedElement = AlwaysFail; current->mAppData = nullptr; - current->InitCounter(apLogStorageResources[bufferIndex].InitializeCounter()); } + InitializeCounter(apCounterKey, aCounterEpoch, apPersistedCounter); + mpEventBuffer = apCircularEventBuffer; mState = EventManagementStates::Idle; mBytesWritten = 0; @@ -275,10 +301,8 @@ CHIP_ERROR EventManagement::EnsureSpaceInCircularBuffer(size_t aRequiredSpace) CHIP_ERROR EventManagement::CalculateEventSize(EventLoggingDelegate * apDelegate, const EventOptions * apOptions, uint32_t & requiredSize) { - CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVWriter writer; - EventLoadOutContext ctxt = - EventLoadOutContext(writer, apOptions->mPriority, GetPriorityBuffer(apOptions->mPriority)->GetLastEventNumber()); + EventLoadOutContext ctxt = EventLoadOutContext(writer, apOptions->mPriority, GetLastEventNumber()); System::PacketBufferHandle buf = System::PacketBufferHandle::New(kMaxEventSizeReserve); if (buf.IsNull()) { @@ -286,22 +310,12 @@ CHIP_ERROR EventManagement::CalculateEventSize(EventLoggingDelegate * apDelegate } writer.Init(std::move(buf)); - ctxt.mCurrentEventNumber = GetPriorityBuffer(apOptions->mPriority)->GetLastEventNumber(); - ctxt.mCurrentTime.mValue = GetPriorityBuffer(apOptions->mPriority)->GetLastEventTimestamp(); - - TLVWriter checkpoint = ctxt.mWriter; - err = ConstructEvent(&ctxt, apDelegate, apOptions); - if (err != CHIP_NO_ERROR) - { - ctxt.mWriter = checkpoint; - } - else + ctxt.mCurrentEventNumber = mLastEventNumber; + ctxt.mCurrentTime = mLastEventTimestamp; + CHIP_ERROR err = ConstructEvent(&ctxt, apDelegate, apOptions); + if (err == CHIP_NO_ERROR) { - // update these variables since ConstructEvent can be used to track the - // state of a set of events over multiple calls. - ctxt.mCurrentEventNumber++; - ctxt.mCurrentTime = apOptions->mTimestamp; - requiredSize = writer.GetLengthWritten(); + requiredSize = writer.GetLengthWritten(); } return err; } @@ -309,7 +323,6 @@ CHIP_ERROR EventManagement::CalculateEventSize(EventLoggingDelegate * apDelegate CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, EventLoggingDelegate * apDelegate, const EventOptions * apOptions) { - uint64_t deltatime = 0; VerifyOrReturnError(apContext->mCurrentEventNumber >= apContext->mStartingEventNumber, CHIP_NO_ERROR /* no-op: don't write event, but advance current event Number */); @@ -330,17 +343,16 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even .IsUrgent(false) .EndOfEventPathIB(); ReturnErrorOnFailure(eventPathBuilder.GetError()); - eventDataIBBuilder.Priority(chip::to_underlying(apContext->mPriority)); + eventDataIBBuilder.EventNumber(apContext->mCurrentEventNumber).Priority(chip::to_underlying(apContext->mPriority)); ReturnErrorOnFailure(eventDataIBBuilder.GetError()); - deltatime = apOptions->mTimestamp.mValue - apContext->mCurrentTime.mValue; if (apOptions->mTimestamp.IsSystem()) { - eventDataIBBuilder.DeltaSystemTimestamp(deltatime); + eventDataIBBuilder.SystemTimestamp(apOptions->mTimestamp.mValue); } else { - eventDataIBBuilder.DeltaEpochTimestamp(deltatime); + eventDataIBBuilder.EpochTimestamp(apOptions->mTimestamp.mValue); } ReturnErrorOnFailure(eventDataIBBuilder.GetError()); @@ -358,10 +370,13 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even void EventManagement::CreateEventManagement(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, CircularEventBuffer * apCircularEventBuffer, - const LogStorageResources * const apLogStorageResources) + const LogStorageResources * const apLogStorageResources, + Platform::PersistedStorage::Key * apCounterKey, uint32_t aCounterEpoch, + PersistedCounter * apPersistedCounter) { - sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources); + sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apCounterKey, aCounterEpoch, + apPersistedCounter); } /** @@ -377,34 +392,6 @@ void EventManagement::DestroyEventManagement() sInstance.mpExchangeMgr = nullptr; } -EventNumber CircularEventBuffer::VendEventNumber() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // Assign event Number to the buffer's counter's value. - mLastEventNumber = static_cast(mpEventNumberCounter->GetValue()); - - // Now advance the counter. - err = mpEventNumberCounter->Advance(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(EventLogging, "%s Advance() for priority %u failed with %" CHIP_ERROR_FORMAT, __FUNCTION__, - static_cast(mPriority), err.Format()); - } - - return mLastEventNumber; -} - -EventNumber EventManagement::GetLastEventNumber(PriorityLevel aPriority) -{ - return GetPriorityBuffer(aPriority)->GetLastEventNumber(); -} - -EventNumber EventManagement::GetFirstEventNumber(PriorityLevel aPriority) -{ - return GetPriorityBuffer(aPriority)->GetFirstEventNumber(); -} - CircularEventBuffer * EventManagement::GetPriorityBuffer(PriorityLevel aPriority) const { CircularEventBuffer * buf = mpEventBuffer; @@ -419,51 +406,39 @@ CircularEventBuffer * EventManagement::GetPriorityBuffer(PriorityLevel aPriority CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, size_t aDepth, void * apContext) { - CHIP_ERROR err; + CHIP_ERROR err = CHIP_NO_ERROR; CopyAndAdjustDeltaTimeContext * ctx = static_cast(apContext); TLVReader reader(aReader); - if (aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)) || - aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaEpochTimestamp))) + if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst)) { - if (ctx->mpContext->mFirst) // First event gets a timestamp, subsequent ones get a delta T - { - if (ctx->mpContext->mCurrentTime.IsSystem()) - { - err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp)), - ctx->mpContext->mCurrentTime.mValue); - } - else - { - err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp)), - ctx->mpContext->mCurrentTime.mValue); - } - } - else - { - if (ctx->mpContext->mCurrentTime.IsSystem()) - { - err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)), - ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue); - } - else - { - err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaEpochTimestamp)), - ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue); - } - } + err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)), + ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue); + } + else if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) && !(ctx->mpContext->mFirst)) + { + err = ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaEpochTimestamp)), + ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue); } else { err = ctx->mpWriter->CopyElement(reader); } + return err; +} - if (aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kPath))) +void EventManagement::VendEventNumber() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + // Now advance the counter. + err = mpEventNumberCounter->Advance(); + if (err != CHIP_NO_ERROR) { - err = - ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kEventNumber)), ctx->mpContext->mCurrentEventNumber); + ChipLogError(EventLogging, "%s Advance() failed with %" CHIP_ERROR_FORMAT, __FUNCTION__, err.Format()); } - return err; + + // Assign event Number to the buffer's counter's value. + mLastEventNumber = static_cast(mpEventNumberCounter->GetValue()); } CHIP_ERROR EventManagement::LogEvent(EventLoggingDelegate * apDelegate, EventOptions & aEventOptions, EventNumber & aEventNumber) @@ -490,8 +465,7 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, E aEventNumber = 0; CircularEventBuffer checkpoint = *mpEventBuffer; CircularEventBuffer * buffer = nullptr; - EventLoadOutContext ctxt = - EventLoadOutContext(writer, aEventOptions.mPriority, GetPriorityBuffer(aEventOptions.mPriority)->GetLastEventNumber()); + EventLoadOutContext ctxt = EventLoadOutContext(writer, aEventOptions.mPriority, mLastEventNumber); EventOptions opts; #if CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS & CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME Timestamp timestamp; @@ -507,23 +481,16 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, E opts = EventOptions(timestamp); // Start the event container (anonymous structure) in the circular buffer writer.Init(*mpEventBuffer); - // check whether the entry is to be logged or discarded silently - VerifyOrExit(aEventOptions.mPriority >= CHIP_CONFIG_EVENT_GLOBAL_PRIORITY, /* no-op */); opts.mPriority = aEventOptions.mPriority; // Create all event specific data // Timestamp; encoded as a delta time - if (GetPriorityBuffer(aEventOptions.mPriority)->GetFirstEventTimestamp() == 0) - { - GetPriorityBuffer(aEventOptions.mPriority)->UpdateFirstLastEventTime(opts.mTimestamp); - } - opts.mUrgent = aEventOptions.mUrgent; opts.mPath = aEventOptions.mPath; - ctxt.mCurrentEventNumber = GetPriorityBuffer(opts.mPriority)->GetLastEventNumber(); - ctxt.mCurrentTime.mValue = GetPriorityBuffer(opts.mPriority)->GetLastEventTimestamp(); + ctxt.mCurrentEventNumber = mLastEventNumber; + ctxt.mCurrentTime.mValue = mLastEventTimestamp.mValue; err = CalculateEventSize(apDelegate, &opts, requestSize); SuccessOrExit(err); @@ -562,10 +529,9 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, E } else if (opts.mPriority >= CHIP_CONFIG_EVENT_GLOBAL_PRIORITY) { - CircularEventBuffer * currentBuffer = GetPriorityBuffer(opts.mPriority); - aEventNumber = currentBuffer->VendEventNumber(); - currentBuffer->UpdateFirstLastEventTime(opts.mTimestamp); - + aEventNumber = mLastEventNumber; + VendEventNumber(); + mLastEventTimestamp = timestamp; #if CHIP_CONFIG_EVENT_LOGGING_VERBOSE_DEBUG_LOGS ChipLogDetail(EventLogging, "LogEvent event number: 0x" ChipLogFormatX64 " schema priority: %u, endpoint id: 0x%" PRIx16 @@ -656,18 +622,13 @@ CHIP_ERROR EventManagement::EventIterator(const TLVReader & aReader, size_t aDep } ReturnErrorOnFailure(err); - if (event.mPriority == apEventLoadOutContext->mPriority) + apEventLoadOutContext->mCurrentTime = event.mCurrentTime; + apEventLoadOutContext->mCurrentEventNumber = event.mEventNumber; + if (IsInterestedEventPaths(apEventLoadOutContext, event)) { - apEventLoadOutContext->mCurrentTime.mValue += event.mDeltaTime.mValue; - // If the retrieved event has the same priority as the one set by FetchEventSince, we need to use mSamePriorityEvent to - // increase the event number after encoding the current event number. Then this updated event number will be used by - // FetchEventSince for next use - apEventLoadOutContext->mSamePriorityEvent = true; - if (IsInterestedEventPaths(apEventLoadOutContext, event)) - { - return CHIP_EVENT_ID_FOUND; - } + return CHIP_EVENT_ID_FOUND; } + return CHIP_NO_ERROR; } @@ -696,40 +657,25 @@ CHIP_ERROR EventManagement::CopyEventsSince(const TLVReader & aReader, size_t aD loadOutContext->mFirst = false; loadOutContext->mEventCount++; } - if (loadOutContext->mSamePriorityEvent) - { - // Update to next Event Number - loadOutContext->mCurrentEventNumber++; - loadOutContext->mSamePriorityEvent = false; - } - return err; } -CHIP_ERROR EventManagement::FetchEventsSince(TLVWriter & aWriter, ClusterInfo * apClusterInfolist, PriorityLevel aPriority, - EventNumber & aEventNumber, size_t & aEventCount) +CHIP_ERROR EventManagement::FetchEventsSince(TLVWriter & aWriter, ClusterInfo * apClusterInfolist, EventNumber & aEventMin, + size_t & aEventCount) { // TODO: Add particular set of event Paths in FetchEventsSince so that we can filter the interested paths CHIP_ERROR err = CHIP_NO_ERROR; const bool recurse = false; TLVReader reader; CircularEventBufferWrapper bufWrapper; - EventLoadOutContext context(aWriter, aPriority, aEventNumber); + EventLoadOutContext context(aWriter, PriorityLevel::Invalid, aEventMin); - CircularEventBuffer * buf = mpEventBuffer; #if !CHIP_SYSTEM_CONFIG_NO_LOCKING ScopedLock lock(sInstance); #endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING - while (!buf->IsFinalDestinationForPriority(aPriority)) - { - buf = buf->GetNextCircularEventBuffer(); - } - context.mpInterestedEventPaths = apClusterInfolist; - context.mCurrentTime.mValue = buf->GetFirstEventTimestamp(); - context.mCurrentEventNumber = buf->GetFirstEventNumber(); - err = GetEventReader(reader, aPriority, &bufWrapper); + err = GetEventReader(reader, PriorityLevel::Critical, &bufWrapper); SuccessOrExit(err); err = TLV::Utilities::Iterate(reader, CopyEventsSince, &context, recurse); @@ -739,7 +685,7 @@ CHIP_ERROR EventManagement::FetchEventsSince(TLVWriter & aWriter, ClusterInfo * } exit: - aEventNumber = context.mCurrentEventNumber; + aEventMin = context.mCurrentEventNumber + 1; aEventCount += context.mEventCount; return err; } @@ -781,20 +727,25 @@ CHIP_ERROR EventManagement::FetchEventParameters(const TLVReader & aReader, size envelope->mFieldsToRead |= 1 << to_underlying(EventDataIB::Tag::kPriority); } - if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp))) + if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEventNumber))) { - uint64_t deltaSystemTime; - ReturnErrorOnFailure(reader.Get(deltaSystemTime)); - envelope->mDeltaTime.mType = Timestamp::Type::kSystem; - envelope->mDeltaTime.mValue = deltaSystemTime; + ReturnErrorOnFailure(reader.Get(envelope->mEventNumber)); } - if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaEpochTimestamp))) + if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) { - uint64_t deltaEpochTime; - ReturnErrorOnFailure(reader.Get(deltaEpochTime)); - envelope->mDeltaTime.mType = Timestamp::Type::kEpoch; - envelope->mDeltaTime.mValue = deltaEpochTime; + uint64_t systemTime; + ReturnErrorOnFailure(reader.Get(systemTime)); + envelope->mCurrentTime.mType = Timestamp::Type::kSystem; + envelope->mCurrentTime.mValue = systemTime; + } + + if (reader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) + { + uint64_t epochTime; + ReturnErrorOnFailure(reader.Get(epochTime)); + envelope->mCurrentTime.mType = Timestamp::Type::kEpoch; + envelope->mCurrentTime.mValue = epochTime; } return CHIP_NO_ERROR; } @@ -827,15 +778,11 @@ CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void * CircularEventBuffer * const eventBuffer = ctx->mpEventBuffer; if (eventBuffer->IsFinalDestinationForPriority(imp)) { - // event is getting dropped. Increase the event number and first timestamp. - EventNumber numEventsToDrop = 1; - eventBuffer->RemoveEvent(numEventsToDrop); - eventBuffer->SetFirstEventTimestamp(eventBuffer->GetFirstEventTimestamp() + context.mDeltaTime.mValue); - ChipLogProgress( - EventLogging, - "Dropped events from buffer with priority %u due to overflow: { event priority_level: %u, count: 0x" ChipLogFormatX64 - " };", - static_cast(eventBuffer->GetPriority()), static_cast(imp), ChipLogValueX64(numEventsToDrop)); + ChipLogProgress(EventLogging, + "Dropped 1 event from buffer with priority %u and event number 0x" ChipLogFormatX64 + " due to overflow: event priority_level: %u", + static_cast(eventBuffer->GetPriority()), ChipLogValueX64(context.mEventNumber), + static_cast(imp)); ctx->mSpaceNeededForMovedEvent = 0; return CHIP_NO_ERROR; } @@ -845,40 +792,22 @@ CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void * return CHIP_END_OF_TLV; } -void EventManagement::SetScheduledEventEndpoint(EventNumber * apEventEndpoints) +void EventManagement::SetScheduledEventNumber(EventNumber & aEventNumber) { - CircularEventBuffer * eventBuffer = mpEventBuffer; - #if !CHIP_SYSTEM_CONFIG_NO_LOCKING ScopedLock lock(sInstance); #endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING - while (eventBuffer != nullptr) - { - if (eventBuffer->GetPriority() >= PriorityLevel::First && (eventBuffer->GetPriority() <= PriorityLevel::Last)) - { - apEventEndpoints[static_cast(eventBuffer->GetPriority())] = eventBuffer->GetLastEventNumber(); - } - eventBuffer = eventBuffer->GetNextCircularEventBuffer(); - } + aEventNumber = mLastEventNumber; } void CircularEventBuffer::Init(uint8_t * apBuffer, uint32_t aBufferLength, CircularEventBuffer * apPrev, CircularEventBuffer * apNext, PriorityLevel aPriorityLevel) { CHIPCircularTLVBuffer::Init(apBuffer, aBufferLength); - mpPrev = apPrev; - mpNext = apNext; - mPriority = aPriorityLevel; - mFirstEventNumber = 1; - mLastEventNumber = 0; -#if CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS & CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME - mFirstEventTimestamp = Timestamp::Epoch(System::Clock::kZero); - mLastEventTimestamp = Timestamp::Epoch(System::Clock::kZero); -#else - mFirstEventTimestamp = Timestamp::System(System::Clock::kZero); - mLastEventTimestamp = Timestamp::System(System::Clock::kZero); -#endif + mpPrev = apPrev; + mpNext = apNext; + mPriority = aPriorityLevel; mpEventNumberCounter = nullptr; } @@ -887,21 +816,6 @@ bool CircularEventBuffer::IsFinalDestinationForPriority(PriorityLevel aPriority) return !((mpNext != nullptr) && (mpNext->mPriority <= aPriority)); } -void CircularEventBuffer::UpdateFirstLastEventTime(Timestamp aEventTimestamp) -{ - if (mFirstEventTimestamp.mValue == 0) - { - mFirstEventTimestamp = aEventTimestamp; - mLastEventTimestamp = aEventTimestamp; - } - mLastEventTimestamp = aEventTimestamp; -} - -void CircularEventBuffer::RemoveEvent(EventNumber aNumEvents) -{ - mFirstEventNumber = mFirstEventNumber + aNumEvents; -} - void CircularEventReader::Init(CircularEventBufferWrapper * apBufWrapper) { CircularEventBuffer * prev; diff --git a/src/app/EventManagement.h b/src/app/EventManagement.h index 217b05f0bf77d5..55374ae67f03f4 100644 --- a/src/app/EventManagement.h +++ b/src/app/EventManagement.h @@ -88,44 +88,6 @@ class CircularEventBuffer : public TLV::CHIPCircularTLVBuffer */ bool IsFinalDestinationForPriority(PriorityLevel aPriority) const; - /** - * @brief - * Allocate a new event Number based on the event priority, and advance the counter - * if we have one. - * - * @return EventNumber Event Number for this priority. - */ - EventNumber VendEventNumber(); - - /** - * @brief - * Remove the number of event - * - * @param[in] aNumEvents the number of the event. - */ - void RemoveEvent(EventNumber aNumEvents); - - /** - * @brief - * Given a timestamp of an event, compute the delta time to store in the log - * - * @param aEventTimestamp The event timestamp. - * - */ - void UpdateFirstLastEventTime(Timestamp aEventTimestamp); - - void InitCounter(MonotonicallyIncreasingCounter * apEventNumberCounter) - { - if (apEventNumberCounter == nullptr) - { - mNonPersistedCounter.Init(1); - mpEventNumberCounter = &(mNonPersistedCounter); - return; - } - mpEventNumberCounter = apEventNumberCounter; - mFirstEventNumber = mpEventNumberCounter->GetValue(); - } - PriorityLevel GetPriority() { return mPriority; } CircularEventBuffer * GetPreviousCircularEventBuffer() { return mpPrev; } @@ -134,14 +96,6 @@ class CircularEventBuffer : public TLV::CHIPCircularTLVBuffer void SetRequiredSpaceforEvicted(size_t aRequiredSpace) { mRequiredSpaceForEvicted = aRequiredSpace; } size_t GetRequiredSpaceforEvicted() { return mRequiredSpaceForEvicted; } - EventNumber GetFirstEventNumber() { return mFirstEventNumber; } - EventNumber GetLastEventNumber() { return mLastEventNumber; } - - uint64_t GetFirstEventTimestamp() { return mFirstEventTimestamp.mValue; } - void SetFirstEventTimestamp(uint64_t aValue) { mLastEventTimestamp.mValue = aValue; } - - uint64_t GetLastEventTimestamp() { return mLastEventTimestamp.mValue; } - virtual ~CircularEventBuffer() = default; private: @@ -158,10 +112,6 @@ class CircularEventBuffer : public TLV::CHIPCircularTLVBuffer MonotonicallyIncreasingCounter mNonPersistedCounter; size_t mRequiredSpaceForEvicted = 0; ///< Required space for previous buffer to evict event to new buffer - EventNumber mFirstEventNumber = 0; ///< First event Number stored in the logging subsystem for this priority - EventNumber mLastEventNumber = 0; ///< Last event Number vended for this priority - Timestamp mFirstEventTimestamp; ///< The timestamp of the first event in this buffer - Timestamp mLastEventTimestamp; ///< The timestamp of the last event in this buffer }; class CircularEventReader; @@ -207,22 +157,8 @@ struct LogStorageResources nullptr; // Buffer to be used as a storage at the particular priority level and shared with more important events. // Must not be nullptr. Must be large enough to accommodate the largest event emitted by the system. uint32_t mBufferSize = 0; ///< The size, in bytes, of the `mBuffer`. - Platform::PersistedStorage::Key * mCounterKey = - nullptr; // Name of the key naming persistent counter for events of this priority. When NULL, the persistent - // counters will not be used for this priority level. - uint32_t mCounterEpoch = 0; // The interval used in incrementing persistent counters. When 0, the persistent counters will not - // be used for this priority level. - PersistedCounter * mpCounterStorage = nullptr; // application provided storage for persistent counter for this priority level. PriorityLevel mPriority = PriorityLevel::Invalid; // Log priority level associated with the resources provided in this structure. - PersistedCounter * InitializeCounter() const - { - if (mpCounterStorage != nullptr && mCounterKey != nullptr && mCounterEpoch != 0) - { - return (mpCounterStorage->Init(*mCounterKey, mCounterEpoch) == CHIP_NO_ERROR) ? mpCounterStorage : nullptr; - } - return nullptr; - } }; /** @@ -259,7 +195,11 @@ class EventManagement * */ void Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, CircularEventBuffer * apCircularEventBuffer, - const LogStorageResources * const apLogStorageResources); + const LogStorageResources * const apLogStorageResources, Platform::PersistedStorage::Key * apCounterKey, + uint32_t aCounterEpoch, PersistedCounter * apPersistedCounter); + + void InitializeCounter(Platform::PersistedStorage::Key * apCounterKey, uint32_t aCounterEpoch, + PersistedCounter * apPersistedCounter); static EventManagement & GetInstance(); @@ -285,7 +225,9 @@ class EventManagement */ static void CreateEventManagement(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, CircularEventBuffer * apCircularEventBuffer, - const LogStorageResources * const apLogStorageResources); + const LogStorageResources * const apLogStorageResources, + Platform::PersistedStorage::Key * apCounterKey, uint32_t aCounterEpoch, + PersistedCounter * apPersistedCounter); static void DestroyEventManagement(); @@ -367,19 +309,17 @@ class EventManagement * A function to retrieve events of specified priority since a specified event ID. * * Given a TLV::TLVWriter, an priority type, and an event ID, the - * function will fetch events of specified priority since the - * specified event. The function will continue fetching events until + * function will fetch events since the + * specified event number. The function will continue fetching events until * it runs out of space in the TLV::TLVWriter or in the log. The function - * will terminate the event writing on event boundary. + * will terminate the event writing on event boundary. The function would filter out event based upon interested path + * specified by read/subscribe request. * * @param[in] aWriter The writer to use for event storage * @param[in] apClusterInfolist the interested cluster info list with event path inside - * @param[in] aPriority The priority of events to be fetched * - * @param[in,out] aEventNumber On input, the Event number immediately - * prior to the one we're fetching. On - * completion, the event number of the last event - * fetched. + * @param[in,out] aEventMin On input, the Event number is the one we're fetching. On + * completion, the event number of the next one we plan to fetch. * * @param[out] aEventCount The number of fetched event * @retval #CHIP_END_OF_TLV The function has reached the end of the @@ -395,8 +335,8 @@ class EventManagement * available. * */ - CHIP_ERROR FetchEventsSince(chip::TLV::TLVWriter & aWriter, ClusterInfo * apClusterInfolist, PriorityLevel aPriority, - EventNumber & aEventNumber, size_t & aEventCount); + CHIP_ERROR FetchEventsSince(chip::TLV::TLVWriter & aWriter, ClusterInfo * apClusterInfolist, EventNumber & aEventMin, + size_t & aEventCount); /** * @brief @@ -406,17 +346,7 @@ class EventManagement * * @return EventNumber most recently vended event Number for that event priority */ - EventNumber GetLastEventNumber(PriorityLevel aPriority); - - /** - * @brief - * Fetch the first event Number currently stored for a particular priority level - * - * @param aPriority Priority level - * - * @return EventNumber First currently stored event Number for that event priority - */ - EventNumber GetFirstEventNumber(PriorityLevel aPriority); + EventNumber GetLastEventNumber() { return mLastEventNumber; } /** * @brief @@ -427,9 +357,10 @@ class EventManagement /** * Logger would save last logged event number for each logger buffer into schedule event number array */ - void SetScheduledEventEndpoint(EventNumber * aEventEndpoints); + void SetScheduledEventNumber(EventNumber & aEventNumber); private: + void VendEventNumber(); CHIP_ERROR CalculateEventSize(EventLoggingDelegate * apDelegate, const EventOptions * apOptions, uint32_t & requiredSize); /** * @brief Helper function for writing event header and data according to event @@ -540,6 +471,15 @@ class EventManagement #if !CHIP_SYSTEM_CONFIG_NO_LOCKING System::Mutex mAccessLock; #endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING + + // The counter we're going to actually use. + MonotonicallyIncreasingCounter * mpEventNumberCounter = nullptr; + + // The backup counter to use if no counter is provided for us. + MonotonicallyIncreasingCounter mNonPersistedCounter; + + EventNumber mLastEventNumber = 0; ///< Last event Number vended for this priority + Timestamp mLastEventTimestamp; ///< The timestamp of the last event in this buffer }; } // namespace app } // namespace chip diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 1c075f5c801567..3a48b2650a9095 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -555,7 +555,7 @@ CHIP_ERROR ReadClient::ProcessEventReportIBs(TLV::TLVReader & aEventReportIBsRea header.mTimestamp = mEventTimestamp; ReturnErrorOnFailure(data.DecodeEventHeader(header)); mEventTimestamp = header.mTimestamp; - + mEventMin = header.mEventNumber + 1; ReturnErrorOnFailure(data.GetData(&dataReader)); mpCallback->OnEventData(this, header, &dataReader, nullptr); @@ -681,16 +681,17 @@ CHIP_ERROR ReadClient::SendSubscribeRequest(ReadPrepareParams & aReadPreparePara if (aReadPrepareParams.mEventNumber != 0) { - // EventNumber is optional - EventFilterIBs::Builder & eventFilters = request.CreateEventFilters(); - SuccessOrExit(err = request.GetError()); - EventFilterIB::Builder & eventFilter = eventFilters.CreateEventFilter(); - SuccessOrExit(err = eventFilters.GetError()); - eventFilter.EventMin(aReadPrepareParams.mEventNumber).EndOfEventFilterIB(); - SuccessOrExit(err = eventFilter.GetError()); - eventFilters.EndOfEventFilters(); - SuccessOrExit(err = eventFilters.GetError()); + mEventMin = aReadPrepareParams.mEventNumber; } + + EventFilterIBs::Builder & eventFilters = request.CreateEventFilters(); + SuccessOrExit(err = request.GetError()); + EventFilterIB::Builder & eventFilter = eventFilters.CreateEventFilter(); + SuccessOrExit(err = eventFilters.GetError()); + eventFilter.EventMin(mEventMin).EndOfEventFilterIB(); + SuccessOrExit(err = eventFilter.GetError()); + eventFilters.EndOfEventFilters(); + SuccessOrExit(err = eventFilters.GetError()); } request.IsFabricFiltered(false).EndOfSubscribeRequestMessage(); diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index f64b537fb85263..b71cf470ea40dc 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -291,6 +291,7 @@ class ReadClient : public Messaging::ExchangeDelegate FabricIndex mFabricIndex = kUndefinedFabricIndex; InteractionType mInteractionType = InteractionType::Read; Timestamp mEventTimestamp; + EventNumber mEventMin = 0; }; }; // namespace app diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index eb8ada48e8e624..c2cbaa844b8fe7 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -47,12 +47,9 @@ CHIP_ERROR ReadHandler::Init(Messaging::ExchangeManager * apExchangeMgr, Interac mpAttributeClusterInfoList = nullptr; mpEventClusterInfoList = nullptr; mCurrentPriority = PriorityLevel::Invalid; - for (size_t index = 0; index < kNumPriorityLevel; index++) - { - mSelfProcessedEvents[index] = 0; - mLastScheduledEventNumber[index] = 0; - } - mIsPrimingReports = true; + mEventMin = 0; + mLastScheduledEventNumber = 0; + mIsPrimingReports = true; MoveToState(HandlerState::Initialized); mpDelegate = apDelegate; mSubscriptionId = 0; @@ -108,19 +105,16 @@ void ReadHandler::Shutdown(ShutdownOptions aOptions) mpAttributeClusterInfoList = nullptr; mpEventClusterInfoList = nullptr; mCurrentPriority = PriorityLevel::Invalid; - for (size_t index = 0; index < kNumPriorityLevel; index++) - { - mSelfProcessedEvents[index] = 0; - mLastScheduledEventNumber[index] = 0; - } - mIsPrimingReports = false; - mpDelegate = nullptr; - mHoldReport = false; - mDirty = false; - mActiveSubscription = false; - mIsChunkedReport = false; - mInitiatorNodeId = kUndefinedNodeId; - mHoldSync = false; + mEventMin = 0; + mLastScheduledEventNumber = 0; + mIsPrimingReports = false; + mpDelegate = nullptr; + mHoldReport = false; + mDirty = false; + mActiveSubscription = false; + mIsChunkedReport = false; + mInitiatorNodeId = kUndefinedNodeId; + mHoldSync = false; } CHIP_ERROR ReadHandler::OnReadInitialRequest(System::PacketBufferHandle && aPayload) @@ -282,19 +276,15 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa ReadRequestMessage::Parser readRequestParser; EventPathIBs::Parser eventPathListParser; - + EventFilterIBs::Parser eventFilterIBsParser; AttributePathIBs::Parser attributePathListParser; reader.Init(std::move(aPayload)); - err = reader.Next(); - SuccessOrExit(err); - - err = readRequestParser.Init(reader); - SuccessOrExit(err); + ReturnErrorOnFailure(reader.Next()); + ReturnErrorOnFailure(readRequestParser.Init(reader)); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - err = readRequestParser.CheckSchemaValidity(); - SuccessOrExit(err); + ReturnErrorOnFailure(readRequestParser.CheckSchemaValidity()); #endif err = readRequestParser.GetAttributeRequests(&attributePathListParser); @@ -302,34 +292,35 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa { err = CHIP_NO_ERROR; } - else + else if (err == CHIP_NO_ERROR) { - SuccessOrExit(err); - err = ProcessAttributePathList(attributePathListParser); + ReturnErrorOnFailure(ProcessAttributePathList(attributePathListParser)); } - SuccessOrExit(err); + ReturnErrorOnFailure(err); err = readRequestParser.GetEventRequests(&eventPathListParser); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; } - else - { - SuccessOrExit(err); - err = ProcessEventPaths(eventPathListParser); - } - SuccessOrExit(err); - - // if we have exhausted this container - if (CHIP_END_OF_TLV == err) + else if (err == CHIP_NO_ERROR) { - err = CHIP_NO_ERROR; + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(ProcessEventPaths(eventPathListParser)); + err = readRequestParser.GetEventFilters(&eventFilterIBsParser); + if (err == CHIP_END_OF_TLV) + { + err = CHIP_NO_ERROR; + } + else if (err == CHIP_NO_ERROR) + { + ReturnErrorOnFailure(ProcessEventFilters(eventFilterIBsParser)); + } } + ReturnErrorOnFailure(err); MoveToState(HandlerState::GeneratingReports); - err = InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun(); - SuccessOrExit(err); + ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun()); // mpExchangeCtx can be null here due to // https://github.com/project-chip/connectedhomeip/issues/8031 @@ -341,8 +332,7 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa // There must be no code after the WillSendMessage() call that can cause // this method to return a failure. -exit: - return err; + return CHIP_NO_ERROR; } CHIP_ERROR ReadHandler::ProcessAttributePathList(AttributePathIBs::Parser & aAttributePathListParser) @@ -477,6 +467,27 @@ CHIP_ERROR ReadHandler::ProcessEventPaths(EventPathIBs::Parser & aEventPathsPars return err; } +CHIP_ERROR ReadHandler::ProcessEventFilters(EventFilterIBs::Parser & aEventFiltersParser) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + TLV::TLVReader reader; + aEventFiltersParser.GetReader(&reader); + + while (CHIP_NO_ERROR == (err = reader.Next())) + { + VerifyOrReturnError(TLV::AnonymousTag == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG); + EventFilterIB::Parser filter; + ReturnErrorOnFailure(filter.Init(reader)); + // this is for current node, and would have only one event filter. + ReturnErrorOnFailure(filter.GetEventMin(&(mEventMin))); + } + if (CHIP_END_OF_TLV == err) + { + err = CHIP_NO_ERROR; + } + return err; +} + const char * ReadHandler::GetStateStr() const { #if CHIP_DETAIL_LOGGING @@ -506,45 +517,24 @@ void ReadHandler::MoveToState(const HandlerState aTargetState) bool ReadHandler::CheckEventClean(EventManagement & aEventManager) { - if (mCurrentPriority == PriorityLevel::Invalid) + if (mIsChunkedReport) { - // Upload is not in middle, previous mLastScheduledEventNumber is not valid, Check for new events from Critical high - // priority to Debug low priority, and set a checkpoint when there is dirty events - for (int index = ArraySize(mSelfProcessedEvents) - 1; index >= 0; index--) + if ((mLastScheduledEventNumber != 0) && (mEventMin <= mLastScheduledEventNumber)) { - EventNumber lastEventNumber = aEventManager.GetLastEventNumber(static_cast(index)); - if ((lastEventNumber != 0) && (lastEventNumber >= mSelfProcessedEvents[index])) - { - // We have more events. snapshot last event IDs - aEventManager.SetScheduledEventEndpoint(&(mLastScheduledEventNumber[0])); - // initialize the next dirty priority level to transfer - MoveToNextScheduledDirtyPriority(); - return false; - } + return false; } - return true; } else { - // Upload is in middle, previous mLastScheduledEventNumber is still valid, recheck via MoveToNextScheduledDirtyPriority, - // if finally mCurrentPriority is invalid, it means no more event - MoveToNextScheduledDirtyPriority(); - return mCurrentPriority == PriorityLevel::Invalid; - } -} - -void ReadHandler::MoveToNextScheduledDirtyPriority() -{ - for (int i = ArraySize(mSelfProcessedEvents) - 1; i >= 0; i--) - { - if ((mLastScheduledEventNumber[i] != 0) && mSelfProcessedEvents[i] <= mLastScheduledEventNumber[i]) + EventNumber lastEventNumber = aEventManager.GetLastEventNumber(); + if ((lastEventNumber != 0) && (mEventMin <= lastEventNumber)) { - mCurrentPriority = static_cast(i); - return; + // We have more events. snapshot last event number + aEventManager.SetScheduledEventNumber(mLastScheduledEventNumber); + return false; } } - - mCurrentPriority = PriorityLevel::Invalid; + return true; } CHIP_ERROR ReadHandler::SendSubscribeResponse() @@ -609,6 +599,16 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP else if (err == CHIP_NO_ERROR) { ReturnErrorOnFailure(ProcessEventPaths(eventPathListParser)); + EventFilterIBs::Parser eventFilterIBsParser; + err = subscribeRequestParser.GetEventFilters(&eventFilterIBsParser); + if (err == CHIP_END_OF_TLV) + { + err = CHIP_NO_ERROR; + } + else if (err == CHIP_NO_ERROR) + { + ReturnErrorOnFailure(ProcessEventFilters(eventFilterIBsParser)); + } } ReturnErrorOnFailure(err); diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index d973fe1c8e9799..0402d8fb5d1372 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -118,7 +118,7 @@ class ReadHandler : public Messaging::ExchangeDelegate ClusterInfo * GetAttributeClusterInfolist() { return mpAttributeClusterInfoList; } ClusterInfo * GetEventClusterInfolist() { return mpEventClusterInfoList; } - EventNumber * GetVendedEventNumberList() { return mSelfProcessedEvents; } + EventNumber & GetEventMin() { return mEventMin; } PriorityLevel GetCurrentPriority() { return mCurrentPriority; } // if current priority is in the middle, it has valid snapshoted last event number, it check cleaness via comparing @@ -126,10 +126,6 @@ class ReadHandler : public Messaging::ExchangeDelegate // sanpshotted last event, check with latest last event number, re-setup snapshoted checkpoint, and compare again. bool CheckEventClean(EventManagement & aEventManager); - // Move to the next dirty priority from critical high priority to debug low priority, where last schedule event number - // is larger than current self vended event number - void MoveToNextScheduledDirtyPriority(); - bool IsReadType() { return mInteractionType == InteractionType::Read; } bool IsSubscriptionType() { return mInteractionType == InteractionType::Subscribe; } bool IsChunkedReport() { return mIsChunkedReport; } @@ -181,6 +177,7 @@ class ReadHandler : public Messaging::ExchangeDelegate CHIP_ERROR ProcessReadRequest(System::PacketBufferHandle && aPayload); CHIP_ERROR ProcessAttributePathList(AttributePathIBs::Parser & aAttributePathListParser); CHIP_ERROR ProcessEventPaths(EventPathIBs::Parser & aEventPathsParser); + CHIP_ERROR ProcessEventFilters(EventFilterIBs::Parser & aEventFiltersParser); CHIP_ERROR OnStatusResponse(Messaging::ExchangeContext * apExchangeContext, System::PacketBufferHandle && aPayload); CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) override; @@ -203,13 +200,12 @@ class ReadHandler : public Messaging::ExchangeDelegate PriorityLevel mCurrentPriority = PriorityLevel::Invalid; - // The event number of the last processed event for each priority level - EventNumber mSelfProcessedEvents[kNumPriorityLevel] = { 0 }; + EventNumber mEventMin = 0; // The last schedule event number snapshoted in the beginning when preparing to fill new events to reports - EventNumber mLastScheduledEventNumber[kNumPriorityLevel] = { 0 }; - Messaging::ExchangeManager * mpExchangeMgr = nullptr; - InteractionModelDelegate * mpDelegate = nullptr; + EventNumber mLastScheduledEventNumber = 0; + Messaging::ExchangeManager * mpExchangeMgr = nullptr; + InteractionModelDelegate * mpDelegate = nullptr; // Tracks whether we're in the initial phase of receiving priming // reports, which is always true for reads and true for subscriptions diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 8baa297c0c595e..deb493519e3e52 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -48,20 +48,6 @@ void Engine::Shutdown() mpGlobalDirtySet = nullptr; } -EventNumber Engine::CountEvents(ReadHandler * apReadHandler, EventNumber * apInitialEvents) -{ - EventNumber event_count = 0; - EventNumber * vendedEventNumberList = apReadHandler->GetVendedEventNumberList(); - for (size_t index = 0; index < kNumPriorityLevel; index++) - { - if (vendedEventNumberList[index] > apInitialEvents[index]) - { - event_count += vendedEventNumberList[index] - apInitialEvents[index]; - } - } - return event_count; -} - CHIP_ERROR Engine::RetrieveClusterData(const SubjectDescriptor & aSubjectDescriptor, AttributeReportIBs::Builder & aAttributeReportIBs, const ConcreteReadAttributePath & aPath, AttributeValueEncoder::AttributeEncodeState * aEncoderState) @@ -237,7 +223,7 @@ CHIP_ERROR Engine::BuildSingleReportDataEventReports(ReportDataMessage::Builder TLV::TLVWriter backup; bool eventClean = true; ClusterInfo * clusterInfoList = apReadHandler->GetEventClusterInfolist(); - EventNumber * eventNumberList = apReadHandler->GetVendedEventNumberList(); + EventNumber & eventMin = apReadHandler->GetEventMin(); EventManagement & eventManager = EventManagement::GetInstance(); bool hasMoreChunks = false; @@ -260,52 +246,39 @@ CHIP_ERROR Engine::BuildSingleReportDataEventReports(ReportDataMessage::Builder { EventReportIBs::Builder & eventReportIBs = aReportDataBuilder.CreateEventReports(); SuccessOrExit(err = aReportDataBuilder.GetError()); - while (apReadHandler->GetCurrentPriority() != PriorityLevel::Invalid) - { - uint8_t priorityIndex = static_cast(apReadHandler->GetCurrentPriority()); - err = eventManager.FetchEventsSince(*(eventReportIBs.GetWriter()), clusterInfoList, apReadHandler->GetCurrentPriority(), - eventNumberList[priorityIndex], eventCount); + err = eventManager.FetchEventsSince(*(eventReportIBs.GetWriter()), clusterInfoList, eventMin, eventCount); - if ((err == CHIP_END_OF_TLV) || (err == CHIP_ERROR_TLV_UNDERRUN) || (err == CHIP_NO_ERROR)) + if ((err == CHIP_END_OF_TLV) || (err == CHIP_ERROR_TLV_UNDERRUN) || (err == CHIP_NO_ERROR)) + { + err = CHIP_NO_ERROR; + hasMoreChunks = false; + } + else if ((err == CHIP_ERROR_BUFFER_TOO_SMALL) || (err == CHIP_ERROR_NO_MEMORY)) + { + // when first cluster event is too big to fit in the packet, ignore that cluster event. + if (eventCount == 0) { - // We have successfully reached the end of the log for - // the current priority. Advance to the next - // priority level. + eventMin++; + ChipLogDetail(DataManagement, " first cluster event is too big so that it fails to fit in the packet!"); err = CHIP_NO_ERROR; - apReadHandler->MoveToNextScheduledDirtyPriority(); - hasMoreChunks = false; - } - else if ((err == CHIP_ERROR_BUFFER_TOO_SMALL) || (err == CHIP_ERROR_NO_MEMORY)) - { - // when first cluster event is too big to fit in the packet, ignore that cluster event. - if (eventCount == 0) - { - eventNumberList[priorityIndex]++; - ChipLogDetail(DataManagement, " first cluster event is too big so that it fails to fit in the packet!"); - err = CHIP_NO_ERROR; - } - else - { - // `FetchEventsSince` has filled the available space - // within the allowed buffer before it fit all the - // available events. This is an expected condition, - // so we do not propagate the error to higher levels; - // instead, we terminate the event processing for now - // (we will get another chance immediately afterwards, - // with a ew buffer) and do not advance the processing - // to the next priority level. - err = CHIP_NO_ERROR; - break; - } - hasMoreChunks = true; } else { - // All other errors are propagated to higher level. - // Exiting here and returning an error will lead to - // abandoning subscription. - ExitNow(); + // `FetchEventsSince` has filled the available space + // within the allowed buffer before it fit all the + // available events. This is an expected condition, + // so we do not propagate the error to higher levels; + // instead, we terminate the event processing for now + err = CHIP_NO_ERROR; } + hasMoreChunks = true; + } + else + { + // All other errors are propagated to higher level. + // Exiting here and returning an error will lead to + // abandoning subscription. + ExitNow(); } eventReportIBs.EndOfEventReports(); diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index c100e007ccadfb..cebf74d1ee4cb9 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -112,7 +112,6 @@ class Engine AttributeReportIBs::Builder & aAttributeReportIBs, const ConcreteReadAttributePath & aClusterInfo, AttributeValueEncoder::AttributeEncodeState * apEncoderState); - EventNumber CountEvents(ReadHandler * apReadHandler, EventNumber * apInitialEvents); /** * Check all active subscription, if the subscription has no paths that intersect with global dirty set, diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index ba8c981e86037f..1437560ff3154b 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -75,9 +75,7 @@ Server Server::sServer; static uint8_t sInfoEventBuffer[CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE]; static uint8_t sDebugEventBuffer[CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE]; static uint8_t sCritEventBuffer[CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE]; -static ::chip::PersistedCounter sCritEventIdCounter; -static ::chip::PersistedCounter sInfoEventIdCounter; -static ::chip::PersistedCounter sDebugEventIdCounter; +static ::chip::PersistedCounter sGlobalEventIdCounter; static ::chip::app::CircularEventBuffer sLoggingBuffer[CHIP_NUM_EVENT_LOGGING_BUFFERS]; #endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT @@ -171,21 +169,18 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint #if CHIP_CONFIG_ENABLE_SERVER_IM_EVENT // Initialize event logging subsystem { - ::chip::Platform::PersistedStorage::Key debugEventIdCounterStorageKey = CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY; - ::chip::Platform::PersistedStorage::Key critEventIdCounterStorageKey = CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY; - ::chip::Platform::PersistedStorage::Key infoEventIdCounterStorageKey = CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY; + ::chip::Platform::PersistedStorage::Key globalEventIdCounterStorageKey = + CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY; ::chip::app::LogStorageResources logStorageResources[] = { - { &sDebugEventBuffer[0], sizeof(sDebugEventBuffer), &debugEventIdCounterStorageKey, - CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, &sDebugEventIdCounter, ::chip::app::PriorityLevel::Debug }, - { &sInfoEventBuffer[0], sizeof(sInfoEventBuffer), &infoEventIdCounterStorageKey, - CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, &sInfoEventIdCounter, ::chip::app::PriorityLevel::Info }, - { &sCritEventBuffer[0], sizeof(sCritEventBuffer), &critEventIdCounterStorageKey, - CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, &sCritEventIdCounter, ::chip::app::PriorityLevel::Critical } + { &sDebugEventBuffer[0], sizeof(sDebugEventBuffer), ::chip::app::PriorityLevel::Debug }, + { &sInfoEventBuffer[0], sizeof(sInfoEventBuffer), ::chip::app::PriorityLevel::Info }, + { &sCritEventBuffer[0], sizeof(sCritEventBuffer), ::chip::app::PriorityLevel::Critical } }; chip::app::EventManagement::GetInstance().Init(&mExchangeMgr, CHIP_NUM_EVENT_LOGGING_BUFFERS, &sLoggingBuffer[0], - &logStorageResources[0]); + &logStorageResources[0], &globalEventIdCounterStorageKey, + CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, &sGlobalEventIdCounter); } #endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT diff --git a/src/app/tests/TestEventLogging.cpp b/src/app/tests/TestEventLogging.cpp index ebfb3f74877f76..016df1659dcc2f 100644 --- a/src/app/tests/TestEventLogging.cpp +++ b/src/app/tests/TestEventLogging.cpp @@ -66,14 +66,14 @@ class TestContext : public chip::Test::AppContext auto * ctx = static_cast(context); chip::app::LogStorageResources logStorageResources[] = { - { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Debug }, - { &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Info }, - { &gCritEventBuffer[0], sizeof(gCritEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Critical }, + { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, + { &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info }, + { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; chip::app::EventManagement::CreateEventManagement(&ctx->GetExchangeManager(), sizeof(logStorageResources) / sizeof(logStorageResources[0]), - gCircularEventBuffer, logStorageResources); + gCircularEventBuffer, logStorageResources, nullptr, 0, nullptr); return SUCCESS; } @@ -129,8 +129,8 @@ static void CheckLogState(nlTestSuite * apSuite, chip::app::EventManagement & aL printf("elementCount vs expectedNumEvents : %zu vs %zu \n", elementCount, expectedNumEvents); } -static void CheckLogReadOut(nlTestSuite * apSuite, chip::app::EventManagement & alogMgmt, chip::app::PriorityLevel priority, - chip::EventNumber startingEventNumber, size_t expectedNumEvents, chip::app::ClusterInfo * clusterInfo) +static void CheckLogReadOut(nlTestSuite * apSuite, chip::app::EventManagement & alogMgmt, chip::EventNumber startingEventNumber, + size_t expectedNumEvents, chip::app::ClusterInfo * clusterInfo) { CHIP_ERROR err; chip::TLV::TLVReader reader; @@ -139,13 +139,16 @@ static void CheckLogReadOut(nlTestSuite * apSuite, chip::app::EventManagement & uint8_t backingStore[1024]; size_t totalNumElements; writer.Init(backingStore, 1024); - err = alogMgmt.FetchEventsSince(writer, clusterInfo, priority, startingEventNumber, eventCount); + err = alogMgmt.FetchEventsSince(writer, clusterInfo, startingEventNumber, eventCount); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR || err == CHIP_END_OF_TLV); reader.Init(backingStore, writer.GetLengthWritten()); err = chip::TLV::Utilities::Count(reader, totalNumElements, false); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + + printf("totalNumElements vs expectedNumEvents vs eventCount : %zu vs %zu vs %zu \n", totalNumElements, expectedNumEvents, + eventCount); NL_TEST_ASSERT(apSuite, totalNumElements == expectedNumEvents && totalNumElements == eventCount); reader.Init(backingStore, writer.GetLengthWritten()); chip::TLV::Debug::Dump(reader, SimpleDumpWriter); @@ -228,12 +231,12 @@ static void CheckLogEventWithEvictToNextBuffer(nlTestSuite * apSuite, void * apC testClusterInfo2.mClusterId = kLivenessClusterId; testClusterInfo2.mEventId = kLivenessChangeEvent; - CheckLogReadOut(apSuite, logMgmt, chip::app::PriorityLevel::Info, eid1, 3, &testClusterInfo1); - CheckLogReadOut(apSuite, logMgmt, chip::app::PriorityLevel::Info, eid2, 2, &testClusterInfo1); - CheckLogReadOut(apSuite, logMgmt, chip::app::PriorityLevel::Info, eid3, 1, &testClusterInfo1); - CheckLogReadOut(apSuite, logMgmt, chip::app::PriorityLevel::Info, eid4, 3, &testClusterInfo2); - CheckLogReadOut(apSuite, logMgmt, chip::app::PriorityLevel::Info, eid5, 2, &testClusterInfo2); - CheckLogReadOut(apSuite, logMgmt, chip::app::PriorityLevel::Info, eid6, 1, &testClusterInfo2); + CheckLogReadOut(apSuite, logMgmt, 0, 3, &testClusterInfo1); + CheckLogReadOut(apSuite, logMgmt, 1, 2, &testClusterInfo1); + CheckLogReadOut(apSuite, logMgmt, 2, 1, &testClusterInfo1); + CheckLogReadOut(apSuite, logMgmt, 3, 3, &testClusterInfo2); + CheckLogReadOut(apSuite, logMgmt, 4, 2, &testClusterInfo2); + CheckLogReadOut(apSuite, logMgmt, 5, 1, &testClusterInfo2); } static void CheckLogEventWithDiscardLowEvent(nlTestSuite * apSuite, void * apContext) @@ -249,33 +252,33 @@ static void CheckLogEventWithDiscardLowEvent(nlTestSuite * apSuite, void * apCon testEventGenerator.SetStatus(0); err = logMgmt.LogEvent(&testEventGenerator, options, eid1); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - CheckLogState(apSuite, logMgmt, 4, chip::app::PriorityLevel::Debug); + CheckLogState(apSuite, logMgmt, 3, chip::app::PriorityLevel::Debug); testEventGenerator.SetStatus(1); err = logMgmt.LogEvent(&testEventGenerator, options, eid2); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - CheckLogState(apSuite, logMgmt, 4, chip::app::PriorityLevel::Debug); + CheckLogState(apSuite, logMgmt, 3, chip::app::PriorityLevel::Debug); testEventGenerator.SetStatus(0); err = logMgmt.LogEvent(&testEventGenerator, options, eid3); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - CheckLogState(apSuite, logMgmt, 4, chip::app::PriorityLevel::Debug); - CheckLogState(apSuite, logMgmt, 8, chip::app::PriorityLevel::Info); + CheckLogState(apSuite, logMgmt, 3, chip::app::PriorityLevel::Debug); + CheckLogState(apSuite, logMgmt, 6, chip::app::PriorityLevel::Info); // Start to drop off debug event since debug event can only be saved in debug buffer testEventGenerator.SetStatus(1); err = logMgmt.LogEvent(&testEventGenerator, options, eid4); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - CheckLogState(apSuite, logMgmt, 4, chip::app::PriorityLevel::Debug); - CheckLogState(apSuite, logMgmt, 8, chip::app::PriorityLevel::Info); + CheckLogState(apSuite, logMgmt, 3, chip::app::PriorityLevel::Debug); + CheckLogState(apSuite, logMgmt, 6, chip::app::PriorityLevel::Info); testEventGenerator.SetStatus(0); err = logMgmt.LogEvent(&testEventGenerator, options, eid5); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - CheckLogState(apSuite, logMgmt, 4, chip::app::PriorityLevel::Debug); - CheckLogState(apSuite, logMgmt, 8, chip::app::PriorityLevel::Info); + CheckLogState(apSuite, logMgmt, 3, chip::app::PriorityLevel::Debug); + CheckLogState(apSuite, logMgmt, 6, chip::app::PriorityLevel::Info); testEventGenerator.SetStatus(1); err = logMgmt.LogEvent(&testEventGenerator, options, eid6); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - CheckLogState(apSuite, logMgmt, 4, chip::app::PriorityLevel::Debug); + CheckLogState(apSuite, logMgmt, 3, chip::app::PriorityLevel::Debug); } /** * Test Suite. It lists all the test functions. diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 3e9749da553bf9..2f3c862b8724a8 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -67,13 +67,13 @@ class TestContext : public chip::Test::AppContext auto * ctx = static_cast(context); chip::app::LogStorageResources logStorageResources[] = { - { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Debug }, - { &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Info }, - { &gCritEventBuffer[0], sizeof(gCritEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Critical }, + { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, + { &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info }, + { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; chip::app::EventManagement::CreateEventManagement(&ctx->GetExchangeManager(), ArraySize(logStorageResources), - gCircularEventBuffer, logStorageResources); + gCircularEventBuffer, logStorageResources, nullptr, 0, nullptr); return SUCCESS; } @@ -165,18 +165,7 @@ class MockInteractionModelApp : public chip::app::ReadClient::Callback, public c void OnEventData(const chip::app::ReadClient * apReadClient, const chip::app::EventHeader & aEventHeader, chip::TLV::TLVReader * apData, const chip::app::StatusIB * apStatus) override { - static int numDataElementIndex = 0; - - if (numDataElementIndex == 0) - { - VerifyOrReturn(aEventHeader.mPriorityLevel == chip::app::PriorityLevel::Critical); - } - else if (numDataElementIndex == 1) - { - VerifyOrReturn(aEventHeader.mPriorityLevel == chip::app::PriorityLevel::Info); - } - - ++numDataElementIndex; + ++mNumDataElementIndex; mGotEventResponse = true; } @@ -210,6 +199,7 @@ class MockInteractionModelApp : public chip::app::ReadClient::Callback, public c return CHIP_NO_ERROR; } + int mNumDataElementIndex = 0; bool mGotEventResponse = false; int mNumAttributeResponse = 0; bool mGotReport = false; @@ -695,11 +685,12 @@ void TestReadInteraction::TestReadRoundtrip(nlTestSuite * apSuite, void * apCont readPrepareParams.mEventPathParamsListSize = 1; readPrepareParams.mpAttributePathParamsList = attributePathParams; readPrepareParams.mAttributePathParamsListSize = 2; - + readPrepareParams.mEventNumber = 1; err = chip::app::InteractionModelEngine::GetInstance()->SendReadRequest(readPrepareParams, &delegate); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); InteractionModelEngine::GetInstance()->GetReportingEngine().Run(); + NL_TEST_ASSERT(apSuite, delegate.mNumDataElementIndex == 1); NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse); NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 2); NL_TEST_ASSERT(apSuite, delegate.mGotReport); diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index 8c8b5f699e19a2..123689a4852cff 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -142,13 +142,13 @@ chip::app::CircularEventBuffer gCircularEventBuffer[3]; void InitializeEventLogging(chip::Messaging::ExchangeManager * apMgr) { chip::app::LogStorageResources logStorageResources[] = { - { &gCritEventBuffer[0], sizeof(gDebugEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Debug }, - { &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Info }, - { &gDebugEventBuffer[0], sizeof(gCritEventBuffer), nullptr, 0, nullptr, chip::app::PriorityLevel::Critical }, + { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, + { &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info }, + { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; chip::app::EventManagement::CreateEventManagement(apMgr, sizeof(logStorageResources) / sizeof(logStorageResources[0]), - gCircularEventBuffer, logStorageResources); + gCircularEventBuffer, logStorageResources, nullptr, 0, nullptr); } void MutateClusterHandler(chip::System::Layer * systemLayer, void * appState) diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index f1324d78b8eb73..16dfaee83e0fcb 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -887,33 +887,13 @@ #endif /** - * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY + * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY * * @brief - * The critical event id counter (eidc) persisted storage key. + * The Global event id counter (eidc) persisted storage key. */ -#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY "crit-eidc" -#endif - -/** - * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY - * - * @brief - * The info event id counter (eidc) persisted storage key. - */ -#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY "info-eidc" -#endif - -/** - * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY - * - * @brief - * The debug event id counter (eidc) persisted storage key. - */ -#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY "debug-eidc" +#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY "global-eidc" #endif // -------------------- Software Update Manager Configuration -------------------- diff --git a/src/platform/EFR32/CHIPDevicePlatformConfig.h b/src/platform/EFR32/CHIPDevicePlatformConfig.h index a32bb6a651db78..36ea40f8ebe700 100644 --- a/src/platform/EFR32/CHIPDevicePlatformConfig.h +++ b/src/platform/EFR32/CHIPDevicePlatformConfig.h @@ -47,10 +47,7 @@ #define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 #define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 - -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 3 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 4 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY 2 // ========== Platform-specific Configuration ========= diff --git a/src/platform/cc13x2_26x2/CHIPPlatformConfig.h b/src/platform/cc13x2_26x2/CHIPPlatformConfig.h index 6fabd3d32fa7e4..4d6fec8a2309dd 100644 --- a/src/platform/cc13x2_26x2/CHIPPlatformConfig.h +++ b/src/platform/cc13x2_26x2/CHIPPlatformConfig.h @@ -40,10 +40,7 @@ #define CHIP_CONFIG_PERSISTED_STORAGE_KEY_GLOBAL_MESSAGE_COUNTER 0x2 // ==================== Security Adaptations ==================== - -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 1 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 2 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 3 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY 2 // This platform uses mbedtls, but these defines don't seem to be used in source #define CHIP_CONFIG_USE_OPENSSL_ECC 0 diff --git a/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h b/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h index b55382633713af..8bbfc047b3edb6 100644 --- a/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h +++ b/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h @@ -43,9 +43,7 @@ #define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 3 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 4 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY 2 // ========== Platform-specific Configuration ========= diff --git a/src/platform/qpg/CHIPDevicePlatformConfig.h b/src/platform/qpg/CHIPDevicePlatformConfig.h index 2a950414f6cc26..81bcbcfa269419 100644 --- a/src/platform/qpg/CHIPDevicePlatformConfig.h +++ b/src/platform/qpg/CHIPDevicePlatformConfig.h @@ -40,9 +40,7 @@ #define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 3 -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 4 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_GLOBAL_EIDC_KEY 2 #define CHIP_DEVICE_CONFIG_ENABLE_DNSSD 1