F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BufferQueue.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title BufferQueue.hpp
3 // \author dinkel
4 // \brief A generic buffer queue data structure.
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #ifndef OS_PTHREADS_BUFFER_QUEUE_HPP
14 #define OS_PTHREADS_BUFFER_QUEUE_HPP
15 
16 #include <Fw/Types/BasicTypes.hpp>
17 
18 // This is a generic buffer queue interface.
19 namespace Os {
20 
26  class BufferQueue {
27  // Public interface:
28  public:
33  BufferQueue();
38  ~BufferQueue();
49  bool create(NATIVE_UINT_TYPE depth, NATIVE_UINT_TYPE msgSize);
59  bool push(const U8* buffer, NATIVE_UINT_TYPE size, NATIVE_INT_TYPE priority);
72  bool pop(U8* buffer, NATIVE_UINT_TYPE& size, NATIVE_INT_TYPE &priority);
77  bool isFull();
82  bool isEmpty();
104 
105  // Internal member functions:
106  private:
107  // Initialize data structures necessary for the queue:
108  bool initialize(NATIVE_UINT_TYPE depth, NATIVE_UINT_TYPE msgSize);
109  // Destroy queue data structures:
110  void finalize();
111  // Enqueue a message into the data structure:
112  bool enqueue(const U8* buffer, NATIVE_UINT_TYPE size, NATIVE_INT_TYPE priority);
113  // Dequeue a message from the data structure:
114  bool dequeue(U8* buffer, NATIVE_UINT_TYPE& size, NATIVE_INT_TYPE &priority);
115  // Low level enqueue which does the copying onto the queue:
116  void enqueueBuffer(const U8* buffer, NATIVE_UINT_TYPE size, U8* data, NATIVE_UINT_TYPE index);
117  // Low level dequeue which does the copying from the queue:
118  bool dequeueBuffer(U8* buffer, NATIVE_UINT_TYPE& size, U8* data, NATIVE_UINT_TYPE index);
119  // Helper function to get the buffer index into the queue for particular
120  // queue index.
121  NATIVE_UINT_TYPE getBufferIndex(NATIVE_INT_TYPE index);
122 
123  // Member variables:
124  void* queue; // The queue can be implemented in various ways
125  NATIVE_UINT_TYPE msgSize; // Max size of message on the queue
126  NATIVE_UINT_TYPE depth; // Max number of messages on the queue
127  NATIVE_UINT_TYPE count; // Current number of messages on the queue
128  NATIVE_UINT_TYPE maxCount; // Maximum number of messages ever seen on the queue
129  };
130 }
131 
132 #endif // OS_PTHREADS_BUFFER_QUEUE_HPP
Os
Definition: File.cpp:7
Os::BufferQueue::getDepth
NATIVE_UINT_TYPE getDepth()
Get the queue depths.
Definition: BufferQueueCommon.cpp:112
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Os::BufferQueue::getCount
NATIVE_UINT_TYPE getCount()
Get the current number of items on the queue.
Definition: BufferQueueCommon.cpp:99
Os::BufferQueue::~BufferQueue
~BufferQueue()
BufferQueue deconstructor.
Definition: BufferQueueCommon.cpp:34
Os::BufferQueue::push
bool push(const U8 *buffer, NATIVE_UINT_TYPE size, NATIVE_INT_TYPE priority)
push an item onto the queue
Definition: BufferQueueCommon.cpp:51
Os::BufferQueue
A generic buffer queue data structure.
Definition: BufferQueue.hpp:26
Os::BufferQueue::BufferQueue
BufferQueue()
BufferQueue constructor.
Definition: BufferQueueCommon.cpp:25
Os::BufferQueue::getMaxCount
NATIVE_UINT_TYPE getMaxCount()
Get the maximum number of items seen on the queue.
Definition: BufferQueueCommon.cpp:103
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Os::BufferQueue::isEmpty
bool isEmpty()
check if the queue is empty
Definition: BufferQueueCommon.cpp:95
Os::BufferQueue::isFull
bool isFull()
check if the queue is full
Definition: BufferQueueCommon.cpp:91
Os::BufferQueue::getMsgSize
NATIVE_UINT_TYPE getMsgSize()
Get the maximum message size.
Definition: BufferQueueCommon.cpp:108
Os::BufferQueue::create
bool create(NATIVE_UINT_TYPE depth, NATIVE_UINT_TYPE msgSize)
BufferQueue creation.
Definition: BufferQueueCommon.cpp:38
Os::BufferQueue::pop
bool pop(U8 *buffer, NATIVE_UINT_TYPE &size, NATIVE_INT_TYPE &priority)
pop an item off the queue
Definition: BufferQueueCommon.cpp:72
BasicTypes.hpp
Declares ISF basic types.
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29