fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / BackgroundLoader / OSGBackgroundLoader.h
blob9910372ed8d89ee26d535a3a8ce258693857641a
1 #ifndef _OSG_BACKGROUND_LOADER_H_
2 #define _OSG_BACKGROUND_LOADER_H_
4 #include "OSGContribBackgroundLoaderDef.h"
6 #include "OSGBaseTypes.h"
7 #include "OSGSingletonHolder.h"
8 #include "OSGRequest.h"
9 #include "OSGThread.h"
10 #include "OSGLock.h"
11 #include "OSGCondVar.h"
13 #include <deque>
15 OSG_BEGIN_NAMESPACE
17 /** Helper class that supports processing requests
18 * such as loading files in a background thread.
21 class OSG_CONTRIBBACKGROUNDLOADER_DLLMAPPING BackgroundLoaderBase
23 public:
25 typedef std::vector<std::string> desc_list_t;
27 public:
29 /**
30 * Start load thread and start handling background requests.
32 void start(const OSG::UInt16 numThreads = 1);
34 /**
35 * Stop load thread and handling background requests.
37 void stop(void);
39 /** Add a new request to the queue to be processed. */
40 void addRequest(RequestPtr req);
42 /** Request removal of an existing request.
43 * If request is found, it is removed.
45 void removeRequest(RequestPtr req);
47 /** Sync up with the background loader and it's pending changes.
48 * @args reqLimit The max number of requests to process. 0-All
50 void sync(unsigned reqLimit = 0);
52 /** Process a single request.
53 * This method can only be called if we are not running
54 * in a background thread but instead want to run synchronously.
56 void processOne(void);
58 /** Return the number of pending requests. */
59 unsigned getNumPendingRequests(void);
61 /** Return a list of the descriptions of all pending requests. */
62 desc_list_t getPendingDescriptionList();
64 protected:
66 //void workerThread(void *);
67 //void renderThread(void *);
68 BackgroundLoaderBase(void);
69 virtual ~BackgroundLoaderBase(void);
71 static void loadProc(void* arg);
73 private:
75 template <class SingletonT>
76 friend class SingletonHolder;
78 /** default function (move to 'public' if needed). */
79 BackgroundLoaderBase(const BackgroundLoaderBase &source);
81 /** \brief prohibit default function (move to 'public' if needed) */
82 void operator =(const BackgroundLoaderBase &source);
84 typedef std::list<RequestPtr> request_queue_t;
85 request_queue_t mPendingRequests;
86 request_queue_t mFinishedRequests;
87 std::vector<ThreadRefPtr> mLoadThreads;
88 LockRefPtr mFinishedLock;
89 CondVarRefPtr mLoadCondVar; // Cond var to protect
90 // the request queue
91 bool mStopRunning;
94 #if defined(WIN32)
95 OSG_CONTRIBBACKGROUNDLOADER_EXPIMP_TMPL
96 template class OSG_CONTRIBBACKGROUNDLOADER_DLLMAPPING
97 SingletonHolder<BackgroundLoaderBase>;
98 #endif
100 typedef SingletonHolder<BackgroundLoaderBase> BackgroundLoader;
102 OSG_END_NAMESPACE
104 #endif /*_OSG_BACKGROUND_LOADER_H_*/