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() { SharedRingBuffer::~SharedRingBuffer() {
MutexFactory::instance()->deleteMutex(mutex); MutexFactory::instance()->deleteMutex(mutex);
if (receiveSizesFIFO != nullptr) { if (receiveSizesFifo != nullptr) {
delete (receiveSizesFIFO); delete (receiveSizesFifo);
} }
} }
@ -36,37 +36,29 @@ MutexIF* SharedRingBuffer::getMutexHandle() const { return mutex; }
ReturnValue_t SharedRingBuffer::initialize() { ReturnValue_t SharedRingBuffer::initialize() {
if (fifoDepth > 0) { if (fifoDepth > 0) {
receiveSizesFIFO = new DynamicFIFO<size_t>(fifoDepth); receiveSizesFifo = new DynamicFIFO<size_t>(fifoDepth);
} }
return SystemObject::initialize(); return SystemObject::initialize();
} }
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() { DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFifo() {
if (receiveSizesFIFO == nullptr) { if (receiveSizesFifo == nullptr) {
// Configuration error. // Configuration error.
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer" sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer"
<< " was not configured to have sizes FIFO, returning nullptr!" << std::endl; << " was not configured to have sizes FIFO, returning nullptr!" << std::endl;
#endif #endif
} }
return receiveSizesFIFO; return receiveSizesFifo;
} }
ReturnValue_t SharedRingBuffer::lockedWrite(const uint8_t* data, size_t dataLen,
MutexIF::TimeoutType lockType, uint32_t waitTimeMs) { ReturnValue_t SharedRingBuffer::fifoEmpty(bool& empty, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
MutexGuard mg(mutex, lockType, waitTimeMs); if(receiveSizesFifo == nullptr) {
if (availableWriteSpace() < dataLen || return returnvalue::FAILED;
(receiveSizesFIFO != nullptr && receiveSizesFIFO->full())) {
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! * Do not forget to protect access with a lock if required!
* @return * @return
*/ */
DynamicFIFO<size_t>* getReceiveSizesFIFO(); DynamicFIFO<size_t>* getReceiveSizesFifo();
ReturnValue_t lockedWrite(const uint8_t* data, size_t dataLen, MutexIF::TimeoutType lockType, ReturnValue_t fifoEmpty(bool& empty, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs);
uint32_t waitTimeMs);
private: private:
MutexIF* mutex = nullptr; MutexIF* mutex = nullptr;
size_t fifoDepth = 0; size_t fifoDepth = 0;
DynamicFIFO<size_t>* receiveSizesFIFO = nullptr; DynamicFIFO<size_t>* receiveSizesFifo = nullptr;
}; };
#endif /* FSFW_CONTAINER_SHAREDRINGBUFFER_H_ */ #endif /* FSFW_CONTAINER_SHAREDRINGBUFFER_H_ */