This is Unofficial EPICS BASE Doxygen Site
comBuf Class Reference

#include "comBuf.h"

+ Inheritance diagram for comBuf:
+ Collaboration diagram for comBuf:

Classes

class  insufficentBytesAvailable
 
struct  popStatus
 

Public Member Functions

 comBuf ()
 
unsigned unoccupiedBytes () const
 
unsigned occupiedBytes () const
 
unsigned uncommittedBytes () const
 
void clear ()
 
unsigned copyInBytes (const void *pBuf, unsigned nBytes)
 
unsigned push (comBuf &)
 
template<class T >
bool push (const T &value)
 
template<class T >
unsigned push (const T *pValue, unsigned nElem)
 
unsigned push (const epicsInt8 *pValue, unsigned nElem)
 
unsigned push (const epicsUInt8 *pValue, unsigned nElem)
 
unsigned push (const epicsOldString *pValue, unsigned nElem)
 
void commitIncomming ()
 
void clearUncommittedIncomming ()
 
bool copyInAllBytes (const void *pBuf, unsigned nBytes)
 
unsigned copyOutBytes (void *pBuf, unsigned nBytes)
 
bool copyOutAllBytes (void *pBuf, unsigned nBytes)
 
unsigned removeBytes (unsigned nBytes)
 
bool flushToWire (wireSendAdapter &, const epicsTime &currentTime)
 
void fillFromWire (wireRecvAdapter &, statusWireIO &)
 
template<class T >
popStatus pop (T &)
 
void * operator new (size_t size, comBufMemoryManager &)
 
void operator delete (void *)
 
template<class T >
bool push (const T *)
 
- Public Member Functions inherited from tsDLNode< comBuf >
 tsDLNode ()
 
 tsDLNode (const tsDLNode< comBuf > &)
 
const tsDLNode< comBuf > & operator= (const tsDLNode< comBuf > &)
 

Static Public Member Functions

static unsigned capacityBytes ()
 
static void throwInsufficentBytesException ()
 

Public Attributes

epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex )
 
unsigned nextReadIndex
 
epicsUInt8 buf [comBufSize]
 

Detailed Description

Definition at line 75 of file comBuf.h.

Constructor & Destructor Documentation

comBuf::comBuf ( )
inline

Definition at line 135 of file comBuf.h.

135  : commitIndex ( 0u ),
136  nextWriteIndex ( 0u ), nextReadIndex ( 0u )
137 {
138 }
unsigned nextReadIndex
Definition: comBuf.h:114
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110

Member Function Documentation

unsigned comBuf::capacityBytes ( )
inlinestatic

Definition at line 171 of file comBuf.h.

172 {
173  return comBufSize;
174 }
void comBuf::clear ( )
inline

Definition at line 140 of file comBuf.h.

141 {
142  this->commitIndex = 0u;
143  this->nextWriteIndex = 0u;
144  this->nextReadIndex = 0u;
145 }
unsigned nextReadIndex
Definition: comBuf.h:114
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
void comBuf::clearUncommittedIncomming ( )
inline

Definition at line 247 of file comBuf.h.

248 {
249  this->nextWriteIndex = this->commitIndex;
250 }
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
void comBuf::commitIncomming ( )
inline

Definition at line 242 of file comBuf.h.

243 {
244  this->commitIndex = this->nextWriteIndex;
245 }
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
bool comBuf::copyInAllBytes ( const void *  pBuf,
unsigned  nBytes 
)
inline

Definition at line 252 of file comBuf.h.

253 {
254  unsigned index = this->nextWriteIndex;
255  unsigned available = sizeof ( this->buf ) - index;
256  if ( nBytes <= available ) {
257  memcpy ( & this->buf[index], pBuf, nBytes );
258  this->nextWriteIndex = index + nBytes;
259  return true;
260  }
261  return false;
262 }
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
unsigned comBuf::copyInBytes ( const void *  pBuf,
unsigned  nBytes 
)
inline

Definition at line 264 of file comBuf.h.

265 {
266  unsigned index = this->nextWriteIndex;
267  unsigned available = sizeof ( this->buf ) - index;
268  if ( nBytes > available ) {
269  nBytes = available;
270  }
271  memcpy ( & this->buf[index], pBuf, nBytes );
272  this->nextWriteIndex = index + nBytes;
273  return nBytes;
274 }
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
bool comBuf::copyOutAllBytes ( void *  pBuf,
unsigned  nBytes 
)
inline

Definition at line 276 of file comBuf.h.

