mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Add new Fw::StringBase type StaticString for strings backed my immutable literals * Spellcheck fix * Add disclaimer comment about use of StaticString * Refactor the StringBase interface into an immutable ConstStringBase abstract base class and the now mutable StringBase class * Rename StaticString to ConstExternalString and inherit from ConstStringBase * Fix typo * Change references from StringBase to ConstStringBase where applicable * Updates following review meeting: add missing deserialize function and add new error status, move length function implementation into ConstStringBase so it is not pure virtual * Clang format fix * Additional clang-format fixes * Fix the copy-assignment operator for StringBase not being correctly evaluated * Clang format fix * Explicitly delete the Serializable assignment operator and provide a skeleton implementation for RawTimeInterface to appease the compiler * Revert "Explicitly delete the Serializable assignment operator and provide a skeleton implementation for RawTimeInterface to appease the compiler" This reverts commit 086d7bcd3ca9c4f6e553d7fc34d0d126a69a165b. * Move ConstStringBase to separate hpp/cpp files, plus other pull request feedback * Clang format fix * Update length implementation for ConstStringBase and ConstExternalString * Improved asserts in ConstExternalString constructor Co-authored-by: Rob Bocchino <bocchino@icloud.com> * Fixed ConstStringBase length implementation Co-authored-by: Rob Bocchino <bocchino@icloud.com> * Clang format fix * Add some UTs for ConstExternalString, fix non-overridden interfaces, and fix ConstStringBase::maxLength asserting for zero capacity strings * Spell-check fix for ConstExternalString UTs * Revise length implementation in ConstStringBase If the capacity is zero, return zero * Format --------- Co-authored-by: Ian Brault <ian.r.brault@jpl.nasa.gov> Co-authored-by: Rob Bocchino <bocchino@icloud.com> Co-authored-by: Rob Bocchino <bocchino@jpl.nasa.gov> 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::ConstStringBase& 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
|