Remove default Event scheduler pointer in EventManagement (#36906)
* Remove default Event scheduler pointer in EventManagement
* Restyled by clang-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp
index 1321475..bcac83c 100644
--- a/src/app/EventManagement.cpp
+++ b/src/app/EventManagement.cpp
@@ -80,26 +80,20 @@
EventLoadOutContext * mpContext = nullptr;
};
-void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
- CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
- MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
- System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter)
+CHIP_ERROR EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
+ CircularEventBuffer * apCircularEventBuffer,
+ const LogStorageResources * const apLogStorageResources,
+ MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
+ System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter)
{
+ VerifyOrReturnError(apEventReporter != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
+ VerifyOrReturnError(aNumBuffers != 0, CHIP_ERROR_INVALID_ARGUMENT);
+ VerifyOrReturnError(mState == EventManagementStates::Shutdown, CHIP_ERROR_INCORRECT_STATE);
+
CircularEventBuffer * current = nullptr;
CircularEventBuffer * prev = nullptr;
CircularEventBuffer * next = nullptr;
- if (aNumBuffers == 0)
- {
- ChipLogError(EventLogging, "Invalid aNumBuffers");
- return;
- }
-
- if (mState != EventManagementStates::Shutdown)
- {
- ChipLogError(EventLogging, "Invalid EventManagement State");
- return;
- }
mpExchangeMgr = apExchangeManager;
for (uint32_t bufferIndex = 0; bufferIndex < aNumBuffers; bufferIndex++)
@@ -125,15 +119,9 @@
mMonotonicStartupTime = aMonotonicStartupTime;
- // TODO(#36890): Should remove using the global instance and rely only on passed in variable.
- if (apEventReporter == nullptr)
- {
- mpEventReporter = &InteractionModelEngine::GetInstance()->GetReportingEngine();
- }
- else
- {
- mpEventReporter = apEventReporter;
- }
+ mpEventReporter = apEventReporter;
+
+ return CHIP_NO_ERROR;
}
CHIP_ERROR EventManagement::CopyToNextBuffer(CircularEventBuffer * apEventBuffer)
@@ -355,7 +343,7 @@
{
sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter,
- aMonotonicStartupTime);
+ aMonotonicStartupTime, &InteractionModelEngine::GetInstance()->GetReportingEngine());
}
/**
diff --git a/src/app/EventManagement.h b/src/app/EventManagement.h
index f5687b5..81babec 100644
--- a/src/app/EventManagement.h
+++ b/src/app/EventManagement.h
@@ -228,11 +228,13 @@
*
* @param[in] apEventReporter Event reporter to be notified when events are generated.
*
+ * @return CHIP_ERROR CHIP Error Code
+ *
*/
- void Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, CircularEventBuffer * apCircularEventBuffer,
- const LogStorageResources * const apLogStorageResources,
- MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
- System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter = nullptr);
+ CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
+ CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
+ MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
+ System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter);
static EventManagement & GetInstance();
diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp
index 2afb524..128ccd6 100644
--- a/src/app/server/Server.cpp
+++ b/src/app/server/Server.cpp
@@ -283,9 +283,12 @@
{ &sCritEventBuffer[0], sizeof(sCritEventBuffer), app::PriorityLevel::Critical }
};
- app::EventManagement::GetInstance().Init(&mExchangeMgr, CHIP_NUM_EVENT_LOGGING_BUFFERS, &sLoggingBuffer[0],
- &logStorageResources[0], &sGlobalEventIdCounter,
- std::chrono::duration_cast<System::Clock::Milliseconds64>(mInitTimestamp));
+ err = app::EventManagement::GetInstance().Init(&mExchangeMgr, CHIP_NUM_EVENT_LOGGING_BUFFERS, &sLoggingBuffer[0],
+ &logStorageResources[0], &sGlobalEventIdCounter,
+ std::chrono::duration_cast<System::Clock::Milliseconds64>(mInitTimestamp),
+ &app::InteractionModelEngine::GetInstance()->GetReportingEngine());
+
+ SuccessOrExit(err);
}
#endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT