Skip to content

Commit

Permalink
Fix urgent event support (#15884)
Browse files Browse the repository at this point in the history
Add python event urgency test support
  • Loading branch information
yunhanw-google authored Mar 9, 2022
1 parent 8a07515 commit cd44f9b
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 108 deletions.
1 change: 1 addition & 0 deletions src/app/ClusterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct ClusterInfo
ListIndex mListIndex = kInvalidListIndex; // uint16
EndpointId mEndpointId = kInvalidEndpointId; // uint16
Optional<DataVersion> mDataVersion; // uint32
bool mIsUrgentEvent = false; // uint8
};
} // namespace app
} // namespace chip
9 changes: 2 additions & 7 deletions src/app/EventLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,18 @@ class EventLogger : public EventLoggingDelegate
* LogEvent has 2 variant, one for fabric-scoped events and one for non-fabric-scoped events.
* @param[in] aEventData The event cluster object
* @param[in] aEndpoint The current cluster's Endpoint Id
* @param[in] aUrgent The EventOption Type, kUrgent or kNotUrgent
* @param[out] aEventNumber The event Number if the event was written to the
* log, 0 otherwise. The Event number is expected to monotonically increase.
*
* @return CHIP_ERROR CHIP Error Code
*/
template <typename T, std::enable_if_t<DataModel::IsFabricScoped<T>::value, bool> = true>
CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventNumber & aEventNumber,
EventOptions::Type aUrgent = EventOptions::Type::kNotUrgent)
CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventNumber & aEventNumber)
{
EventLogger<T> eventData(aEventData);
ConcreteEventPath path(aEndpoint, aEventData.GetClusterId(), aEventData.GetEventId());
EventManagement & logMgmt = chip::app::EventManagement::GetInstance();
EventOptions eventOptions;
eventOptions.mUrgent = aUrgent;
eventOptions.mPath = path;
eventOptions.mPriority = aEventData.GetPriorityLevel();
eventOptions.mFabricIndex = aEventData.GetFabricIndex();
Expand All @@ -88,14 +85,12 @@ CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventNumber & aE
}

template <typename T, std::enable_if_t<!DataModel::IsFabricScoped<T>::value, bool> = true>
CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventNumber & aEventNumber,
EventOptions::Type aUrgent = EventOptions::Type::kNotUrgent)
CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventNumber & aEventNumber)
{
EventLogger<T> eventData(aEventData);
ConcreteEventPath path(aEndpoint, aEventData.GetClusterId(), aEventData.GetEventId());
EventManagement & logMgmt = chip::app::EventManagement::GetInstance();
EventOptions eventOptions;
eventOptions.mUrgent = aUrgent;
eventOptions.mPath = path;
eventOptions.mPriority = aEventData.GetPriorityLevel();
return logMgmt.LogEvent(&eventData, eventOptions, aEventNumber);
Expand Down
14 changes: 2 additions & 12 deletions src/app/EventLoggingTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,11 @@ struct Timestamp
class EventOptions
{
public:
enum class Type
{
kUrgent = 0,
kNotUrgent,
};
EventOptions() : mPriority(PriorityLevel::Invalid), mUrgent(Type::kNotUrgent) {}
EventOptions(Timestamp aTimestamp) : mTimestamp(aTimestamp), mPriority(PriorityLevel::Invalid), mUrgent(Type::kNotUrgent) {}

EventOptions(Timestamp aTimestamp, Type aUrgent) : mTimestamp(aTimestamp), mPriority(PriorityLevel::Invalid), mUrgent(aUrgent)
{}
EventOptions() : mPriority(PriorityLevel::Invalid) {}
EventOptions(Timestamp aTimestamp) : mTimestamp(aTimestamp), mPriority(PriorityLevel::Invalid) {}
ConcreteEventPath mPath;
Timestamp mTimestamp;
PriorityLevel mPriority = PriorityLevel::Invalid;
Type mUrgent = Type::kNotUrgent; /**< A flag denoting if the event is time sensitive. When kUrgent is set, it causes
the event log to be flushed. */
// kUndefinedFabricIndex 0 means not fabric associated at all
FabricIndex mFabricIndex = kUndefinedFabricIndex;
};
Expand Down
5 changes: 1 addition & 4 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even
eventPathBuilder.Endpoint(apOptions->mPath.mEndpointId)
.Cluster(apOptions->mPath.mClusterId)
.Event(apOptions->mPath.mEventId)
.IsUrgent(apOptions->mUrgent == EventOptions::Type::kUrgent)
.EndOfEventPathIB();
ReturnErrorOnFailure(eventPathBuilder.GetError());
eventDataIBBuilder.EventNumber(apContext->mCurrentEventNumber).Priority(chip::to_underlying(apContext->mPriority));
Expand Down Expand Up @@ -476,7 +475,6 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c
// Create all event specific data
// Timestamp; encoded as a delta time

opts.mUrgent = aEventOptions.mUrgent;
opts.mPath = aEventOptions.mPath;
opts.mFabricIndex = aEventOptions.mFabricIndex;

Expand Down Expand Up @@ -533,8 +531,7 @@ 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

err = InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleEventDelivery(opts.mPath, opts.mUrgent,
mBytesWritten);
err = InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleEventDelivery(opts.mPath, mBytesWritten);
}

