Skip to content

Commit

Permalink
add urgent IM event support (#12459)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Feb 18, 2022
1 parent a180077 commit 2355561
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 45 deletions.
12 changes: 5 additions & 7 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,11 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, E
opts.mTimestamp.mType == Timestamp::Type::kSystem ? "Sys" : "Epoch", ChipLogValueX64(opts.mTimestamp.mValue));
#endif // CHIP_CONFIG_EVENT_LOGGING_VERBOSE_DEBUG_LOGS

ScheduleFlushIfNeeded(opts.mUrgent);
if (opts.mUrgent == EventOptions::Type::kUrgent)
{
ConcreteEventPath path(opts.mpEventSchema->mEndpointId, opts.mpEventSchema->mClusterId, opts.mpEventSchema->mEventId);
err = InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleUrgentEventDelivery(path);
}
}

return err;
Expand Down Expand Up @@ -851,12 +855,6 @@ CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void *
return CHIP_END_OF_TLV;
}

CHIP_ERROR EventManagement::ScheduleFlushIfNeeded(EventOptions::Type aUrgent)
{
// TODO: Implement ScheduleFlushIfNeeded
return CHIP_NO_ERROR;
}

void EventManagement::SetScheduledEventEndpoint(EventNumber * apEventEndpoints)
{
CircularEventBuffer * eventBuffer = mpEventBuffer;
Expand Down
33 changes: 0 additions & 33 deletions src/app/EventManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,39 +398,6 @@ class EventManagement
CHIP_ERROR FetchEventsSince(chip::TLV::TLVWriter & aWriter, ClusterInfo * apClusterInfolist, PriorityLevel aPriority,
EventNumber & aEventNumber, size_t & aEventCount);

/**
* @brief
* Schedule a log offload task.
*
* The function decides whether to schedule a task offload process,
* and if so, it schedules the `LoggingFlushHandler` to be run
* asynchronously on the Chip thread.
*
* The decision to schedule a flush is dependent on three factors:
*
* -- an explicit request to flush the buffer
*
* -- the state of the event buffer and the amount of data not yet
* synchronized with the event consumers
*
* -- whether there is an already pending request flush request event.
*
* The explicit request to schedule a flush is passed via an input
* parameter.
*
* The automatic flush is typically scheduled when the event buffers
* contain enough data to merit starting a new offload. Additional
* triggers -- such as minimum and maximum time between offloads --
* may also be taken into account depending on the offload strategy.
*
*
* @param aUrgent indiate whether the flush should be scheduled if it is urgent
*
* @retval #CHIP_ERROR_INCORRECT_STATE EventManagement module was not initialized fully.
* @retval #CHIP_NO_ERROR On success.
*/
CHIP_ERROR ScheduleFlushIfNeeded(EventOptions::Type aUrgent);

/**
* @brief
* Fetch the most recently vended Number for a particular priority level
Expand Down
5 changes: 5 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ uint16_t InteractionModelEngine::GetWriteClientArrayIndex(const WriteClient * co
return static_cast<uint16_t>(apWriteClient - mWriteClients);
}

uint16_t InteractionModelEngine::GetReadHandlerArrayIndex(const ReadHandler * const apReadHandler) const
{
return static_cast<uint16_t>(apReadHandler - mReadHandlers);
}

void InteractionModelEngine::ReleaseClusterInfoList(ClusterInfo *& aClusterInfo)
{
ClusterInfo * lastClusterInfo = aClusterInfo;
Expand Down
1 change: 1 addition & 0 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class InteractionModelEngine : public Messaging::ExchangeDelegate, public Comman

uint16_t GetWriteClientArrayIndex(const WriteClient * const apWriteClient) const;

uint16_t GetReadHandlerArrayIndex(const ReadHandler * const apReadHandler) const;
/**
* The Magic number of this InteractionModelEngine, the magic number is set during Init()
*/
Expand Down
6 changes: 6 additions & 0 deletions src/app/ReadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ class ReadHandler : public Messaging::ExchangeDelegate
NodeId GetInitiatorNodeId() const { return mInitiatorNodeId; }
FabricIndex GetAccessingFabricIndex() const { return mFabricIndex; }

void UnblockUrgentEventDelivery()
{
mHoldReport = false;
mDirty = true;
}

private:
friend class TestReadInteraction;
enum class HandlerState
Expand Down
17 changes: 17 additions & 0 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,23 @@ void Engine::OnReportConfirm()
ChipLogDetail(DataManagement, "<RE> OnReportConfirm: NumReports = %" PRIu32, mNumReportsInFlight);
}

