Tezzeret  1
Tezzeret
GmRingBuffer.hpp
1 /*
2  * GmRingBuffer.hpp
3  *
4  * Created on: Jul 23, 2016
5  * Author: rcram
6  */
7 
8 #ifndef GMRINGBUFFER_HPP_
9 #define GMRINGBUFFER_HPP_
10 
11 namespace Geometrics
12 {
13 
14  #define GM_RING_BUFFER_OK 0
15  #define GM_RING_BUFFER_WRONG_RECORD_SIZE 1
16  #define GM_RING_BUFFER_INVALID_INDEX 2
17  #define GM_RING_BUFFER_NO_RECORDS 3
18  #define GM_RING_BUFFER_FAILURE 4
19  #define GM_RING_BUFFER_OVERRUN_OVERWROTE 5
20  #define GM_RING_BUFFER_OVERRUN_NO_WRITE 6
21  #define GM_RING_BUFFER_EMPTY 7
22  #define GM_RING_BUFFER_NO_UNNOTICED 8
23  #define GM_RING_BUFFER_NULL_DESTINATION 9
24 
25 
26  // Initially, this is FIFO only.
27  // This class has no concurrency control. That must occur
28  // in the clients of this class.
29  // Would be nice to add priority, so that for purposes
30  // such as task switching,
31  // we could put higher-priority items in the buffer.
33  {
34  public:
35  CRingBuffer (int iMaxItems,
36  int iItemSize,
37  Bool bOkToOverrun,
38  Bool bNotices);
39  CRingBuffer (int iMaxItems,
40  int iItemSize,
41  Bool bOkToOverrun,
42  Bool bNotices,
43  UInt8 *puiBuffer,
44  UInt32 uiBufferSize);
45  ~CRingBuffer ();
46 
47  int ReadRecord (UInt8 *pcDestination,
48  int iSize);
49  int NoticeRecord (int *piDestination);
50  int WriteRecord (UInt8 *pcSource,
51  int iSize);
52  int ForgetNextRecord ();
53  int CheckToWrite (int iSize);
54  void SetEmpty ();
55  Bool IsEmpty ();
56  Bool HasData ();
57  Bool HasUnnoticedData ();
58  int ReserveRecord (int iSize, int *pIndex);
59  UInt8 *GetBuffer (int iBufferIndex);
60  int CopyAndCommitData (UInt8 *pcSource,
61  int index,
62  int iSize);
63  int CommitData (int index);
64  int Size();
65  int MaxSize();
66 
67  protected:
68  int InternalWriteRecord (UInt8 *pcSource,
69  int iSize);
70 
71  // UInt8 *GetBuffer (int iBufferIndex);
72 
73  int m_iMaxItems,
74  m_iItemSize,
75  m_iLastBufferRead,
76  m_iLastBufferNoticed,
77  m_iLastBufferWritten;
78 
79  // To manage overruns. See notes in CPP
80  Bool m_bNextWriteWouldOverrun,
81  m_bNextWriteWouldOverrunNotice,
82  m_bOkToOverrun,
83  m_bNotices;
84 
85  UInt8 *m_Buffer;
86  };
87 }
88 #endif /* GMRINGBUFFER_HPP_ */
Definition: GmRingBuffer.hpp:33
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47