File indexing completed on 2024-04-21 05:54:05
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 */ 0004 0005 #ifndef RSIBREAK_RSITIMERCOUNTER_H 0006 #define RSIBREAK_RSITIMERCOUNTER_H 0007 0008 class RSITimerCounter 0009 { 0010 private: 0011 const int m_delayTicks; 0012 const int m_breakLength; 0013 const int m_resetThreshold; 0014 0015 int m_counter; // counts ticks of user activity. 0016 0017 public: 0018 RSITimerCounter(const int delay, const int breakLength, const int resetThreshold) 0019 : m_delayTicks(delay) 0020 , m_breakLength(breakLength) 0021 , m_resetThreshold(resetThreshold) 0022 , m_counter(0) 0023 { 0024 } 0025 0026 ~RSITimerCounter() 0027 { 0028 } 0029 0030 // Counts `elapsed` ticks. 0031 // @param idleTime time idle for this tick. 0032 // @returns non zero if break is due, for the number of ticks to break for. 0033 int tick(const int idleTime); 0034 0035 // Resets the counter. 0036 void reset(); 0037 0038 // @returns ticks left till break for this counter. 0039 int counterLeft() const; 0040 0041 // @returns ticks this timer delays for. 0042 int getDelayTicks() const; 0043 0044 // @param ticks Postpones the timer by `ticks` ticks. 0045 void postpone(int ticks); 0046 0047 // Returns if the timer was just reset. 0048 bool isReset(); 0049 }; 0050 0051 #endif // RSIBREAK_RSITIMERCOUNTER_H