From efa5682d6019e762f95016b4c59583eda8b7c43e Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 30 Nov 2021 15:33:34 -0800 Subject: [PATCH] [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. --- src/core/common/timer.hpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/core/common/timer.hpp b/src/core/common/timer.hpp index 6489961be..3faf09f00 100644 --- a/src/core/common/timer.hpp +++ b/src/core/common/timer.hpp @@ -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 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); }