This is Unofficial EPICS BASE Doxygen Site
netSubscription.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 #include <string>
21 #include <stdexcept>
22 
23 #include "errlog.h"
24 
25 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
26 
27 #include "iocinf.h"
28 #include "nciu.h"
29 #include "cac.h"
30 #include "db_access.h" // for dbf_type_to_text
31 #include "caerr.h"
32 
34  privateInterfaceForIO & chanIn,
35  unsigned typeIn, arrayElementCount countIn,
36  unsigned maskIn, cacStateNotify & notifyIn ) :
37  count ( countIn ), privateChanForIO ( chanIn ),
38  notify ( notifyIn ), type ( typeIn ), mask ( maskIn ),
39  subscribed ( false )
40 {
41  if ( ! dbr_type_is_valid ( typeIn ) ) {
42  throw cacChannel::badType ();
43  }
44  if ( this->mask == 0u ) {
46  }
47 }
48 
50 {
51 }
52 
54  epicsGuard < epicsMutex > & guard, cacRecycle & recycle )
55 {
56  this->~netSubscription ();
57  recycle.recycleSubscription ( guard, *this );
58 }
59 
60 class netSubscription * netSubscription::isSubscription ()
61 {
62  return this;
63 }
64 
65 void netSubscription::show ( unsigned /* level */ ) const
66 {
67  ::printf ( "event subscription IO at %p, type %s, element count %lu, mask %u\n",
68  static_cast < const void * > ( this ),
69  dbf_type_to_text ( static_cast < int > ( this->type ) ),
70  this->count, this->mask );
71 }
72 
74  epicsGuard < epicsMutex > &, unsigned level ) const
75 {
76  this->show ( level );
77 }
78 
79 void netSubscription::completion (
81 {
82  errlogPrintf ( "subscription update w/o data ?\n" );
83 }
84 
85 void netSubscription::exception (
86  epicsGuard < epicsMutex > & guard, cacRecycle & recycle,
87  int status, const char * pContext )
88 {
89  if ( status == ECA_DISCONN ) {
90  this->subscribed = false;
91  }
92  if ( status == ECA_CHANDESTROY ) {
93  this->privateChanForIO.ioCompletionNotify ( guard, *this );
94  this->notify.exception (
95  guard, status, pContext, UINT_MAX, 0 );
96  this->~netSubscription ();
97  recycle.recycleSubscription ( guard, *this );
98  }
99  else {
100  // guard.assertIdenticalMutex ( this->mutex );
101  if ( this->privateChanForIO.connected ( guard ) ) {
102  this->notify.exception (
103  guard, status, pContext, UINT_MAX, 0 );
104  }
105  }
106 }
107 
108 void netSubscription::exception (
110  cacRecycle & recycle, int status, const char * pContext,
111  unsigned typeIn, arrayElementCount countIn )
112 {
113  if ( status == ECA_DISCONN ) {
114  this->subscribed = false;
115  }
116  if ( status == ECA_CHANDESTROY ) {
117  this->privateChanForIO.ioCompletionNotify ( guard, *this );
118  this->notify.exception (
119  guard, status, pContext, UINT_MAX, 0 );
120  this->~netSubscription ();
121  recycle.recycleSubscription ( guard, *this );
122  }
123  else {
124  //guard.assertIdenticalMutex ( this->mutex );
125  if ( this->privateChanForIO.connected ( guard ) ) {
126  this->notify.exception (
127  guard, status, pContext, typeIn, countIn );
128  }
129  }
130 }
131 
132 void netSubscription::completion (
134  unsigned typeIn, arrayElementCount countIn,
135  const void * pDataIn )
136 {
137  // guard.assertIdenticalMutex ( this->mutex );
138  if ( this->privateChanForIO.connected ( guard ) ) {
139  this->notify.current (
140  guard, typeIn, countIn, pDataIn );
141  }
142 }
143 
145  epicsGuard < epicsMutex > & guard, nciu & chan )
146 {
147  if ( ! this->subscribed ) {
148  chan.getPIIU(guard)->subscriptionRequest (
149  guard, chan, *this );
150  this->subscribed = true;
151  }
152 }
153 
155  epicsGuard < epicsMutex > & guard, nciu & chan )
156 {
157  if ( this->subscribed ) {
158  chan.getPIIU(guard)->subscriptionCancelRequest (
159  guard, chan, *this );
160  this->subscribed = false;
161  }
162 }
163 
164 void netSubscription::forceSubscriptionUpdate (
165  epicsGuard < epicsMutex > & guard, nciu & chan )
166 {
167  chan.getPIIU(guard)->subscriptionUpdateRequest (
168  guard, chan, *this );
169 }
170 
171 void netSubscription::operator delete ( void * )
172 {
173  // Visual C++ .net appears to require operator delete if
174  // placement operator delete is defined? I smell a ms rat
175  // because if I declare placement new and delete, but
176  // comment out the placement delete definition there are
177  // no undefined symbols.
178  errlogPrintf ( "%s:%d this compiler is confused about placement delete - memory was probably leaked",
179  __FILE__, __LINE__ );
180 }
181 
182 
183 
184 
185 
186 
187 
virtual void ioCompletionNotify(epicsGuard< epicsMutex > &, class baseNMIU &)=0
virtual void subscriptionCancelRequest(epicsGuard< epicsMutex > &, nciu &chan, netSubscription &subscr)=0
Definition: netiiu.cpp:81
virtual void current(epicsGuard< epicsMutex > &, unsigned type, arrayElementCount count, const void *pData)=0
virtual void recycleSubscription(epicsGuard< epicsMutex > &, netSubscription &io)=0
#define dbf_type_to_text(type)
Definition: db_access.h:677
void subscribeIfRequired(epicsGuard< epicsMutex > &guard, nciu &chan)
virtual void subscriptionRequest(epicsGuard< epicsMutex > &, nciu &, netSubscription &)=0
Definition: netiiu.cpp:76
#define printf
Definition: epicsStdio.h:41
pvd::StructureConstPtr type
#define dbr_type_is_valid(type)
Definition: db_access.h:644
#define ECA_DISCONN
Definition: caerr.h:101
netSubscription(class privateInterfaceForIO &, unsigned type, arrayElementCount count, unsigned mask, cacStateNotify &)
Definition: cac.h:50
netiiu * getPIIU(epicsGuard< epicsMutex > &)
Definition: nciu.h:321
virtual void subscriptionUpdateRequest(epicsGuard< epicsMutex > &, nciu &, netSubscription &)=0
Definition: netiiu.cpp:86
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
virtual void destroy(epicsGuard< epicsMutex > &, class cacRecycle &)=0
unsigned long arrayElementCount
Definition: cacIO.h:57
virtual bool connected(epicsGuard< epicsMutex > &) const =0
void unsubscribeIfRequired(epicsGuard< epicsMutex > &guard, nciu &chan)
#define ECA_CHANDESTROY
Definition: caerr.h:132
void show(unsigned level) const
#define false
Definition: flexdef.h:85
Definition: nciu.h:127