GCC Code Coverage Report


Directory: Os/
File: Queue.cpp
Date: 2026-09-03 21:15:10
Exec Total Coverage
Lines: 0 77 0.0%
Functions: 0 17 0.0%
Branches: 0 46 0.0%

Line Branch Exec Source
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"
7 #include "Fw/Types/Serializable.hpp"
8
9 namespace Os {
10
11 FwSizeType Queue::s_queueCount = 0;
12 #if FW_QUEUE_REGISTRATION
13 QueueRegistry* Queue::s_queueRegistry = nullptr;
14 #endif
15
16 Queue::Queue() : m_name(""), m_depth(0), m_size(0), m_delegate(*QueueInterface::getDelegate(m_handle_storage)) {}
17
18 Queue::~Queue() {
19 m_delegate.~QueueInterface();
20 }
21
22 QueueInterface::Status Queue ::create(FwEnumStoreType id,
23 const Fw::ConstStringBase& name,
24 FwSizeType depth,
25 FwSizeType messageSize) {
26 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
27 FW_ASSERT(depth > 0);
28 FW_ASSERT(messageSize > 0);
29 // Check for previous creation call
30 if (this->m_depth > 0 || this->m_size > 0) {
31 return QueueInterface::Status::ALREADY_CREATED;
32 }
33 QueueInterface::Status status = this->m_delegate.create(id, name, depth, messageSize);
34 if (status == QueueInterface::Status::OP_OK) {
35 this->m_name = name;
36 this->m_depth = depth;
37 this->m_size = messageSize;
38 ScopeLock lock(Queue::getStaticMutex());
39 Queue::s_queueCount++;
40 #if FW_QUEUE_REGISTRATION
41 if (Queue::s_queueRegistry != nullptr) {
42 Queue::s_queueRegistry->registerQueue(this);
43 }
44 #endif
45 }
46 return status;
47 }
48
49 void Queue::teardown() {
50 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
51 return this->m_delegate.teardown();
52 }
53
54 QueueInterface::Status Queue::send(const U8* buffer,
55 FwSizeType size,
56 FwQueuePriorityType priority,
57 QueueInterface::BlockingType blockType) {
58 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
59 FW_ASSERT(buffer != nullptr);
60 // Check if initialized
61 if (this->m_depth == 0 || this->m_size == 0) {
62 return QueueInterface::Status::UNINITIALIZED;
63 }
64 // Check size before proceeding
65 else if (size > this->getMessageSize()) {
66 return QueueInterface::Status::SIZE_MISMATCH;
67 }
68 return this->m_delegate.send(buffer, size, priority, blockType);
69 }
70
71 QueueInterface::Status Queue::receive(U8* destination,
72 FwSizeType capacity,
73 QueueInterface::BlockingType blockType,
74 FwSizeType& actualSize,
75 FwQueuePriorityType& priority) {
76 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
77 FW_ASSERT(destination != nullptr);
78 // Check if initialized
79 if (this->m_depth == 0 || this->m_size == 0) {
80 return QueueInterface::Status::UNINITIALIZED;
81 }
82 // Check capacity before proceeding
83 else if (capacity < this->getMessageSize()) {
84 return QueueInterface::Status::SIZE_MISMATCH;
85 }
86 return this->m_delegate.receive(destination, capacity, blockType, actualSize, priority);
87 }
88
89 FwSizeType Queue::getMessagesAvailable() const {
90 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
91 return this->m_delegate.getMessagesAvailable();
92 }
93
94 FwSizeType Queue::getMessageHighWaterMark() const {
95 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
96 return this->m_delegate.getMessageHighWaterMark();
97 }
98
99 QueueHandle* Queue::getHandle() {
100 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
101 return this->m_delegate.getHandle();
102 }
103
104 QueueInterface::Status Queue::send(const Fw::LinearBufferBase& message,
105 FwQueuePriorityType priority,
106 QueueInterface::BlockingType blockType) {
107 return this->send(message.getBuffAddr(), message.getSize(), priority, blockType);
108 }
109
110 QueueInterface::Status Queue::receive(Fw::LinearBufferBase& destination,
111 QueueInterface::BlockingType blockType,
112 FwQueuePriorityType& priority) {
113 FwSizeType actualSize = 0;
114 destination.resetSer(); // Reset the buffer
115 QueueInterface::Status status =
116 this->receive(destination.getBuffAddrSer(), destination.getCapacity(), blockType, actualSize, priority);
117 if (status == QueueInterface::Status::OP_OK) {
118 Fw::SerializeStatus serializeStatus =
119 destination.setBuffLen(static_cast<Fw::Serializable::SizeType>(actualSize));
120 if (serializeStatus != Fw::SerializeStatus::FW_SERIALIZE_OK) {
121 status = QueueInterface::Status::SIZE_MISMATCH;
122 }
123 }
124 return status;
125 }
126
127 FwSizeType Queue::getDepth() const {
128 return this->m_depth;
129 }
130
131 FwSizeType Queue::getMessageSize() const {
132 return this->m_size;
133 }
134
135 const QueueString& Queue::getName() const {
136 return this->m_name;
137 }
138
139 FwSizeType Queue::getNumQueues() {
140 ScopeLock lock(Queue::getStaticMutex());
141 return Queue::s_queueCount;
142 }
143
144 Os::Mutex& Queue::getStaticMutex() {
145 static Os::Mutex s_mutex;
146 return s_mutex;
147 }
148
149 #if FW_QUEUE_REGISTRATION
150 void Queue::setRegistry(QueueRegistry* registry) {
151 ScopeLock lock(Queue::getStaticMutex());
152 Queue::s_queueRegistry = registry;
153 }
154 #endif
155
156 } // namespace Os
157