fsfw/container/SharedRingBuffer.cpp

56 lines
1.5 KiB
C++
Raw Normal View History

2020-09-04 15:13:32 +02:00
#include "SharedRingBuffer.h"
2020-08-28 18:33:29 +02:00
#include "../ipc/MutexFactory.h"
#include "../ipc/MutexHelper.h"
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
bool overwriteOld, size_t maxExcessBytes):
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld,
maxExcessBytes) {
mutex = MutexFactory::instance()->createMutex();
}
2020-09-22 02:12:02 +02:00
2020-08-28 18:33:29 +02:00
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
const size_t size, bool overwriteOld, size_t maxExcessBytes):
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld,
maxExcessBytes) {
mutex = MutexFactory::instance()->createMutex();
}
2020-09-22 02:12:02 +02:00
void SharedRingBuffer::setToUseReceiveSizeFIFO(uint32_t fifoDepth) {
this->fifoDepth = fifoDepth;
}
2020-08-28 18:33:29 +02:00
ReturnValue_t SharedRingBuffer::lockRingBufferMutex(
MutexIF::TimeoutType timeoutType, dur_millis_t timeout) {
return mutex->lockMutex(timeoutType, timeout);
}
ReturnValue_t SharedRingBuffer::unlockRingBufferMutex() {
return mutex->unlockMutex();
}
2020-09-22 02:12:02 +02:00
2020-08-28 18:33:29 +02:00
MutexIF* SharedRingBuffer::getMutexHandle() const {
return mutex;
}
2020-09-22 02:12:02 +02:00
ReturnValue_t SharedRingBuffer::initialize() {
if(fifoDepth > 0) {
receiveSizesFIFO = new DynamicFIFO<size_t>(fifoDepth);
}
return SystemObject::initialize();
}
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() {
if(receiveSizesFIFO == nullptr) {
// Configuration error.
sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer"
<< " was not configured to have sizes FIFO, returning nullptr!"
<< std::endl;
}
return receiveSizesFIFO;
}