CARMA C++
carma::util::IPQbuffer Class Reference

Shared memory storage mechanism for an IPQ buffer. More...

#include <carma/util/IPQbuffer.h>

Inheritance diagram for carma::util::IPQbuffer:
carma::util::IPQbufferBase carma::util::IPQbasicTypeBuffer carma::util::IPQreader< ElementType > carma::util::IPQwriter< ElementType > carma::util::IPQreader< carma::canbus::carma::canbus::Message > carma::util::IPQreader< DriveCommand > carma::util::IPQreader< RxCommand > carma::util::IPQreader< TelemetryCommand > carma::util::IPQwriter< carma::canbus::carma::canbus::Message > carma::util::IPQwriter< DriveCommand > carma::util::IPQwriter< TelemetryCommand >

Public Member Functions

virtual ~IPQbuffer ()
 Destructor. More...
 
- Public Member Functions inherited from carma::util::IPQbufferBase
int getElementSize () const
 Returns the size of each element in the queue in bytes. More...
 
::std::string getFileName () const
 Get the filename. More...
 
unsigned int getGetOffset () const
 Useful only for debugging. More...
 
unsigned int getLostElementCount () const
 Get the number of elements lost on the last read. More...
 
unsigned int getMaxOffset () const
 Useful only for debugging. More...
 
int getNumAvailable () const
 Gets the number of unread elements available in the queue. More...
 
unsigned int getPutOffset () const
 Used internally, but made public for debugging. More...
 
int getQueueSize () const
 Returns the allocated size of the queue. More...
 
bool isDataAvailable () const
 Checks to see if there are any unread elements (would a read not block?). More...
 
bool isEmpty () const
 Checks to see if the queue is empty. More...
 
unsigned int read ()
 Read the oldest unread element from the queue. More...
 
bool readNewest ()
 Get the newest element from the queue (with locking). More...
 
bool readNewestConditionalCopy ()
 Reads and copies the newest element from the queue into the localElement buffer, but only if has not been previously read. More...
 
void setNoneAvailable ()
 Sets the number of available (unread) elements to zero (catches up) More...
 
virtual ~IPQbufferBase ()
 Destructor Making this d'tor virtual causes the d'tors of inheriting classes to be called first when the d'tor is called on this base class (polymorphic), followed by the base class d'tor. More...
 
- Public Member Functions inherited from carma::util::IPQinterface
virtual int getElementSize () const =0
 Returns the size of each element in the queue in bytes. More...
 
virtual ::std::string getFileName () const =0
 Get the filename. More...
 
virtual unsigned int getGetOffset () const =0
 Useful only for debugging. More...
 
virtual unsigned int getLostElementCount () const =0
 Get the number of elements lost on the last read. More...
 
virtual unsigned int getMaxOffset () const =0
 Useful only for debugging. More...
 
virtual int getNumAvailable () const =0
 Gets the number of unread elements available in the queue. More...
 
virtual unsigned int getPutOffset () const =0
 
virtual int getQueueSize () const =0
 Returns the allocated size of the queue. More...
 
virtual bool isDataAvailable () const =0
 Checks to see if there are any unread elements (would a read not block?). More...
 
virtual bool isEmpty () const =0
 Checks to see if the queue is empty. More...
 
virtual unsigned int read ()=0
 Read the oldest unread element from the queue. More...
 
virtual bool readNewest ()=0
 Get the newest element from the queue (with locking). More...
 
virtual bool readNewestConditionalCopy ()=0
 Reads and copies the newest element from the queue into the localElement buffer, but only if has not been previously read. More...
 
virtual void setNoneAvailable ()=0
 Sets the number of available (unread) elements to zero (catches up) More...
 
virtual ~IPQinterface ()=0
 Destructor Making this d'tor virtual causes the d'tors of inheriting classes to be called first when the d'tor is called on this base class (polymorphic), followed by the base class d'tor. More...
 

Protected Member Functions

 IPQbuffer (void *localElement, int elementSize, const ::std::string &filename, bool isCreator=false, int nElements=0, unsigned int testOffset=0)
 Constructor. More...
 
- Protected Member Functions inherited from carma::util::IPQbufferBase
::std::string getTrimmedFilename ()
 Get the trimmed filename. More...
 
void init ()
 This does all the real constructor work. More...
 
 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. More...
 
void trimShmemFilename ()
 Shared memory filenames must contain only one '/' and it must be the first character; this routine fixes up the filename. More...
 
void write ()
 Put an element into the queue. More...
 
- Protected Member Functions inherited from carma::util::IPQinterface
virtual void write ()=0
 Useful only for debugging. More...
 

Additional Inherited Members

- Protected Attributes inherited from carma::util::IPQbufferBase
bool debug_
 
int fileDescriptor_
 
const int openMask_
 
const int protectionMask_
 

Detailed Description

Shared memory storage mechanism for an IPQ buffer.

Once the shared memory is formed it persists as a file in /dev/shm. It can be manually deleted if so desired (say, if it corrupted). On Linux 2.4 kernels it can have a maximum size of one half of physical memory.

This class is a base class for reader and writer classes. See for e.g.

See Also
IPQreader, IPQwriter

Definition at line 37 of file IPQbuffer.h.

Constructor & Destructor Documentation

carma::util::IPQbuffer::IPQbuffer ( void *  localElement,
int  elementSize,
const ::std::string &  filename,
bool  isCreator = false,
int  nElements = 0,
unsigned int  testOffset = 0 
)
protected

Constructor.

Parameters
localElementaddress of the data buffer for reads/writes
elementSizeof an individual queue element in bytes
filenameShared memory filename. Must start with '/' and be less than 15 chars long.
isCreatorIf true, create a new file if one doesn't exist, and make its size match nElements
nElementsNumber of elements to allocate (queue length); ignored if not a creator.
testOffsetWhen shared memory is created, set the putoffset to have testOffset full queues before it wraps around. Obviously for testing wrap around; zero (default) inhibits this feature.
Exceptions
std::exception
virtual carma::util::IPQbuffer::~IPQbuffer ( )
virtual

Destructor.


The documentation for this class was generated from the following file: