Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #include <sstream> |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 9 | #include <ndn-cpp/common.hpp> |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 10 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 11 | #if NDN_CPP_HAVE_TIME_H |
| 12 | #include <time.h> |
| 13 | #endif |
| 14 | #if NDN_CPP_HAVE_SYS_TIME_H |
| 15 | #include <sys/time.h> |
| 16 | #endif |
| 17 | |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 18 | using namespace std; |
| 19 | |
| 20 | namespace ndn { |
| 21 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 22 | string |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 23 | toHex(const vector<uint8_t>& array) |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 24 | { |
Jeff Thompson | b0948a5 | 2013-09-12 14:38:26 -0700 | [diff] [blame] | 25 | if (!&array) |
| 26 | return ""; |
| 27 | |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 28 | ostringstream result; |
| 29 | result.flags(ios::hex | ios::uppercase); |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 30 | for (size_t i = 0; i < array.size(); ++i) { |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 31 | uint8_t x = array[i]; |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 32 | if (x < 16) |
| 33 | result << '0'; |
| 34 | result << (unsigned int)x; |
| 35 | } |
| 36 | |
| 37 | return result.str(); |
| 38 | } |
| 39 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 40 | MillisecondsSince1970 |
| 41 | getNow() |
| 42 | { |
| 43 | struct timeval t; |
| 44 | // Note: configure.ac requires gettimeofday. |
| 45 | gettimeofday(&t, 0); |
| 46 | return t.tv_sec * 1000.0 + t.tv_usec / 1000.0; |
| 47 | } |
| 48 | |
| 49 | |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 50 | } |
| 51 | |