Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bctimer.C

Go to the documentation of this file.
00001 #include "bctimer.h"
00002 #include <sys/time.h>
00003 #include <sys/types.h>
00004 #include <unistd.h>
00005 
00006 Timer::Timer()
00007 {
00008 }
00009 
00010 Timer::~Timer()
00011 {
00012 }
00013 
00014 int Timer::update()
00015 {
00016         gettimeofday(&current_time, 0);
00017         return 0;
00018 }
00019 
00020 int64_t Timer::get_difference(struct timeval *result)
00021 {
00022         gettimeofday(&new_time, 0);
00023         
00024         result->tv_usec = new_time.tv_usec - current_time.tv_usec;
00025         result->tv_sec = new_time.tv_sec - current_time.tv_sec;
00026         if(result->tv_usec < 0) 
00027         {
00028                 result->tv_usec += 1000000; 
00029                 result->tv_sec--; 
00030         }
00031         
00032         return (int64_t)result->tv_sec * 1000 + (int64_t)result->tv_usec / 1000;
00033 }
00034 
00035 int64_t Timer::get_difference()
00036 {
00037         gettimeofday(&new_time, 0);
00038 
00039         new_time.tv_usec -= current_time.tv_usec;
00040         new_time.tv_sec -= current_time.tv_sec;
00041         if(new_time.tv_usec < 0)
00042         {
00043                 new_time.tv_usec += 1000000;
00044                 new_time.tv_sec--;
00045         }
00046 
00047         return (int64_t)new_time.tv_sec * 1000 + 
00048                 (int64_t)new_time.tv_usec / 1000;
00049 }
00050 
00051 int64_t Timer::get_scaled_difference(long denominator)
00052 {
00053         get_difference(&new_time);
00054         return (int64_t)new_time.tv_sec * denominator + 
00055                 (int64_t)((double)new_time.tv_usec / 1000000 * denominator);
00056 }
00057 
00058 int Timer::delay(long milliseconds)
00059 {
00060         struct timeval delay_duration;
00061         delay_duration.tv_sec = 0;
00062         delay_duration.tv_usec = milliseconds * 1000;
00063         select(0,  NULL,  NULL, NULL, &delay_duration);
00064         return 0;
00065 }

Generated on Sun Jan 8 13:26:33 2006 for Guicast-svn by  doxygen 1.4.4