QueueCommon.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <Os/Queue.hpp>
  2. #include <Fw/Types/Assert.hpp>
  3. #include <cstring>
  4. namespace Os {
  5. #if FW_QUEUE_REGISTRATION
  6. QueueRegistry* Queue::s_queueRegistry = nullptr;
  7. #endif
  8. NATIVE_INT_TYPE Queue::s_numQueues = 0;
  9. Queue::QueueStatus Queue::send(const Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE priority, QueueBlocking block) {
  10. const U8* msgBuff = buffer.getBuffAddr();
  11. NATIVE_INT_TYPE buffLength = buffer.getBuffLength();
  12. return this->send(msgBuff,buffLength,priority, block);
  13. }
  14. Queue::QueueStatus Queue::receive(Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE &priority, QueueBlocking block) {
  15. U8* msgBuff = buffer.getBuffAddr();
  16. NATIVE_INT_TYPE buffCapacity = buffer.getBuffCapacity();
  17. NATIVE_INT_TYPE recvSize = 0;
  18. Queue::QueueStatus recvStat = this->receive(msgBuff, buffCapacity, recvSize, priority, block);
  19. if (QUEUE_OK == recvStat) {
  20. if (buffer.setBuffLen(recvSize) == Fw::FW_SERIALIZE_OK) {
  21. return QUEUE_OK;
  22. } else {
  23. return QUEUE_SIZE_MISMATCH;
  24. }
  25. } else {
  26. return recvStat;
  27. }
  28. }
  29. Queue::QueueStatus Queue::create(const Fw::StringBase &name, NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize) {
  30. FW_ASSERT(depth > 0, depth);
  31. FW_ASSERT(msgSize > 0, depth);
  32. return createInternal(name, depth, msgSize);
  33. }
  34. #if FW_QUEUE_REGISTRATION
  35. void Queue::setQueueRegistry(QueueRegistry* reg) {
  36. // NULL is okay if a deregistration is desired
  37. Queue::s_queueRegistry = reg;
  38. }
  39. #endif
  40. NATIVE_INT_TYPE Queue::getNumQueues() {
  41. return Queue::s_numQueues;
  42. }
  43. const QueueString& Queue::getName() {
  44. return this->m_name;
  45. }
  46. }