fsfw/container/SharedRingBuffer.cpp

56 lines
1.5 KiB
C++
Raw Normal View History

2020-09-04 15:11:53 +02:00
#include "SharedRingBuffer.h"
2020-09-04 15:10:44 +02:00
#include "../ipc/MutexFactory.h"
#include "../ipc/MutexHelper.h"
2020-08-18 11:25:57 +02:00
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 16:22:37 +02:00
2020-08-18 11:25:57 +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 16:22:37 +02:00
2020-09-22 16:32:59 +02:00
void SharedRingBuffer::setToUseReceiveSizeFIFO(size_t fifoDepth) {
2020-09-22 16:22:37 +02:00
this->fifoDepth = fifoDepth;
}
2020-08-18 11:25:57 +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 16:22:37 +02:00
2020-08-18 11:25:57 +02:00
MutexIF* SharedRingBuffer::getMutexHandle() const {
return mutex;
}
2020-09-22 16:22:37 +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;
}