return err;
Expand Down
5 changes: 3 additions & 2 deletions src/app/EventPathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace chip {
namespace app {
struct EventPathParams
{
EventPathParams(EndpointId aEndpointId, ClusterId aClusterId, EventId aEventId) :
mEndpointId(aEndpointId), mClusterId(aClusterId), mEventId(aEventId)
EventPathParams(EndpointId aEndpointId, ClusterId aClusterId, EventId aEventId, bool aUrgentEvent = false) :
mEndpointId(aEndpointId), mClusterId(aClusterId), mEventId(aEventId), mIsUrgentEvent(aUrgentEvent)
{}
EventPathParams() {}
bool IsSamePath(const EventPathParams & other) const
Expand All @@ -47,6 +47,7 @@ struct EventPathParams
EndpointId mEndpointId = kInvalidEndpointId;
ClusterId mClusterId = kInvalidClusterId;
EventId mEventId = kInvalidEventId;
bool mIsUrgentEvent = false;
};
} // namespace app
} // namespace chip
4 changes: 4 additions & 0 deletions src/app/MessageDef/EventPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ CHIP_ERROR EventPathIB::Builder::Encode(const EventPathParams & aEventPathParams
Event(aEventPathParams.mEventId);
}

if (aEventPathParams.mIsUrgentEvent)
{
IsUrgent(aEventPathParams.mIsUrgentEvent);
}
EndOfEventPathIB();
return GetError();
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,13 @@ CHIP_ERROR ReadHandler::ProcessEventPaths(EventPathIBs::Parser & aEventPathsPars
}
ReturnErrorOnFailure(err);

err = path.GetIsUrgent(&(clusterInfo.mIsUrgentEvent));
if (CHIP_END_OF_TLV == err)
{
err = CHIP_NO_ERROR;
}
ReturnErrorOnFailure(err);

ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->PushFront(mpEventClusterInfoList, clusterInfo));
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/clusters/basic/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class PlatformMgrDelegate : public DeviceLayer::PlatformManagerDelegate
Events::StartUp::Type event{ softwareVersion };
EventNumber eventNumber;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber, EventOptions::Type::kUrgent);
CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "PlatformMgrDelegate: Failed to record StartUp event: %" CHIP_ERROR_FORMAT, err.Format());
Expand All @@ -359,7 +359,7 @@ class PlatformMgrDelegate : public DeviceLayer::PlatformManagerDelegate
Events::ShutDown::Type event;
EventNumber eventNumber;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber, EventOptions::Type::kUrgent);
CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "PlatformMgrDelegate: Failed to record ShutDown event: %" CHIP_ERROR_FORMAT, err.Format());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
Events::BootReason::Type event{ static_cast<EmberAfBootReasonType>(bootReason) };
EventNumber eventNumber;

