mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Created new SerialBufferBase as a parent of SerializeBufferBase. Renaming interface functions to be less confusing. * Deprecating copyRawOffset. No direct use-cases in F' core. * Make SerialBufferBase a true pure virtual interface. * Changing Serializable to work with SerialBufferBase parent interface. * Changing copyRaw and copyRawOffset to work with SerialBufferBase * Updating documentation for SerialBufferBase usage * Adding some documentation. Adding missing ASSERT in copyRaw. Fixing some bugs that new ASSERT uncovered. * Renaming SerializeBufferBase to LinearBufferBase. Add a using declaration to maintain backwards compatability. Properly mark LinearBufferBase functions as override. * Filling in the rest of the docstrings for the classes in Serializable * Removing redundant virtual keyword on override function * Applying clang formatting * Incorporating PR comments * Fix compile issues * Bump version to alpha * Format * v --------- Co-authored-by: M Starch <LeStarch@googlemail.com>
142 lines
5.1 KiB
C++
142 lines
5.1 KiB
C++
// ======================================================================
|
|
// \title Os/Queue.cpp
|
|
// \brief common function implementation for Os::Queue
|
|
// ======================================================================
|
|
#include "Os/Queue.hpp"
|
|
#include "Fw/Types/Assert.hpp"
|
|
#include "Fw/Types/Serializable.hpp"
|
|
|
|
namespace Os {
|
|
|
|
FwSizeType Queue::s_queueCount = 0;
|
|
#if FW_QUEUE_REGISTRATION
|
|
QueueRegistry* Queue::s_queueRegistry = nullptr;
|
|
#endif
|
|
|
|
Queue::Queue() : m_name(""), m_depth(0), m_size(0), m_delegate(*QueueInterface::getDelegate(m_handle_storage)) {}
|
|
|
|
Queue::~Queue() {
|
|
m_delegate.~QueueInterface();
|
|
}
|
|
|
|
QueueInterface::Status Queue ::create(const Fw::StringBase& name, FwSizeType depth, FwSizeType messageSize) {
|
|
FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
|
|
FW_ASSERT(depth > 0);
|
|
FW_ASSERT(messageSize > 0);
|
|
// Check for previous creation call
|
|
if (this->m_depth > 0 || this->m_size > 0) {
|
|
return QueueInterface::Status::ALREADY_CREATED;
|
|
}
|
|
QueueInterface::Status status = this->m_delegate.create(name, depth, messageSize);
|
|
if (status == QueueInterface::Status::OP_OK) {
|
|
this->m_name = name;
|
|
this->m_depth = depth;
|
|
this->m_size = messageSize;
|
|
ScopeLock lock(Queue::getStaticMutex());
|
|
Queue::s_queueCount++;
|
|
#if FW_QUEUE_REGISTRATION
|
|
if (Queue::s_queueRegistry != nullptr) {
|
|
Queue::s_queueRegistry->registerQueue(this);
|
|
}
|
|
#endif
|
|
}
|
|
return status;
|
|
}
|
|
|
|
QueueInterface::Status Queue::send(const U8* buffer,
|
|
FwSizeType size,
|
|
FwQueuePriorityType priority,
|
|
QueueInterface::BlockingType blockType) {
|
|
FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
|
|
FW_ASSERT(buffer != nullptr);
|
|
// Check if initialized
|
|
if (this->m_depth == 0 || this->m_size == 0) {
|
|
return QueueInterface::Status::UNINITIALIZED;
|
|
}
|
|
// Check size before proceeding
|
|
else if (size > this->getMessageSize()) {
|
|
return QueueInterface::Status::SIZE_MISMATCH;
|
|
}
|
|
return this->m_delegate.send(buffer, size, priority, blockType);
|
|
}
|
|
|
|
QueueInterface::Status Queue::receive(U8* destination,
|
|
FwSizeType capacity,
|
|
QueueInterface::BlockingType blockType,
|
|
FwSizeType& actualSize,
|
|
FwQueuePriorityType& priority) {
|
|
FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
|
|
FW_ASSERT(destination != nullptr);
|
|
// Check if initialized
|
|
if (this->m_depth == 0 || this->m_size == 0) {
|
|
return QueueInterface::Status::UNINITIALIZED;
|
|
}
|
|
// Check capacity before proceeding
|
|
else if (capacity < this->getMessageSize()) {
|
|
return QueueInterface::Status::SIZE_MISMATCH;
|
|
}
|
|
return this->m_delegate.receive(destination, capacity, blockType, actualSize, priority);
|
|
}
|
|
|
|
FwSizeType Queue::getMessagesAvailable() const {
|
|
FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
|
|
return this->m_delegate.getMessagesAvailable();
|
|
}
|
|
|
|
FwSizeType Queue::getMessageHighWaterMark() const {
|
|
FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
|
|
return this->m_delegate.getMessageHighWaterMark();
|
|
}
|
|
|
|
QueueHandle* Queue::getHandle() {
|
|
FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
|
|
return this->m_delegate.getHandle();
|
|
}
|
|
|
|
QueueInterface::Status Queue::send(const Fw::LinearBufferBase& message,
|
|
FwQueuePriorityType priority,
|
|
QueueInterface::BlockingType blockType) {
|
|
return this->send(message.getBuffAddr(), message.getSize(), priority, blockType);
|
|
}
|
|
|
|
QueueInterface::Status Queue::receive(Fw::LinearBufferBase& destination,
|
|
QueueInterface::BlockingType blockType,
|
|
FwQueuePriorityType& priority) {
|
|
FwSizeType actualSize = 0;
|
|
destination.resetSer(); // Reset the buffer
|
|
QueueInterface::Status status =
|
|
this->receive(destination.getBuffAddrSer(), destination.getCapacity(), blockType, actualSize, priority);
|
|
if (status == QueueInterface::Status::OP_OK) {
|
|
Fw::SerializeStatus serializeStatus =
|
|
destination.setBuffLen(static_cast<Fw::Serializable::SizeType>(actualSize));
|
|
if (serializeStatus != Fw::SerializeStatus::FW_SERIALIZE_OK) {
|
|
status = QueueInterface::Status::SIZE_MISMATCH;
|
|
}
|
|
}
|
|
return status;
|
|
}
|
|
|
|
FwSizeType Queue::getDepth() const {
|
|
return this->m_depth;
|
|
}
|
|
|
|
FwSizeType Queue::getMessageSize() const {
|
|
return this->m_size;
|
|
}
|
|
|
|
const QueueString& Queue::getName() const {
|
|
return this->m_name;
|
|
}
|
|
|
|
FwSizeType Queue::getNumQueues() {
|
|
ScopeLock lock(Queue::getStaticMutex());
|
|
return Queue::s_queueCount;
|
|
}
|
|
|
|
Os::Mutex& Queue::getStaticMutex() {
|
|
static Os::Mutex s_mutex;
|
|
return s_mutex;
|
|
}
|
|
|
|
} // namespace Os
|