CHIP_ERROR Engine::ScheduleUrgentEventDelivery(ConcreteEventPath & aPath)
{
for (auto & handler : InteractionModelEngine::GetInstance()->mReadHandlers)
{
for (auto clusterInfo = handler.GetEventClusterInfolist(); clusterInfo != nullptr; clusterInfo = clusterInfo->mpNext)
{
if (clusterInfo->IsEventPathSupersetOf(aPath))
{
ChipLogProgress(DataManagement, "<RE> Unblock Urgent Event Delivery for readHandler[%d]",
InteractionModelEngine::GetInstance()->GetReadHandlerArrayIndex(&handler));
handler.UnblockUrgentEventDelivery();
}
}
}
return ScheduleRun();
}

}; // namespace reporting
} // namespace app
} // namespace chip
Expand Down
7 changes: 7 additions & 0 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class Engine
*/
CHIP_ERROR SetDirty(ClusterInfo & aClusterInfo);

/**
* @brief
* Schedule the urgent event delivery
*
*/
CHIP_ERROR ScheduleUrgentEventDelivery(ConcreteEventPath & aPath);

private:
friend class TestReportingEngine;
/**
Expand Down
15 changes: 10 additions & 5 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class TestEventGenerator : public chip::app::EventLoggingDelegate
int32_t mStatus;
};

void GenerateEvents(nlTestSuite * apSuite, void * apContext)
void GenerateEvents(nlTestSuite * apSuite, void * apContext, bool aIsUrgent = false)
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::EventNumber eid1, eid2;
Expand All @@ -117,8 +117,12 @@ void GenerateEvents(nlTestSuite * apSuite, void * apContext)
chip::app::EventOptions options2;
TestEventGenerator testEventGenerator;

options1.mpEventSchema = &schema1;
options2.mpEventSchema = &schema2;
options1.mpEventSchema = &schema1;
options2.mpEventSchema = &schema2;
if (aIsUrgent)
{
options2.mUrgent = chip::app::EventOptions::Type::kUrgent;
}
chip::app::EventManagement & logMgmt = chip::app::EventManagement::GetInstance();
testEventGenerator.SetStatus(0);
err = logMgmt.LogEvent(&testEventGenerator, options1, eid1);
Expand Down Expand Up @@ -974,8 +978,6 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a
// Shouldn't have anything in the retransmit table when starting the test.
NL_TEST_ASSERT(apSuite, rm->TestGetCountRetransTable() == 0);

GenerateEvents(apSuite, apContext);

MockInteractionModelApp delegate;
auto * engine = chip::app::InteractionModelEngine::GetInstance();
err = engine->Init(&ctx.GetExchangeManager(), &delegate);
Expand Down Expand Up @@ -1024,6 +1026,9 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a
NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 2);
NL_TEST_ASSERT(apSuite, delegate.mNumSubscriptions == 1);

GenerateEvents(apSuite, apContext, true /*aIsUrgent*/);
NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->mHoldReport == false);
NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->mDirty == true);
chip::app::ClusterInfo dirtyPath1;
dirtyPath1.mClusterId = kTestClusterId;
dirtyPath1.mEndpointId = kTestEndpointId;
Expand Down

0 comments on commit 2355561

Please sign in to comment.