This is Unofficial EPICS BASE Doxygen Site
repeaterSubscribeTimer.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 /*
10  *
11  * L O S A L A M O S
12  * Los Alamos National Laboratory
13  * Los Alamos, New Mexico 87545
14  *
15  * Copyright, 1986, The Regents of the University of California.
16  *
17  * Author: Jeff Hill
18  *
19  */
20 
21 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
22 
23 #include "cac.h"
24 #include "iocinf.h"
25 #include "repeaterSubscribeTimer.h"
26 
27 #include "udpiiu.h"
28 
29 static const double repeaterSubscribeTimerInitialPeriod = 10.0; // sec
30 static const double repeaterSubscribeTimerPeriod = 1.0; // sec
31 
33  repeaterTimerNotify & iiuIn, epicsTimerQueue & queueIn,
34  epicsMutex & cbMutexIn, cacContextNotify & ctxNotifyIn ) :
35  timer ( queueIn.createTimer () ), iiu ( iiuIn ),
36  cbMutex ( cbMutexIn ),ctxNotify ( ctxNotifyIn ),
37  stateMutex(__FILE__, __LINE__),
38  attempts ( 0 ), registered ( false ), once ( false )
39 {
40 }
41 
43 {
44  this->timer.destroy ();
45 }
46 
48 {
49  this->timer.start (
50  *this, repeaterSubscribeTimerInitialPeriod );
51 }
52 
54  epicsGuard < epicsMutex > & cbGuard,
56 {
57  epicsGuardRelease < epicsMutex > unguard ( guard );
58  {
59  epicsGuardRelease < epicsMutex > cbUnguard ( cbGuard );
60  this->timer.cancel ();
61  }
62 }
63 
64 epicsTimerNotify::expireStatus repeaterSubscribeTimer::
65  expire ( const epicsTime & /* currentTime */ )
66 {
67  epicsGuard < epicsMutex > guard ( this->stateMutex );
68 
69  static const unsigned nTriesToMsg = 50;
70  if ( this->attempts > nTriesToMsg && ! this->once ) {
71  callbackManager mgr ( this->ctxNotify, this->cbMutex );
72  this->iiu.printFormated ( mgr.cbGuard,
73  "CA client library is unable to contact CA repeater after %u tries.\n",
74  nTriesToMsg );
75  this->iiu.printFormated ( mgr.cbGuard,
76  "Silence this message by starting a CA repeater daemon\n") ;
77  this->iiu.printFormated ( mgr.cbGuard,
78  "or by calling ca_pend_event() and or ca_poll() more often.\n" );
79  this->once = true;
80  }
81 
82  this->iiu.repeaterRegistrationMessage ( this->attempts );
83  this->attempts++;
84 
85  if ( this->registered ) {
86  return noRestart;
87  }
88  else {
89  return expireStatus ( restart, repeaterSubscribeTimerPeriod );
90  }
91 }
92 
93 void repeaterSubscribeTimer::show ( unsigned /* level */ ) const
94 {
95  epicsGuard < epicsMutex > guard ( this->stateMutex );
96 
97  ::printf ( "repeater subscribe timer: attempts=%u registered=%u once=%u\n",
98  this->attempts, this->registered, this->once );
99 }
100 
102 {
103  epicsGuard < epicsMutex > guard ( this->stateMutex );
104  this->registered = true;
105 }
106 
void destroy()
Definition: timer.cpp:47
#define printf
Definition: epicsStdio.h:41
void shutdown(epicsGuard< epicsMutex > &cbGuard, epicsGuard< epicsMutex > &guard)
virtual void repeaterRegistrationMessage(unsigned attemptNumber)=0
epicsGuard< epicsMutex > cbGuard
Definition: cac.h:94
void cancel()
Definition: timer.cpp:135
repeaterSubscribeTimer(repeaterTimerNotify &, epicsTimerQueue &, epicsMutex &cbMutex, cacContextNotify &ctxNotify)
virtual int printFormated(epicsGuard< epicsMutex > &callbackControl, const char *pformat,...)=0
void show(unsigned level) const
#define false
Definition: flexdef.h:85
void start(class epicsTimerNotify &, const epicsTime &)
Definition: timer.cpp:59