diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 089d2dae3b46ee..79471aef7556f6 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -432,16 +432,24 @@ CHIP_ERROR Engine::ScheduleRun() return CHIP_NO_ERROR; } - if (InteractionModelEngine::GetInstance()->GetExchangeManager() != nullptr) + Messaging::ExchangeManager * exchangeManager = InteractionModelEngine::GetInstance()->GetExchangeManager(); + if (exchangeManager == nullptr) { - mRunScheduled = true; - return InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->ScheduleWork(Run, - this); + return CHIP_ERROR_INCORRECT_STATE; } - else + SessionManager * sessionManager = exchangeManager->GetSessionManager(); + if (sessionManager == nullptr) + { + return CHIP_ERROR_INCORRECT_STATE; + } + System::Layer * systemLayer = sessionManager->SystemLayer(); + if (systemLayer == nullptr) { return CHIP_ERROR_INCORRECT_STATE; } + ReturnErrorOnFailure(systemLayer->ScheduleWork(Run, this)); + mRunScheduled = true; + return CHIP_NO_ERROR; } void Engine::Run()