I hate C++, this is awful

This commit is contained in:
Robin Müller 2024-03-21 16:10:45 +01:00
parent 008ded64b1
commit 0bd88a2689
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 20 additions and 29 deletions

View File

@ -18,8 +18,8 @@ SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const
SharedRingBuffer::~SharedRingBuffer() {
MutexFactory::instance()->deleteMutex(mutex);
if (receiveSizesFIFO != nullptr) {
delete (receiveSizesFIFO);
if (receiveSizesFifo != nullptr) {
delete (receiveSizesFifo);
}
}
@ -36,37 +36,29 @@ MutexIF* SharedRingBuffer::getMutexHandle() const { return mutex; }
ReturnValue_t SharedRingBuffer::initialize() {
if (fifoDepth > 0) {
receiveSizesFIFO = new DynamicFIFO<size_t>(fifoDepth);
receiveSizesFifo = new DynamicFIFO<size_t>(fifoDepth);
}
return SystemObject::initialize();
}
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() {
if (receiveSizesFIFO == nullptr) {
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFifo() {
if (receiveSizesFifo == nullptr) {
// Configuration error.
#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;
return receiveSizesFifo;
}
ReturnValue_t SharedRingBuffer::lockedWrite(const uint8_t* data, size_t dataLen,
MutexIF::TimeoutType lockType, uint32_t waitTimeMs) {
MutexGuard mg(mutex, lockType, waitTimeMs);
if (availableWriteSpace() < dataLen ||
(receiveSizesFIFO != nullptr && receiveSizesFIFO->full())) {
ReturnValue_t SharedRingBuffer::fifoEmpty(bool& empty, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
if(receiveSizesFifo == nullptr) {
return returnvalue::FAILED;
}
// The following two operation should not fail..
ReturnValue_t result = writeData(data, dataLen);
if (result != returnvalue::OK) {
return result;
}
if (receiveSizesFIFO != nullptr) {
result = receiveSizesFIFO->insert(dataLen);
if (result != returnvalue::OK) {
return result;
}
MutexGuard mg(mutex, timeoutType, timeoutMs);
if(mg.getLockResult() != returnvalue::OK) {
return mg.getLockResult();
}
return receiveSizesFifo->empty();
}

View File

@ -78,16 +78,15 @@ class SharedRingBuffer : public SystemObject, public SimpleRingBuffer {
* Do not forget to protect access with a lock if required!
* @return
*/
DynamicFIFO<size_t>* getReceiveSizesFIFO();
DynamicFIFO<size_t>* getReceiveSizesFifo();
ReturnValue_t lockedWrite(const uint8_t* data, size_t dataLen, MutexIF::TimeoutType lockType,
uint32_t waitTimeMs);
ReturnValue_t fifoEmpty(bool& empty, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs);
private:
MutexIF* mutex = nullptr;
size_t fifoDepth = 0;
DynamicFIFO<size_t>* receiveSizesFIFO = nullptr;
DynamicFIFO<size_t>* receiveSizesFifo = nullptr;
};
#endif /* FSFW_CONTAINER_SHAREDRINGBUFFER_H_ */