From 03d24fbbdc8334eb38ca10ccb50c6dfd6a31e0b9 Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Fri, 17 Apr 2020 11:16:21 -0400 Subject: [PATCH] cwTime.h/cpp,cwDnsSd.cpp,cwMdns.cpp : Changed cwTime interface to use all references rather than pointers as arguments. --- cwDnsSd.cpp | 2 +- cwMdns.cpp | 2 +- cwTime.cpp | 46 +++++++++++++++++++++++----------------------- cwTime.h | 20 +++++++++++--------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/cwDnsSd.cpp b/cwDnsSd.cpp index b1194f1..cbff1d5 100644 --- a/cwDnsSd.cpp +++ b/cwDnsSd.cpp @@ -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; diff --git a/cwMdns.cpp b/cwMdns.cpp index c2b9b56..5963bb4 100644 --- a/cwMdns.cpp +++ b/cwMdns.cpp @@ -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; diff --git a/cwTime.cpp b/cwTime.cpp index ab2c34b..fb4d4a4 100644 --- a/cwTime.cpp +++ b/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; } diff --git a/cwTime.h b/cwTime.h index c380dea..7f31f1d 100644 --- a/cwTime.h +++ b/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 ); //)