From 41fd1ff1f8254e62a75939fde23bac56953e31f8 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 19 Sep 2002 19:32:29 +0000 Subject: [PATCH] installed beacon anomaly generator --- src/cas/build/Makefile | 2 + src/cas/generic/caServer.cc | 7 ++ src/cas/generic/caServerI.cc | 118 ++++++------------------------- src/cas/generic/casdef.h | 8 +-- src/cas/generic/server.h | 25 ++++--- src/cas/generic/st/caServerOS.cc | 38 ---------- src/cas/generic/st/casOSD.h | 9 +-- 7 files changed, 47 insertions(+), 160 deletions(-) diff --git a/src/cas/build/Makefile b/src/cas/build/Makefile index 283f8e52b..e71bb8a34 100644 --- a/src/cas/build/Makefile +++ b/src/cas/build/Makefile @@ -58,6 +58,8 @@ LIBSRCS += casBufferFactory.cc LIBSRCS += pvExistReturn.cc LIBSRCS += pvAttachReturn.cc LIBSRCS += caNetAddr.cc +LIBSRCS += beaconTimer.cc +LIBSRCS += beaconAnomalyGovernor.cc LIBSRCS += caServerOS.cc LIBSRCS += casIntfOS.cc diff --git a/src/cas/generic/caServer.cc b/src/cas/generic/caServer.cc index f17becee2..450a9b3ad 100644 --- a/src/cas/generic/caServer.cc +++ b/src/cas/generic/caServer.cc @@ -205,6 +205,13 @@ epicsShareFunc unsigned caServer::subscriptionEventsPosted () const // X aCC 361 } } +epicsShareFunc void caServer::generateBeaconAnomaly () +{ + if ( pCAS ) { + this->pCAS->generateBeaconAnomaly (); + } +} + // // casRes::~casRes() // diff --git a/src/cas/generic/caServerI.cc b/src/cas/generic/caServerI.cc index 9db06d410..256b2d467 100644 --- a/src/cas/generic/caServerI.cc +++ b/src/cas/generic/caServerI.cc @@ -23,66 +23,29 @@ #define caServerGlobal #include "server.h" #include "casCtxIL.h" // casCtx in line func +#include "beaconTimer.h" +#include "beaconAnomalyGovernor.h" static const char *id = "@(#) " EPICS_VERSION_STRING ", CA Portable Server Library" "$Date$"; -// -// the maximum beacon period if EPICS_CA_BEACON_PERIOD isnt available -// -static const double CAServerMaxBeaconPeriod = 15.0; // seconds - -// -// the initial beacon period -// -static const double CAServerMinBeaconPeriod = 1.0e-3; // seconds - // // caServerI::caServerI() // caServerI::caServerI (caServer &tool) : - // - // Set up periodic beacon interval - // (exponential back off to a plateau - // from this intial period) - // - beaconPeriod (CAServerMinBeaconPeriod), adapter (tool), + beaconTmr ( * new beaconTimer ( *this ) ), + beaconAnomalyGov ( * new beaconAnomalyGovernor ( *this ) ), debugLevel (0u), nEventsProcessed (0u), - nEventsPosted (0u), - beaconCounter (0u) + nEventsPosted (0u) { - caStatus status; - double maxPeriod; + assert ( & adapter != NULL ); - assert (&adapter != NULL); - - // // create predefined event types - // this->valueEvent = registerEvent ("value"); this->logEvent = registerEvent ("log"); this->alarmEvent = registerEvent ("alarm"); - - if ( envGetConfigParamPtr ( & EPICS_CAS_BEACON_PERIOD ) ) { - status = envGetDoubleConfigParam ( & EPICS_CAS_BEACON_PERIOD, & maxPeriod ); - } - else { - status = envGetDoubleConfigParam ( & EPICS_CA_BEACON_PERIOD, & maxPeriod ); - } - if ( status || maxPeriod <= 0.0 ) { - this->maxBeaconInterval = CAServerMaxBeaconPeriod; - errlogPrintf ( - "EPICS \"%s\" float fetch failed\n", EPICS_CAS_BEACON_PERIOD.name ); - errlogPrintf ( - "Setting \"%s\" = %f\n", EPICS_CAS_BEACON_PERIOD.name, - this->maxBeaconInterval); - } - else { - this->maxBeaconInterval = maxPeriod; - } - this->locateInterfaces (); if (this->intfList.count()==0u) { @@ -101,9 +64,10 @@ caServerI::~caServerI() { epicsGuard < epicsMutex > locker ( this->mutex ); - // + delete & this->beaconAnomalyGov; + delete & this->beaconTmr; + // delete all clients - // tsDLIter iter = this->clientList.firstIter (); while ( iter.valid () ) { tsDLIter tmp = iter; @@ -116,7 +80,7 @@ caServerI::~caServerI() } casIntfOS *pIF; - while ( (pIF = this->intfList.get()) ) { + while ( ( pIF = this->intfList.get() ) ) { delete pIF; } } @@ -151,27 +115,6 @@ void caServerI::connectCB ( casIntfOS & intf ) } } -// -// caServerI::advanceBeaconPeriod() -// -// compute delay to the next beacon -// -void caServerI::advanceBeaconPeriod() -{ - // - // return if we are already at the plateau - // - if (this->beaconPeriod >= this->maxBeaconInterval) { - return; - } - - this->beaconPeriod += this->beaconPeriod; - - if (this->beaconPeriod >= this->maxBeaconInterval) { - this->beaconPeriod = this->maxBeaconInterval; - } -} - // // casVerifyFunc() // @@ -217,42 +160,23 @@ caStatus caServerI::attachInterface (const caNetAddr &addr, bool autoBeaconAddr, return S_cas_success; } - // // caServerI::sendBeacon() -// (implemented here because this has knowledge of the protocol) +// send a beacon over each configured address // -void caServerI::sendBeacon() +void caServerI::sendBeacon ( ca_uint32_t beaconNo ) { - // - // send a broadcast beacon over each configured - // interface unless EPICS_CA_AUTO_ADDR_LIST specifies - // otherwise. Also send a beacon to all configured - // addresses. - // - { - epicsGuard < epicsMutex > locker ( this->mutex ); - tsDLIter iter = this->intfList.firstIter (); - while ( iter.valid () ) { - iter->sendBeacon ( this->beaconCounter ); - iter++; - } - } - - this->beaconCounter++; - - // - // double the period between beacons (but dont exceed max) - // - this->advanceBeaconPeriod(); + epicsGuard < epicsMutex > locker ( this->mutex ); + tsDLIter iter = this->intfList.firstIter (); + while ( iter.valid () ) { + iter->sendBeacon ( beaconNo ); + iter++; + } } -// -// caServerI::getBeaconPeriod() -// -double caServerI::getBeaconPeriod() const -{ - return this->beaconPeriod; +void caServerI::generateBeaconAnomaly () +{ + this->beaconAnomalyGov.start (); } // diff --git a/src/cas/generic/casdef.h b/src/cas/generic/casdef.h index 634df9260..74800f9d6 100644 --- a/src/cas/generic/casdef.h +++ b/src/cas/generic/casdef.h @@ -267,12 +267,12 @@ public: epicsShareFunc unsigned subscriptionEventsPosted () const; epicsShareFunc unsigned subscriptionEventsProcessed () const; - epicsShareFunc void generateBeaconAnomaly () const; - epicsShareFunc class epicsTimer & createTimer (); - //caStatus enableClients (); - //caStatus disableClients (); + epicsShareFunc void generateBeaconAnomaly (); + + // caStatus enableClients (); + // caStatus disableClients (); private: caServerI *pCAS; diff --git a/src/cas/generic/server.h b/src/cas/generic/server.h index 2541f3297..3304fec82 100644 --- a/src/cas/generic/server.h +++ b/src/cas/generic/server.h @@ -843,6 +843,8 @@ private: #include "casOSD.h" // OS dependent class casClientMon; +class beaconTimer; +class beaconAnomalyGovernor; // // caServerI @@ -918,19 +920,18 @@ public: void lock () const; void unlock () const; -private: - void advanceBeaconPeriod(); + void generateBeaconAnomaly (); +private: mutable epicsMutex mutex; tsDLList clientList; tsDLList intfList; - double maxBeaconInterval; - double beaconPeriod; - caServer &adapter; + caServer & adapter; + beaconTimer & beaconTmr; + beaconAnomalyGovernor & beaconAnomalyGov; unsigned debugLevel; unsigned nEventsProcessed; unsigned nEventsPosted; - ca_uint32_t beaconCounter; // // predefined event types @@ -939,18 +940,16 @@ private: casEventMask logEvent; // DBE_LOG registerEvent("log") casEventMask alarmEvent; // DBE_ALARM registerEvent("alarm") - double getBeaconPeriod () const; - - // - // send beacon and advance beacon timer - // - void sendBeacon (); - caStatus attachInterface (const caNetAddr &addr, bool autoBeaconAddr, bool addConfigAddr); + void sendBeacon ( ca_uint32_t beaconNo ); + caServerI ( const caServerI & ); caServerI & operator = ( const caServerI & ); + + friend class beaconAnomalyGovernor; + friend class beaconTimer; }; #define CAServerConnectPendQueueSize 10 diff --git a/src/cas/generic/st/caServerOS.cc b/src/cas/generic/st/caServerOS.cc index d93de9c9d..a60f0265e 100644 --- a/src/cas/generic/st/caServerOS.cc +++ b/src/cas/generic/st/caServerOS.cc @@ -22,38 +22,11 @@ #include "server.h" #include "fdManager.h" -// -// casBeaconTimer -// -class casBeaconTimer : public epicsTimerNotify { -public: - casBeaconTimer ( double delay, caServerOS &osIn ); - virtual ~casBeaconTimer (); -private: - epicsTimer &timer; - caServerOS &os; - expireStatus expire ( const epicsTime & currentTime ); - casBeaconTimer ( const casBeaconTimer & ); - casBeaconTimer & operator = ( const casBeaconTimer & ); -}; - -casBeaconTimer::casBeaconTimer ( double delay, caServerOS &osIn ) : - timer ( fileDescriptorManager.createTimer() ), os ( osIn ) -{ - this->timer.start ( *this, delay ); -} - -casBeaconTimer::~casBeaconTimer () -{ - this->timer.destroy (); -} - // // caServerOS::caServerOS() // caServerOS::caServerOS () { - this->pBTmr = new casBeaconTimer(0.0, *this); } // @@ -61,17 +34,6 @@ caServerOS::caServerOS () // caServerOS::~caServerOS() { - if ( this->pBTmr ) { - delete this->pBTmr; - } } -// -// casBeaconTimer::expire() -// -epicsTimerNotify::expireStatus casBeaconTimer::expire( const epicsTime & /* currentTime */ ) -{ - os.sendBeacon (); - return expireStatus ( restart, os.getBeaconPeriod() ); -} diff --git a/src/cas/generic/st/casOSD.h b/src/cas/generic/st/casOSD.h index be894d7a5..27371ad69 100644 --- a/src/cas/generic/st/casOSD.h +++ b/src/cas/generic/st/casOSD.h @@ -32,23 +32,16 @@ class caServerI; class caServerOS; class casServerReg; -class casBeaconTimer; // // caServerOS // class caServerOS { - friend class casServerReg; - friend class casBeaconTimer; public: caServerOS (); virtual ~caServerOS (); - private: - casBeaconTimer *pBTmr; - - virtual double getBeaconPeriod() const = 0; - virtual void sendBeacon() = 0; + friend class casServerReg; }; class casDGReadReg;