F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Queue.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Queue.hpp
3 // \brief common function definitions for Os::Queue
4 // ======================================================================
5 #ifndef Os_Queue_hpp_
6 #define Os_Queue_hpp_
7 
8 #include <FpConfig.hpp>
9 #include <Fw/Obj/ObjBase.hpp>
11 #include <Os/Os.hpp>
12 #include <Os/QueueString.hpp>
13 #include <Os/Mutex.hpp>
14 namespace Os {
15 // Forward declaration for registry
16 class QueueRegistry;
17 
19 class QueueHandle {};
20 
28  public:
30  enum Status {
39  FULL,
41  };
42 
44  enum BlockingType {
47  };
48 
50  QueueInterface() = default;
51 
53  virtual ~QueueInterface() = default;
54 
56  QueueInterface(const QueueInterface& other) = delete;
57 
59  QueueInterface(const QueueInterface* other) = delete;
60 
62  virtual QueueInterface& operator=(const QueueInterface& other) = delete;
63 
74  virtual Status create(const Fw::StringBase& name, FwSizeType depth, FwSizeType messageSize) = 0;
75 
90  virtual Status send(const U8* buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) = 0;
91 
107  virtual Status receive(U8* destination,
108  FwSizeType capacity,
109  BlockingType blockType,
110  FwSizeType& actualSize,
111  FwQueuePriorityType& priority) = 0;
112 
118  virtual FwSizeType getMessagesAvailable() const = 0;
119 
125  virtual FwSizeType getMessageHighWaterMark() const = 0;
126 
129  virtual QueueHandle* getHandle() = 0;
130 
150  static QueueInterface* getDelegate(QueueHandleStorage& aligned_placement_new_memory);
151 };
152 
153 class Queue final : public QueueInterface {
154  public:
156  Queue();
157 
159  virtual ~Queue();
160 
162  Queue(const Queue& other) = delete;
163 
165  Queue(const Queue* other) = delete;
166 
168  QueueInterface& operator=(const QueueInterface& other) override = delete;
169 
180  Status create(const Fw::StringBase& name, FwSizeType depth, FwSizeType messageSize) override;
181 
196  Status send(const U8* buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override;
197 
214  Status receive(U8* destination,
215  FwSizeType capacity,
216  BlockingType blockType,
217  FwSizeType& actualSize,
218  FwQueuePriorityType& priority) override;
219 
226  FwSizeType getMessagesAvailable() const override;
227 
233  FwSizeType getMessageHighWaterMark() const override;
234 
237  QueueHandle* getHandle() override;
238 
250 
263 
265  FwSizeType getDepth() const;
266 
268  FwSizeType getMessageSize() const;
269 
271  const QueueString& getName() const;
272 
274  static FwSizeType getNumQueues();
275 
277  static Os::Mutex& getStaticMutex();
278 
279  private:
280  QueueString m_name;
281  FwSizeType m_depth;
282  FwSizeType m_size;
283  static Os::Mutex s_countLock;
284  static FwSizeType s_queueCount;
285 
286 #if FW_QUEUE_REGISTRATION
287  public:
291  static void setRegistry(QueueRegistry* registry);
292 
293  private:
294  static QueueRegistry* s_queueRegistry;
295 #endif
296 
297  // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
298  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
299  // the byte-array here and set `handle` to that address for storage.
300  //
301  alignas(FW_HANDLE_ALIGNMENT) QueueHandleStorage m_handle_storage;
302  QueueInterface& m_delegate;
303 };
309  public:
311  QueueRegistry() = default;
313  virtual ~QueueRegistry() = default;
314 
320  virtual void registerQueue(Queue* queue) = 0;
321 };
322 } // namespace Os
323 #endif
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition: FpConfig.h:440
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
PlatformQueuePriorityType FwQueuePriorityType
Definition: FpConfig.h:55
C++-compatible configuration header for fprime configuration.
Declarations for Fw::ObjBase and Fw::ObjRegistry.
U8 QueueHandleStorage[FW_QUEUE_HANDLE_MAX_SIZE]
Storage type for OSAL handles.
Definition: Os.hpp:10
QueueHandle parent class.
Definition: Queue.hpp:19
Queue(const Queue &other)=delete
copy constructor is forbidden
Queue()
queue constructor
Definition: Queue.cpp:14
Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override
send a message into the queue through delegate
FwSizeType getMessagesAvailable() const override
get number of messages available
Definition: Queue.cpp:77
FwSizeType getDepth() const
get the queue's depth in messages
Definition: Queue.cpp:115
QueueHandle * getHandle() override
return the underlying queue handle (implementation specific). Delegates to implementation.
Definition: Queue.cpp:87
Status receive(U8 *destination, FwSizeType capacity, BlockingType blockType, FwSizeType &actualSize, FwQueuePriorityType &priority) override
receive a message from the queue through delegate
const QueueString & getName() const
get the queue's name
Definition: Queue.cpp:123
Status create(const Fw::StringBase &name, FwSizeType depth, FwSizeType messageSize) override
create queue storage through delegate
Definition: Queue.cpp:20
virtual ~Queue()
default queue destructor
Definition: Queue.cpp:16
Status send(const Fw::SerializeBufferBase &message, FwQueuePriorityType priority, BlockingType blockType)
send a message to a queue
Queue(const Queue *other)=delete
copy constructor is forbidden
static Os::Mutex & getStaticMutex()
get static mutex
Definition: Queue.cpp:132
Status receive(Fw::SerializeBufferBase &destination, BlockingType blockType, FwQueuePriorityType &priority)
receive a message from a queue
QueueInterface & operator=(const QueueInterface &other) override=delete
assignment operator is forbidden
static FwSizeType getNumQueues()
get number of queues system-wide
Definition: Queue.cpp:127
FwSizeType getMessageHighWaterMark() const override
get maximum messages stored at any given time through delegate
Definition: Queue.cpp:82
FwSizeType getMessageSize() const
get the queue's message maximum size
Definition: Queue.cpp:119
base queue interface
Definition: Queue.hpp:27
QueueInterface(const QueueInterface &other)=delete
copy constructor is forbidden
virtual QueueHandle * getHandle()=0
return the underlying queue handle (implementation specific)
BlockingType
message type
Definition: Queue.hpp:44
@ BLOCKING
Message will block until space is available.
Definition: Queue.hpp:45
@ NONBLOCKING
Message will return with status when space is unavailable.
Definition: Queue.hpp:46
static QueueInterface * getDelegate(QueueHandleStorage &aligned_placement_new_memory)
provide a pointer to a queue delegate object
virtual ~QueueInterface()=default
default queue destructor
virtual Status create(const Fw::StringBase &name, FwSizeType depth, FwSizeType messageSize)=0
create queue storage
virtual FwSizeType getMessageHighWaterMark() const =0
get maximum messages stored at any given time
virtual Status receive(U8 *destination, FwSizeType capacity, BlockingType blockType, FwSizeType &actualSize, FwQueuePriorityType &priority)=0
receive a message from the queue
Status
status returned from the queue send function
Definition: Queue.hpp:30
@ EMPTY
If non-blocking, all the messages have been drained.
Definition: Queue.hpp:33
@ RECEIVE_ERROR
message receive error
Definition: Queue.hpp:37
@ INVALID_PRIORITY
invalid priority requested
Definition: Queue.hpp:38
@ ALREADY_CREATED
creating an already created queue
Definition: Queue.hpp:32
@ UNINITIALIZED
Queue wasn't initialized successfully.
Definition: Queue.hpp:34
@ FULL
queue was full when attempting to send a message
Definition: Queue.hpp:39
@ OP_OK
message sent/received okay
Definition: Queue.hpp:31
@ SEND_ERROR
message send error
Definition: Queue.hpp:36
@ SIZE_MISMATCH
attempted to send or receive with buffer too large, too small
Definition: Queue.hpp:35
@ UNKNOWN_ERROR
Unexpected error; can't match with returns.
Definition: Queue.hpp:40
virtual Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType)=0
send a message into the queue
virtual FwSizeType getMessagesAvailable() const =0
get number of messages available
QueueInterface(const QueueInterface *other)=delete
copy constructor is forbidden
virtual QueueInterface & operator=(const QueueInterface &other)=delete
assignment operator is forbidden
QueueInterface()=default
default queue interface constructor
queue registry interface
Definition: Queue.hpp:308
virtual ~QueueRegistry()=default
Default ~QueueRegistry.
QueueRegistry()=default
Default QueueRegistry.
virtual void registerQueue(Queue *queue)=0
queue registry callback