cwTime.h/cpp,cwDnsSd.cpp,cwMdns.cpp : Changed cwTime interface to use all references rather than pointers as arguments.
This commit is contained in:
parent
3ecea739f1
commit
03d24fbbdc
@ -150,7 +150,7 @@ namespace cw
|
||||
|
||||
time::spec_t t1;
|
||||
time::get(t1);
|
||||
unsigned ms = time::elapsedMs( &p->t0, &t1 );
|
||||
unsigned ms = time::elapsedMs( p->t0, t1 );
|
||||
if( ms > 50 )
|
||||
{
|
||||
p->cbCnt+=1;
|
||||
|
@ -1099,7 +1099,7 @@ bool tcpReceiveCallback( void* arg )
|
||||
case 2:
|
||||
{
|
||||
time::get(t1);
|
||||
if( time::elapsedMs( &app->t0, &t1 ) >= 4000 )
|
||||
if( time::elapsedMs( app->t0, t1 ) >= 4000 )
|
||||
{
|
||||
send_heart_beat(app,sockH);
|
||||
app->t0 = t1;
|
||||
|
46
cwTime.cpp
46
cwTime.cpp
@ -47,25 +47,25 @@ void cw::time::get( spec_t& t )
|
||||
|
||||
// this assumes that the seconds have been normalized to a recent start time
|
||||
// so as to avoid overflow
|
||||
unsigned cw::time::elapsedMicros( const spec_t* t0, const spec_t* t1 )
|
||||
unsigned cw::time::elapsedMicros( const spec_t& t0, const spec_t& t1 )
|
||||
{
|
||||
// convert seconds to usecs
|
||||
long u0 = t0->tv_sec * 1000000;
|
||||
long u1 = t1->tv_sec * 1000000;
|
||||
long u0 = t0.tv_sec * 1000000;
|
||||
long u1 = t1.tv_sec * 1000000;
|
||||
|
||||
// convert nanoseconds to usec
|
||||
u0 += t0->tv_nsec / 1000;
|
||||
u1 += t1->tv_nsec / 1000;
|
||||
u0 += t0.tv_nsec / 1000;
|
||||
u1 += t1.tv_nsec / 1000;
|
||||
|
||||
// take diff between t1 and t0
|
||||
return u1 - u0;
|
||||
}
|
||||
|
||||
unsigned cw::time::elapsedMs( const spec_t* t0, const spec_t* t1 )
|
||||
unsigned cw::time::elapsedMs( const spec_t& t0, const spec_t& t1 )
|
||||
{ return elapsedMicros(t0,t1)/1000; }
|
||||
|
||||
|
||||
unsigned cw::time::absElapsedMicros( const spec_t* t0, const spec_t* t1 )
|
||||
unsigned cw::time::absElapsedMicros( const spec_t& t0, const spec_t& t1 )
|
||||
{
|
||||
if( isLTE(t0,t1) )
|
||||
return elapsedMicros(t0,t1);
|
||||
@ -73,7 +73,7 @@ unsigned cw::time::absElapsedMicros( const spec_t* t0, const spec_t* t1 )
|
||||
return elapsedMicros(t1,t0);
|
||||
}
|
||||
|
||||
int cw::time::diffMicros( const spec_t* t0, const spec_t* t1 )
|
||||
int cw::time::diffMicros( const spec_t& t0, const spec_t& t1 )
|
||||
{
|
||||
if( isLTE(t0,t1) )
|
||||
return elapsedMicros(t0,t1);
|
||||
@ -81,38 +81,38 @@ int cw::time::diffMicros( const spec_t* t0, const spec_t* t1 )
|
||||
return -((int)elapsedMicros(t1,t0));
|
||||
}
|
||||
|
||||
bool cw::time::isLTE( const spec_t* t0, const spec_t* t1 )
|
||||
bool cw::time::isLTE( const spec_t& t0, const spec_t& t1 )
|
||||
{
|
||||
if( t0->tv_sec < t1->tv_sec )
|
||||
if( t0.tv_sec < t1.tv_sec )
|
||||
return true;
|
||||
|
||||
if( t0->tv_sec == t1->tv_sec )
|
||||
return t0->tv_nsec <= t1->tv_nsec;
|
||||
if( t0.tv_sec == t1.tv_sec )
|
||||
return t0.tv_nsec <= t1.tv_nsec;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cw::time::isGTE( const spec_t* t0, const spec_t* t1 )
|
||||
bool cw::time::isGTE( const spec_t& t0, const spec_t& t1 )
|
||||
{
|
||||
if( t0->tv_sec > t1->tv_sec )
|
||||
if( t0.tv_sec > t1.tv_sec )
|
||||
return true;
|
||||
|
||||
if( t0->tv_sec == t1->tv_sec )
|
||||
return t0->tv_nsec >= t1->tv_nsec;
|
||||
if( t0.tv_sec == t1.tv_sec )
|
||||
return t0.tv_nsec >= t1.tv_nsec;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cw::time::isEqual( const spec_t* t0, const spec_t* t1 )
|
||||
{ return t0->tv_sec==t1->tv_sec && t0->tv_nsec==t1->tv_nsec; }
|
||||
bool cw::time::isEqual( const spec_t& t0, const spec_t& t1 )
|
||||
{ return t0.tv_sec==t1.tv_sec && t0.tv_nsec==t1.tv_nsec; }
|
||||
|
||||
bool cw::time::isZero( const spec_t* t0 )
|
||||
{ return t0->tv_sec==0 && t0->tv_nsec==0; }
|
||||
bool cw::time::isZero( const spec_t& t0 )
|
||||
{ return t0.tv_sec==0 && t0.tv_nsec==0; }
|
||||
|
||||
void cw::time::setZero( spec_t* t0 )
|
||||
void cw::time::setZero( spec_t& t0 )
|
||||
{
|
||||
t0->tv_sec = 0;
|
||||
t0->tv_nsec = 0;
|
||||
t0.tv_sec = 0;
|
||||
t0.tv_nsec = 0;
|
||||
}
|
||||
|
||||
|
||||
|
20
cwTime.h
20
cwTime.h
@ -23,36 +23,38 @@ namespace cw
|
||||
|
||||
// Return the elapsed time (t1 - t0) in microseconds
|
||||
// t1 is assumed to be at a later time than t0.
|
||||
unsigned elapsedMicros( const spec_t* t0, const spec_t* t1 );
|
||||
unsigned elapsedMicros( const spec_t& t0, const spec_t& t1 );
|
||||
|
||||
// Wrapper on elapsedMicros()
|
||||
unsigned elapsedMs( const spec_t* t0, const spec_t* t1 );
|
||||
unsigned elapsedMs( const spec_t& t0, const spec_t& t1 );
|
||||
|
||||
// Same as elapsedMicros() but the times are not assumed to be ordered.
|
||||
// The function therefore begins by swapping t1 and t0 if t0 is after t1.
|
||||
unsigned absElapsedMicros( const spec_t* t0, const spec_t* t1 );
|
||||
unsigned absElapsedMicros( const spec_t& t0, const spec_t& t1 );
|
||||
|
||||
|
||||
// Same as elapsedMicros() but returns a negative value if t0 is after t1.
|
||||
int diffMicros( const spec_t* t0, const spec_t* t1 );
|
||||
int diffMicros( const spec_t& t0, const spec_t& t1 );
|
||||
|
||||
|
||||
// Returns true if t0 <= t1.
|
||||
bool isLTE( const spec_t* t0, const spec_t* t1 );
|
||||
bool isLTE( const spec_t& t0, const spec_t& t1 );
|
||||
|
||||
// Return true if t0 >= t1.
|
||||
bool isGTE( const spec_t* t0, const spec_t* t1 );
|
||||
bool isGTE( const spec_t& t0, const spec_t& t1 );
|
||||
|
||||
bool isEqual( const spec_t* t0, const spec_t* t1 );
|
||||
bool isEqual( const spec_t& t0, const spec_t& t1 );
|
||||
|
||||
bool isZero( const spec_t* t0 );
|
||||
bool isZero( const spec_t& t0 );
|
||||
|
||||
void setZero( spec_t* t0 );
|
||||
void setZero( spec_t& t0 );
|
||||
|
||||
rc_t now( spec_t& ts );
|
||||
|
||||
// Advance 'ts' by 'ms' milliseconds.
|
||||
void advanceMs( spec_t& ts, unsigned ms );
|
||||
|
||||
// Advance the current time by 'ms' milliseconds;
|
||||
rc_t futureMs( spec_t& ts, unsigned ms );
|
||||
|
||||
//)
|
||||
|
Loading…
Reference in New Issue
Block a user