F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ComQueue.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ComQueue.hpp
3 // \author vbai
4 // \brief hpp file for ComQueue component implementation class
5 // ======================================================================
6 
7 #ifndef Svc_ComQueue_HPP
8 #define Svc_ComQueue_HPP
9 
10 #include <Fw/Buffer/Buffer.hpp>
11 #include <Fw/Com/ComBuffer.hpp>
13 #include <Utils/Types/Queue.hpp>
14 #include <limits>
16 #include "Os/Mutex.hpp"
17 
18 namespace Svc {
19 
20 // ----------------------------------------------------------------------
21 // Types
22 // ----------------------------------------------------------------------
23 
24 class ComQueue final : public ComQueueComponentBase {
25  // Added to enable easy testing of set queue priority command
26  friend class ComQueueTester;
27 
29  enum BufferState { OWNED, UNOWNED };
30 
31  public:
34 
37 
38  static_assert((COM_PORT_COUNT + BUFFER_PORT_COUNT) <= std::numeric_limits<FwIndexType>::max(),
39  "FwIndexType not large enough to hold com and buffer ports");
42 
63  };
64 
80  };
81 
82  private:
83  // ----------------------------------------------------------------------
84  // Internal data structures
85  // ----------------------------------------------------------------------
86 
92  struct QueueMetadata {
93  FwSizeType depth;
94  FwIndexType priority;
95  Types::QueueMode mode;
96  Types::QueueOverflowMode overflowMode;
97  FwIndexType index;
98  FwSizeType msgSize;
99  };
100 
104  enum SendState {
105  READY,
106  WAITING
107  };
108 
109  public:
110  // ----------------------------------------------------------------------
111  // Construction, initialization, and destruction
112  // ----------------------------------------------------------------------
113 
116  ComQueue(const char* const compName
117  );
118 
121  ~ComQueue();
122 
127  void configure(QueueConfigurationTable queueConfig,
128  FwEnumStoreType allocationId,
129  Fw::MemAllocator& allocator
130  );
131 
134  void cleanup();
135 
136  private:
137  // ----------------------------------------------------------------------
138  // Handler implementations for commands
139  // ----------------------------------------------------------------------
140 
145  void FLUSH_QUEUE_cmdHandler(FwOpcodeType opCode,
146  U32 cmdSeq,
147  Svc::QueueType queueType,
148  FwIndexType indexType
149  ) override;
150 
155  void FLUSH_ALL_QUEUES_cmdHandler(FwOpcodeType opCode,
156  U32 cmdSeq
157  ) override;
158 
161  void SET_QUEUE_PRIORITY_cmdHandler(
162  FwOpcodeType opCode,
163  U32 cmdSeq,
164  Svc::QueueType queueType,
165  FwIndexType indexType,
166  FwIndexType newPriority
167  ) override;
168 
169  private:
170  // ----------------------------------------------------------------------
171  // Handler implementations for user-defined typed input ports
172  // ----------------------------------------------------------------------
173 
176  void bufferQueueIn_handler(const FwIndexType portNum,
177  Fw::Buffer& fwBuffer ) override;
178 
181  void comPacketQueueIn_handler(const FwIndexType portNum,
182  Fw::ComBuffer& data,
183  U32 context
184  ) override;
185 
188  void comStatusIn_handler(const FwIndexType portNum,
189  Fw::Success& condition
190  ) override;
191 
194  void run_handler(const FwIndexType portNum,
195  U32 context
196  ) override;
197 
201  void dataReturnIn_handler(FwIndexType portNum,
202  Fw::Buffer& data,
203  const ComCfg::FrameContext& context) override;
204 
205  // ----------------------------------------------------------------------
206  // Hook implementations for typed async input ports
207  // ----------------------------------------------------------------------
208 
211  void bufferQueueIn_overflowHook(FwIndexType portNum,
212  Fw::Buffer& fwBuffer
213  ) override;
214 
215  // ----------------------------------------------------------------------
216  // Helper Functions
217  // ----------------------------------------------------------------------
218 
221  bool enqueue(const FwIndexType queueNum,
222  QueueType queueType,
223  const U8* data,
224  const FwSizeType size
225  );
226 
229  void sendComBuffer(Fw::ComBuffer& comBuffer,
230  FwIndexType queueIndex
231  );
232 
235  void sendBuffer(Fw::Buffer& buffer,
236  FwIndexType queueIndex
237  );
238 
239  void drainQueue(FwIndexType queueNum
240  );
241 
244  void processQueue();
245 
247  FwIndexType getQueueNum(Svc::QueueType queueType, FwIndexType portNum);
248 
249  private:
250  // ----------------------------------------------------------------------
251  // Member variables
252  // ----------------------------------------------------------------------
253  Fw::ComBuffer m_dequeued_com_buffer;
254  Types::Queue m_queues[TOTAL_PORT_COUNT];
255  QueueMetadata m_prioritizedList[TOTAL_PORT_COUNT];
256  bool m_throttle[TOTAL_PORT_COUNT];
257  SendState m_state;
258  BufferState m_buffer_state;
259 
260  // Storage for Fw::MemAllocator properties
261  FwEnumStoreType m_allocationId;
262  Fw::MemAllocator* m_allocator;
263  void* m_allocation;
264 };
265 
266 } // end namespace Svc
267 
268 #endif
configuration data for each queue
Definition: ComQueue.hpp:58
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
I32 FwEnumStoreType
QueueConfigurationEntry entries[TOTAL_PORT_COUNT]
Definition: ComQueue.hpp:75
configuration table for each queue
Definition: ComQueue.hpp:74
static const FwIndexType TOTAL_PORT_COUNT
Total count of input buffer ports and thus total queues.
Definition: ComQueue.hpp:41
ComQueue(const char *const compName)
Definition: ComQueue.cpp:33
void cleanup()
Definition: ComQueue.cpp:50
static const FwIndexType BUFFER_PORT_COUNT
Definition: ComQueue.hpp:36
static const FwIndexType COM_PORT_COUNT
< Count of Fw::Com input ports and thus Fw::Com queues
Definition: ComQueue.hpp:33
QueueConfigurationTable()
constructs a basic un-prioritized table with depth 0
Definition: ComQueue.cpp:21
An enumeration of queue data types.
FwIndexType priority
Priority of the queue [0, TOTAL_PORT_COUNT)
Definition: ComQueue.hpp:60
FwSizeType depth
Depth of the queue [0, infinity)
Definition: ComQueue.hpp:59
friend class ComQueueTester
Definition: ComQueue.hpp:26
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
QueueMode
Queue ordering mode.
Definition: Queue.hpp:25
Memory Allocation base class.
Types::QueueOverflowMode overflowMode
Overflow handling mode (DROP_NEWEST or DROP_OLDEST)
Definition: ComQueue.hpp:62
PlatformIndexType FwIndexType
Types::QueueMode mode
Queue mode (FIFO or LIFO)
Definition: ComQueue.hpp:61
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
Defines a base class for a memory allocator for classes.
QueueOverflowMode
Queue overflow behavior mode.
Definition: Queue.hpp:33
Success/Failure.
void configure(QueueConfigurationTable queueConfig, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
Definition: ComQueue.cpp:57
Auto-generated base for ComQueue component.