VR-Exchange 2.2 API Documentation
List of all members | Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions
MAKVrExchange::DtSubscribableMessageQueue Class Reference

Implements a message queue for multiple subscribers. More...

Inheritance diagram for MAKVrExchange::DtSubscribableMessageQueue:
Inheritance graph
[legend]

Classes

struct  DtBucketHeader
 DtBucketHeader is a structure found at the front of each message to keep track of the number of bytes used. More...
struct  DtQueueHeader
 DtQueueHeader exists at the front of the message queue and contains useful information about the state of the queue. More...

Public Member Functions

 DtSubscribableMessageQueue (const DtString &name, DtU8 subscriberId)
 Creates an instance of a Shared Memory Queue with the given name IMPORTANT: memory with the given name must have already been allocated somewhere, This class will only attach to it.
virtual ~DtSubscribableMessageQueue ()
virtual bool isEmpty ()
 Returns true if the queue has messages no messages in it.
virtual bool isSubscribed (DtU8 subscriberId) const
 Test if subscriberId is subscribed.
virtual DtU32 subscriberDrops (DtU8 subscriberId) const
 Returns the number of dropped messages for subscriberId, will return 0 if not subscribed.
virtual void sendMessage (const void *message, unsigned int size)
 Sends a packet at address message of size bytes to the queue.
virtual void * message (unsigned int *outSize=0)
 Returns a copy of the message which must be freed by the caller or returns null if there are not messages to read.
virtual void unsubscribe (DtU8 id)
 Unsubscribes subscriber id from the queue.
void subscribe (DtU8 id)
 Subscribes subscriber id from the queue.
virtual void resetQueue (DtU32 numberOfBuckets, DtU32 payloadSize)
 Empties the queue.
virtual void initLocks ()
 Initializes Shared Memory locks.
virtual void clearLocks ()
 This clears all locks and should only be called by the queue manager.
virtual std::ostream & printDataToStream (std::ostream &str) const
 prints the state of the queue to the given stream
virtual DtString name () const
 returns the name of the queue.
DtQueueHeaderqueueHeader () const
 returns a pointer to the queue header, called from CTOR
DtU32 numberOfBuckets () const
 Returns the number of buckets in this queue.
DtU32 payloadSize () const
 Returns the number of bytes used in a bucket payload.
virtual char * payloadInBucket (unsigned int bucketNum) const
 returns a pointer to the payload in the bucket.
virtual DtBucketHeaderbucketHeader (unsigned int bucketNum) const
 returns a pointer to the message header at index
- Public Member Functions inherited from MAKVrExchange::DtMessageQueue
 DtMessageQueue ()
virtual ~DtMessageQueue ()

Static Public Member Functions

static unsigned int poolSize (DtU32 numberOfBuckets, DtU32 payloadSize)
 Used to compute the size in bytes, required for a DtSmSubscribableMessageQueue instance using numberOfBuckets with a payload size of payloadSize.

Static Public Attributes

static const unsigned int theMaxSubscribers = 255
 The maximum number of subscribers allowed in this queue.

Protected Member Functions

virtual void lockForRead ()
 Locks the queue for a read.
virtual void unlockForRead ()
 Unlocks the queue for a read.
virtual void lockForWrite ()
 Locks the queue for a write.
virtual void unlockForWrite ()
 Unlocks the queue for writes.

Protected Attributes

DtSharedMemoryPoolClient * myShmPool
DtString myShmName
DtU8 mySubscriberId
std::vector< char > myReadBuffer

Private Member Functions

 DtSubscribableMessageQueue (const DtSubscribableMessageQueue &other)
 Copy Ctor Not implemented – Class Not Copyable.
DtSubscribableMessageQueueoperator= (const DtSubscribableMessageQueue &other)
 Assignment Operator Not implemented – Class Not Copyable.

Detailed Description

Implements a message queue for multiple subscribers.

This is a fixed length queue, of fixed length messages. It is implemented as a circular list and will not fill up, but rather overwrite the oldest unread messages. Subscribers are given a 8 bit id and register their interest in messages merely by creating an instance of this class. A subscriber can unsubscribe at any time. Before an instance of this class can be created there must already be a shared memory pool of the correct size open. The correct size is computed using DtSubscribableMessageQueue::poolSize(). Before a queue can be used one subscriber (and only one subscriber) must call queue->reset(...); queue->initlocks();

Constructor & Destructor Documentation

MAKVrExchange::DtSubscribableMessageQueue::DtSubscribableMessageQueue ( const DtString name,
DtU8  subscriberId 
)

Creates an instance of a Shared Memory Queue with the given name IMPORTANT: memory with the given name must have already been allocated somewhere, This class will only attach to it.

The memory must be at least as big as ::poolSize(), this queue can't check.

virtual MAKVrExchange::DtSubscribableMessageQueue::~DtSubscribableMessageQueue ( )
virtual
MAKVrExchange::DtSubscribableMessageQueue::DtSubscribableMessageQueue ( const DtSubscribableMessageQueue other)
private

Copy Ctor Not implemented – Class Not Copyable.

Member Function Documentation

DtSubscribableMessageQueue& MAKVrExchange::DtSubscribableMessageQueue::operator= ( const DtSubscribableMessageQueue other)
private

Assignment Operator Not implemented – Class Not Copyable.

virtual bool MAKVrExchange::DtSubscribableMessageQueue::isEmpty ( )
virtual

Returns true if the queue has messages no messages in it.

Implements MAKVrExchange::DtMessageQueue.

virtual bool MAKVrExchange::DtSubscribableMessageQueue::isSubscribed ( DtU8  subscriberId) const
virtual

Test if subscriberId is subscribed.

virtual DtU32 MAKVrExchange::DtSubscribableMessageQueue::subscriberDrops ( DtU8  subscriberId) const
virtual

Returns the number of dropped messages for subscriberId, will return 0 if not subscribed.

virtual void MAKVrExchange::DtSubscribableMessageQueue::sendMessage ( const void *  message,
unsigned int  size 
)
virtual

Sends a packet at address message of size bytes to the queue.

If the queue is full this message will knock the oldest message off the queue.

Implements MAKVrExchange::DtMessageQueue.

virtual void* MAKVrExchange::DtSubscribableMessageQueue::message ( unsigned int *  outSize = 0)
virtual

Returns a copy of the message which must be freed by the caller or returns null if there are not messages to read.

If outsize is passed then the size of the message is returned.

Implements MAKVrExchange::DtMessageQueue.

virtual void MAKVrExchange::DtSubscribableMessageQueue::unsubscribe ( DtU8  id)
virtual

Unsubscribes subscriber id from the queue.

This is called by the DTOR and should not be called by users of this class. It is public however, so that some classes which are managing the queue, can force unsubscribe someone who is misbehaving. USE with CAUTION

void MAKVrExchange::DtSubscribableMessageQueue::subscribe ( DtU8  id)

Subscribes subscriber id from the queue.

This is called by the DTOR and should not be called by users of this class. It is public however, so that some classes which are managing the queue, can force subscribe someone. USE with CAUTION

virtual void MAKVrExchange::DtSubscribableMessageQueue::resetQueue ( DtU32  numberOfBuckets,
DtU32  payloadSize 
)
virtual

Empties the queue.

This should only be called by the queue manager, as all unread messages are lost and all subscribers are unsubscribed.

virtual void MAKVrExchange::DtSubscribableMessageQueue::initLocks ( )
virtual

Initializes Shared Memory locks.

one party, the queue manager.

virtual void MAKVrExchange::DtSubscribableMessageQueue::clearLocks ( )
virtual

This clears all locks and should only be called by the queue manager.

virtual std::ostream& MAKVrExchange::DtSubscribableMessageQueue::printDataToStream ( std::ostream &  str) const
virtual

prints the state of the queue to the given stream

Implements MAKVrExchange::DtMessageQueue.

static unsigned int MAKVrExchange::DtSubscribableMessageQueue::poolSize ( DtU32  numberOfBuckets,
DtU32  payloadSize 
)
static

Used to compute the size in bytes, required for a DtSmSubscribableMessageQueue instance using numberOfBuckets with a payload size of payloadSize.

Each bucket is the size of the payload + the size of a bucketHeader

virtual DtString MAKVrExchange::DtSubscribableMessageQueue::name ( ) const
virtual

returns the name of the queue.

DtQueueHeader* MAKVrExchange::DtSubscribableMessageQueue::queueHeader ( ) const

returns a pointer to the queue header, called from CTOR

DtU32 MAKVrExchange::DtSubscribableMessageQueue::numberOfBuckets ( ) const

Returns the number of buckets in this queue.

DtU32 MAKVrExchange::DtSubscribableMessageQueue::payloadSize ( ) const

Returns the number of bytes used in a bucket payload.

virtual char* MAKVrExchange::DtSubscribableMessageQueue::payloadInBucket ( unsigned int  bucketNum) const
virtual

returns a pointer to the payload in the bucket.

Where a bucket is composed of the bucketHeader and the bucketPayload

virtual DtBucketHeader* MAKVrExchange::DtSubscribableMessageQueue::bucketHeader ( unsigned int  bucketNum) const
virtual

returns a pointer to the message header at index

virtual void MAKVrExchange::DtSubscribableMessageQueue::lockForRead ( )
protectedvirtual

Locks the queue for a read.

virtual void MAKVrExchange::DtSubscribableMessageQueue::unlockForRead ( )
protectedvirtual

Unlocks the queue for a read.

virtual void MAKVrExchange::DtSubscribableMessageQueue::lockForWrite ( )
protectedvirtual

Locks the queue for a write.

virtual void MAKVrExchange::DtSubscribableMessageQueue::unlockForWrite ( )
protectedvirtual

Unlocks the queue for writes.

Member Data Documentation

const unsigned int MAKVrExchange::DtSubscribableMessageQueue::theMaxSubscribers = 255
static

The maximum number of subscribers allowed in this queue.

DtSharedMemoryPoolClient* MAKVrExchange::DtSubscribableMessageQueue::myShmPool
protected
DtString MAKVrExchange::DtSubscribableMessageQueue::myShmName
protected
DtU8 MAKVrExchange::DtSubscribableMessageQueue::mySubscriberId
protected
std::vector<char> MAKVrExchange::DtSubscribableMessageQueue::myReadBuffer
protected

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

Document ID: Generated on Mon Apr 15 17:15:50 EDT 2013 from SVN revision 126154
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)