Skip to content

Commit

Permalink
Rename it to EventReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
yyzhong-g committed Dec 13, 2024
1 parent d14ef63 commit 2edc0ed
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
9 changes: 8 additions & 1 deletion src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ source_set("test-event-trigger") {
sources = [ "TestEventTriggerDelegate.h" ]
}

source_set("event-reporter") {
sources = [
"EventReporter.h",
]
}

# interaction-model is a static-library because it currently requires global functions (app/util/...) that are stubbed in different test files that depend on the app static_library
# which in tern depens on the interaction-model.
# Using source_set prevents the unit test to build correctly.
Expand All @@ -163,7 +169,6 @@ static_library("interaction-model") {
"CommandSender.h",
"DeviceProxy.cpp",
"DeviceProxy.h",
"EventScheduler.h",
"InteractionModelDelegatePointers.cpp",
"InteractionModelDelegatePointers.h",
"InteractionModelEngine.cpp",
Expand Down Expand Up @@ -211,6 +216,7 @@ static_library("interaction-model") {
":app_config",
":command-handler-impl",
":constants",
":event-reporter",
":paths",
":subscription-info-provider",
"${chip_root}/src/app/MessageDef",
Expand Down Expand Up @@ -456,6 +462,7 @@ static_library("app") {
":app_config",
":attribute-access",
":constants",
":event-reporter",
":global-attributes",
":interaction-model",
"${chip_root}/src/app/data-model",
Expand Down
13 changes: 7 additions & 6 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct CopyAndAdjustDeltaTimeContext
void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
System::Clock::Milliseconds64 aMonotonicStartupTime, EventScheduler * apEventScheduler)
System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter)
{
CircularEventBuffer * current = nullptr;
CircularEventBuffer * prev = nullptr;
Expand Down Expand Up @@ -125,13 +125,14 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3

mMonotonicStartupTime = aMonotonicStartupTime;

if (apEventScheduler == nullptr)
// Should remove using the global instance and rely only on passed in variable.
if (apEventReporter == nullptr)
{
mpEventScheduler = &InteractionModelEngine::GetInstance()->GetReportingEngine();
mpEventReporter = &InteractionModelEngine::GetInstance()->GetReportingEngine();
}
else
{
mpEventScheduler = apEventScheduler;
mpEventReporter = apEventReporter;
}
}

Expand Down Expand Up @@ -499,9 +500,9 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c
opts.mTimestamp.mType == Timestamp::Type::kSystem ? "Sys" : "Epoch", ChipLogValueX64(opts.mTimestamp.mValue));
#endif // CHIP_CONFIG_EVENT_LOGGING_VERBOSE_DEBUG_LOGS

if (mpEventScheduler)
if (mpEventReporter)
{
err = mpEventScheduler->ScheduleEventDelivery(opts.mPath, mBytesWritten);
err = mpEventReporter->NewEventGenerated(opts.mPath, mBytesWritten);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/EventManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "EventLoggingDelegate.h"
#include <access/SubjectDescriptor.h>
#include <app/EventLoggingTypes.h>
#include <app/EventScheduler.h>
#include <app/EventReporter.h>
#include <app/MessageDef/EventDataIB.h>
#include <app/MessageDef/StatusIB.h>
#include <app/data-model-provider/EventsGenerator.h>
Expand Down Expand Up @@ -226,14 +226,14 @@ class EventManagement : public DataModel::EventsGenerator
* time 0" for cases when we use
* system-time event timestamps.
*
* @param[in] apEventScheduler Scheduler to deliver the event, default is the reporting
* @param[in] apEventReporter Event reporter to deliver the event, default is the reporting
* engine in InteractionModelEngine.
*
*/
void Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, CircularEventBuffer * apCircularEventBuffer,
const LogStorageResources * const apLogStorageResources,
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
System::Clock::Milliseconds64 aMonotonicStartupTime, EventScheduler * apEventScheduler = nullptr);
System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter = nullptr);

static EventManagement & GetInstance();

Expand Down Expand Up @@ -568,7 +568,7 @@ class EventManagement : public DataModel::EventsGenerator

System::Clock::Milliseconds64 mMonotonicStartupTime;

