Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

RageUtil_BackgroundLoader.h

Go to the documentation of this file.
00001 /* BackgroundLoader - Loads files in a thread. */ 00002 00003 #ifndef RAGE_UTIL_BACKGROUND_LOADER_H 00004 #define RAGE_UTIL_BACKGROUND_LOADER_H 00005 00006 #include "RageThreads.h" 00007 #include <map> 00008 00009 class RageFileDriverCached; 00010 00011 class BackgroundLoader 00012 { 00013 public: 00014 BackgroundLoader(); 00015 00016 /* Note that destruction of this object will wait for any existing requests 00017 * to finish aborting before returning. */ 00018 ~BackgroundLoader(); 00019 00020 /* Read the file in a background thread. Files will be read in the order requested. */ 00021 void CacheFile( const CString &file ); 00022 00023 /* Return true if the requested CacheFile request has finished. If true is returned, 00024 * the cached file can be read using the path returned in sActualPath. */ 00025 bool IsCacheFileFinished( const CString &sFile, CString &sActualPath ); 00026 00027 /* Call this when finished with a cached file, to release any resources. */ 00028 void FinishedWithCachedFile( CString sFile ); 00029 00030 /* Abort all loads. */ 00031 void Abort(); 00032 00033 private: 00034 RageThread m_LoadThread; 00035 bool m_bShutdownThread; 00036 void LoadThread(); 00037 static int LoadThread_Start( void *p ) { ((BackgroundLoader *) p)->LoadThread(); return 0; } 00038 00039 CString GetRequest(); 00040 00041 CString GetCachePath( CString sPath ) const; 00042 CString m_sCachePathPrefix; 00043 00044 RageSemaphore m_StartSem; 00045 00046 /* Lock before accessing any of the rest of the object. Don't keep this locked 00047 * while doing expensive operations, like reading files. */ 00048 RageMutex m_Mutex; 00049 00050 vector<CString> m_CacheRequests; 00051 00052 /* Filename to number of completed requests */ 00053 map<CString,int> m_FinishedRequests; 00054 00055 bool m_sThreadIsActive; 00056 bool m_sThreadShouldAbort; 00057 00058 RageFileDriverCached *m_pDriver; 00059 }; 00060 00061 #endif 00062 00063 /* 00064 * (c) 2004 Glenn Maynard 00065 * All rights reserved. 00066 * 00067 * Permission is hereby granted, free of charge, to any person obtaining a 00068 * copy of this software and associated documentation files (the 00069 * "Software"), to deal in the Software without restriction, including 00070 * without limitation the rights to use, copy, modify, merge, publish, 00071 * distribute, and/or sell copies of the Software, and to permit persons to 00072 * whom the Software is furnished to do so, provided that the above 00073 * copyright notice(s) and this permission notice appear in all copies of 00074 * the Software and that both the above copyright notice(s) and this 00075 * permission notice appear in supporting documentation. 00076 * 00077 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00078 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00079 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00080 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00081 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00082 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00083 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00084 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00085 * PERFORMANCE OF THIS SOFTWARE. 00086 */

Generated on Thu Jan 27 20:57:30 2005 for StepMania by doxygen 1.3.7