ML Reference
MeVis/Foundation/Sources/ML/include/host/mlPageRequestProcessorBase.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //-------------------------------------------------------------------------
00008 //-------------------------------------------------------------------------
00009 #ifndef __mlPageRequestProcessorBase_H
00010 #define __mlPageRequestProcessorBase_H
00011 
00012 #include "mlInitSystemML.h"
00013 
00014 #include "mlPageRequestProcessor.h"
00015 #include "mlProcessingTimeLine.h"
00016 
00017 ML_START_NAMESPACE
00018 
00019 class Host;
00020 class PagedImage;
00021 class UserThreadData;
00022 
00023 //-------------------------------------------------------------------------------------------
00025 //-------------------------------------------------------------------------------------------
00026 class MLEXPORT PageRequestProcessorBase : public PageRequestProcessor
00027 {
00028 public:
00029   PageRequestProcessorBase(Host* host);
00030   ~PageRequestProcessorBase();
00031 
00033   virtual bool supportsMultiThreading() = 0;
00034 
00038   virtual void removeCancelledRequests();
00039 
00041   ProcessingTimeLine& getProcessingTimeLine() { return _profile; }
00042 
00044   ProcessingTimeLine::TimeLine* getOverviewTimeLine() { return _useTimeLineProfiling?_overviewTimeLine:NULL; }
00045 
00047   void enableTimeLineProfiling(bool flag);
00048 
00050   bool isTimeLineProfilingEnabled() const { return _useTimeLineProfiling; }
00051 
00053   int getProcessingScope() const { return _processingScope; }
00054 
00056   virtual void enterProcessingScope();
00057 
00059   virtual void leaveProcessingScope();
00060 
00061 protected:
00063   bool createMoreWork(bool sleepWhenBlocked);
00064   
00066   void setupCurrentProcessingScope();
00067  
00069   virtual void handleErrorsInGUIThread();
00070 
00072   void terminateAllRequestsInGUIThread();
00073 
00075   void addNewCursor(PageRequestCursor* cursor);
00076  
00078   virtual void getAllPageRequestQueues(std::vector< std::deque<PageRequest*>* >& queues);
00079 
00081   Host* _host;
00082 
00084   bool _terminated;
00085 
00087   bool _workProduced;
00088 
00090   int _rootTileRequests;
00091 
00094   std::vector< std::vector<PageRequestCursor*> > _cursors;
00095 
00097 
00098   bool _useTimeLineProfiling;
00099   ProcessingTimeLine _profile;
00100   ProcessingTimeLine::TimeLine* _guiThreadTimeLine;
00101   ProcessingTimeLine::TimeLine* _overviewTimeLine;
00103 
00105   int _processingScope;
00107   int _producerProcessingScope;
00109   int _producerCursorCounter;
00111   int _guiThreadRecursionCounter;
00112 
00115   struct ScopeStackEntry
00116   {
00117     ScopeStackEntry() {
00118       rootTilesToWaitFor = 0;
00119       errorOccurred = false;
00120     }
00121 
00123     std::deque<PageRequest*> guiQueue;
00125     int rootTilesToWaitFor;
00126 
00128     bool errorOccurred;
00129 
00131     std::vector<PageRequest*> pageRequestsWithErrors;
00132   };
00133 
00135   ScopeStackEntry* _currentScope;
00136 
00139   std::vector<ScopeStackEntry> _scopeStack;
00140 
00142   TimeCounter _progressUpdateTimer;
00143 
00147   struct PerThreadStorage {
00148     ~PerThreadStorage() { clear(); }
00149 
00151     void clear();
00152 
00155     std::map<PagedImage*, UserThreadData*> userThreadDataMap;
00156   };
00157 
00159   PerThreadStorage _guiPerThreadStorage;
00160 
00162   UserThreadData* getUserThreadData(PageRequest* request, PerThreadStorage& perThreadStorage);
00163 
00164 };
00165 
00166 ML_END_NAMESPACE
00167 
00168 #endif
00169