diff --git a/src/gdd/aitHelpers.cc b/src/gdd/aitHelpers.cc index b550359f0..2453e4bfb 100644 --- a/src/gdd/aitHelpers.cc +++ b/src/gdd/aitHelpers.cc @@ -5,6 +5,9 @@ // $Id$ // // $Log$ +// Revision 1.9 1998/05/05 21:08:26 jhill +// fixed warning +// // Revision 1.8 1997/08/05 00:51:05 jhill // fixed problems in aitString and the conversion matrix // @@ -31,10 +34,28 @@ // new in EPICS base // // + #define epicsExportSharedSymbols #include "aitTypes.h" + +// +// force this module to include code that can convert +// to an EPICS time stamp, but dont force this library +// to link with libCom +// +#define INC_tsDefs_h +typedef struct { + aitUint32 secPastEpoch; /* seconds since 0000 Jan 1, 1990 */ + aitUint32 nsec; /* nanoseconds within second */ +} TS_STAMP; + #include "aitHelpers.h" +// +// 1/1/90 20 yr (5 leap) of seconds +// +const unsigned aitTimeStamp::epicsEpochSecPast1970 = 7305 * 86400; + void aitString::mallocFailure(void) { str=(char *)""; diff --git a/src/gdd/aitHelpers.h b/src/gdd/aitHelpers.h index df6cd5c05..4200f667a 100644 --- a/src/gdd/aitHelpers.h +++ b/src/gdd/aitHelpers.h @@ -8,6 +8,9 @@ * $Id$ * * $Log$ + * Revision 1.17 1999/04/30 00:09:47 jhill + * proper borrow + * * Revision 1.16 1998/05/05 21:08:49 jhill * fixed warning * @@ -106,7 +109,8 @@ public: // fetched as fields so this file is not required // to include os dependent struct timeval // - void getTV(long &tv_secOut, long &uSecOut) { + void getTV(long &tv_secOut, long &uSecOut) const + { assert (this->tv_sec<=LONG_MAX); tv_secOut = (long) this->tv_sec; assert (this->tv_nsec<=LONG_MAX); @@ -115,25 +119,58 @@ public: // // for use when loading struct timeval // - void get(unsigned long &tv_secOut, unsigned long &tv_nsecOut) { + void get(unsigned long &tv_secOut, unsigned long &tv_nsecOut) const + { tv_secOut = this->tv_sec; tv_nsecOut = this->tv_nsec; } - operator double() + operator double() const { return ((double)this->tv_nsec)/NSecPerSec+this->tv_sec; } - operator float() + operator float() const { return ((float)this->tv_nsec)/NSecPerSec+this->tv_sec; } + // + // convert to and from EPICS TS_STAMP format + // + // include tsDefs.h prior to including osiTime.h + // if you need these capabilities + // +#ifdef INC_tsDefs_h + operator TS_STAMP () const + { + TS_STAMP ts; + assert (this->tv_sec>=aitTimeStamp::epicsEpochSecPast1970); + ts.secPastEpoch = this->tv_sec - aitTimeStamp::epicsEpochSecPast1970; + ts.nsec = this->tv_nsec; + return ts; + } + + aitTimeStamp (const TS_STAMP &ts) + { + this->tv_sec = ts.secPastEpoch + aitTimeStamp::epicsEpochSecPast1970; + this->tv_nsec = ts.nsec; + } + + operator = (const TS_STAMP &rhs) + { + this->tv_sec = rhs.secPastEpoch + aitTimeStamp::epicsEpochSecPast1970; + this->tv_nsec = rhs.nsec; + } +#endif + static aitTimeStamp getCurrent(); // private: unsigned long tv_sec; unsigned long tv_nsec; + +private: + static const unsigned epicsEpochSecPast1970; }; inline aitTimeStamp operator+ (const aitTimeStamp &lhs, const aitTimeStamp &rhs)