time: Add ability to specialize system and steady clocks
Default implementation is "optimized" to use boost::chrono clocks. When
specialization is used, now() calls are redirected to the virtual
methods of the specified specialization.
This commit also includes an implementation of UnitTestClock that
can be used in unit tests to eliminate dependency on the wall clock.
Change-Id: I7ced774634d90ce32714a71e2a66129cba91b9ae
Refs: #2158
diff --git a/src/util/monotonic_deadline_timer.hpp b/src/util/monotonic_deadline_timer.hpp
index 3328a86..6572ca4 100644
--- a/src/util/monotonic_deadline_timer.hpp
+++ b/src/util/monotonic_deadline_timer.hpp
@@ -32,11 +32,11 @@
namespace boost {
namespace asio {
-template <>
-struct time_traits<ndn::time::steady_clock::TimePoint::clock>
+template<>
+struct time_traits<ndn::time::steady_clock>
{
typedef ndn::time::steady_clock::TimePoint time_type;
- typedef ndn::time::steady_clock::TimePoint::clock::duration duration_type;
+ typedef ndn::time::steady_clock::Duration duration_type;
static time_type
now()
@@ -65,15 +65,7 @@
static boost::posix_time::time_duration
to_posix_duration(const duration_type& duration)
{
- return
-#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
- boost::posix_time::nanoseconds(
- ndn::time::duration_cast<ndn::time::nanoseconds>(duration).count())
-#else
- boost::posix_time::microseconds(
- ndn::time::duration_cast<ndn::time::microseconds>(duration).count())
-#endif
- ;
+ return ndn::time::steady_clock::to_posix_duration(duration);
}
};
@@ -82,7 +74,7 @@
namespace ndn {
-typedef boost::asio::basic_deadline_timer<time::steady_clock::TimePoint::clock> monotonic_deadline_timer;
+typedef boost::asio::basic_deadline_timer<time::steady_clock> monotonic_deadline_timer;
} // namespace ndn