MAK RTIspy API Documentation for HLA 1.3
vlShmSubscribableMessageQueue__rti__.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  ** Copyright (c) 2005 MaK Technologies, Inc.
00003  ** All rights reserved.
00004  *********************************************************************/
00005 /*********************************************************************
00006  ** $RCSfile: vlShmSubscribableMessageQueue__rti__.h,v $ $Revision: 1.3 $ $State: Exp $
00007  *********************************************************************/
00008 #ifndef vlShmSubscribableMessageQueue__rti___H_
00009 #define vlShmSubscribableMessageQueue__rti___H_
00010 
00014 
00015 #include "rtiMsConfig.h"
00016 #include "vlShmMessageQueue__rti__.h"
00017 #include "vlShmPool__rti__.h"
00018 #include <vlutil/vlTime.h>
00019 #include "vlIpcRdWrLock__rti__.h"
00020 #include "vlIpcMutex__rti__.h"
00021 #include <vlutil/vlNetTypes.h>
00022 #include <vector>
00023 #include <limits.h>
00024 
00025 #ifndef WIN32
00026 #include <pthread.h>
00027 #endif //! !WIN32
00028 
00029 #ifdef DtUSE_UTILITIES_NAMESPACE
00030 namespace DtUSE_UTILITIES_NAMESPACE
00031 {
00032 #endif
00033 
00034 #define DtSm_QUEUE_STATE_UNINITIALIZED 0x0
00035 #define DtSm_QUEUE_STATE_INITIALIZED   0xFAD2FADE
00036 #define DtSm_QUEUE_STATE_SHUTDOWN      0xDEADBEEF
00037 #define DtSM_INVALID_SUBSCRIBER_ID     UINT_MAX
00038 
00041 #define DtSMQ_FETCH_DEFAULT   0x00  //! fetch according to default behavior
00042 #define DtSMQ_SKIP_MINE       0x40  //! fetch all messages except sender's own
00043 #define DtSMQ_FETCH_ALL       0x80  //! fetch all messages
00044 
00050 #define DtSmSubMsgQ_theMaxSubscribers 255
00051 
00053 //
00066 class DT_DLL_RTIUTIL DtSmSubscribableMessageQueue__rti__: public DtMessageQueue__rti__
00067 {
00068 
00069 public:
00070 
00075    DtSmSubscribableMessageQueue__rti__(const MAKRti::DtString &name);
00076    virtual ~DtSmSubscribableMessageQueue__rti__();
00077 
00078 private:
00079 
00081    DtSmSubscribableMessageQueue__rti__(const DtSmSubscribableMessageQueue__rti__ &other);
00082 
00084    DtSmSubscribableMessageQueue__rti__& operator=(const DtSmSubscribableMessageQueue__rti__ &other);
00085 
00086 public:
00087 
00090    virtual int subscribe(MAKRti::DtU32 subscriberId = DtSM_INVALID_SUBSCRIBER_ID);
00091 
00101    virtual void unsubscribe(MAKRti::DtU32 id);
00102 
00104    virtual bool isSubscribed(MAKRti::DtU32 subscriberId) const;
00105 
00107    virtual MAKRti::DtU32 subscriberId() const;
00108 
00110    virtual int subscriberCount() const;
00111 
00118    virtual bool isEmpty();
00119    virtual bool isEmpty(int *nextSize, MAKRti::DtU32 flagsMask = DtSMQ_FETCH_DEFAULT);
00120 
00123    //
00124    virtual void setDefaultReadBehavior(MAKRti::DtU32 flagsMask);
00125 
00130    virtual bool sendMessage(const void *message, unsigned int size);
00131 
00137    virtual void* message(unsigned int *outSize = 0);
00138    virtual void* message(void *recvBuffer, unsigned int *outSize);
00139 
00141    //
00144    virtual void resetQueue(MAKRti::DtU32 numberOfBuckets, MAKRti::DtU32 payloadSize);
00145 
00147    virtual bool sm_shutdown( bool ruthless = false );
00148 
00150    virtual volatile MAKRti::DtU32 queueState() const;
00151 
00153    //
00156    virtual void initSyncVars();
00157 
00160    virtual void clearSyncVars();
00161 
00163    virtual std::ostream &printDataToStream(std::ostream &str) const;
00164 
00165 public:
00166 
00169    //
00171    static unsigned int poolSize(MAKRti::DtU32 numberOfBuckets, MAKRti::DtU32 payloadSize);
00172 
00173 protected:
00174 
00177    struct DtQueueHeader;
00178    struct DtBucketHeader;
00179 
00181    virtual int assignSubscriberId();
00182 
00184    virtual unsigned int maxSubscribers() const;
00185 
00187    volatile DtQueueHeader *queueHeader() const;
00188 
00190    virtual MAKRti::DtU32 queueHeaderSize() const;
00191 
00193    virtual MAKRti::DtU32 numberOfBuckets() const;
00194 
00196    virtual MAKRti::DtU32 payloadSize() const;
00197 
00200    virtual volatile MAKRti::DtU32 queueFront(unsigned int sub) const;
00201 
00203    virtual volatile MAKRti::DtU32 queueBack() const;
00204 
00207    virtual volatile MAKRti::DtU32 queueBackstop() const;
00208 
00211    virtual MAKRti::DtU32 updateFront(unsigned int sub, unsigned int val);
00212 
00215    virtual MAKRti::DtU32 updateBack(unsigned int val);
00216 
00219    virtual MAKRti::DtU32 updateBackstop(unsigned int val);
00220 
00222    virtual void setSubscribed(unsigned int sub, unsigned int val);
00223 
00225    virtual int setSubscriberCount(MAKRti::DtU32 val);
00226 
00228    virtual int incrementSubscriberCount();
00229 
00231    virtual int decrementSubscriberCount();
00232 
00234    virtual void  setState(MAKRti::DtU32 val);
00235 
00238    virtual volatile char* payloadInBucket(unsigned int bucketNum) const;
00239 
00241    virtual volatile void * bucketHeader(unsigned int bucketNum) const;
00242 
00244    virtual MAKRti::DtU32 bucketHeaderSize() const;
00245 
00247    virtual MAKRti::DtU32 bucketSenderId(unsigned int bucketNum) const;
00248    virtual MAKRti::DtU32 bucketMsgSn(unsigned int bucketNum) const;
00249    virtual MAKRti::DtU32 bucketOutstandingReadCount(unsigned int bucketNum) const;
00250    virtual MAKRti::DtU32 bucketPayloadLen(unsigned int bucketNum) const;
00251    virtual bool  bucketIsFirst(unsigned int bucketNum) const;
00252    virtual bool  bucketIsLast(unsigned int bucketNum) const;
00253 
00255    virtual void  setSenderId(unsigned int bucketNum, MAKRti::DtU32 sid);
00256    virtual void  setMsgSn(unsigned int bucketNum, MAKRti::DtU32 seqnum);
00257    virtual void  setOutstandingReadCount(unsigned int bucketNum, MAKRti::DtU32 val);
00258    virtual void  decrementOutstandingReadCount(unsigned int bucketNum);
00259    virtual void  setPayloadLen(unsigned int bucketNum, MAKRti::DtU32 len);
00260    virtual void  setFirst(unsigned int bucketNum, MAKRti::DtU32 val);
00261    virtual void  setLast(unsigned int bucketNum, MAKRti::DtU32 val);
00262 
00264    virtual void lockForRead();
00266    virtual void unlockForRead();
00267 
00269    virtual void lockForWrite();
00270 
00272    virtual void unlockForWrite();
00273 
00276    virtual bool stalledSubscribers(unsigned int bucketNum, 
00277                                    unsigned int numStalled);
00278 
00281    virtual bool checkForStalls();
00282 
00283 #ifndef WIN32
00284 
00285 
00286 
00287    virtual pthread_rwlock_t * rdWrLock();
00288    virtual pthread_mutex_t  * orcMutex();
00289 #endif //! !WIN32
00290 
00291 protected:
00292 
00293    DtSharedMemoryPoolClient__rti__ *myShmPool;
00294    MAKRti::DtString                  myShmName;
00295    MAKRti::DtU32                     mySubscriberId;
00296    MAKRti::DtU32                     myMessagesSentCnt;
00297    DtIpcRdWrLock__rti__   *  myRdWrLock;
00298    DtIpcMutex__rti__      *  myOrcMutex;
00299    std::vector<char>         myReadBuffer;
00300    MAKRti::DtU32                     myDefaultReadMask;
00301 
00302 //TO DO -- DAA workaround for MSVC6 bug ID #241569
00303 //A bug in MSVC++6 prevents initializing a static const member within a class
00304 //declaration. It must be initialized outside the class. The bug is fixed
00305 //in MSVC7, so when support for MSVC6 is dropped we can do away with this
00306 //kludgy workaround
00307 //static const unsigned int theMaxSubscribers = 255;
00309    unsigned int theMaxSubscribers;
00310 
00311 protected:
00312 
00321    struct DtBucketHeader
00322    {
00323       MAKRti::DtU32 senderId;       
00324       MAKRti::DtU32 msgSn;            
00325       MAKRti::DtU32 outstandingReadCount;  
00326       MAKRti::DtU32 sizeInBytes : 24;  
00327       MAKRti::DtU32 reserved_1   : 6;  
00328       MAKRti::DtU32 last         : 1;  
00329       MAKRti::DtU32 first        : 1;  
00330    };
00331 
00339    struct DtQueueHeader
00340    {
00341       MAKRti::DtU32 state;         
00342       MAKRti::DtU32 payloadSize;
00343       MAKRti::DtU32 numberOfBuckets;
00344       MAKRti::DtU32 numberOfSubscribers;
00345       MAKRti::DtU32 front[DtSmSubMsgQ_theMaxSubscribers];
00346       MAKRti::DtU32 subscribed[DtSmSubMsgQ_theMaxSubscribers];
00347       MAKRti::DtU32 back;
00348       MAKRti::DtU32 backstop;
00349 #ifndef WIN32
00350 
00351 
00352       pthread_rwlock_t  rwlock;
00353       pthread_mutex_t   ptOrcMutex;   
00354 #endif //! !WIN32
00355    };
00356 };
00357 
00358 #ifdef DtUSE_UTILITIES_NAMESPACE
00359 } 
00360 #endif
00361 
00362 #endif
00363 
00364 

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)