This is Unofficial EPICS BASE Doxygen Site
comQueSend.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  *
14  * L O S A L A M O S
15  * Los Alamos National Laboratory
16  * Los Alamos, New Mexico 87545
17  *
18  * Copyright, 1986, The Regents of the University of California.
19  *
20  *
21  * Author Jeffrey O. Hill
22  * johill@lanl.gov
23  * 505 665 1831
24  */
25 
26 #ifndef INC_comQueSend_H
27 #define INC_comQueSend_H
28 
29 #include <new>
30 
31 #include "tsDLList.h"
32 #include "comBuf.h"
33 
34 #define comQueSendCopyDispatchSize 39
35 
36 class epicsMutex;
37 template < class T > class epicsGuard;
38 
40 public:
44  void commit ();
45 private:
46  class comQueSend * pSendQue;
47 };
48 
49 //
50 // Notes.
51 // o calling popNextComBufToSend() will clear any uncommitted bytes
52 //
53 class comQueSend {
54 public:
56  ~comQueSend ();
57  void clear ();
58  unsigned occupiedBytes () const;
59  bool flushEarlyThreshold ( unsigned nBytesThisMsg ) const;
60  bool flushBlockThreshold () const;
61  void pushUInt16 ( const ca_uint16_t value );
62  void pushUInt32 ( const ca_uint32_t value );
63  void pushFloat32 ( const ca_float32_t value );
64  void pushString ( const char *pVal, unsigned nChar );
65  void insertRequestHeader (
66  ca_uint16_t request, ca_uint32_t payloadSize,
67  ca_uint16_t dataType, ca_uint32_t nElem, ca_uint32_t cid,
68  ca_uint32_t requestDependent, bool v49Ok );
69  void insertRequestWithPayLoad (
70  ca_uint16_t request, unsigned dataType, arrayElementCount nElem,
71  ca_uint32_t cid, ca_uint32_t requestDependent,
72  const void * pPayload, bool v49Ok );
73  comBuf * popNextComBufToSend ();
74 private:
75  comBufMemoryManager & comBufMemMgr;
77  tsDLIter < comBuf > pFirstUncommited;
78  wireSendAdapter & wire;
79  unsigned nBytesPending;
80 
81  typedef void ( comQueSend::*copyScalarFunc_t ) (
82  const void * pValue );
83  static const copyScalarFunc_t dbrCopyScalar [comQueSendCopyDispatchSize];
84  void copy_dbr_string ( const void * pValue );
85  void copy_dbr_short ( const void * pValue );
86  void copy_dbr_float ( const void * pValue );
87  void copy_dbr_char ( const void * pValue );
88  void copy_dbr_long ( const void * pValue );
89  void copy_dbr_double ( const void * pValue );
90  void copy_dbr_invalid ( const void * pValue );
91 
92  typedef void ( comQueSend::*copyVectorFunc_t ) (
93  const void * pValue, unsigned nElem );
94  static const copyVectorFunc_t dbrCopyVector [comQueSendCopyDispatchSize];
95  void copy_dbr_string ( const void *pValue, unsigned nElem );
96  void copy_dbr_short ( const void *pValue, unsigned nElem );
97  void copy_dbr_float ( const void *pValue, unsigned nElem );
98  void copy_dbr_char ( const void *pValue, unsigned nElem );
99  void copy_dbr_long ( const void *pValue, unsigned nElem );
100  void copy_dbr_double ( const void *pValue, unsigned nElem );
101  void copy_dbr_invalid ( const void * pValue, unsigned nElem );
102 
103  void pushComBuf ( comBuf & );
104  comBuf * newComBuf ();
105 
106  void beginMsg ();
107  void commitMsg ();
108  void clearUncommitedMsg ();
109 
110  friend class comQueSendMsgMinder;
111 
112  //
113  // visual C++ versions 6 & 7 do not allow out of
114  // class member template function definition
115  //
116  template < class T >
117  inline void push ( const T *pVal, const unsigned nElem )
118  {
119  comBuf * pLastBuf = this->bufs.last ();
120  unsigned nCopied;
121  if ( pLastBuf ) {
122  nCopied = pLastBuf->push ( pVal, nElem );
123  }
124  else {
125  nCopied = 0u;
126  }
127  while ( nElem > nCopied ) {
128  comBuf * pComBuf = newComBuf ();
129  nCopied += pComBuf->push
130  ( &pVal[nCopied], nElem - nCopied );
131  this->pushComBuf ( *pComBuf );
132  }
133  }
134 
135  //
136  // visual C++ versions 6 and 7 do not allow out of
137  // class member template function definition
138  //
139  template < class T >
140  inline void push ( const T & val )
141  {
142  comBuf * pComBuf = this->bufs.last ();
143  if ( pComBuf && pComBuf->push ( val ) ) {
144  return;
145  }
146  pComBuf = newComBuf ();
147  bool success = pComBuf->push ( val );
148  assert ( success );
149  this->pushComBuf ( *pComBuf );
150  }
151 
152  template < class T >
153  inline void push ( const T * ); // disabled
154 
155  comQueSend ( const comQueSend & );
156  comQueSend & operator = ( const comQueSend & );
157 };
158 
159 extern const char cacNillBytes[];
160 
162  class comQueSend & sendQueIn, epicsGuard < epicsMutex > & ) :
163  pSendQue ( & sendQueIn )
164 {
165  sendQueIn.beginMsg ();
166 }
167 
169 {
170  if ( this->pSendQue ) {
171  this->pSendQue->clearUncommitedMsg ();
172  }
173 }
174 
176 {
177  if ( this->pSendQue ) {
178  this->pSendQue->commitMsg ();
179  this->pSendQue = 0;
180  }
181 }
182 
183 inline void comQueSend::beginMsg ()
184 {
185  this->pFirstUncommited = this->bufs.lastIter ();
186 }
187 
188 inline void comQueSend::pushUInt16 ( const ca_uint16_t value )
189 {
190  this->push ( value );
191 }
192 
193 inline void comQueSend::pushUInt32 ( const ca_uint32_t value )
194 {
195  this->push ( value );
196 }
197 
198 inline void comQueSend::pushFloat32 ( const ca_float32_t value )
199 {
200  this->push ( value );
201 }
202 
203 inline void comQueSend::pushString ( const char *pVal, unsigned nChar )
204 {
205  this->push ( pVal, nChar );
206 }
207 
208 inline void comQueSend::pushComBuf ( comBuf & cb )
209 {
210  this->bufs.add ( cb );
211  if ( ! this->pFirstUncommited.valid() ) {
212  this->pFirstUncommited = this->bufs.lastIter ();
213  }
214 }
215 
216 inline unsigned comQueSend::occupiedBytes () const
217 {
218  return this->nBytesPending;
219 }
220 
222 {
223  return ( this->nBytesPending > 16 * comBuf::capacityBytes () );
224 }
225 
226 inline bool comQueSend::flushEarlyThreshold ( unsigned nBytesThisMsg ) const
227 {
228  return ( this->nBytesPending + nBytesThisMsg > 4 * comBuf::capacityBytes () );
229 }
230 
231 // wrapping this with a function avoids WRS T2.2 Cygnus GNU compiler bugs
232 inline comBuf * comQueSend::newComBuf ()
233 {
234  return new ( this->comBufMemMgr ) comBuf;
235 }
236 
237 #endif // ifndef INC_comQueSend_H
unsigned push(comBuf &)
Definition: comBuf.h:162
void pushUInt32(const ca_uint32_t value)
Definition: comQueSend.h:193
Definition: link.h:174
comQueSendMsgMinder(class comQueSend &, epicsGuard< epicsMutex > &)
Definition: comQueSend.h:161
std::string request
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
void add(T &item)
Definition: tsDLList.h:313
void pushString(const char *pVal, unsigned nChar)
Definition: comQueSend.h:203
void pushUInt16(const ca_uint16_t value)
Definition: comQueSend.h:188
bool flushEarlyThreshold(unsigned nBytesThisMsg) const
Definition: comQueSend.h:226
unsigned int ca_uint32_t
Definition: caProto.h:76
unsigned short ca_uint16_t
Definition: caProto.h:75
bool valid() const
Definition: tsDLList.h:607
float ca_float32_t
Definition: caProto.h:77
void pushFloat32(const ca_float32_t value)
Definition: comQueSend.h:198
unsigned occupiedBytes() const
Definition: comQueSend.h:216
T * last(void) const
Definition: tsDLList.h:199
bool flushBlockThreshold() const
Definition: comQueSend.h:221
unsigned long arrayElementCount
Definition: cacIO.h:57
Definition: comBuf.h:75
const char cacNillBytes[]
Definition: comQueSend.cpp:74
static unsigned capacityBytes()
Definition: comBuf.h:171
tsDLIterConst< T > lastIter() const
Definition: tsDLList.h:471
#define comQueSendCopyDispatchSize
Definition: comQueSend.h:34