26 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" 49 unsigned initialBeaconNumber,
const inetAddrID & addr ) :
50 inetAddrID ( addr ), timeStamp ( initialTimeStamp ), averagePeriod ( - DBL_MAX ),
51 mutex ( mutexIn ), pIIU ( 0 ), lastBeaconNumber ( initialBeaconNumber )
56 addr.
name ( name,
sizeof ( name ) );
57 ::printf (
"created beacon entry for %s\n", name );
75 void bhe::logBeacon (
const char * pDiagnostic,
76 const double & currentPeriod,
81 this->
name ( name,
sizeof ( name ) );
83 currentTime.strftime ( date,
sizeof ( date ),
84 "%a %b %d %Y %H:%M:%S.%f");
86 pDiagnostic, currentPeriod,
87 this->averagePeriod, name, date );
91 inline void bhe::logBeacon (
const char * ,
99 void bhe::logBeaconDiscard (
unsigned beaconAdvance,
104 this->
name ( name,
sizeof ( name ) );
106 currentTime.strftime ( date,
sizeof ( date ),
107 "%a %b %d %Y %H:%M:%S.%f");
109 beaconAdvance, name, date );
113 void bhe::logBeaconDiscard (
unsigned ,
127 unsigned protocolRevision )
136 if ( this->timeStamp == epicsTime () ) {
137 if (
CA_V410 ( protocolRevision ) ) {
138 this->lastBeaconNumber = beaconNumber;
141 this->beaconAnomalyNotify ( guard );
149 this->timeStamp = currentTime;
151 logBeacon (
"fb", - DBL_MAX, currentTime );
158 if (
CA_V410 ( protocolRevision ) ) {
159 unsigned beaconSeqAdvance;
160 if ( beaconNumber >= this->lastBeaconNumber ) {
161 beaconSeqAdvance = beaconNumber - this->lastBeaconNumber;
164 beaconSeqAdvance = (
ca_uint32_max - this->lastBeaconNumber ) + beaconNumber;
166 this->lastBeaconNumber = beaconNumber;
170 if ( beaconSeqAdvance == 0 || beaconSeqAdvance >
ca_uint32_max - 256 ) {
171 logBeaconDiscard ( beaconSeqAdvance, currentTime );
178 if ( beaconSeqAdvance > 1 && beaconSeqAdvance < 4 ) {
179 logBeaconDiscard ( beaconSeqAdvance, currentTime );
185 bool netChange =
false;
186 double currentPeriod = currentTime - this->timeStamp;
188 if ( this->averagePeriod < 0.0 ) {
189 double totalRunningTime;
191 this->beaconAnomalyNotify ( guard );
198 this->averagePeriod = currentPeriod;
200 logBeacon (
"fp", currentPeriod, currentTime );
209 totalRunningTime = this->timeStamp - programBeginTime;
210 if ( currentPeriod <= totalRunningTime ) {
225 if ( currentPeriod >= this->averagePeriod * 1.25 ) {
231 this->beaconAnomalyNotify ( guard );
233 if ( currentPeriod >= this->averagePeriod * 3.25 ) {
240 logBeacon (
"bah", currentPeriod, currentTime );
254 else if ( currentPeriod <= this->averagePeriod * 0.80 ) {
255 this->beaconAnomalyNotify ( guard );
257 logBeacon (
"bal", currentPeriod, currentTime );
259 else if ( this->pIIU ) {
263 logBeacon (
"vb", currentPeriod, currentTime );
267 this->averagePeriod = currentPeriod * 0.125 +
268 this->averagePeriod * 0.875;
271 this->timeStamp = currentTime;
279 this->
show ( guard, level );
285 this->
name ( host,
sizeof ( host ) );
286 if ( this->averagePeriod == -DBL_MAX ) {
287 ::printf (
"CA beacon hash entry for %s <no period estimate>\n",
291 ::printf (
"CA beacon hash entry for %s with period estimate %f\n",
292 host, this->averagePeriod );
296 this->timeStamp.strftime ( date,
sizeof ( date ),
"%a %b %d %Y %H:%M:%S");
297 ::printf (
"\tbeacon number %u, on %s\n",
298 this->lastBeaconNumber, date );
305 return this->averagePeriod;
311 return this->timeStamp;
325 if ( this->pIIU == & iiu ) {
327 this->timeStamp = epicsTime();
328 this->averagePeriod = - DBL_MAX;
329 logBeacon (
"ui", this->averagePeriod, epicsTime::getCurrent () );
333 void bhe::operator
delete (
void * )
340 errlogPrintf (
"%s:%d this compiler is confused about placement delete - memory was probably leaked",
341 __FILE__, __LINE__ );
346 return freeList.allocate ( size );
351 freeList.release ( pCadaver );
LIBCA_API bhe(epicsMutex &, const epicsTime &initialTimeStamp, unsigned initialBeaconNumber, const inetAddrID &addr)
LIBCA_API bool updatePeriod(epicsGuard< epicsMutex > &, const epicsTime &programBeginTime, const epicsTime ¤tTime, ca_uint32_t beaconNumber, unsigned protocolRevision)
void assertIdenticalMutex(const T &) const
LIBCA_API void registerIIU(epicsGuard< epicsMutex > &, tcpiiu &)
LIBCA_API epicsTime updateTime(epicsGuard< epicsMutex > &) const
int errlogPrintf(const char *pFormat,...)
LIBCA_API void show(unsigned level) const
void beaconArrivalNotify(epicsGuard< epicsMutex > &)
void date(const char *format)
LIBCA_API void unregisterIIU(epicsGuard< epicsMutex > &, tcpiiu &)
virtual ~bheMemoryManager()
void beaconAnomalyNotify(epicsGuard< epicsMutex > &)
LIBCA_API double period(epicsGuard< epicsMutex > &) const
void name(char *pBuf, unsigned bufSize) const