EventScheduler * mpEventScheduler = nullptr;
EventReporter * mpEventReporter = nullptr;
};

} // namespace app
Expand Down
10 changes: 5 additions & 5 deletions src/app/EventScheduler.h → src/app/EventReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @file
*
* @brief
* Define EventScheduler interface. Event scheduler is used by EventManagement to notify that events are ready to be scheduled.
* Define EventReporter interface. Event reproter is used by EventManagement to notify that events are ready to be reported.
* Usually this is implemented by the Reporting Engine to find the proper ReadHandlers and deliver the events.
*
*/
Expand All @@ -32,19 +32,19 @@
namespace chip {
namespace app {

class EventScheduler
class EventReporter
{
public:
virtual ~EventScheduler() = default;
virtual ~EventReporter() = default;

/**
* @brief
* Schedule the event delivery
* Notify of a new event generated.
*
* @param[in] aPath The path to the event.
* @param[in] aBytesWritten Bytes that the event is written into the buffer in EventManagement.
*/
CHIP_ERROR virtual ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBytesWritten) = 0;
CHIP_ERROR virtual NewEventGenerated(ConcreteEventPath & aPath, uint32_t aBytesWritten) = 0;
};

} // namespace app
Expand Down
2 changes: 1 addition & 1 deletion src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ CHIP_ERROR InteractionModelEngine::Init(Messaging::ExchangeManager * apExchangeM
ReturnErrorOnFailure(mpFabricTable->AddFabricDelegate(this));
ReturnErrorOnFailure(mpExchangeMgr->RegisterUnsolicitedMessageHandlerForProtocol(Protocols::InteractionModel::Id, this));

mReportingEngine.Init(eventManagement);
mReportingEngine.Init((eventManagement != nullptr) ? eventManagement : &EventManagement::GetInstance());

StatusIB::RegisterErrorFormatter();

Expand Down
13 changes: 3 additions & 10 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,10 @@ Engine::Engine(InteractionModelEngine * apImEngine) : mpImEngine(apImEngine) {}

CHIP_ERROR Engine::Init(EventManagement * apEventManagement)
{
VerifyOrReturnError(apEventManagement != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mNumReportsInFlight = 0;
mCurReadHandlerIdx = 0;

if (apEventManagement == nullptr)
{
mpEventManagement = &EventManagement::GetInstance();
}
else
{
mpEventManagement = apEventManagement;
}
mpEventManagement = apEventManagement;

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -1138,7 +1131,7 @@ CHIP_ERROR Engine::ScheduleBufferPressureEventDelivery(uint32_t aBytesWritten)
return CHIP_NO_ERROR;
}

CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBytesWritten)
CHIP_ERROR Engine::NewEventGenerated(ConcreteEventPath & aPath, uint32_t aBytesWritten)
{
// If we literally have no read handlers right now that care about any events,
// we don't need to call schedule run for event.
Expand Down
21 changes: 10 additions & 11 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#pragma once

#include <access/AccessControl.h>
#include <app/EventScheduler.h>
#include <app/EventReporter.h>
#include <app/MessageDef/ReportDataMessage.h>
#include <app/ReadHandler.h>
#include <app/data-model-provider/ProviderChangeListener.h>
Expand Down Expand Up @@ -56,7 +56,7 @@ namespace reporting {
* At its core, it tries to gather and pack as much relevant attributes changes and/or events as possible into a report
* message before sending that to the reader. It continues to do so until it has no more work to do.
*/
class Engine : public DataModel::ProviderChangeListener, public EventScheduler
class Engine : public DataModel::ProviderChangeListener, public EventReporter
{
public:
/**
Expand All @@ -67,12 +67,12 @@ class Engine : public DataModel::ProviderChangeListener, public EventScheduler
/**
* Initializes the reporting engine. Should only be called once.
*
* @param[in] A pointer to EventManagement. Use the global one by default.
* @param[in] A pointer to EventManagement, should not be a nullptr.
*
* @retval #CHIP_NO_ERROR On success.
* @retval other Was unable to retrieve data and write it into the writer.
*/
CHIP_ERROR Init(EventManagement * apEventManagement = nullptr);
CHIP_ERROR Init(EventManagement * apEventManagement);

void Shutdown();

Expand All @@ -99,13 +99,6 @@ class Engine : public DataModel::ProviderChangeListener, public EventScheduler
*/
CHIP_ERROR SetDirty(const AttributePathParams & aAttributePathParams);

/**
* @brief
* Schedule the event delivery
*
*/
CHIP_ERROR ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBytesWritten) override;

/*
* Resets the tracker that tracks the currently serviced read handler.
* apReadHandler can be non-null to indicate that the reset is due to a
Expand Down Expand Up @@ -185,6 +178,12 @@ class Engine : public DataModel::ProviderChangeListener, public EventScheduler
bool IsClusterDataVersionMatch(const SingleLinkedListNode<DataVersionFilter> * aDataVersionFilterList,
const ConcreteReadAttributePath & aPath);

/**
* EventReporter implementations.
*
*/
CHIP_ERROR NewEventGenerated(ConcreteEventPath & aPath, uint32_t aBytesWritten) override;

/**
* Send Report via ReadHandler
*
Expand Down

0 comments on commit 2edc0ed

Please sign in to comment.