[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:
Abtin Keshavarzian
2021-11-30 15:33:34 -08:00
committed by GitHub
parent d5d4d2b2ff
commit efa5682d60
+7 -15
View File
@@ -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); }