Skip to content

Commit

Permalink
Added mechanism to emit report when switching to active mode if
Browse files Browse the repository at this point in the history
necessary
  • Loading branch information
lpbeliveau-silabs committed Jul 25, 2023
1 parent 5b4f800 commit a6d1048
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/app/icd/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ void ICDManager::UpdateOperationState(OperationalState state)
{
ChipLogError(AppServer, "Failed to set Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format());
}

InteractionModelEngine::GetInstance()->GetReportScheduler()->OnActiveModeEntered();
}
else
{
Expand Down
62 changes: 52 additions & 10 deletions src/app/reporting/ReportScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ class ReportScheduler : public ReadHandler::Observer
MinIntervalElapsed = (1 << 0),
MaxIntervalElapsed = (1 << 1),
};
void SetTestFlags(TestFlags aFlag, bool aValue) { mFlags.Set(aFlag, aValue); }
bool GetTestFlags(TestFlags aFlag) const { return mFlags.Has(aFlag); }
void SetTestFlags(TestFlags aFlag, bool aValue)
{
mFlags.Set(aFlag, aValue);
}
bool GetTestFlags(TestFlags aFlag) const
{
return mFlags.Has(aFlag);
}
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST

ReadHandlerNode(ReadHandler * aReadHandler, TimerDelegate * aTimerDelegate, ReportScheduler * aScheduler) :
Expand All @@ -83,7 +89,10 @@ class ReportScheduler : public ReadHandler::Observer
mReadHandler = aReadHandler;
SetIntervalTimeStamps(aReadHandler);
}
ReadHandler * GetReadHandler() const { return mReadHandler; }
ReadHandler * GetReadHandler() const
{
return mReadHandler;
}

/// @brief Check if the Node is reportable now, meaning its readhandler was made reportable by attribute dirtying and
/// handler state, and minimal time interval since last report has elapsed, or the maximal time interval since last
Expand All @@ -102,7 +111,10 @@ class ReportScheduler : public ReadHandler::Observer
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
}

bool IsEngineRunScheduled() const { return mEngineRunScheduled; }
bool IsEngineRunScheduled() const
{
return mEngineRunScheduled;
}
void SetEngineRunScheduled(bool aEngineRunScheduled)
{
mEngineRunScheduled = aEngineRunScheduled;
Expand Down Expand Up @@ -140,9 +152,18 @@ class ReportScheduler : public ReadHandler::Observer
mSyncTimestamp = aSyncTimestamp;
}

System::Clock::Timestamp GetMinTimestamp() const { return mMinTimestamp; }
System::Clock::Timestamp GetMaxTimestamp() const { return mMaxTimestamp; }
System::Clock::Timestamp GetSyncTimestamp() const { return mSyncTimestamp; }
System::Clock::Timestamp GetMinTimestamp() const
{
return mMinTimestamp;
}
System::Clock::Timestamp GetMaxTimestamp() const
{
return mMaxTimestamp;
}
System::Clock::Timestamp GetSyncTimestamp() const
{
return mSyncTimestamp;
}

private:
#ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST
Expand All @@ -167,14 +188,35 @@ class ReportScheduler : public ReadHandler::Observer

virtual void ReportTimerCallback() = 0;

void OnActiveModeEntered()
{
for (auto & iter : mReadHandlerList)
{
if (iter.IsReportableNow())
{
OnBecameReportable(iter.GetReadHandler());
break;
}
}
}

/// @brief Check whether a ReadHandler is reportable right now, taking into account its minimum and maximum intervals.
/// @param aReadHandler read handler to check
bool IsReportableNow(ReadHandler * aReadHandler) { return FindReadHandlerNode(aReadHandler)->IsReportableNow(); }
bool IsReportableNow(ReadHandler * aReadHandler)
{
return FindReadHandlerNode(aReadHandler)->IsReportableNow();
}
/// @brief Check if a ReadHandler is reportable without considering the timing
bool IsReadHandlerReportable(ReadHandler * aReadHandler) const { return aReadHandler->IsReportable(); }
bool IsReadHandlerReportable(ReadHandler * aReadHandler) const
{
return aReadHandler->IsReportable();
}

/// @brief Get the number of ReadHandlers registered in the scheduler's node pool
size_t GetNumReadHandlers() const { return mNodesPool.Allocated(); }
size_t GetNumReadHandlers() const
{
return mNodesPool.Allocated();
}

#ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST
void RunNodeCallbackForHandler(const ReadHandler * aReadHandler)
Expand Down

0 comments on commit a6d1048

Please sign in to comment.