VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
debugDrawerSharedMemoryManager.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2011 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
8 #include "vlutil/vlShmPool.h"
9 #include "vlutil/vlMutex.h"
10 #include "vlutil/vlScopedLock.h"
11 #include "vlutil/vlString.h"
12 
20 #include <vector>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/scoped_array.hpp>
23 #include <boost/noncopyable.hpp>
24 
26 struct DtDebugMemoryBlockHeader;
27 
30 
32 {
33  public:
34  class LocalSharedMemoryPoolManager;
35 
37  typedef DtDebugMemoryBlockHeader DtMemoryHeader;
38 
39  class DT_DLL_simTerrainDrawer ReadLock : boost::noncopyable
40  {
41  public:
42  explicit ReadLock(DtDebugDrawerSharedMemoryManager& manager);
43 
44  ~ReadLock();
45 
46  protected:
48  };
49 
50  class DT_DLL_simTerrainDrawer ScopedFrame : boost::noncopyable
51  {
52  public:
53  explicit ScopedFrame(DtDebugDrawerSharedMemoryManager& manager, bool erase = true);
54 
55  ~ScopedFrame();
56 
57  void reset(DtDebugDrawerSharedMemoryManager& mgr, bool erase = true);
58  void reset();
59 
60  bool isSet() const;
61 
62  void setOutput(bool flag);
63 
64  protected:
67  };
68 
69  friend class ScopedLock;
70  friend class ScopedFrame;
71 
73  {
74  Header();
75  };
76 
77  static const unsigned long KB = static_cast<unsigned long>(1) << 10;
78  static const unsigned long MB = static_cast<unsigned long>(1) << 20;
79  static const unsigned long GB = static_cast<unsigned long>(1) << 30;
80 
84  DtDebugDrawerSharedMemoryManager(unsigned long memorySize=30*MB);
85 
89 
97  virtual bool init(MemoryType memoryType, bool clearMemory=false);
98 
99  virtual bool init(
100  std::string tag,
101  bool clearMemory=false,
103 
104  Header header() const;
105  void setHeader(const Header&);
106 
107  long getName() const;
108 
109  bool enabled() const;
110  void setEnabled(bool val);
111 
124  virtual bool push(DtDebugDrawerGeometryMemory* shape);
125 
130 
131  virtual unsigned long frameCount() const;
132 
136  virtual unsigned long numEntries() const;
137 
140  virtual unsigned long currentSize() const;
141 
161  virtual const char* getNext(const char* previousPtr, DtDebugDrawerGeometryMemory** shape);
162 
164  virtual std::vector<DtDebugDrawerNameManager::Slot> getMemoryBlockNames();
165 
173  virtual bool pointToMemoryBlock(long name);
174 
175  protected:
176  void readLock() const;
177  void readUnlock() const;
178 
181  void startNewFrame(bool erase = true);
182  void advanceFrameCount(bool outputErrors = true);
184 
185  unsigned long myRequestedMaxSize;
186 
190  unsigned long myCurrentSize;
191 
195 
197  char* myMemoryPtr;
198 
201 
203  LocalSharedMemoryPoolManager* myManager;
204  DtSharedMemoryPoolClient* myClient;
205 
208 
210 
212 
214 
215  boost::scoped_array<char> myBuffer;
216  size_t myBufferSize;
217 };
218 
220 {
221 public:
222  static const unsigned long KB = DtDebugDrawerSharedMemoryManager::KB;
223  static const unsigned long MB = DtDebugDrawerSharedMemoryManager::MB;
224  static const unsigned long GB = DtDebugDrawerSharedMemoryManager::GB;
225 
226  typedef boost::shared_ptr<DtDebugDrawerSharedMemoryManager> BufferPtr;
227  typedef std::vector<BufferPtr> BufferVector;
228 
229  class DT_DLL_simTerrainDrawer ScopedFrame : boost::noncopyable
230  {
231  public:
232  ScopedFrame(DtMultiBufferDebugDrawer& drawer, bool erase=true);
233  ~ScopedFrame();
234 
235  bool push(DtDebugDrawerGeometryMemory* shape);
236 
237  protected:
239  DtScopedLock myFrameLock;
241  unsigned long myNumDrawn;
242  unsigned long myNumOverflows;
243  BufferVector::iterator myCurrentBuffer;
245  };
246 
247  friend class ScopedFrame;
248 
249  static DtMultiBufferDebugDrawer* Make(
250  std::string tag,
251  unsigned long bufferSize = 5*MB,
252  unsigned long maxSize = 50*MB,
253  double factor = 1.0);
254 
255  explicit DtMultiBufferDebugDrawer(
256  std::string tag,
259  unsigned long bufferSize = 5*MB,
260  unsigned long maxSize = 50*MB,
261  double factor = 1.0);
262 
264  void setHeader(const DtDebugDrawerSharedMemoryManager::Header&);
265 
266  bool enabled() const;
267  void setEnabled(bool);
268 
269 protected:
270  BufferVector::iterator lastBuffer();
271 
272  mutable DtMutex myFrameMutex;
273  std::string myTag;
275  unsigned long myBufferSize;
278  double myFactor;
280 };
281 

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)