2 #include "IAttributeFields.h" 3 #include "IDataLoader.h" 4 #include "util/LogService.h" 7 #include <boost/thread.hpp> 8 #include <boost/asio.hpp> 9 #include <boost/shared_ptr.hpp> 10 #include <boost/enable_shared_from_this.hpp> 13 #define E_TRYAGAIN -123456 22 #define MAX_PROCESS_QUEUE 16 65 enum AssetLogLevelEnum
84 ATTRIBUTE_METHOD1(
CAsyncLoader, GetEstimatedSizeInBytes_s,
int*) { *p1 = cls->GetEstimatedSizeInBytes();
return S_OK; }
85 ATTRIBUTE_METHOD1(
CAsyncLoader, GetItemsLeft_s,
int*) { *p1 = cls->GetItemsLeft();
return S_OK; }
86 ATTRIBUTE_METHOD1(
CAsyncLoader, GetBytesProcessed_s,
int*) { *p1 = cls->GetBytesProcessed();
return S_OK; }
88 ATTRIBUTE_METHOD1(
CAsyncLoader, SetWorkerThreads_s,
Vector2) { cls->CreateWorkerThreads((
int)p1.x, (
int)p1.y);
return S_OK; }
90 ATTRIBUTE_METHOD1(
CAsyncLoader, SetProcessorQueueSize_s,
Vector2) { cls->SetProcessorQueueSize((
int)p1.x, (
int)p1.y);
return S_OK; }
92 ATTRIBUTE_METHOD1(
CAsyncLoader, GetLogLevel_s,
int*) { *p1 = cls->GetLogLevel();
return S_OK; }
93 ATTRIBUTE_METHOD1(
CAsyncLoader, SetLogLevel_s,
int) { cls->SetLogLevel(p1);
return S_OK; }
95 ATTRIBUTE_METHOD1(
CAsyncLoader, log_s,
const char*) { cls->log(p1);
return S_OK; }
96 ATTRIBUTE_METHOD(
CAsyncLoader, WaitForAllItems_s) { cls->WaitForAllItems();
return S_OK; }
99 struct ProcessorWorkerThread;
110 int Start(
int nWorkerCount = 5);
134 HRESULT
RunWorkItem( ResourceRequest_ptr& request );
146 void ProcessDeviceWorkItemImp(ResourceRequest_ptr& pResourceRequest,
bool bRetryLoads =
false);
159 int GetWorkerThreadsCount(
int nProcessorQueueID);
162 int GetProcessorQueueSize(
int nProcessorQueueID);
169 #ifdef PARAENGINE_CLIENT 171 inline LPD3DXFILE GetFileParser() {
return m_pXFileParser; };
174 CDirectXEngine* GetEngine();
202 int GetLogLevel()
const;
203 void SetLogLevel(
int val);
206 void log(
const string& msg);
207 void log(
int nLogLevel,
const string& msg);
270 bool m_bProcessThreadDone;
271 bool m_bIOThreadDone;
274 volatile bool m_bInterruptSignal;
276 int m_NumResourcesToService;
278 int m_NumOutstandingResources;
280 int m_nRemainingBytes;
296 Boost_Thread_ptr_type m_io_thread;
303 ProcessorWorkerThread();
304 ProcessorWorkerThread(
int nQueueID);
306 ~ProcessorWorkerThread();
308 void reset(boost::thread * pThread) {m_thread.reset(pThread);}
309 void reset() {m_thread.reset();}
310 void join() {
if(m_thread.get()) m_thread->join();}
316 bool timed_join(
int nSeconds);
319 virtual int GetProcessorQueueID() {
return m_nQueueID;}
325 virtual void* GetCurlInterface(
int nID = 0);
328 virtual void AddBytesProcessed(
int nBytesProcessed);
334 Boost_Thread_ptr_type m_thread;
343 volatile int m_nBytesProcessed;
347 struct DefaultWorkerThreadData :
public ProcessorWorkerThread
351 virtual void* GetCurlInterface(
int nID = 0);
355 std::vector< ProcessorWorkerThread* > m_workers;
358 DefaultWorkerThreadData* m_default_processor_worker_data;
364 CServiceLogger_ptr g_asset_logger;
367 AssetLogLevelEnum m_nLogLevel;
369 #ifdef PARAENGINE_CLIENT 371 LPD3DXFILE m_pXFileParser;
374 CDirectXEngine* m_pEngine;
385 std::set <std::string> m_pending_requests;
bool CreateWorkerThreads(int nProcessorQueueID, int nMaxCount)
make sure that there are nMaxCount workers threads processing the queue at nProcessorQueueID.
Definition: AsyncLoader.cpp:271
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void CleanUp()
clean up everything, exit all threads created.
Definition: AsyncLoader.cpp:232
void AddPendingRequest(const char *sURL)
add a string url to a set.
Definition: AsyncLoader.cpp:938
void Interrupt()
call this function to interrupt all threads.
Definition: AsyncLoader.cpp:253
void WaitForAllItems()
Wait for all work in the queues to finish.
Definition: AsyncLoader.cpp:396
this allows us to create another device, such as in a worker thread to perform some background work w...
Definition: GDIEngine.h:57
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: AsyncLoader.cpp:988
different physics engine has different winding order.
Definition: EventBinding.h:32
int GetItemsLeft(int nItemType=-1)
Get the number of items left in the asynchronous content loader queue.
Definition: AsyncLoader.cpp:341
the message queue
Definition: IDataLoader.h:156
int FileIOThreadProc_HandleRequest(ResourceRequest_ptr &ResourceRequest)
this is usually called by FileIOThreadProc(), but may be called by other thread as well if IsDeviceOb...
Definition: AsyncLoader.cpp:553
void log(const string &msg)
write formated text to "asset.log".
Definition: AsyncLoader.cpp:258
void RemovePendingRequest(const char *sURL)
remove a string url from a set.
Definition: AsyncLoader.cpp:952
interface of processor worker data
Definition: IDataLoader.h:44
int Stop()
stop everything.
Definition: AsyncLoader.cpp:421
bool HasPendingRequest(const char *sURL)
whether the given request is already in the pending set.
Definition: AsyncLoader.cpp:977
bool interruption_requested()
this is a global interrupt signal.
Definition: AsyncLoader.h:210
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
int Start(int nWorkerCount=5)
call this only once to start async loader
Definition: AsyncLoader.cpp:501
int GetBytesProcessed(int nItemType=-1)
get the total number of bytes processed.
Definition: AsyncLoader.cpp:362
static CAsyncLoader & GetSingleton()
get singleton instance.
Definition: AsyncLoader.cpp:248
IDataProcessor is an interface that the AsyncLoader class uses to process and copy data into locked r...
Definition: IDataLoader.h:76
HRESULT RunWorkItem(IDataLoader *pDataLoader, IDataProcessor *pDataProcessor, HRESULT *pHResult, void **ppDeviceObject)
this is same as AddWorkItem, except that it is a synchronous function.
Definition: AsyncLoader.cpp:749
int FileIOThreadProc()
This is the one IO threadproc.
Definition: AsyncLoader.cpp:640
void ProcessDeviceWorkItems(int CurrentNumResourcesToService=100, bool bRetryLoads=false)
ProcessDeviceWorkItems is called by the graphics thread.
Definition: AsyncLoader.cpp:927
A common interface for all classes implementing IAttributeFields By implementing this class's virtual...
Definition: IAttributeFields.h:59
IDataLoader is an interface that the AsyncLoader class uses to load data from disk.
Definition: IDataLoader.h:14
void ClearAllPendingRequests()
clear all pending request.
Definition: AsyncLoader.cpp:961
It uses architecture proposed by the content streaming sample in DirectX 9&10.
Definition: AsyncLoader.h:62
int ProcessingThreadProc(ProcessorWorkerThread *pThreadData)
This is the threadproc for the processing thread.
Definition: AsyncLoader.cpp:660
void SetProcessorQueueSize(int nProcessorQueueID, int nSize)
message queue size of a given processor id
Definition: AsyncLoader.cpp:321
ParaEngine resource request.
Definition: IDataLoader.h:124
int AddWorkItem(IDataLoader *pDataLoader, IDataProcessor *pDataProcessor, HRESULT *pHResult, void **ppDeviceObject, int nProcessorThreadID=0)
Add a work item to the queue of work items Only call this from graphics thread @ param nProcessorThre...
Definition: AsyncLoader.cpp:786
cross platform mutex
Definition: mutex.h:95
int GetEstimatedSizeInBytes()
get total estimated size in bytes.
Definition: AsyncLoader.cpp:335