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 <atomic>
15 #include <limits>
17 #include "Os/Mutex.hpp"
18 
19 namespace Svc {
20 
21 // ----------------------------------------------------------------------
22 // Types
23 // ----------------------------------------------------------------------
24 
25 class ComQueue final : public ComQueueComponentBase {
26  // Added to enable easy testing of set queue priority command
27  friend class ComQueueTester;
28 
30  enum BufferState { OWNED, UNOWNED };
31 
32  public:
35 
38 
39  static_assert((COM_PORT_COUNT + BUFFER_PORT_COUNT) <= std::numeric_limits<FwIndexType>::max(),
40  "FwIndexType not large enough to hold com and buffer ports");
43 
64  };
65 
81  };
82 
83  private:
84  // ----------------------------------------------------------------------
85  // Internal data structures
86  // ----------------------------------------------------------------------
87 
93  struct QueueMetadata {
94  FwSizeType depth;
95  FwIndexType priority;
96  Types::QueueMode mode;
97  Types::QueueOverflowMode overflowMode;
98  FwIndexType index;
99  FwSizeType msgSize;
100  };
101 
105  enum SendState {
106  READY,
107  WAITING
108  };
109 
110  public:
111  // ----------------------------------------------------------------------
112  // Construction, initialization, and destruction
113  // ----------------------------------------------------------------------
114 
117  ComQueue(const char* const compName
118  );
119 
122  ~ComQueue();
123 
128  void configure(
129  const QueueConfigurationTable& queueConfig,
130  FwEnumStoreType allocationId,
131  Fw::MemAllocator& allocator
132  );
133 
136  void cleanup();
137 
138  private:
139  // ----------------------------------------------------------------------
140  // Handler implementations for commands
141  // ----------------------------------------------------------------------
142 
147  void FLUSH_QUEUE_cmdHandler(FwOpcodeType opCode,
148  U32 cmdSeq,
149  const Svc::QueueType& queueType,
150  FwIndexType indexType
151  ) override;
152 
157  void FLUSH_ALL_QUEUES_cmdHandler(FwOpcodeType opCode,
158  U32 cmdSeq
159  ) override;
160 
163  void SET_QUEUE_PRIORITY_cmdHandler(
164  FwOpcodeType opCode,
165  U32 cmdSeq,
166  const Svc::QueueType& queueType,
167  FwIndexType indexType,
168  FwIndexType newPriority
169  ) override;
170 
171  private:
172  // ----------------------------------------------------------------------
173  // Handler implementations for user-defined typed input ports
174  // ----------------------------------------------------------------------
175 
178  void bufferQueueIn_handler(const FwIndexType portNum,
179  Fw::Buffer& fwBuffer ) override;
180 
183  void comPacketQueueIn_handler(const FwIndexType portNum,
184  Fw::ComBuffer& data,
185  U32 context
186  ) override;
187 
190  void comStatusIn_handler(const FwIndexType portNum,
191  Fw::Success& condition
192  ) override;
193 
196  void run_handler(const FwIndexType portNum,
197  U32 context
198  ) override;
199 
201  void runInternal_internalInterfaceHandler() override;
202 
204  void runInternal_overflowHook() override;
205 
209  void dataReturnIn_handler(FwIndexType portNum,
210  Fw::Buffer& data,
211  const ComCfg::FrameContext& context) override;
212 
213  // ----------------------------------------------------------------------
214  // Hook implementations for typed async input ports
215  // ----------------------------------------------------------------------
216 
218  void comPacketQueueIn_overflowHook(FwIndexType portNum, Fw::ComBuffer& data, U32 context) override;
219 
221  void bufferQueueIn_overflowHook(FwIndexType portNum,
222  Fw::Buffer& fwBuffer
223  ) override;
224 
225  // ----------------------------------------------------------------------
226  // Helper Functions
227  // ----------------------------------------------------------------------
228 
231  bool enqueue(const FwIndexType queueNum,
232  const Fw::ComBuffer& data
233  );
234 
237  bool enqueue(const FwIndexType queueNum,
238  const Fw::Buffer& data
239  );
240 
244  bool handleEnqueueStatus(const FwIndexType queueNum,
245  QueueType queueType,
246  const FwIndexType portNum,
247  const bool preEmptiveOverflow,
248  const Fw::SerializeStatus status
249  );
250 
253  void sendComBuffer(Fw::ComBuffer& comBuffer,
254  FwIndexType queueIndex
255  );
256 
259  void sendBuffer(Fw::Buffer& buffer,
260  FwIndexType queueIndex
261  );
262 
263  void drainQueue(FwIndexType queueNum
264  );
265 
268  void processQueue();
269 
271  FwIndexType getQueueNum(Svc::QueueType queueType, FwIndexType portNum);
272 
274  FwSizeType getQueueDepth(const FwIndexType queueNum
275  ) const;
276 
277  private:
278  // ----------------------------------------------------------------------
279  // Member variables
280  // ----------------------------------------------------------------------
281  Fw::ComBuffer m_dequeued_com_buffer;
282  Types::Queue m_queues[TOTAL_PORT_COUNT];
283  QueueMetadata m_prioritizedList[TOTAL_PORT_COUNT];
284  std::atomic<U32> m_comIngressDrops[COM_PORT_COUNT];
285  std::atomic<U32> m_buffIngressDrops[BUFFER_PORT_COUNT];
286  U32 m_managedDrops[TOTAL_PORT_COUNT];
287  bool m_throttle[TOTAL_PORT_COUNT];
288  SendState m_state;
289  std::atomic<BufferState> m_buffer_state;
290  std::atomic<bool> m_runQueued;
291 
292  // Storage for Fw::MemAllocator properties
293  FwEnumStoreType m_allocationId;
294  Fw::MemAllocator* m_allocator;
295  void* m_allocation;
296 };
297 
298 } // end namespace Svc
299 
300 #endif
configuration data for each queue
Definition: ComQueue.hpp:59
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
void configure(const QueueConfigurationTable &queueConfig, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
Definition: ComQueue.cpp:65
I32 FwEnumStoreType
QueueConfigurationEntry entries[TOTAL_PORT_COUNT]
Definition: ComQueue.hpp:76
configuration table for each queue
Definition: ComQueue.hpp:75
static const FwIndexType TOTAL_PORT_COUNT
Total count of input buffer ports and thus total queues.
Definition: ComQueue.hpp:42
ComQueue(const char *const compName)
Definition: ComQueue.cpp:33
void cleanup()
Definition: ComQueue.cpp:58
static const FwIndexType BUFFER_PORT_COUNT
Definition: ComQueue.hpp:37
static const FwIndexType COM_PORT_COUNT
< Count of Fw::Com input ports and thus Fw::Com queues
Definition: ComQueue.hpp:34
QueueConfigurationTable()
constructs a basic un-prioritized table with depth 0
Definition: ComQueue.cpp:21
An enumeration of queue data types.
SerializeStatus
forward declaration for string
FwIndexType priority
Priority of the queue [0, TOTAL_PORT_COUNT)
Definition: ComQueue.hpp:61
FwSizeType depth
Depth of the queue [0, infinity)
Definition: ComQueue.hpp:60
friend class ComQueueTester
Definition: ComQueue.hpp:27
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:63
PlatformIndexType FwIndexType
Types::QueueMode mode
Queue mode (FIFO or LIFO)
Definition: ComQueue.hpp:62
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.