fsfw/container/SharedRingBuffer.cpp

58 lines
1.7 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"
2021-03-09 11:30:00 +01:00
#include "../ipc/MutexGuard.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-08-18 11:25:57 +02:00
}
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-08-18 11:25:57 +02:00
}
2020-09-22 16:22:37 +02:00
2020-09-22 16:32:59 +02:00
void SharedRingBuffer::setToUseReceiveSizeFIFO(size_t fifoDepth) {
this->fifoDepth = fifoDepth;
2020-09-22 16:22:37 +02:00
}
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();
2020-09-22 16:22:37 +02:00
}
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() {
if(receiveSizesFIFO == nullptr) {
// Configuration error.
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer"
<< " was not configured to have sizes FIFO, returning nullptr!"
<< std::endl;
#endif
}
return receiveSizesFIFO;
2020-09-22 16:22:37 +02:00
}