F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Queue.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title Os/Queue.cpp
3// \brief common function implementation for Os::Queue
4// ======================================================================
5#include "Os/Queue.hpp"
6#include "Fw/Types/Assert.hpp"
8
9namespace Os {
10
11FwSizeType Queue::s_queueCount = 0;
12QueueRegistry* Queue::s_queueRegistry = nullptr;
13
14Queue::Queue() : m_name(""), m_depth(0), m_size(0), m_delegate(*QueueInterface::getDelegate(m_handle_storage)) {}
15
17 m_delegate.~QueueInterface();
18}
19
20QueueInterface::Status Queue ::create(const Fw::StringBase& name, FwSizeType depth, FwSizeType messageSize) {
21 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
22 FW_ASSERT(depth > 0);
23 FW_ASSERT(messageSize > 0);
24 // Check for previous creation call
25 if (this->m_depth > 0 || this->m_size > 0) {
27 }
28 QueueInterface::Status status = this->m_delegate.create(name, depth, messageSize);
29 if (status == QueueInterface::Status::OP_OK) {
30 this->m_name = name;
31 this->m_depth = depth;
32 this->m_size = messageSize;
34 Queue::s_queueCount++;
35 if (Queue::s_queueRegistry != nullptr) {
36 Queue::s_queueRegistry->registerQueue(this);
37 }
38 }
39 return status;
40}
41
43 FwSizeType size,
44 PlatformIntType priority,
46 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
47 FW_ASSERT(buffer != nullptr);
48 // Check if initialized
49 if (this->m_depth == 0 || this->m_size == 0) {
51 }
52 // Check size before proceeding
53 else if (size > this->getMessageSize()) {
55 }
56 return this->m_delegate.send(buffer, size, priority, blockType);
57}
58
60 FwSizeType capacity,
62 FwSizeType& actualSize,
63 PlatformIntType& priority) {
64 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
65 FW_ASSERT(destination != nullptr);
66 // Check if initialized
67 if (this->m_depth == 0 || this->m_size == 0) {
69 }
70 // Check capacity before proceeding
71 else if (capacity < this->getMessageSize()) {
73 }
74 return this->m_delegate.receive(destination, capacity, blockType, actualSize, priority);
75}
76
78 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
79 return this->m_delegate.getMessagesAvailable();
80}
81
83 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
84 return this->m_delegate.getMessageHighWaterMark();
85}
86
88 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
89 return this->m_delegate.getHandle();
90}
91
93 PlatformIntType priority,
95 return this->send(message.getBuffAddr(), message.getBuffLength(), priority, blockType);
96}
97
100 PlatformIntType& priority) {
101 FwSizeType actualSize = 0;
102 destination.resetSer(); // Reset the buffer
104 this->receive(destination.getBuffAddrSer(), destination.getBuffCapacity(), blockType, actualSize, priority);
105 if (status == QueueInterface::Status::OP_OK) {
106 Fw::SerializeStatus serializeStatus =
107 destination.setBuffLen(static_cast<Fw::Serializable::SizeType>(actualSize));
108 if (serializeStatus != Fw::SerializeStatus::FW_SERIALIZE_OK) {
110 }
111 }
112 return status;
113}
114
116 return this->m_depth;
117}
118
120 return this->m_size;
121}
122
124 return this->m_name;
125}
126
129 return Queue::s_queueCount;
130}
131
133 static Os::Mutex s_mutex;
134 return s_mutex;
135}
136
137} // namespace Os
#define FW_ASSERT(...)
Definition Assert.hpp:14
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:30
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformSizeType FwSizeType
Definition FpConfig.h:35
NATIVE_UINT_TYPE SizeType
SerializeStatus setBuffLen(Serializable::SizeType length)
sets buffer length manually after filling with data
void resetSer()
reset to beginning of buffer to reuse for serialization
Serializable::SizeType getBuffLength() const
returns current buffer size
virtual Serializable::SizeType getBuffCapacity() const =0
returns capacity, not current size, of buffer
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
QueueHandle parent class.
Definition Queue.hpp:19
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
virtual ~Queue()
default queue destructor
Definition Queue.cpp:16
static Os::Mutex & getStaticMutex()
get static mutex
Definition Queue.cpp:132
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
BlockingType
message type
Definition Queue.hpp:44
virtual QueueHandle * getHandle()=0
return the underlying queue handle (implementation specific)
virtual ~QueueInterface()=default
default queue destructor
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
@ ALREADY_CREATED
creating an already created queue
Definition Queue.hpp:32
@ UNINITIALIZED
Queue wasn't initialized successfully.
Definition Queue.hpp:34
@ OP_OK
message sent/received okay
Definition Queue.hpp:31
@ SIZE_MISMATCH
attempted to send or receive with buffer too large, too small
Definition Queue.hpp:35
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()=default
default queue interface constructor
locks a mutex within the current scope
Definition Mutex.hpp:79
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.