ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00009 //------------------------------------------------------------------------- 00010 #ifndef __mlTileRequest_H 00011 #define __mlTileRequest_H 00012 00013 // ML-includes 00014 #ifndef __mlInitSystemML_H 00015 #include "mlInitSystemML.h" 00016 #endif 00017 00018 #include "mlSubImage.h" 00019 #include "mlPagedImage.h" 00020 #include "mlPageIDIterator.h" 00021 00022 ML_START_NAMESPACE 00023 00024 class TileRequest; 00025 class PageRequest; 00026 class PageRequestQueueInterface; 00027 00029 typedef void TileRequestFinishedCB(void* data, TileRequest* request); 00030 00031 //------------------------------------------------------------------------------------------- 00043 //------------------------------------------------------------------------------------------- 00044 class ML_UNIX_ONLY_EXPORT(MLEXPORT) TileRequest 00045 { 00046 00047 public: 00049 static TileRequest* allocate(); 00050 00052 static void deallocate(TileRequest* request); 00053 00055 static void clearFreeList(); 00056 00057 private: 00058 TileRequest(); 00059 00061 void cleanup(); 00062 00064 TileRequest* _freeListNext; 00065 00067 static TileRequest* _freeListHead; 00069 static Mutex _freeListMutex; 00070 00071 public: 00072 00077 void init(PagedImage* inputImage, const SubImageBox& box, MLDataType dataType, 00078 const ScaleShiftData& scaleShift, bool readOnlyInputTile = false, bool tryToBecomeMemoryImage = false); 00079 00081 enum AllocationPolicy { 00082 UseMemoryManager = 0, //<! This will allocate the memory using the MemoryManager 00083 UseMLAlloc = 1, //<! This will allocate the memory using MLAlloc 00084 NoAllocation = 2, //<! This can be used if no data should be allocated at all (e.g., for processAllPages) 00085 ExternalBuffer = 3 //<! This can be used to provide the data by the user (and to avoid freeing the data when something goes wrong) 00086 }; 00087 00088 //------------------------------------------------------ 00090 00091 //------------------------------------------------------ 00092 00096 bool prepareForCursorVisit(); 00097 00099 void createInputPageIds(); 00100 00104 void setNeededBy(PageRequest* request) { 00105 _neededByPageRequest = request; 00106 } 00107 00110 bool isBlockedByMemoryImage(); 00111 00115 void pageRequestFinished(SubImage& pageImage, PageRequestQueueInterface& queue); 00116 00118 00119 //------------------------------------------------------ 00121 00122 //------------------------------------------------------ 00123 00127 void setAllocationPolicy(AllocationPolicy policy) { _allocationPolicy = policy; } 00128 00130 AllocationPolicy getAllocationPolicy() const { return _allocationPolicy; } 00131 00133 void allocateData(); 00134 00136 void forgetData() { _subImage.setData(NULL); } 00137 00139 void freeData() { if (_allocationPolicy!=ExternalBuffer) { _subImage.free(); } } 00140 00142 const SubImage& getSubImage() const { return _subImage; } 00143 00146 void setExternalDataBuffer(void* data) { 00147 setAllocationPolicy(TileRequest::ExternalBuffer); 00148 _subImage.setData(data); 00149 } 00150 00152 void setUseTileReadOnly(bool flag) { _readOnlyInputTile = flag; } 00153 00155 00156 //------------------------------------------------------ 00158 00159 //------------------------------------------------------ 00160 00162 bool hasFinished() const; 00163 00165 void setTileRequestFinishedCB(TileRequestFinishedCB* cb, void* data) { 00166 _finishedCB = cb; 00167 _finishedCBData = data; 00168 } 00169 00171 void setInternalTileRequestFinishedCB(TileRequestFinishedCB* cb, void* data) { 00172 _internalFinishedCB = cb; 00173 _internalFinishedCBData = data; 00174 } 00175 00177 double getProgress() const; 00178 00180 00181 //------------------------------------------------------ 00183 00184 //------------------------------------------------------ 00185 00187 bool hasError() const { return _error!=ML_RESULT_OK; } 00188 00190 void setError(MLErrorCode error); 00191 00193 MLErrorCode getError() const { return _error; } 00194 00197 void propagateErrorUpwards(MLErrorCode error); 00198 00202 bool propagateCancellationDownIfRequestNotNeededAnymore(); 00203 00205 void collectPageRequestsWithErrors(std::set<PageRequest*>& result); 00206 00208 00209 //------------------------------------------------------ 00211 00212 //------------------------------------------------------ 00213 00215 MLErrorCode updateImageProperties(); 00216 00218 int getProcessingScope() const { return _processingScope; } 00219 00221 void setProcessingScope(int scope) { _processingScope = scope; } 00222 00224 const SubImageBox& getBox() const { return _subImage.getBox(); } 00225 00227 bool intersectsPagedImage() const; 00228 00230 void updateSourceImageExtent(); 00231 00233 00234 protected: 00236 friend class PageRequestCursor; 00237 00244 PageRequest* createPageRequest(MLint pageId, PageRequestQueueInterface& queue); 00245 00248 bool copyDataFromSubImg(SubImage& pageImage); 00249 00251 void sendTileRequestFinished(PageRequestQueueInterface& queue); 00252 00254 void emitFinishedCallback(); 00255 00257 SubImage _subImage; 00258 00260 AllocationPolicy _allocationPolicy; 00261 00263 ScaleShiftData _scaleShiftData; 00264 00266 bool _readOnlyInputTile; 00268 bool _tileWillBecomeMemoryImage; 00269 00271 PagedImage* _image; 00272 00274 MLint _inputPagesNeeded; 00275 00277 Mutex _inputPagesNeededMutex; 00278 00281 PageIDIterator _inputPageIds; 00282 00284 MLint _traversalCursorPosition; 00285 00287 PageRequest* _neededByPageRequest; 00288 00290 MLErrorCode _error; 00291 00293 int _processingScope; 00294 00296 TileRequestFinishedCB* _finishedCB; 00298 void* _finishedCBData; 00299 00301 TileRequestFinishedCB* _internalFinishedCB; 00303 void* _internalFinishedCBData; 00304 00305 public: 00307 static void enableAllocationFailure(int count = 1); 00309 static void disableAllocationFailure() { _forceAllocationFailure = false; } 00310 00311 private: 00312 static bool _forceAllocationFailure; 00313 static int _forceAllocationFailureCount; 00314 static int _forceAllocationFailureModulo; 00315 00316 }; 00317 00318 ML_END_NAMESPACE 00319 00320 #endif //of __mlTileRequest_H 00321