fsfw/container/SharedRingBuffer.h

61 lines
2.0 KiB
C
Raw Normal View History

2020-07-09 14:26:15 +02:00
#ifndef FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_
#define FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_
2020-07-09 15:49:52 +02:00
2020-07-09 14:26:15 +02:00
#include <framework/container/SimpleRingBuffer.h>
#include <framework/ipc/MutexIF.h>
2020-07-09 15:47:50 +02:00
#include <framework/objectmanager/SystemObject.h>
2020-07-09 14:26:15 +02:00
#include <framework/timemanager/Clock.h>
2020-07-09 15:47:50 +02:00
class SharedRingBuffer: public SystemObject,
public SimpleRingBuffer {
2020-07-09 14:26:15 +02:00
public:
/**
* This constructor allocates a new internal buffer with the supplied size.
* @param size
* @param overwriteOld
* If the ring buffer is overflowing at a write operartion, the oldest data
* will be overwritten.
*/
2020-07-09 15:47:50 +02:00
SharedRingBuffer(object_id_t objectId, const size_t size,
2020-08-04 02:25:10 +02:00
bool overwriteOld, size_t maxExcessBytes,
dur_millis_t mutexTimeout = 10);
2020-07-09 14:26:15 +02:00
/**
* This constructor takes an external buffer with the specified size.
* @param buffer
* @param size
* @param overwriteOld
* If the ring buffer is overflowing at a write operartion, the oldest data
* will be overwritten.
*/
2020-07-09 15:47:50 +02:00
SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const size_t size,
2020-08-04 02:25:10 +02:00
bool overwriteOld, size_t maxExcessBytes,
dur_millis_t mutexTimeout = 10);
2020-07-09 14:26:15 +02:00
2020-07-09 15:47:50 +02:00
void setMutexTimeout(dur_millis_t newTimeout);
2020-08-04 02:25:10 +02:00
/** Performs mutex protected SimpleRingBuffer::getFreeElement call */
ReturnValue_t getFreeElementProtected(uint8_t** writePtr, size_t amount);
2020-07-09 15:47:50 +02:00
/** Performs mutex protected SimpleRingBuffer::writeData call */
ReturnValue_t writeDataProtected(const uint8_t* data, size_t amount);
/** Performs mutex protected SimpleRingBuffer::readData call */
2020-07-09 14:26:15 +02:00
ReturnValue_t readDataProtected(uint8_t *data, size_t amount,
2020-07-09 15:47:50 +02:00
bool incrementReadPtr = false,
2020-07-09 14:26:15 +02:00
bool readRemaining = false, size_t *trueAmount = nullptr);
2020-07-09 15:47:50 +02:00
/** Performs mutex protected SimpleRingBuffer::deleteData call */
2020-07-09 14:26:15 +02:00
ReturnValue_t deleteDataProtected(size_t amount,
2020-07-09 15:47:50 +02:00
bool deleteRemaining = false, size_t* trueAmount = nullptr);
size_t getAvailableReadDataProtected (uint8_t n = 0) const;
2020-07-09 14:26:15 +02:00
private:
2020-07-09 15:47:50 +02:00
dur_millis_t mutexTimeout;
2020-07-09 14:26:15 +02:00
MutexIF* mutex = nullptr;
};
#endif /* FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_ */