1 #ifndef CARMA_UTIL_IPQBUFFERBASE_H
2 #define CARMA_UTIL_IPQBUFFERBASE_H
19 #include "carma/util/IPQinterface.h"
28 class ScopedFlockManager;
102 const ::std::string& filename,
103 bool isCreator =
false,
105 unsigned int testOffset = 0 );
191 unsigned int readNoLock();
230 bool readNewestNoLock();
297 void copyMemory(
void *
const dest,
298 const void *
const src,
299 const size_t bytes )
const;
307 bool readHeader(
bool keepOpen) ;
312 bool doesElementSizeMatch() ;
317 bool hasQueueChanged() ;
330 void createSemFilename();
335 bool openSemaphore();
340 bool createSemaphore();
345 unsigned int adjustReadOffset(
bool& lock, ScopedFlockManager& flockManager,
346 unsigned int readOffset);
348 unsigned int internalRead(
bool lock) ;
349 bool internalReadNewest(
bool lock) ;
352 class BlockedOnSemaphoreQuitRequestHandler;
354 friend class BlockedOnSemaphoreQuitRequestHandler;
356 static const int MEMORYMAPPEDFILE_MAGIC = 0x00000100;
358 struct ControlBlock {
362 volatile unsigned int putOffset;
365 struct MapfileHeader {
367 unsigned int headerSize;
368 unsigned int controlBlockOffset;
369 unsigned int controlBlockSize;
371 unsigned int queueOffset;
373 unsigned int queueElementSize;
375 unsigned int queueElements;
379 const int protectionMask_;
383 const ::std::string filename_;
388 void *
const localElement_;
389 const size_t localElementSize_;
390 const bool isCreator_;
402 size_t controlBlockOffset_;
403 volatile ControlBlock* controlBlock_;
408 size_t queueElementSize_;
410 unsigned int queueElements_;
417 unsigned int getOffset_;
418 unsigned int nLostElements_;
420 ::std::string trimmedFilename_;
421 ::std::string displayFilename_;
422 ::std::string semFilename_;
424 MapfileHeader header_;
426 unsigned int maxOffset_;
429 unsigned int testOffset_;
434 #endif // CARMA_UTIL_IPQBUFFERBASE_H
unsigned int getMaxOffset() const
Useful only for debugging.
int getNumAvailable() const
Gets the number of unread elements available in the queue.
bool readNewestConditionalCopy()
Reads and copies the newest element from the queue into the localElement buffer, but only if has not ...
IPQ (InterProcessQueue) provides a generic way for information to be shared between processes or thre...
A simple wrapper class that makes use of ::pthread_rwlock_t easier in a C++ world.
::std::string getTrimmedFilename()
Get the trimmed filename.
bool isEmpty() const
Checks to see if the queue is empty.
bool readNewest()
Get the newest element from the queue (with locking).
unsigned int getLostElementCount() const
Get the number of elements lost on the last read.
IPQbufferBase(void *localElement, int elementSize, const ::std::string &filename, bool isCreator=false, int nElements=0, unsigned int testOffset=0)
Constructor for a read/write queue.
virtual ~IPQbufferBase()
Destructor Making this d'tor virtual causes the d'tors of inheriting classes to be called first when ...
::std::string getFileName() const
Get the filename.
void trimShmemFilename()
Shared memory filenames must contain only one '/' and it must be the first character; this routine fi...
unsigned int getGetOffset() const
Useful only for debugging.
virtual bool openBuffer()=0
Open an existing file or shared memory.
unsigned int getPutOffset() const
Used internally, but made public for debugging.
unsigned int read()
Read the oldest unread element from the queue.
void setNoneAvailable()
Sets the number of available (unread) elements to zero (catches up)
int getQueueSize() const
Returns the allocated size of the queue.
int getElementSize() const
Returns the size of each element in the queue in bytes.
bool isDataAvailable() const
Checks to see if there are any unread elements (would a read not block?).
virtual bool createBuffer()=0
Create a new file or shared memory.
void write()
Put an element into the queue.
void init()
This does all the real constructor work.