core: time::Duration, time:Point, time::now

refs #1148

Change-Id: I19c3d2f9b638797a6a36ce41a98be4463b4b7a2d
diff --git a/daemon/core/time.cpp b/daemon/core/time.cpp
new file mode 100644
index 0000000..e3a2cda
--- /dev/null
+++ b/daemon/core/time.cpp
@@ -0,0 +1,45 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "time.hpp"
+#include <time.h>
+#include <stdexcept>
+#include <sys/time.h>
+
+namespace ndn {
+namespace time {
+
+Point
+now()
+{
+#ifdef HAVE_RT
+
+  struct timespec t;
+  int res = clock_gettime(CLOCK_MONOTONIC, &t);
+  
+  if (res == -1) {
+    throw std::runtime_error("clock_gettime");
+  }
+  
+  return t.tv_sec * 1000000000 + t.tv_nsec;
+
+#else
+  // fallback to wall clock time
+
+  struct timeval tv;
+  int res = gettimeofday(&tv, 0);
+
+  if (res == -1) {
+    throw std::runtime_error("gettimeofday");
+  }
+  
+  return tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+  
+#endif
+}
+
+} // namespace time
+} // namespace ndn