This is Unofficial EPICS BASE Doxygen Site
udpiiu.h
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  *
12  *
13  * L O S A L A M O S
14  * Los Alamos National Laboratory
15  * Los Alamos, New Mexico 87545
16  *
17  * Copyright, 1986, The Regents of the University of California.
18  *
19  *
20  * Author Jeffrey O. Hill
21  * johill@lanl.gov
22  * 505 665 1831
23  */
24 
25 #ifndef INC_udpiiu_H
26 #define INC_udpiiu_H
27 
28 #include <memory>
29 
30 #include "osiSock.h"
31 #include "epicsThread.h"
32 #include "epicsTime.h"
33 #include "tsDLList.h"
34 
35 #include "libCaAPI.h"
36 #include "netiiu.h"
37 #include "searchTimer.h"
39 #include "repeaterSubscribeTimer.h"
40 #include "SearchDest.h"
41 
42 extern "C" void cacRecvThreadUDP ( void *pParam );
43 
44 LIBCA_API void epicsStdCall caStartRepeaterIfNotInstalled (
45  unsigned repeaterPort );
46 LIBCA_API void epicsStdCall caRepeaterRegistrationMessage (
47  SOCKET sock, unsigned repeaterPort, unsigned attemptNumber );
48 extern "C" LIBCA_API void caRepeaterThread (
49  void * pDummy );
50 LIBCA_API void ca_repeater ( void );
51 
52 class cac;
53 class cacContextNotify;
54 
56  private epicsThreadRunable {
57 public:
59  class udpiiu & iiuIn, cacContextNotify &, epicsMutex &,
60  const char * pName, unsigned stackSize, unsigned priority );
61  virtual ~udpRecvThread ();
62  void start ();
63  bool exitWait ( double delay );
64  void show ( unsigned level ) const;
65 private:
66  class udpiiu & iiu;
67  epicsMutex & cbMutex;
68  cacContextNotify & ctxNotify;
69  epicsThread thread;
70  void run();
71 };
72 
73 static const double minRoundTripEstimate = 32e-3; // seconds
74 static const double maxRoundTripEstimate = 30; // seconds
75 static const double maxSearchPeriodDefault = 5.0 * 60.0; // seconds
76 static const double maxSearchPeriodLowerLimit = 60.0; // seconds
77 static const double beaconAnomalySearchPeriod = 5.0; // seconds
78 
79 class udpiiu :
80  private netiiu,
81  private searchTimerNotify,
82  private disconnectGovernorNotify {
83 public:
84  udpiiu (
85  epicsGuard < epicsMutex > & cacGuard,
86  class epicsTimerQueueActive &,
87  epicsMutex & callbackControl,
88  epicsMutex & mutualExclusion,
90  class cac &,
91  unsigned port,
93  virtual ~udpiiu ();
94  void installNewChannel (
96  void installDisconnectedChannel (
98  void beaconAnomalyNotify (
99  epicsGuard < epicsMutex > & guard );
100  void shutdown ( epicsGuard < epicsMutex > & cbGuard,
101  epicsGuard < epicsMutex > & guard );
102  void show ( unsigned level ) const;
103 
104  // exceptions
105  class noSocket {};
106 
107 private:
108  class SearchDestUDP :
109  public SearchDest {
110  public:
111  SearchDestUDP ( const osiSockAddr &, udpiiu & );
112  void searchRequest (
113  epicsGuard < epicsMutex > &, const char * pBuf, size_t bufLen );
114  void show (
115  epicsGuard < epicsMutex > &, unsigned level ) const;
116  private:
117  int _lastError;
118  osiSockAddr _destAddr;
119  udpiiu & _udpiiu;
120  };
121  class SearchRespCallback :
122  public SearchDest :: Callback {
123  public:
124  SearchRespCallback ( udpiiu & );
125  void notify (
126  const caHdr &, const void * pPayload,
127  const osiSockAddr &, const epicsTime & );
128  void show (
129  epicsGuard < epicsMutex > &, unsigned level ) const;
130  private:
131  udpiiu & _udpiiu;
132  };
133  class M_repeaterTimerNotify :
134  public repeaterTimerNotify {
135  public:
136  M_repeaterTimerNotify ( udpiiu & iiu ) :
137  m_udpiiu ( iiu ) {}
138  ~M_repeaterTimerNotify (); /* for sunpro compiler */
139  // repeaterTimerNotify
140  void repeaterRegistrationMessage (
141  unsigned attemptNumber );
142  int printFormated (
143  epicsGuard < epicsMutex > & callbackControl,
144  const char * pformat, ... );
145  private:
146  udpiiu & m_udpiiu;
147  };
148  char xmitBuf [MAX_UDP_SEND];
149  char recvBuf [MAX_UDP_RECV];
150  udpRecvThread recvThread;
151  M_repeaterTimerNotify m_repeaterTimerNotify;
152  repeaterSubscribeTimer repeaterSubscribeTmr;
154  tsDLList < SearchDest > _searchDestList;
155  const double maxPeriod;
156  double rtteMean;
157  double rtteMeanDev;
158  cac & cacRef;
159  epicsMutex & cbMutex;
160  epicsMutex & cacMutex;
161  const unsigned nTimers;
162  struct SearchArray {
163  typedef std::auto_ptr <searchTimer> value_type;
164  value_type *arr;
165  SearchArray(size_t n) : arr(new value_type[n]) {}
166  ~SearchArray() { delete[] arr; }
167  value_type& operator[](size_t i) const { return arr[i]; }
168  private:
169  SearchArray(const SearchArray&);
170  SearchArray& operator=(const SearchArray&);
171  } ppSearchTmr;
172  unsigned nBytesInXmitBuf;
173  unsigned beaconAnomalyTimerIndex;
174  ca_uint32_t sequenceNumber;
175  ca_uint32_t lastReceivedSeqNo;
176  SOCKET sock;
177  ca_uint16_t repeaterPort;
178  ca_uint16_t serverPort;
179  ca_uint16_t localPort;
180  bool shutdownCmd;
181  bool lastReceivedSeqNoIsValid;
182 
183  bool wakeupMsg ();
184 
185  void postMsg (
186  const osiSockAddr & net_addr,
187  char *pInBuf, arrayElementCount blockSize,
188  const epicsTime &currenTime );
189 
190  bool pushDatagramMsg ( epicsGuard < epicsMutex > &,
191  const caHdr & hdr, const void * pExt,
192  ca_uint16_t extsize);
193 
194  typedef bool ( udpiiu::*pProtoStubUDP ) (
195  const caHdr &,
196  const osiSockAddr &, const epicsTime & );
197 
198  // UDP protocol dispatch table
199  static const pProtoStubUDP udpJumpTableCAC[];
200 
201  // UDP protocol stubs
202  bool versionAction (
203  const caHdr &,
204  const osiSockAddr &, const epicsTime & );
205  bool badUDPRespAction (
206  const caHdr &msg,
207  const osiSockAddr &netAddr, const epicsTime & );
208  bool searchRespAction (
209  const caHdr &msg,
210  const osiSockAddr &net_addr, const epicsTime & );
211  bool exceptionRespAction (
212  const caHdr &msg,
213  const osiSockAddr &net_addr, const epicsTime & );
214  bool beaconAction (
215  const caHdr &msg,
216  const osiSockAddr &net_addr, const epicsTime & );
217  bool notHereRespAction (
218  const caHdr &msg,
219  const osiSockAddr &net_addr, const epicsTime & );
220  bool repeaterAckAction (
221  const caHdr &msg,
222  const osiSockAddr &net_addr, const epicsTime & );
223 
224  // netiiu stubs
225  unsigned getHostName (
226  epicsGuard < epicsMutex > &, char * pBuf,
227  unsigned bufLength ) const throw ();
228  const char * pHostName (
229  epicsGuard < epicsMutex > & ) const throw ();
230  bool ca_v41_ok (
231  epicsGuard < epicsMutex > & ) const;
232  bool ca_v42_ok (
233  epicsGuard < epicsMutex > & ) const;
234  unsigned requestMessageBytesPending (
235  epicsGuard < epicsMutex > & mutualExclusionGuard );
236  void flush (
237  epicsGuard < epicsMutex > & mutualExclusionGuard );
238  void writeRequest (
240  unsigned type, arrayElementCount nElem,
241  const void *pValue );
242  void writeNotifyRequest (
244  nciu &, netWriteNotifyIO &,
245  unsigned type, arrayElementCount nElem,
246  const void *pValue );
247  void readNotifyRequest (
249  netReadNotifyIO &, unsigned type,
250  arrayElementCount nElem );
251  void clearChannelRequest (
253  ca_uint32_t sid, ca_uint32_t cid );
254  void subscriptionRequest (
256  nciu &, netSubscription & );
257  void subscriptionUpdateRequest (
259  nciu &, netSubscription & );
260  void subscriptionCancelRequest (
262  nciu & chan, netSubscription & subscr );
263  void flushRequest (
265  void requestRecvProcessPostponedFlush (
267  osiSockAddr getNetworkAddress (
268  epicsGuard < epicsMutex > & ) const;
269  void uninstallChan (
271  void uninstallChanDueToSuccessfulSearchResponse (
273  const class epicsTime & currentTime );
274  double receiveWatchdogDelay (
275  epicsGuard < epicsMutex > & ) const;
276  bool searchMsg (
278  const char * pName, unsigned nameLength );
279 
280  // searchTimerNotify stubs
281  double getRTTE ( epicsGuard < epicsMutex > & ) const;
282  void updateRTTE ( epicsGuard < epicsMutex > &, double rtte );
283  bool pushVersionMsg ();
284  void boostChannel (
285  epicsGuard < epicsMutex > & guard, nciu & chan );
286  void noSearchRespNotify (
287  epicsGuard < epicsMutex > &, nciu & chan, unsigned index );
288  bool datagramFlush (
289  epicsGuard < epicsMutex > &, const epicsTime & currentTime );
290  ca_uint32_t datagramSeqNumber (
291  epicsGuard < epicsMutex > & ) const;
292 
293  // disconnectGovernorNotify
294  void govExpireNotify (
296 
297  udpiiu ( const udpiiu & );
298  udpiiu & operator = ( const udpiiu & );
299 
300  friend class udpRecvThread;
301 
302  // These are needed for the vxWorks 5.5 compiler:
303  friend class udpiiu::SearchDestUDP;
304  friend class udpiiu::SearchRespCallback;
305  friend class udpiiu::M_repeaterTimerNotify;
306 };
307 
308 #endif // ifndef INC_udpiiu_H
LIBCA_API void ca_repeater(void)
Definition: repeater.cpp:482
Definition: cac.h:97
int(* pProtoStubUDP)(caHdrLargeArray *mp, void *pPayload, struct client *client)
Definition: camessage.c:2355
LIBCA_API int epicsStdCall ca_v42_ok(chid chan)
int i
Definition: scan.c:967
pvd::StructureConstPtr type
unsigned int ca_uint32_t
Definition: caProto.h:76
udpRecvThread(class udpiiu &iiuIn, cacContextNotify &, epicsMutex &, const char *pName, unsigned stackSize, unsigned priority)
Definition: udpiiu.cpp:370
unsigned short ca_uint16_t
Definition: caProto.h:75
virtual ~udpRecvThread()
Definition: udpiiu.cpp:376
void show(unsigned level) const
Definition: udpiiu.cpp:390
LIBCA_API void caRepeaterThread(void *pDummy)
Definition: repeater.cpp:631
void cacRecvThreadUDP(void *pParam)
int SOCKET
Definition: osdSock.h:31
#define MAX_UDP_RECV
Definition: caProto.h:61
unsigned long arrayElementCount
Definition: cacIO.h:57
epicsEventId flush
Definition: errlog.c:70
Definition: udpiiu.h:79
void start()
Definition: udpiiu.cpp:380
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...
C++ and C descriptions for a thread.
Definition: netiiu.h:37
bool exitWait(double delay)
Definition: udpiiu.cpp:385
LIBCA_API void epicsStdCall caRepeaterRegistrationMessage(SOCKET sock, unsigned repeaterPort, unsigned attemptNumber)
Definition: udpiiu.cpp:464
Definition: nciu.h:127
LIBCA_API void epicsStdCall caStartRepeaterIfNotInstalled(unsigned repeaterPort)
Definition: udpiiu.cpp:581
#define MAX_UDP_SEND
Definition: caProto.h:62