277 {
278  unsigned index = this->nextReadIndex;
279  unsigned occupied = this->commitIndex - index;
280  if ( nBytes <= occupied ) {
281  memcpy ( pBuf, &this->buf[index], nBytes);
282  this->nextReadIndex = index + nBytes;
283  return true;
284  }
285  return false;
286 }
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
unsigned nextReadIndex
Definition: comBuf.h:114
unsigned comBuf::copyOutBytes ( void *  pBuf,
unsigned  nBytes 
)
inline

Definition at line 288 of file comBuf.h.

289 {
290  unsigned index = this->nextReadIndex;
291  unsigned occupied = this->commitIndex - index;
292  if ( nBytes > occupied ) {
293  nBytes = occupied;
294  }
295  memcpy ( pBuf, &this->buf[index], nBytes);
296  this->nextReadIndex = index + nBytes;
297  return nBytes;
298 }
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
unsigned nextReadIndex
Definition: comBuf.h:114
void comBuf::fillFromWire ( wireRecvAdapter wire,
statusWireIO stat 
)
inline

Definition at line 176 of file comBuf.h.

178 {
179  wire.recvBytes (
180  & this->buf[this->nextWriteIndex],
181  sizeof ( this->buf ) - this->nextWriteIndex, stat );
182  if ( stat.circuitState == swioConnected ) {
183  this->nextWriteIndex += stat.bytesCopied;
184  }
185 }
swioCircuitState circuitState
Definition: comBuf.h:64
unsigned bytesCopied
Definition: comBuf.h:63
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
virtual void recvBytes(void *pBuf, unsigned nBytesInBuf, statusWireIO &)=0
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
bool comBuf::flushToWire ( wireSendAdapter wire,
const epicsTime &  currentTime 
)

Definition at line 30 of file comBuf.cpp.

31 {
32  unsigned index = this->nextReadIndex;
33  unsigned finalIndex = this->commitIndex;
34  while ( index < finalIndex ) {
35  unsigned nBytes = wire.sendBytes (
36  &this->buf[index], finalIndex - index, currentTime );
37  if ( nBytes == 0u ) {
38  this->nextReadIndex = index;
39  return false;
40  }
41  index += nBytes;
42  }
43  this->nextReadIndex = index;
44  return true;
45 }
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
virtual unsigned sendBytes(const void *pBuf, unsigned nBytesInBuf, const class epicsTime &currentTime)=0
unsigned nextReadIndex
Definition: comBuf.h:114
unsigned comBuf::occupiedBytes ( ) const
inline

Definition at line 152 of file comBuf.h.

153 {
154  return this->commitIndex - this->nextReadIndex;
155 }
unsigned nextReadIndex
Definition: comBuf.h:114
void comBuf::operator delete ( void *  )

Definition at line 54 of file comBuf.cpp.

55 {
56  // Visual C++ .net appears to require operator delete if
57  // placement operator delete is defined? I smell a ms rat
58  // because if I declare placement new and delete, but
59  // comment out the placement delete definition there are
60  // no undefined symbols.
61  errlogPrintf ( "%s:%d this compiler is confused about placement delete - memory was probably leaked",
62  __FILE__, __LINE__ );
63 }
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void * comBuf::operator new ( size_t  size,
comBufMemoryManager mgr 
)
inline

Definition at line 121 of file comBuf.h.

123 {
124  return mgr.allocate ( size );
125 }
virtual void * allocate(size_t)=0
template<class T >
comBuf::popStatus comBuf::pop ( T &  returnVal)

Definition at line 312 of file comBuf.h.

313 {
314  unsigned nrIndex = this->nextReadIndex;
315  unsigned popIndex = nrIndex + sizeof ( returnVal );
316  unsigned cIndex = this->commitIndex;
317  popStatus status;
318  status.success = true;
319  status.nowEmpty = false;
320  if ( popIndex >= cIndex ) {
321  if ( popIndex == cIndex ) {
322  status.nowEmpty = true;
323  }
324  else {
325  status.success = false;
326  return status;
327  }
328  }
329  WireGet ( & this->buf[ nrIndex ], returnVal );
330  this->nextReadIndex = popIndex;
331  return status;
332 }
pvd::Status status
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
void WireGet(const epicsUInt8 *pWireSrc, epicsOldString &dst)
Definition: osdWireFormat.h:83
unsigned nextReadIndex
Definition: comBuf.h:114
unsigned comBuf::push ( comBuf bufIn)
inline

Definition at line 162 of file comBuf.h.

