Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/sched/TmRealTime.cpp
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2005 George Tzanetakis <gtzan@cs.uvic.ca>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include <marsyas/sched/TmRealTime.h>
00020 #include <marsyas/sched/Scheduler.h>
00021 #include <marsyas/Conversions.h> // time2usecs
00022 #include "../common_source.h"
00023 
00024 using namespace std;
00025 using namespace Marsyas;
00026 
00027 TmRealTime::TmRealTime() : TmTimer("TmRealTime","System")
00028 {
00029   last_usecs_=0;
00030   last_usecs_=readTimeSrc();
00031 }
00032 
00033 TmRealTime::TmRealTime(std::string name) : TmTimer("TmRealTime",name)
00034 {
00035   last_usecs_=0;
00036   last_usecs_=readTimeSrc();
00037 }
00038 
00039 TmRealTime::TmRealTime(const TmRealTime& t) : TmTimer(t)
00040 {
00041   name_=t.name_;
00042 }
00043 
00044 TmRealTime::~TmRealTime() { }
00045 
00046 mrs_natural
00047 TmRealTime::getMicroSeconds()
00048 {
00049   /*  struct timeval {
00050        int tv_sec; //seconds
00051        int tv_usec; //microseconds
00052       }; */
00053 #ifndef WIN32
00054   struct timeval tv;
00055   struct timezone tz;
00056   gettimeofday(&tv, &tz);
00057   int u = tv.tv_usec;
00058 #else
00059   int u = 0;
00060 #endif
00061   return u;
00062 }
00063 
00064 mrs_natural
00065 TmRealTime::readTimeSrc()
00066 {
00067   int read_usecs = getMicroSeconds();
00068   int u = read_usecs - last_usecs_;
00069   if (u<0) { u = 1000000 + u; }
00070   last_usecs_ = read_usecs;
00071   return u;
00072 }
00073 
00074 void
00075 TmRealTime::updtime()
00076 {
00077   cur_time_ = getMicroSeconds();
00078 }
00079 
00080 mrs_natural
00081 TmRealTime::intervalsize(std::string interval)
00082 {
00083   return time2usecs(interval);
00084 }