mirror of
https://github.com/espressif/openthread.git
synced 2026-09-21 16:37:37 +00:00
[timer] declare Timer constructor as protected (#7213)
This commit updates `Timer` class constructor to be `protected` which ensures that instances of `Timer` can not be created and only instances of its sub-classes `TimerMilli` or `TimerMicro` can be used. This helps avoid potential incorrect use of `Timer` class directly.
This commit is contained in:
@@ -84,21 +84,6 @@ public:
|
||||
*/
|
||||
typedef void (&Handler)(Timer &aTimer);
|
||||
|
||||
/**
|
||||
* This constructor creates a timer instance.
|
||||
*
|
||||
* @param[in] aInstance A reference to the OpenThread instance.
|
||||
* @param[in] aHandler A pointer to a function that is called when the timer expires.
|
||||
*
|
||||
*/
|
||||
Timer(Instance &aInstance, Handler aHandler)
|
||||
: InstanceLocator(aInstance)
|
||||
, mHandler(aHandler)
|
||||
, mFireTime()
|
||||
, mNext(this)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the fire time of the timer.
|
||||
*
|
||||
@@ -143,6 +128,13 @@ protected:
|
||||
LinkedList<Timer> mTimerList;
|
||||
};
|
||||
|
||||
Timer(Instance &aInstance, Handler aHandler)
|
||||
: InstanceLocator(aInstance)
|
||||
, mHandler(aHandler)
|
||||
, mNext(this)
|
||||
{
|
||||
}
|
||||
|
||||
bool DoesFireBefore(const Timer &aSecondTimer, Time aNow) const;
|
||||
void Fired(void) { mHandler(*this); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user