@@ -63,6 +63,15 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
63
63
class ReadHandlerNode : public TimerContext
64
64
{
65
65
public:
66
+ enum class ReadHandlerNodeFlags : uint8_t
67
+ {
68
+ // Flag to indicate if the engine run is already scheduled so the scheduler can ignore
69
+ // it when calculating the next run time
70
+ EngineRunScheduled = (1 << 0 ),
71
+ // Flag to allow the read handler to be synced with other handlers that have an earlier max timestamp
72
+ CanBeSynced = (1 << 1 ),
73
+ };
74
+
66
75
ReadHandlerNode (ReadHandler * aReadHandler, ReportScheduler * aScheduler, const Timestamp & now) : mScheduler (aScheduler)
67
76
{
68
77
VerifyOrDie (aReadHandler != nullptr );
@@ -80,11 +89,16 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
80
89
bool IsReportableNow (const Timestamp & now) const
81
90
{
82
91
return (mReadHandler ->CanStartReporting () &&
83
- (now >= mMinTimestamp && (mReadHandler ->IsDirty () || now >= mMaxTimestamp || now >= mSyncTimestamp )));
92
+ (now >= mMinTimestamp && (mReadHandler ->IsDirty () || now >= mMaxTimestamp || CanBeSynced () )));
84
93
}
85
94
86
- bool IsEngineRunScheduled () const { return mEngineRunScheduled ; }
87
- void SetEngineRunScheduled (bool aEngineRunScheduled) { mEngineRunScheduled = aEngineRunScheduled; }
95
+ bool IsEngineRunScheduled () const { return mFlags .Has (ReadHandlerNodeFlags::EngineRunScheduled); }
96
+ void SetEngineRunScheduled (bool aEngineRunScheduled)
97
+ {
98
+ mFlags .Set (ReadHandlerNodeFlags::EngineRunScheduled, aEngineRunScheduled);
99
+ }
100
+ bool CanBeSynced () const { return mFlags .Has (ReadHandlerNodeFlags::CanBeSynced); }
101
+ void SetCanBeSynced (bool aCanBeSynced) { mFlags .Set (ReadHandlerNodeFlags::CanBeSynced, aCanBeSynced); }
88
102
89
103
// / @brief Set the interval timestamps for the node based on the read handler reporting intervals
90
104
// / @param aReadHandler read handler to get the intervals from
@@ -94,9 +108,8 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
94
108
{
95
109
uint16_t minInterval, maxInterval;
96
110
aReadHandler->GetReportingIntervals (minInterval, maxInterval);
97
- mMinTimestamp = now + System::Clock::Seconds16 (minInterval);
98
- mMaxTimestamp = now + System::Clock::Seconds16 (maxInterval);
99
- mSyncTimestamp = mMaxTimestamp ;
111
+ mMinTimestamp = now + System::Clock::Seconds16 (minInterval);
112
+ mMaxTimestamp = now + System::Clock::Seconds16 (maxInterval);
100
113
}
101
114
102
115
void TimerFired () override
@@ -105,27 +118,16 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
105
118
SetEngineRunScheduled (true );
106
119
}
107
120
108
- void SetSyncTimestamp (System::Clock::Timestamp aSyncTimestamp)
109
- {
110
- // Prevents the sync timestamp being set to a value lower than the min timestamp to prevent it to appear as reportable
111
- // on the next timeout calculation and cause the scheduler to run the engine too early
112
- VerifyOrReturn (aSyncTimestamp >= mMinTimestamp );
113
- mSyncTimestamp = aSyncTimestamp;
114
- }
115
-
116
121
System::Clock::Timestamp GetMinTimestamp () const { return mMinTimestamp ; }
117
122
System::Clock::Timestamp GetMaxTimestamp () const { return mMaxTimestamp ; }
118
- System::Clock::Timestamp GetSyncTimestamp () const { return mSyncTimestamp ; }
119
123
120
124
private:
121
125
ReadHandler * mReadHandler ;
122
126
ReportScheduler * mScheduler ;
123
127
Timestamp mMinTimestamp ;
124
128
Timestamp mMaxTimestamp ;
125
- Timestamp mSyncTimestamp ; // Timestamp at which the read handler will be allowed to emit a report so it can be synced with
126
- // other handlers that have an earlier max timestamp
127
- bool mEngineRunScheduled = false ; // Flag to indicate if the engine run is already scheduled so the scheduler can ignore
128
- // it when calculating the next run time
129
+
130
+ BitFlags<ReadHandlerNodeFlags> mFlags ;
129
131
};
130
132
131
133
ReportScheduler (TimerDelegate * aTimerDelegate) : mTimerDelegate (aTimerDelegate) {}
0 commit comments