F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
QueueCommon.cpp
Go to the documentation of this file.
1 #include <Os/Queue.hpp>
2 #include <Fw/Types/Assert.hpp>
3 #include <cstring>
4 
5 namespace Os {
6 
7 #if FW_QUEUE_REGISTRATION
8  QueueRegistry* Queue::s_queueRegistry = nullptr;
9 #endif
10 
12 
14 
15  const U8* msgBuff = buffer.getBuffAddr();
16  NATIVE_INT_TYPE buffLength = static_cast<NATIVE_INT_TYPE>(buffer.getBuffLength());
17 
18  return this->send(msgBuff,buffLength,priority, block);
19 
20  }
21 
23 
24  U8* msgBuff = buffer.getBuffAddr();
25  NATIVE_INT_TYPE buffCapacity = static_cast<NATIVE_INT_TYPE>(buffer.getBuffCapacity());
26  NATIVE_INT_TYPE recvSize = 0;
27 
28  Queue::QueueStatus recvStat = this->receive(msgBuff, buffCapacity, recvSize, priority, block);
29 
30  if (QUEUE_OK == recvStat) {
31  if (buffer.setBuffLen(static_cast<NATIVE_UINT_TYPE>(recvSize)) == Fw::FW_SERIALIZE_OK) {
32  return QUEUE_OK;
33  } else {
34  return QUEUE_SIZE_MISMATCH;
35  }
36  } else {
37  return recvStat;
38  }
39  }
40 
42  FW_ASSERT(depth > 0, depth);
43  FW_ASSERT(msgSize > 0, depth);
44  return createInternal(name, depth, msgSize);
45  }
46 
47 
48 #if FW_QUEUE_REGISTRATION
49 
50  void Queue::setQueueRegistry(QueueRegistry* reg) {
51  // NULL is okay if a deregistration is desired
52  Queue::s_queueRegistry = reg;
53  }
54 
55 #endif
56 
58  return Queue::s_numQueues;
59  }
60 
62  return this->m_name;
63  }
64 
65 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
SerializeStatus setBuffLen(Serializable::SizeType length)
sets buffer length manually after filling with data
Serializable::SizeType getBuffLength() const
returns current buffer size
virtual Serializable::SizeType getBuffCapacity() const =0
returns capacity, not current size, of buffer
QueueString m_name
queue name
Definition: Queue.hpp:76
QueueStatus create(const Fw::StringBase &name, NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
create a message queue
Definition: QueueCommon.cpp:41
QueueStatus
Definition: Queue.hpp:27
@ QUEUE_SIZE_MISMATCH
attempted to send or receive with buffer too large, too small
Definition: Queue.hpp:31
@ QUEUE_OK
message sent/received okay
Definition: Queue.hpp:28
QueueStatus send(const Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE priority, QueueBlocking block)
send a message
Definition: QueueCommon.cpp:13
QueueStatus createInternal(const Fw::StringBase &name, NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
create a message queue
Definition: Queue.cpp:42
QueueStatus receive(Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE &priority, QueueBlocking block)
receive a message
Definition: QueueCommon.cpp:22
const QueueString & getName()
get the queue name
Definition: QueueCommon.cpp:61
QueueBlocking
Definition: Queue.hpp:40
static NATIVE_INT_TYPE getNumQueues()
get the number of queues in the system
Definition: QueueCommon.cpp:57
static NATIVE_INT_TYPE s_numQueues
tracks number of queues in the system
Definition: Queue.hpp:80
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.