CLAM-Development  1.4.0
BufferedSDIFFileReader.hxx
Go to the documentation of this file.
1 #ifndef _BufferedSDIFFileReader_
2 #define _BufferedSDIFFileReader_
3 
4 #include "SDIFInConfig.hxx"
5 #include "SDIFFileReader.hxx"
6 #include "Frame.hxx"
7 #include "Thread.hxx"
8 #include "Mutex.hxx"
9 #include <deque>
10 
14 #define DEFAULT_INITIAL_NUMBER_OF_FRAMES_TO_BUFFER 50
15 
16 
17 #define DEFAULT_FRAME_LOAD_CHUNK_SIZE 5
18 
19 
20 #define DEFAULT_THRESHHOLD_FOR_PRELOADING 5
21 
22 
23 #define DEFAULT_THRESHHOLD_FOR_PRELOADING_ON_THREAD 20
24 
25 namespace CLAM
26 {
27 
39 {
40 public:
45  BufferedSDIFFileReader(const SDIFInConfig& argSDIFInConfig);
46 
47  virtual ~BufferedSDIFFileReader();
48 
54  bool Configure(const SDIFInConfig& c);
55 
56  const SDIFInConfig GetConfig();
57 
61  virtual Frame* ReadFrame();
62 
67  void LoadFramesIntoBufferOnThread(Thread* argThread);
68 
77 
81  bool IsThreaded();
82 
87 
88 protected:
90  void SetFrameBufferPosition(int frameBufferPosition);
91  Frame* GetFrame( int frameBufferPosition );
92 
93 private:
97  bool LoadFramesIntoBuffer(int argNumberOfBuffers);
98 
102  void Run();
103 
105  SDIFFileReader mSDIFFileReader;
107  std::deque<Frame*> frameBuffer;
109  int frameBufferPosition;
110 
112  int mFrameLoadChunkSize;
114  int mThreshholdForPreloading;
118  int mThreshholdForPreloadingOnThread;
119  // The maximum amount of time that a thread can remain idle. After this
120  // threshhold is crossed, the thread is stopped thereby returning it to the
121  // pool where it can be reused.
122  int mMaximumThreadIdleTime;
124  bool mReaderHasMoreFrames;
126  Thread* mThreadPtr;
128  CBL::Functor0 mFunctor;
129  // This is used to prevent the main thread and the reader thread from trying
130  // to access the deque of frames simultaneously
131  Mutex dequeMutex;
134  // if mThreshholdForPreloadingOnThread > mThreshholdForPreloading.
135  Mutex readSDIFMutex;
138  int totalNumberOfFramesToLoad;
139 };
140 
141 }
142 
143 #endif
144