CHIP_ERROR err = LogEvent(event, 0, eventNumber, EventOptions::Type::kUrgent);
CHIP_ERROR err = LogEvent(event, 0, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record BootReason event: %" CHIP_ERROR_FORMAT, err.Format());
Expand All @@ -233,7 +233,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
reinterpret_cast<const HardwareFaultType *>(previous.data()), previous.size());
Events::HardwareFaultChange::Type event{ currentList, previousList };

if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber, EventOptions::Type::kUrgent))
if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber))
{
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record HardwareFault event");
}
Expand All @@ -259,7 +259,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
DataModel::List<const RadioFaultType>(reinterpret_cast<const RadioFaultType *>(previous.data()), previous.size());
Events::RadioFaultChange::Type event{ currentList, previousList };

if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber, EventOptions::Type::kUrgent))
if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber))
{
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record RadioFault event");
}
Expand All @@ -285,7 +285,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
reinterpret_cast<const NetworkFaultType *>(previous.data()), previous.size());
Events::NetworkFaultChange::Type event{ currentList, previousList };

if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber, EventOptions::Type::kUrgent))
if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber))
{
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record NetworkFault event");
}
Expand Down
23 changes: 11 additions & 12 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,18 +735,21 @@ CHIP_ERROR Engine::ScheduleBufferPressureEventDelivery(uint32_t aBytesWritten)
return CHIP_NO_ERROR;
}

CHIP_ERROR Engine::ScheduleUrgentEventDelivery(ConcreteEventPath & aPath)
CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBytesWritten)
{
InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([&aPath](ReadHandler * handler) {
bool isUrgentEvent = false;
InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([&aPath, &isUrgentEvent](ReadHandler * handler) {
if (handler->IsType(ReadHandler::InteractionType::Read))
{
return Loop::Continue;
}

for (auto clusterInfo = handler->GetEventClusterInfolist(); clusterInfo != nullptr; clusterInfo = clusterInfo->mpNext)
for (auto * interestedPath = handler->GetEventClusterInfolist(); interestedPath != nullptr;
interestedPath = interestedPath->mpNext)
{
if (clusterInfo->IsEventPathSupersetOf(aPath))
if (interestedPath->IsEventPathSupersetOf(aPath) && interestedPath->mIsUrgentEvent)
{
isUrgentEvent = true;
handler->UnblockUrgentEventDelivery();
break;
}
Expand All @@ -755,18 +758,14 @@ CHIP_ERROR Engine::ScheduleUrgentEventDelivery(ConcreteEventPath & aPath)
return Loop::Continue;
});

return ScheduleRun();
}

CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, EventOptions::Type aUrgent, uint32_t aBytesWritten)
{
if (aUrgent != EventOptions::Type::kUrgent)
if (isUrgentEvent)
{
return ScheduleBufferPressureEventDelivery(aBytesWritten);
ChipLogDetail(DataManagement, "urgent event schedule run");
return ScheduleRun();
}
else
{
return ScheduleUrgentEventDelivery(aPath);
return ScheduleBufferPressureEventDelivery(aBytesWritten);
}
return CHIP_NO_ERROR;
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Engine
* Schedule the event delivery
*
*/
CHIP_ERROR ScheduleEventDelivery(ConcreteEventPath & aPath, EventOptions::Type aUrgent, uint32_t aBytesWritten);
CHIP_ERROR ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBytesWritten);

/*
* Resets the tracker that tracks the currently serviced read handler.
Expand Down Expand Up @@ -164,7 +164,6 @@ class Engine
*/
static void Run(System::Layer * aSystemLayer, void * apAppState);

CHIP_ERROR ScheduleUrgentEventDelivery(ConcreteEventPath & aPath);
CHIP_ERROR ScheduleBufferPressureEventDelivery(uint32_t aBytesWritten);
void GetMinEventLogPosition(uint32_t & aMinLogPosition);

Expand Down
Loading

0 comments on commit cd44f9b

Please sign in to comment.