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"
11 #include "OSGCondVar.h"
17 /** Helper class that supports processing requests
18 * such as loading files in a background thread.
21 class OSG_CONTRIBBACKGROUNDLOADER_DLLMAPPING BackgroundLoaderBase
25 typedef std::vector
<std::string
> desc_list_t
;
30 * Start load thread and start handling background requests.
32 void start(const OSG::UInt16 numThreads
= 1);
35 * Stop load thread and handling background requests.
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();
66 //void workerThread(void *);
67 //void renderThread(void *);
68 BackgroundLoaderBase(void);
69 virtual ~BackgroundLoaderBase(void);
71 static void loadProc(void* arg
);
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
95 OSG_CONTRIBBACKGROUNDLOADER_EXPIMP_TMPL
96 template class OSG_CONTRIBBACKGROUNDLOADER_DLLMAPPING
97 SingletonHolder
<BackgroundLoaderBase
>;
100 typedef SingletonHolder
<BackgroundLoaderBase
> BackgroundLoader
;
104 #endif /*_OSG_BACKGROUND_LOADER_H_*/