[timer] add helper methods for common timer use patterns and simplify code (#4243)

This commit adds helper methods in `Timer` class which cover commonly
repeated use patterns by other modules.

Method `FireAt()` allows a timer to be started with a given fire time.
`FireAtIfEarlier()` (re-)schedules the timer with a given a fire time
only if the timer is not running or if the new given fire time is
earlier than the current fire time.

Modules mle, coap, ip6-mpl, joiner-router, dns-clinet, and sntp-client
are updated to use the new methods.
This commit is contained in:
Abtin Keshavarzian
2019-11-07 04:45:34 -08:00
committed by Jonathan Hui
parent ecf7a7050f
commit aab693f9c3
16 changed files with 179 additions and 364 deletions
+10
View File
@@ -633,6 +633,16 @@ int TestTimerTime(void)
VerifyOrQuit((t1 >= t2), "Time >= failed.\n");
VerifyOrQuit(t1 - t2 == duration, "Time difference failed\n");
t2 = t1.GetDistantFuture();
VerifyOrQuit((t1 < t2), "GetDistanceFuture() failed\n");
t2 += 1;
VerifyOrQuit(!(t1 < t2), "GetDistanceFuture() failed\n");
t2 = t1.GetDistantPast();
VerifyOrQuit((t1 > t2), "GetDistantPast() failed\n");
t2 -= 1;
VerifyOrQuit(!(t1 > t2), "GetDistantPast() failed\n");
printf("--> PASSED\n");
}
}