VR-Exchange 2.1 API Documentation
smSubscribableMessageQueue.h
Go to the documentation of this file.
1 /*********************************************************************
2  ** Copyright (c) 1992-2010 VT MAK
3  ** All rights reserved.
4  *********************************************************************/
5 
6 #ifndef smFixedMessageQueue_H_
7 #define smFixedMessageQueue_H_
8 
12 
13 
14 #include <portal/messageQueue.h>
15 #include <vlutil/vlShmPool.h>
16 #include <vlutil/vlNetTypes.h>
17 #include <vector>
18 
19 #include <pthread.h>
20 
21 namespace MAKVrExchange {
22 
25 //
33 //
38 {
39 
40 public:
41 
46  DtSubscribableMessageQueue(const DtString &name, DtU8 subscriberId);
47  virtual ~DtSubscribableMessageQueue();
48 
49 private:
50 
53 
56 
57 public:
58 
60  virtual bool isEmpty();
61 
63  virtual bool isSubscribed(DtU8 subscriberId) const;
64 
67  virtual DtU32 subscriberDrops(DtU8 subscriberId) const;
68 
70  //
73  virtual void sendMessage(const void *message, unsigned int size);
74 
77  //
79  virtual void* message(unsigned int *outSize = 0);
80 
81 
83  //
88  virtual void unsubscribe(DtU8 id);
89 
91  //
96  void subscribe(DtU8 id);
97 
99  //
102  virtual void resetQueue(DtU32 numberOfBuckets, DtU32 payloadSize);
103 
105  //
106  //This should only be called after the queue is created, and only by
108  virtual void initLocks();
109 
111  virtual void clearLocks();
112 
114  virtual std::ostream &printDataToStream(std::ostream &str) const;
115 
116 public:
117 
118  struct DtQueueHeader;
119  struct DtBucketHeader;
120 
123  //
125  static unsigned int poolSize(DtU32 numberOfBuckets, DtU32 payloadSize);
126 
128  virtual DtString name() const;
129 
130 
132  DtQueueHeader *queueHeader() const;
133 
135  DtU32 numberOfBuckets() const;
136 
138  DtU32 payloadSize() const;
139 
142  virtual char* payloadInBucket(unsigned int bucketNum) const;
143 
145  virtual DtBucketHeader* bucketHeader(unsigned int bucketNum) const;
146 
148  static const unsigned int theMaxSubscribers = 255;
149 
150 protected:
151 
153  virtual void lockForRead();
155  virtual void unlockForRead();
156 
158  virtual void lockForWrite();
159 
161  virtual void unlockForWrite();
162 
163 protected:
164 
165  DtSharedMemoryPoolClient *myShmPool;
168  std::vector<char> myReadBuffer;
169 
170 
171 
172 public:
173 
178  {
179  DtNetU8 senderId;
180  DtNetU32 sizeInBytes;
181  };
182 
187  {
188  DtNetU32 payloadSize;
189  DtNetU32 numberOfBuckets;
190  DtNetU32 front[theMaxSubscribers];
191  DtNetU32 subscribed[theMaxSubscribers];
192  DtNetU32 subscriberDrops[theMaxSubscribers];
193  DtNetU32 back;
194  pthread_rwlock_t rwlock;
195 
196  //The following are used strictly for performance information
197  DtNetU32 lastXPtr;
198  DtNetU32 lastXSize;
201  };
202 };
203 }
204 
205 #endif //end smFixedMessageQueue_H_

Document ID: Generated on Tue Aug 7 22:07:13 EDT 2012 from SVN revision 117874
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)