#include <stdlib.h>
#include "Platform.h"
#include "Watch.h"
using namespace std;
/*
#ifdef __MACH__
//clock_gettime is not implemented on OSX
int clock_gettime(int , struct timespec* t) {
struct timeval now;
int rv = gettimeofday(&now, NULL);
if (rv) return rv;
t->tv_sec = now.tv_sec;
t->tv_nsec = now.tv_usec * 1000;
return 0;
}
//CLOCK_REALTIME is not defined on OSX
#define CLOCK_REALTIME 0
#endif
*/
Watch::Watch(void)
{
Reset();
}
void Watch::Start() {
system_time(&_startTime);
_isRunning = true;
}
void Watch::Stop() {
system_time(&_stopTime);
_isRunning = false;
}
void Watch::Reset(){
_startTime = _stopTime;
_isRunning = false;
}
// Get elapsed time in millisec
long Watch::GetElapsedTime(){
if(_isRunning){
sys_time_t now;
system_time(&now);
return time_to_msec(now)-time_to_msec(_startTime);
}
return time_to_msec(_stopTime)-time_to_msec(_startTime);
}