AGX Dynamics  2.37.3.2
FileTrack.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 
18 #ifndef AGXDATA_FILE_TRACK_H
19 #define AGXDATA_FILE_TRACK_H
20 
21 #include <agx/config/AGX_USE_AIO.h>
22 #include <agx/agx.h>
23 #include <agx/Logger.h>
24 #include <agx/List.h>
25 #include <agxData/DiskTrack.h>
27 #include <agxData/FileJournal.h>
28 #include <fstream>
29 
30 
31 #if AGX_USE_AIO()
32 #include <aio.h>
33 #endif
34 
35 namespace agx
36 {
37  class TiXmlDocument;
38  class TiXmlElement;
39 }
40 
41 namespace agxData
42 {
44 
49  {
50  public:
52 
53  virtual const agxData::JournalArchive::Session* getSession() const override;
54 
55  virtual bool jumpToFrame(agx::UInt frameIndex) override;
56  virtual bool jumpToTime(agx::Real time) override;
57 
59  agx::UInt getFrameOffset() const;
60 
67  enum BinaryReadStrategy { FSTREAM, CACHED, DIRECT };
68 
69  void setBinaryReadStrategy( BinaryReadStrategy strategy );
70  BinaryReadStrategy getBinaryReadStrategy() const;
71 
72 #if AGX_USE_AIO()
73 
77  void setEnableUseAio( bool useAio );
78  bool getEnableUseAio() const;
79 #endif
80 
81  protected:
82  virtual ~FileFrameReader();
83 
84  virtual void prepareSequence(agx::UInt startFrame, agx::UInt lastFrame) override;
85  virtual void endSequence() override;
86 
87  private:
88 
89 
90  bool isValidFrame(agx::UInt frameIndex);
91  virtual Frame* readFrame(agx::UInt frameIndex) override;
92  using DiskFrameReader::readFrame;
93 
94  // void readComponent(agx::Component* parent, agx::TiXmlElement* eElement, std::istream& binaryFile);
95  // void readBuffer(agx::Component* parent, agx::TiXmlElement* eElement, std::istream& binaryFile);
96  // void readValue(agx::Component* parent, agx::TiXmlElement* eElement, std::istream& binaryFile);
97 
98 
99  void removeUnwantedBuffers( agx::TiXmlElement* eElement, const agxData::Frame::DataBindingRefVector& bindings, const agx::String& path );
100 
101 
102  private:
103  BinaryReadStrategy m_readStrategy;
104 
105 #if AGX_USE_AIO()
106  bool m_useAio;
107  PreloadedFrameRef m_preloadedFrame;
108 #endif
109 
110  FileJournal::SessionRef m_session;
111 
112  std::ifstream m_journalFile;
114  bool m_activeMergeSequence;
115  };
116 
117 
118 
119 #if AGX_USE_AIO()
120 
123  class FileFrameReader::PreloadedFrame : public agx::Referenced
124  {
125  public:
126  PreloadedFrame();
127 
134  bool queueFrameLoad( const agx::String& filePath, agxData::FileFrameReader::BinaryReadStrategy strategy );
135 
143  BinaryData* getFrameData();
144 
148  bool hasQueuedRead() const;
149 
154  const agx::String& getQueuedFilePath() const;
155 
156  private:
157  bool waitForCurrentReadToComplete();
158  void clear();
159  virtual ~PreloadedFrame();
160  private:
161  struct aiocb m_aioHandle;
162  agx::UInt8* m_frameData;
163  size_t m_frameDataSize;
164  size_t m_alignmentRequirement;
165  agx::String m_filePath;
166  };
167 #endif
168 
169  //---------------------------------------------------------------
170 
171 
174  {
175  public:
180 
181 
182  virtual void writeFrame(const agxData::Frame* frame) override;
183  virtual const JournalArchive::Session* getSession() const override;
184  virtual void endOfStream() override;
185 
186  protected:
187  virtual ~FileFrameWriter();
188 
189  private:
190  agx::String getFilePath() const;
191 
192  private:
194  // bool m_storeAsciiValues;
195 
197  };
198 
199 
200 
201 
202  /* Implementation */
203  AGX_FORCE_INLINE agx::UInt FileFrameReader::getFrameOffset() const { return (agx::UInt)m_session->getFirstFrameIndex(); }
204 }
205 
206 
207 
208 /* AGXDATA_FILE_TRACK_H */
209 #endif
Helper class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:34
AGXTERRAIN_EXPORT void clear()
Session(const agx::Name &name)
Base class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:107
uint8_t UInt8
Definition: Integer.h:38
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
Base class providing referencing counted objects.
Definition: Referenced.h:119
uint32_t UInt
Definition: Integer.h:34
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Contains classes for low level data storage for AGX.
Definition: Container.h:23
Frame reader that supports the files-and-foldes prototype format.
Definition: FileTrack.h:48
double Real
Definition: Real.h:42
#define AGXCORE_EXPORT
BinaryReadStrategy
Controls how the binary data of a frame is read from disk.
Definition: FileTrack.h:67