Skip to content

Commit 9235f36

Browse files
yyzhong-grestyled-commits
authored andcommittedJan 12, 2025
Remove default Event scheduler pointer in EventManagement (project-chip#36906)
* Remove default Event scheduler pointer in EventManagement * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 370894a commit 9235f36

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed
 

‎src/app/EventManagement.cpp

+13-25
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,20 @@ struct CopyAndAdjustDeltaTimeContext
8080
EventLoadOutContext * mpContext = nullptr;
8181
};
8282

83-
void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
84-
CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
85-
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
86-
System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter)
83+
CHIP_ERROR EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
84+
CircularEventBuffer * apCircularEventBuffer,
85+
const LogStorageResources * const apLogStorageResources,
86+
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
87+
System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter)
8788
{
89+
VerifyOrReturnError(apEventReporter != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
90+
VerifyOrReturnError(aNumBuffers != 0, CHIP_ERROR_INVALID_ARGUMENT);
91+
VerifyOrReturnError(mState == EventManagementStates::Shutdown, CHIP_ERROR_INCORRECT_STATE);
92+
8893
CircularEventBuffer * current = nullptr;
8994
CircularEventBuffer * prev = nullptr;
9095
CircularEventBuffer * next = nullptr;
9196

92-
if (aNumBuffers == 0)
93-
{
94-
ChipLogError(EventLogging, "Invalid aNumBuffers");
95-
return;
96-
}
97-
98-
if (mState != EventManagementStates::Shutdown)
99-
{
100-
ChipLogError(EventLogging, "Invalid EventManagement State");
101-
return;
102-
}
10397
mpExchangeMgr = apExchangeManager;
10498

10599
for (uint32_t bufferIndex = 0; bufferIndex < aNumBuffers; bufferIndex++)
@@ -125,15 +119,9 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3
125119

126120
mMonotonicStartupTime = aMonotonicStartupTime;
127121

128-
// TODO(#36890): Should remove using the global instance and rely only on passed in variable.
129-
if (apEventReporter == nullptr)
130-
{
131-
mpEventReporter = &InteractionModelEngine::GetInstance()->GetReportingEngine();
132-
}
133-
else
134-
{
135-
mpEventReporter = apEventReporter;
136-
}
122+
mpEventReporter = apEventReporter;
123+
124+
return CHIP_NO_ERROR;
137125
}
138126

139127
CHIP_ERROR EventManagement::CopyToNextBuffer(CircularEventBuffer * apEventBuffer)
@@ -355,7 +343,7 @@ void EventManagement::CreateEventManagement(Messaging::ExchangeManager * apExcha
355343
{
356344

357345
sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter,
358-
aMonotonicStartupTime);
346+
aMonotonicStartupTime, &InteractionModelEngine::GetInstance()->GetReportingEngine());
359347
}
360348

361349
/**

‎src/app/EventManagement.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,13 @@ class EventManagement : public DataModel::EventsGenerator
228228
*
229229
* @param[in] apEventReporter Event reporter to be notified when events are generated.
230230
*
231+
* @return CHIP_ERROR CHIP Error Code
232+
*
231233
*/
232-
void Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, CircularEventBuffer * apCircularEventBuffer,
233-
const LogStorageResources * const apLogStorageResources,
234-
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
235-
System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter = nullptr);
234+
CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
235+
CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
236+
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
237+
System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter);
236238

237239
static EventManagement & GetInstance();
238240

‎src/app/server/Server.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,12 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
283283
{ &sCritEventBuffer[0], sizeof(sCritEventBuffer), app::PriorityLevel::Critical }
284284
};
285285

286-
app::EventManagement::GetInstance().Init(&mExchangeMgr, CHIP_NUM_EVENT_LOGGING_BUFFERS, &sLoggingBuffer[0],
287-
&logStorageResources[0], &sGlobalEventIdCounter,
288-
std::chrono::duration_cast<System::Clock::Milliseconds64>(mInitTimestamp));
286+
err = app::EventManagement::GetInstance().Init(&mExchangeMgr, CHIP_NUM_EVENT_LOGGING_BUFFERS, &sLoggingBuffer[0],
287+
&logStorageResources[0], &sGlobalEventIdCounter,
288+
std::chrono::duration_cast<System::Clock::Milliseconds64>(mInitTimestamp),
289+
&app::InteractionModelEngine::GetInstance()->GetReportingEngine());
290+
291+
SuccessOrExit(err);
289292
}
290293
#endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT
291294

0 commit comments

Comments
 (0)
Please sign in to comment.