From 12397283c2343cdd8a22e335ae4a06f7fb6e412b Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 17 Feb 2022 20:38:27 -0800 Subject: [PATCH] Best-effort flush events at shutdown (#15331) --- src/app/reporting/Engine.cpp | 19 +++++++++++++++++++ src/app/reporting/Engine.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index a2da0d446ee95c..667a5909647dd6 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -42,6 +42,9 @@ CHIP_ERROR Engine::Init() void Engine::Shutdown() { + // Flush out the event buffer synchronously + ScheduleUrgentEventDeliverySync(); + mNumReportsInFlight = 0; mCurReadHandlerIdx = 0; mGlobalDirtySet.ReleaseAll(); @@ -746,6 +749,22 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, EventOptions return CHIP_NO_ERROR; } +void Engine::ScheduleUrgentEventDeliverySync() +{ + InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([](ReadHandler * handler) { + if (handler->IsType(ReadHandler::InteractionType::Read)) + { + return Loop::Continue; + } + + handler->UnblockUrgentEventDelivery(); + + return Loop::Continue; + }); + + Run(); +} + }; // namespace reporting } // namespace app } // namespace chip diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index b8f430bd8c6663..759d6d50dc8f09 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -146,6 +146,7 @@ class Engine CHIP_ERROR ScheduleUrgentEventDelivery(ConcreteEventPath & aPath); CHIP_ERROR ScheduleBufferPressureEventDelivery(uint32_t aBytesWritten); void GetMinEventLogPosition(uint32_t & aMinLogPosition); + void ScheduleUrgentEventDeliverySync(); /** * If the provided path is a superset of our of our existing paths, update that existing path to match the