163 {
164  unsigned nBytes = this->copyInBytes (
165  & bufIn.buf[ bufIn.nextReadIndex ],
166  bufIn.commitIndex - bufIn.nextReadIndex );
167  bufIn.nextReadIndex += nBytes;
168  return nBytes;
169 }
unsigned copyInBytes(const void *pBuf, unsigned nBytes)
Definition: comBuf.h:264
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
unsigned nextReadIndex
Definition: comBuf.h:114
template<class T >
bool comBuf::push ( const T &  value)
inline

Definition at line 188 of file comBuf.h.

189 {
190  unsigned index = this->nextWriteIndex;
191  unsigned available = sizeof ( this->buf ) - index;
192  if ( sizeof ( value ) > available ) {
193  return false;
194  }
195  WireSet ( value, & this->buf[index] );
196  this->nextWriteIndex = index + sizeof ( value );
197  return true;
198 }
Definition: link.h:174
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
void WireSet(const epicsOldString &src, epicsUInt8 *pWireDst)
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
template<class T >
unsigned comBuf::push ( const T *  pValue,
unsigned  nElem 
)

Definition at line 225 of file comBuf.h.

226 {
227  unsigned index = this->nextWriteIndex;
228  unsigned available = sizeof ( this->buf ) - index;
229  unsigned nBytes = sizeof ( *pValue ) * nElem;
230  if ( nBytes > available ) {
231  nElem = available / sizeof ( *pValue );
232  }
233  for ( unsigned i = 0u; i < nElem; i++ ) {
234  // allow native floating point formats to be converted to IEEE
235  WireSet( pValue[i], &this->buf[index] );
236  index += sizeof ( *pValue );
237  }
238  this->nextWriteIndex = index;
239  return nElem;
240 }
int i
Definition: scan.c:967
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
void WireSet(const epicsOldString &src, epicsUInt8 *pWireDst)
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
unsigned comBuf::push ( const epicsInt8 pValue,
unsigned  nElem 
)
inline

Definition at line 200 of file comBuf.h.

201 {
202  return copyInBytes ( pValue, nElem );
203 }
unsigned copyInBytes(const void *pBuf, unsigned nBytes)
Definition: comBuf.h:264
unsigned comBuf::push ( const epicsUInt8 pValue,
unsigned  nElem 
)
inline

Definition at line 205 of file comBuf.h.

206 {
207  return copyInBytes ( pValue, nElem );
208 }
unsigned copyInBytes(const void *pBuf, unsigned nBytes)
Definition: comBuf.h:264
unsigned comBuf::push ( const epicsOldString pValue,
unsigned  nElem 
)
inline

Definition at line 210 of file comBuf.h.

211 {
212  unsigned index = this->nextWriteIndex;
213  unsigned available = sizeof ( this->buf ) - index;
214  unsigned nBytes = sizeof ( *pValue ) * nElem;
215  if ( nBytes > available ) {
216  nElem = available / sizeof ( *pValue );
217  nBytes = nElem * sizeof ( *pValue );
218  }
219  memcpy ( &this->buf[ index ], pValue, nBytes );
220  this->nextWriteIndex = index + nBytes;
221  return nElem;
222 }
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
template<class T >
bool comBuf::push ( const T *  )
unsigned comBuf::removeBytes ( unsigned  nBytes)
inline

Definition at line 300 of file comBuf.h.

301 {
302  unsigned index = this->nextReadIndex;
303  unsigned occupied = this->commitIndex - index;
304  if ( nBytes > occupied ) {
305  nBytes = occupied;
306  }
307  this->nextReadIndex = index + nBytes;
308  return nBytes;
309 }
unsigned nextReadIndex
Definition: comBuf.h:114
void comBuf::throwInsufficentBytesException ( )
static

Definition at line 49 of file comBuf.cpp.

unsigned comBuf::uncommittedBytes ( ) const
inline

Definition at line 157 of file comBuf.h.

158 {
159  return this->nextWriteIndex - this->commitIndex;
160 }
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110
unsigned comBuf::unoccupiedBytes ( ) const
inline

Definition at line 147 of file comBuf.h.

148 {
149  return sizeof ( this->buf ) - this->nextWriteIndex;
150 }
epicsUInt8 buf[comBufSize]
Definition: comBuf.h:115
epicsPlacementDeleteOperator((void *, comBufMemoryManager &)) private unsigne nextWriteIndex)
Definition: comBuf.h:110

Member Data Documentation

epicsUInt8 comBuf::buf[comBufSize]

Definition at line 115 of file comBuf.h.

unsigned comBuf::nextReadIndex

Definition at line 114 of file comBuf.h.

epicsPlacementDeleteOperator (( void *, comBufMemoryManager & )) private unsigne comBuf::nextWriteIndex)

Definition at line 110 of file comBuf.h.


The documentation for this class was generated from the following files: