Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default Event scheduler pointer in EventManagement #36906

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,20 @@ struct CopyAndAdjustDeltaTimeContext
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++)
Expand All @@ -125,15 +119,9 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3

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)
Expand Down Expand Up @@ -355,7 +343,7 @@ void EventManagement::CreateEventManagement(Messaging::ExchangeManager * apExcha
{

sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter,
aMonotonicStartupTime);
aMonotonicStartupTime, &InteractionModelEngine::GetInstance()->GetReportingEngine());
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/app/EventManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@ class EventManagement : public DataModel::EventsGenerator
*
* @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();

Expand Down
9 changes: 6 additions & 3 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,12 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
{ &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

Expand Down
Loading