Skip to content
Snippets Groups Projects
Commit 0c59a122 authored by Ruud Overeem's avatar Ruud Overeem
Browse files

BugID: 1000

Added 'timeLeft' function to timers.
parent 5be47740
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@ int main (int32 argc, char*argv[]) {
CEPKeyValueLogger kvlPort;
kvlPort.logKeyValue("Observation.nyquistZone", GCFPVInteger(2), KVL_ORIGIN_MAC);
kvlPort.logKeyValue("LOFAR.ObsSW.Observation.nyquistZone", GCFPVInteger(2), KVL_ORIGIN_MAC);
return (0);
}
......
......@@ -111,6 +111,8 @@ class GCFPort : public GCFPortInterface
void** arg = 0);
virtual int cancelAllTimers ();
virtual double timeLeft(long timerID);
public: // GCFPort specific interface methods
/// sets the remote address of a port
......
......@@ -97,6 +97,8 @@ public:
virtual int cancelAllTimers() = 0;
virtual double timeLeft(long timerID) = 0;
/**
* Attribute access functions
*/
......
......@@ -92,6 +92,8 @@ public:
virtual int cancelAllTimers ();
virtual double timeLeft(long timerID);
protected:
// constructors && destructors
/// params see constructor of GCFPortInterface
......
......@@ -366,6 +366,14 @@ int GCFPort::cancelAllTimers()
return (_pSlave->cancelAllTimers());
}
//
// timeLeft(timerid)
//
double GCFPort::timeLeft(long timerID)
{
return (_pSlave ? _pSlave->timeLeft(timerID) : 0);
}
} // namespace TM
} // namespace GCF
} // namespace LOFAR
......@@ -227,6 +227,15 @@ int GCFRawPort::cancelAllTimers()
return _pTimerHandler->cancelAllTimers(*this);
}
//
// timeLeft(timerid)
//
double GCFRawPort::timeLeft(long timerID)
{
ASSERT(_pTimerHandler);
return (_pTimerHandler->timeLeft(timerID));
}
//
// findAddr(addr)
//
......
......@@ -52,70 +52,64 @@ GTMTimer::GTMTimer(GCFRawPort& port,
void GTMTimer::decreaseTime()
{
int64 uSec = getElapsedTime();
if (uSec < 0 || _timeLeft > (uint64) uSec)
{
_timeLeft -= uSec;
}
else
{
struct timeval now;
(void)gettimeofday(&now, NULL);
GCFTimerEvent te;
te.sec = now.tv_sec;
te.usec = now.tv_usec;
te.id = _id;
te.arg = _arg;
_port.dispatch(te);
if (_intervalTime > 0)
{
uint64 timeoverflow = uSec - _timeLeft;
if (_intervalTime < timeoverflow)
{
LOG_ERROR(formatString(
"Timerinterval %fsec of timer %d is to small for performance reasons (tdelta: %lld, tleft: %llu).",
((double) _intervalTime) / 1000000.0,
_id,
uSec,
_timeLeft));
do
{
timeoverflow -= _intervalTime;
} while (_intervalTime < timeoverflow);
}
_timeLeft = _intervalTime - timeoverflow;
}
else
{
_elapsed = true;
}
}
int64 uSec = getElapsedTime();
// REO: uSec < 0 ???
if ((uint64) uSec < _timeLeft || uSec < 0) {
_timeLeft -= uSec;
return;
}
// timer expired
struct timeval now;
(void)gettimeofday(&now, NULL);
GCFTimerEvent te;
te.sec = now.tv_sec;
te.usec = now.tv_usec;
te.id = _id;
te.arg = _arg;
_port.dispatch(te);
if (_intervalTime == 0) {
_elapsed = true;
return;
}
uint64 timeoverflow = uSec - _timeLeft;
if (_intervalTime < timeoverflow) {
LOG_ERROR(formatString(
"Timerinterval %fsec of timer %d is to small for performance reasons (tdelta: %lld, tleft: %llu).",
((double) _intervalTime) / 1000000.0, _id, uSec, _timeLeft));
do {
timeoverflow -= _intervalTime;
} while (_intervalTime < timeoverflow);
}
_timeLeft = _intervalTime - timeoverflow;
}
void GTMTimer::saveTime()
{
struct timezone timeZone;
gettimeofday(&_savedTime, &timeZone);
struct timezone timeZone;
gettimeofday(&_savedTime, &timeZone);
}
int64 GTMTimer::getElapsedTime()
{
timeval oldTime(_savedTime);
int64 uSecDiff(0);
saveTime();
timeval oldTime(_savedTime);
int64 uSecDiff(0);
uSecDiff = ((uint64) (_savedTime.tv_usec) +
(uint64) (_savedTime.tv_sec) * 1000000) -
((uint64) (oldTime.tv_usec) +
(uint64) (oldTime.tv_sec) * 1000000);
saveTime();
return uSecDiff;
uSecDiff = ((uint64) (_savedTime.tv_usec) +
(uint64) (_savedTime.tv_sec) * 1000000) -
((uint64) (oldTime.tv_usec) +
(uint64) (oldTime.tv_sec) * 1000000);
return (uSecDiff);
}
} // namespace TM
} // namespace GCF
} // namespace LOFAR
......@@ -44,7 +44,7 @@ class GTMTimerHandler;
*/
class GTMTimer
{
public:
public:
GTMTimer (GCFRawPort& port,
unsigned long id,
uint64 timeVal,
......@@ -52,36 +52,38 @@ class GTMTimer
void* arg = 0);
virtual ~GTMTimer () {};
inline void* getTimerArg () const {return _arg;}
inline GCFRawPort& getPort () const {return _port;}
inline bool isElapsed () const {return _elapsed;}
inline bool isCanceled () const {return _canceled;}
inline void cancel () {_canceled = true;}
inline void* getTimerArg() const { return (_arg); }
inline GCFRawPort& getPort () const { return (_port); }
inline bool isElapsed () const { return (_elapsed); }
inline bool isCanceled () const { return (_canceled); }
inline void cancel () { _canceled = true; }
inline double getTimeLeft() const { return ((double)_timeLeft / 1000000.0); }
/**
* Decreases the time of this timer
* It will be called by workProc method of the GTMTimerHandler, which
* determines the elapsed time to the previous workProc invocation for all
* registered timers once.
*/
void decreaseTime ();
/**
* Decreases the time of this timer
* It will be called by workProc method of the GTMTimerHandler, which
* determines the elapsed time to the previous workProc invocation for all
* registered timers once.
*/
void decreaseTime ();
private: // helper methods
void saveTime ();
int64 getElapsedTime();
private:
// helper methods
void saveTime ();
int64 getElapsedTime();
private: // attributes
GCFRawPort& _port;
unsigned long _id;
uint64 _time;
uint64 _timeLeft;
uint64 _intervalTime;
void* _arg; // this pointer should NEVER be modified by the GTMTimer class!!
// attributes
GCFRawPort& _port;
unsigned long _id;
uint64 _time; // in uSec
uint64 _timeLeft; // in uSec
uint64 _intervalTime; // in uSec
void* _arg; // this pointer should NEVER be modified by the GTMTimer class!!
private: // helper attribs.
bool _elapsed;
bool _canceled;
timeval _savedTime;
// helper attribs.
bool _elapsed;
bool _canceled;
timeval _savedTime;
};
} // namespace TM
} // namespace GCF
......
......@@ -170,6 +170,21 @@ int GTMTimerHandler::cancelAllTimers(GCFRawPort& port)
}
return result;
}
double GTMTimerHandler::timeLeft(unsigned long timerID)
{
GTMTimer* pCurTimer(0);
TTimers::iterator iter(_timers.find(timerID));
if (iter == _timers.end()) {
return (0.0);
}
pCurTimer = iter->second;
ASSERT(pCurTimer);
return (pCurTimer->getTimeLeft());
}
} // namespace TM
} // namespace GCF
} // namespace LOFAR
......@@ -56,6 +56,7 @@ class GTMTimerHandler : GCFHandler
void* arg = 0);
int cancelTimer (unsigned long timerid, void** arg = 0);
int cancelAllTimers (GCFRawPort& port);
double timeLeft (unsigned long timerID);
private: // helper methods
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment