WebLVC 1.7d API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | 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]

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. More...
 
virtual ~DtSubscribableMessageQueue ()
 Virtual DTOR. More...
 
virtual bool isEmpty ()
 Returns true if the queue has messages no messages in it. More...
 
virtual bool isSubscribed (DtU8 subscriberId) const
 Test if subscriberId is subscribed. More...
 
virtual DtU32 subscriberDrops (DtU8 subscriberId) const
 Returns the number of dropped messages for subscriberId, will return 0 if not subscribed. More...
 
virtual void sendMessage (const void *message, unsigned int size, bool global=false)
 Sends a packet at address message of size bytes to the queue. More...
 
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. More...
 
virtual void unsubscribe (DtU8 id)
 Unsubscribes subscriber id from the queue. More...
 
void subscribe (DtU8 id)
 Subscribes subscriber id from the queue. More...
 
virtual void resetQueue (DtU32 numberOfBuckets, DtU32 payloadSize)
 Empties the queue. More...
 
virtual std::ostream & printDataToStream (std::ostream &str) const
 prints the state of the queue to the given stream More...
 
virtual DtString name () const
 returns the name of the queue. More...
 
DtQueueHeaderqueueHeader () const
 returns a pointer to the queue header, called from CTOR More...
 
DtU32 numberOfBuckets () const
 Returns the number of buckets in this queue. More...
 
DtU32 payloadSize () const
 Returns the number of bytes used in a bucket payload. More...
 
virtual char * payloadInBucket (unsigned int bucketNum) const
 returns a pointer to the payload in the bucket. More...
 
virtual DtBucketHeaderbucketHeader (unsigned int bucketNum) const
 returns a pointer to the message header at index More...
 
virtual int usedBucketCount () const
 Computes the number of used buckets and returns it. More...
 
- Public Member Functions inherited from MAKVrExchange::DtMessageQueue
 DtMessageQueue ()
 CTOR. More...
 
virtual ~DtMessageQueue ()
 Virtual DTOR. More...
 

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. More...
 

Static Public Attributes

static const unsigned int theMaxSubscribers = 256
 The maximum number of subscribers allowed in this queue. More...
 
static unsigned long theLockFailureTimeoutMs
 The timeout for lock attempts (in seconds). More...
 

Protected Attributes

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

Private Member Functions

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

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. Also: Subscriber ID is the id used to reference this queue when reading and writing messages to/from the queue. The following IDs are reserved: ID 0: Reserved for identifying globally sent messages. ID 1: Reserved for the queue manager. ID 4: Reserved for messageDump.

virtual MAKVrExchange::DtSubscribableMessageQueue::~DtSubscribableMessageQueue ( )
virtual

Virtual DTOR.

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

Copy Ctor Not implemented – Class Not Copyable.

Member Function Documentation

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

returns a pointer to the message header at index

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 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 DtString MAKVrExchange::DtSubscribableMessageQueue::name ( ) const
virtual

returns the name of the queue.

DtU32 MAKVrExchange::DtSubscribableMessageQueue::numberOfBuckets ( ) const

Returns the number of buckets in this queue.

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

Assignment Operator Not implemented – Class Not Copyable.

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

DtU32 MAKVrExchange::DtSubscribableMessageQueue::payloadSize ( ) const

Returns the number of bytes used in a bucket payload.

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 std::ostream& MAKVrExchange::DtSubscribableMessageQueue::printDataToStream ( std::ostream &  str) const
virtual

prints the state of the queue to the given stream

Implements MAKVrExchange::DtMessageQueue.

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

returns a pointer to the queue header, called from CTOR

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::sendMessage ( const void *  message,
unsigned int  size,
bool  global = false 
)
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. The global parameter indicates whether this message should be sent 'globally' - this is primarily used for sending message which can be discovered by all subscribers.

Implements MAKVrExchange::DtMessageQueue.

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 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::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

virtual int MAKVrExchange::DtSubscribableMessageQueue::usedBucketCount ( ) const
virtual

Computes the number of used buckets and returns it.

Member Data Documentation

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

The timeout for lock attempts (in seconds).

If lock is not successful after this amount of time, the lock is retried.

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

The maximum number of subscribers allowed in this queue.


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

Document ID: Generated on Wed Jun 21 15:05:44 EDT 2023 from SVN revision 256253
Copyright © 2005-2023 MAK Technologies. All Rights Reserved (www.mak.com)