This is Unofficial EPICS BASE Doxygen Site
nciu.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  * L O S A L A M O S
13  * Los Alamos National Laboratory
14  * Los Alamos, New Mexico 87545
15  *
16  * Copyright, 1986, The Regents of the University of California.
17  *
18  *
19  * Author Jeffrey O. Hill
20  * johill@lanl.gov
21  * 505 665 1831
22  */
23 
24 #ifndef INC_nciu_H
25 #define INC_nciu_H
26 
27 #include "resourceLib.h"
28 #include "tsDLList.h"
29 #include "tsFreeList.h"
30 #include "epicsMutex.h"
31 #include "compilerDependencies.h"
32 
33 #include "libCaAPI.h"
34 
35 #define CA_MINOR_PROTOCOL_REVISION 13
36 #include "caProto.h"
37 
38 #include "cacIO.h"
39 
40 class cac;
41 class netiiu;
42 
43 // The node and the state which tracks the list membership
44 // are in the channel, but belong to the circuit.
45 // Protected by the callback mutex
46 class channelNode : public tsDLNode < class nciu >
47 {
48 protected:
49  channelNode ();
51  bool isConnected ( epicsGuard < epicsMutex > & ) const;
52 public:
53  static unsigned getMaxSearchTimerCount ();
54 private:
55  enum channelState {
56  cs_none,
57  cs_disconnGov,
58  // note: indexing is used here
59  // so these must be contiguous
60  cs_searchReqPending0,
61  cs_searchReqPending1,
62  cs_searchReqPending2,
63  cs_searchReqPending3,
64  cs_searchReqPending4,
65  cs_searchReqPending5,
66  cs_searchReqPending6,
67  cs_searchReqPending7,
68  cs_searchReqPending8,
69  cs_searchReqPending9,
70  cs_searchReqPending10,
71  cs_searchReqPending11,
72  cs_searchReqPending12,
73  cs_searchReqPending13,
74  cs_searchReqPending14,
75  cs_searchReqPending15,
76  cs_searchReqPending16,
77  cs_searchReqPending17,
78  // note: indexing is used here
79  // so these must be contiguous
80  cs_searchRespPending0,
81  cs_searchRespPending1,
82  cs_searchRespPending2,
83  cs_searchRespPending3,
84  cs_searchRespPending4,
85  cs_searchRespPending5,
86  cs_searchRespPending6,
87  cs_searchRespPending7,
88  cs_searchRespPending8,
89  cs_searchRespPending9,
90  cs_searchRespPending10,
91  cs_searchRespPending11,
92  cs_searchRespPending12,
93  cs_searchRespPending13,
94  cs_searchRespPending14,
95  cs_searchRespPending15,
96  cs_searchRespPending16,
97  cs_searchRespPending17,
98  cs_createReqPend,
99  cs_createRespPend,
100  cs_v42ConnCallbackPend,
101  cs_subscripReqPend,
102  cs_connected,
103  cs_unrespCircuit,
104  cs_subscripUpdateReqPend
105  } listMember;
106  void setRespPendingState ( epicsGuard < epicsMutex > &, unsigned index );
107  void setReqPendingState ( epicsGuard < epicsMutex > &, unsigned index );
108  unsigned getSearchTimerIndex ( epicsGuard < epicsMutex > & );
109  friend class tcpiiu;
110  friend class udpiiu;
111  friend class tcpSendThread;
112  friend class searchTimer;
114 };
115 
117 public:
118  virtual void ioCompletionNotify (
119  epicsGuard < epicsMutex > &, class baseNMIU & ) = 0;
120  virtual arrayElementCount nativeElementCount (
121  epicsGuard < epicsMutex > & ) const = 0;
122  virtual bool connected ( epicsGuard < epicsMutex > & ) const = 0;
123 protected:
125 };
126 
127 class nciu :
128  public cacChannel,
129  public chronIntIdRes < nciu >,
130  public channelNode,
131  private privateInterfaceForIO {
132 public:
133  nciu ( cac &, netiiu &, cacChannelNotify &,
134  const char * pNameIn, cacChannel::priLev );
135  ~nciu ();
136  void connect ( unsigned nativeType,
137  unsigned nativeCount, unsigned sid,
138  epicsGuard < epicsMutex > & cbGuard,
139  epicsGuard < epicsMutex > & guard );
140  void connect ( epicsGuard < epicsMutex > & cbGuard,
141  epicsGuard < epicsMutex > & guard );
142  void unresponsiveCircuitNotify (
143  epicsGuard < epicsMutex > & cbGuard,
144  epicsGuard < epicsMutex > & guard );
145  void circuitHangupNotify ( class udpiiu &,
146  epicsGuard < epicsMutex > & cbGuard,
147  epicsGuard < epicsMutex > & guard );
148  void setServerAddressUnknown (
149  netiiu & newiiu, epicsGuard < epicsMutex > & guard );
150  bool searchMsg (
152  void serviceShutdownNotify (
153  epicsGuard < epicsMutex > & callbackControlGuard,
154  epicsGuard < epicsMutex > & mutualExclusionGuard );
156  epicsGuard < epicsMutex > & cbGuard,
157  epicsGuard < epicsMutex > & guard );
158  ca_uint32_t getSID (
159  epicsGuard < epicsMutex > & ) const;
160  ca_uint32_t getCID (
161  epicsGuard < epicsMutex > & ) const;
162  netiiu * getPIIU (
164  const netiiu * getConstPIIU (
165  epicsGuard < epicsMutex > & ) const;
166  cac & getClient ();
167  void searchReplySetUp ( netiiu &iiu, unsigned sidIn,
168  ca_uint16_t typeIn, arrayElementCount countIn,
170  void show (
171  unsigned level ) const;
172  void show (
174  unsigned level ) const;
175  unsigned getName (
177  char * pBuf, unsigned bufLen ) const throw ();
178  const char * pName (
179  epicsGuard < epicsMutex > & ) const throw ();
180  unsigned nameLen (
181  epicsGuard < epicsMutex > & ) const;
182  unsigned getHostName (
184  char * pBuf, unsigned bufLen ) const throw ();
185  void writeException (
187  int status, const char *pContext, unsigned type, arrayElementCount count );
188  cacChannel::priLev getPriority (
189  epicsGuard < epicsMutex > & ) const;
190  void * operator new (
192  epicsPlacementDeleteOperator (
194  //arrayElementCount nativeElementCount ( epicsGuard < epicsMutex > & ) const;
195  void resubscribe ( epicsGuard < epicsMutex > & );
196  void sendSubscriptionUpdateRequests ( epicsGuard < epicsMutex > & );
197  void disconnectAllIO (
199  bool connected ( epicsGuard < epicsMutex > & ) const;
200  unsigned getcount() const { return count; }
201 
202 private:
204  caAccessRights accessRightState;
205  cac & cacCtx;
206  char * pNameStr;
207  netiiu * piiu;
208  ca_uint32_t sid; // server id
209  unsigned count;
210  unsigned retry; // search retry number
211  unsigned short nameLength; // channel name length
212  ca_uint16_t typeCode;
213  ca_uint8_t priority;
214  virtual void destroy (
215  CallbackGuard & callbackGuard,
216  epicsGuard < epicsMutex > & mutualExclusionGuard );
217  void initiateConnect (
219  unsigned requestMessageBytesPending (
220  epicsGuard < epicsMutex > & mutualExclusionGuard );
221  void flush (
222  epicsGuard < epicsMutex > & mutualExclusionGuard );
223  ioStatus read (
225  unsigned type, arrayElementCount count,
226  cacReadNotify &, ioid * );
227  void write (
229  unsigned type, arrayElementCount count,
230  const void *pValue );
231  ioStatus write (
233  unsigned type, arrayElementCount count,
234  const void *pValue, cacWriteNotify &, ioid * );
235  void subscribe (
237  unsigned type, arrayElementCount nElem,
238  unsigned mask, cacStateNotify &notify, ioid * );
239  // The primary mutex must be released when calling the user's
240  // callback, and therefore a finite interval exists when we are
241  // moving forward with the intent to call the users callback
242  // but the users IO could be deleted during this interval.
243  // To prevent the user's callback from being called after
244  // destroying his IO we must past a guard for the callback
245  // mutex here.
246  virtual void ioCancel (
247  CallbackGuard & callbackGuard,
248  epicsGuard < epicsMutex > & mutualExclusionGuard,
249  const ioid & );
250  void ioShow (
252  const ioid &, unsigned level ) const;
253  short nativeType (
254  epicsGuard < epicsMutex > & ) const;
255  caAccessRights accessRights (
256  epicsGuard < epicsMutex > & ) const;
257  unsigned searchAttempts (
258  epicsGuard < epicsMutex > & ) const;
259  double beaconPeriod (
260  epicsGuard < epicsMutex > & ) const;
261  double receiveWatchdogDelay (
262  epicsGuard < epicsMutex > & ) const;
263  bool ca_v42_ok (
264  epicsGuard < epicsMutex > & ) const;
265  arrayElementCount nativeElementCount (
266  epicsGuard < epicsMutex > & ) const;
267  static void stringVerify ( const char *pStr, const unsigned count );
268  void ioCompletionNotify (
269  epicsGuard < epicsMutex > &, class baseNMIU & );
270  const char * pHostName (
271  epicsGuard < epicsMutex > & guard ) const throw ();
272  nciu ( const nciu & );
273  nciu & operator = ( const nciu & );
274  void operator delete ( void * );
275 };
276 
277 inline void * nciu::operator new ( size_t size,
279 {
280  return freeList.allocate ( size );
281 }
282 
283 #ifdef CXX_PLACEMENT_DELETE
284 inline void nciu::operator delete ( void * pCadaver,
286 {
287  freeList.release ( pCadaver, sizeof ( nciu ) );
288 }
289 #endif
290 
292  epicsGuard < epicsMutex > & ) const
293 {
294  return this->sid;
295 }
296 
298  epicsGuard < epicsMutex > & ) const
299 {
300  return this->id;
301 }
302 
303 // this is to only be used by early protocol revisions
304 inline void nciu::connect ( epicsGuard < epicsMutex > & cbGuard,
305  epicsGuard < epicsMutex > & guard )
306 {
307  this->connect ( this->typeCode, this->count,
308  this->sid, cbGuard, guard );
309 }
310 
311 inline void nciu::searchReplySetUp ( netiiu &iiu, unsigned sidIn,
312  ca_uint16_t typeIn, arrayElementCount countIn,
314 {
315  this->piiu = & iiu;
316  this->typeCode = typeIn;
317  this->count = countIn;
318  this->sid = sidIn;
319 }
320 
323 {
324  return this->piiu;
325 }
326 
327 inline void nciu::writeException (
328  epicsGuard < epicsMutex > & /* cbGuard */,
330  int status, const char * pContext,
331  unsigned typeIn, arrayElementCount countIn )
332 {
333  this->notify().writeException ( guard,
334  status, pContext, typeIn, countIn );
335 }
336 
337 inline const netiiu * nciu::getConstPIIU (
338  epicsGuard < epicsMutex > & ) const
339 {
340  return this->piiu;
341 }
342 
343 inline cac & nciu::getClient ()
344 {
345  return this->cacCtx;
346 }
347 
349  epicsGuard < epicsMutex > & ) const
350 {
351  return this->priority;
352 }
353 
355  listMember ( cs_none )
356 {
357 }
358 
360 {
361  return
362  this->listMember == cs_connected ||
363  this->listMember == cs_subscripReqPend ||
364  this->listMember == cs_subscripUpdateReqPend;
365 }
366 
368 {
369  return
370  this->listMember == cs_connected ||
371  this->listMember == cs_subscripReqPend ||
372  this->listMember == cs_unrespCircuit ||
373  this->listMember == cs_subscripUpdateReqPend;
374 }
375 
376 #endif // ifdef INC_nciu_H
Definition: cac.h:97
LIBCA_API int epicsStdCall ca_v42_ok(chid chan)
pvd::Status status
Definition: netIO.h:44
void connect(unsigned nativeType, unsigned nativeCount, unsigned sid, epicsGuard< epicsMutex > &cbGuard, epicsGuard< epicsMutex > &guard)
Definition: nciu.cpp:114
ca_uint32_t getCID(epicsGuard< epicsMutex > &) const
Definition: nciu.h:297
pvd::StructureConstPtr type
unsigned int ca_uint32_t
Definition: caProto.h:76
const tsDLNode< class nciu > & operator=(const tsDLNode< class nciu > &)
void searchReplySetUp(netiiu &iiu, unsigned sidIn, ca_uint16_t typeIn, arrayElementCount countIn, epicsGuard< epicsMutex > &)
Definition: nciu.h:311
unsigned short ca_uint16_t
Definition: caProto.h:75
unsigned priLev
Definition: cacIO.h:165
static unsigned getMaxSearchTimerCount()
Definition: nciu.cpp:598
unsigned ioid
Definition: cacIO.h:173
void writeException(epicsGuard< epicsMutex > &, epicsGuard< epicsMutex > &, int status, const char *pContext, unsigned type, arrayElementCount count)
Definition: nciu.h:327
netiiu * getPIIU(epicsGuard< epicsMutex > &)
Definition: nciu.h:321
APIs for the epicsMutex mutual exclusion semaphore.
cacChannel::priLev getPriority(epicsGuard< epicsMutex > &) const
Definition: nciu.h:348
const netiiu * getConstPIIU(epicsGuard< epicsMutex > &) const
Definition: nciu.h:337
channelNode()
Definition: nciu.h:354
unsigned getcount() const
Definition: nciu.h:200
unsigned long arrayElementCount
Definition: cacIO.h:57
epicsEventId flush
Definition: errlog.c:70
cac & getClient()
Definition: nciu.h:343
Definition: udpiiu.h:79
void accessRightsStateChange(struct access_rights_handler_args args)
Definition: acctst.c:302
Compiler specific declarations.
bool isInstalledInServer(epicsGuard< epicsMutex > &) const
Definition: nciu.h:367
bool isConnected(epicsGuard< epicsMutex > &) const
Definition: nciu.h:359
unsigned char ca_uint8_t
Definition: caProto.h:74
Definition: netiiu.h:37
ca_uint32_t getSID(epicsGuard< epicsMutex > &) const
Definition: nciu.h:291
Definition: nciu.h:127
virtual ~privateInterfaceForIO()
Definition: nciu.h:124