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 
203  void dataReturnIn_handler(FwIndexType portNum,
204  Fw::Buffer& data,
205  const ComCfg::FrameContext& context) override;
206 
207  // ----------------------------------------------------------------------
208  // Hook implementations for typed async input ports
209  // ----------------------------------------------------------------------
210 
213  void bufferQueueIn_overflowHook(FwIndexType portNum,
214  Fw::Buffer& fwBuffer
215  ) override;
216 
217  // ----------------------------------------------------------------------
218  // Helper Functions
219  // ----------------------------------------------------------------------
220 
223  bool enqueue(const FwIndexType queueNum,
224  const Fw::ComBuffer& data
225  );
226 
229  bool enqueue(const FwIndexType queueNum,
230  const Fw::Buffer& data
231  );
232 
236  bool handleEnqueueStatus(const FwIndexType queueNum,
237  QueueType queueType,
238  const FwIndexType portNum,
239  const bool preEmptiveOverflow,
240  const Fw::SerializeStatus status
241  );
242 
245  void sendComBuffer(Fw::ComBuffer& comBuffer,
246  FwIndexType queueIndex
247  );
248 
251  void sendBuffer(Fw::Buffer& buffer,
252  FwIndexType queueIndex
253  );
254 
255  void drainQueue(FwIndexType queueNum
256  );
257 
260  void processQueue();
261 
263  FwIndexType getQueueNum(Svc::QueueType queueType, FwIndexType portNum);
264 
265  private:
266  // ----------------------------------------------------------------------
267  // Member variables
268  // ----------------------------------------------------------------------
269  Fw::ComBuffer m_dequeued_com_buffer;
270  Types::Queue m_queues[TOTAL_PORT_COUNT];
271  QueueMetadata m_prioritizedList[TOTAL_PORT_COUNT];
272  bool m_throttle[TOTAL_PORT_COUNT];
273  SendState m_state;
274  std::atomic<BufferState> m_buffer_state;
275 
276  // Storage for Fw::MemAllocator properties
277  FwEnumStoreType m_allocationId;
278  Fw::MemAllocator* m_allocator;
279  void* m_allocation;
280 };
281 
282 } // end namespace Svc
283 
284 #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:57
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:50
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.