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(
128  const QueueConfigurationTable& queueConfig,
129  FwEnumStoreType allocationId,
130  Fw::MemAllocator& allocator
131  );
132 
135  void cleanup();
136 
137  private:
138  // ----------------------------------------------------------------------
139  // Handler implementations for commands
140  // ----------------------------------------------------------------------
141 
146  void FLUSH_QUEUE_cmdHandler(FwOpcodeType opCode,
147  U32 cmdSeq,
148  const Svc::QueueType& queueType,
149  FwIndexType indexType
150  ) override;
151 
156  void FLUSH_ALL_QUEUES_cmdHandler(FwOpcodeType opCode,
157  U32 cmdSeq
158  ) override;
159 
162  void SET_QUEUE_PRIORITY_cmdHandler(
163  FwOpcodeType opCode,
164  U32 cmdSeq,
165  const Svc::QueueType& queueType,
166  FwIndexType indexType,
167  FwIndexType newPriority
168  ) override;
169 
170  private:
171  // ----------------------------------------------------------------------
172  // Handler implementations for user-defined typed input ports
173  // ----------------------------------------------------------------------
174 
177  void bufferQueueIn_handler(const FwIndexType portNum,
178  Fw::Buffer& fwBuffer ) override;
179 
182  void comPacketQueueIn_handler(const FwIndexType portNum,
183  Fw::ComBuffer& data,
184  U32 context
185  ) override;
186 
189  void comStatusIn_handler(const FwIndexType portNum,
190  Fw::Success& condition
191  ) override;
192 
195  void run_handler(const FwIndexType portNum,
196  U32 context
197  ) override;
198 
202  void dataReturnIn_handler(FwIndexType portNum,
203  Fw::Buffer& data,
204  const ComCfg::FrameContext& context) override;
205 
206  // ----------------------------------------------------------------------
207  // Hook implementations for typed async input ports
208  // ----------------------------------------------------------------------
209 
212  void bufferQueueIn_overflowHook(FwIndexType portNum,
213  Fw::Buffer& fwBuffer
214  ) override;
215 
216  // ----------------------------------------------------------------------
217  // Helper Functions
218  // ----------------------------------------------------------------------
219 
222  bool enqueue(const FwIndexType queueNum,
223  QueueType queueType,
224  const U8* data,
225  const FwSizeType size
226  );
227 
230  void sendComBuffer(Fw::ComBuffer& comBuffer,
231  FwIndexType queueIndex
232  );
233 
236  void sendBuffer(Fw::Buffer& buffer,
237  FwIndexType queueIndex
238  );
239 
240  void drainQueue(FwIndexType queueNum
241  );
242 
245  void processQueue();
246 
248  FwIndexType getQueueNum(Svc::QueueType queueType, FwIndexType portNum);
249 
250  private:
251  // ----------------------------------------------------------------------
252  // Member variables
253  // ----------------------------------------------------------------------
254  Fw::ComBuffer m_dequeued_com_buffer;
255  Types::Queue m_queues[TOTAL_PORT_COUNT];
256  QueueMetadata m_prioritizedList[TOTAL_PORT_COUNT];
257  bool m_throttle[TOTAL_PORT_COUNT];
258  SendState m_state;
259  BufferState m_buffer_state;
260 
261  // Storage for Fw::MemAllocator properties
262  FwEnumStoreType m_allocationId;
263  Fw::MemAllocator* m_allocator;
264  void* m_allocation;
265 };
266 
267 } // end namespace Svc
268 
269 #endif
configuration data for each queue
Definition: ComQueue.hpp:58
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
void configure(const QueueConfigurationTable &queueConfig, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
Definition: ComQueue.cpp:57
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:54
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.
Auto-generated base for ComQueue component.