llvfsthread.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLVFSTHREAD_H
00033 #define LL_LLVFSTHREAD_H
00034 
00035 #include <queue>
00036 #include <string>
00037 #include <map>
00038 #include <set>
00039 
00040 #include "llapr.h"
00041 
00042 #include "llqueuedthread.h"
00043 
00044 #include "llvfs.h"
00045 
00046 //============================================================================
00047 
00048 class LLVFSThread : public LLQueuedThread
00049 {
00050         //------------------------------------------------------------------------
00051 public:
00052         enum operation_t {
00053                 FILE_READ,
00054                 FILE_WRITE,
00055                 FILE_RENAME
00056         };
00057 
00058         //------------------------------------------------------------------------
00059 public:
00060 
00061         class Request : public QueuedRequest
00062         {
00063         protected:
00064                 ~Request() {}; // use deleteRequest()
00065                 
00066         public:
00067                 Request(handle_t handle, U32 priority, U32 flags,
00068                                 operation_t op, LLVFS* vfs,
00069                                 const LLUUID &file_id, const LLAssetType::EType file_type,
00070                                 U8* buffer, S32 offset, S32 numbytes);
00071 
00072                 S32 getBytesRead()
00073                 {
00074                         return mBytesRead;
00075                 }
00076                 S32 getOperation()
00077                 {
00078                         return mOperation;
00079                 }
00080                 U8* getBuffer()
00081                 {
00082                         return mBuffer;
00083                 }
00084                 LLVFS* getVFS()
00085                 {
00086                         return mVFS;
00087                 }
00088                 std::string getFilename()
00089                 {
00090                         char tbuf[40];  /* Flawfinder: ignore */
00091                         mFileID.toString(tbuf);
00092                         return std::string(tbuf);
00093                 }
00094                 
00095                 /*virtual*/ bool processRequest();
00096                 /*virtual*/ void finishRequest(bool completed);
00097                 /*virtual*/ void deleteRequest();
00098                 
00099         private:
00100                 operation_t mOperation;
00101                 
00102                 LLVFS* mVFS;
00103                 LLUUID mFileID;
00104                 LLAssetType::EType mFileType;
00105                 
00106                 U8* mBuffer;    // dest for reads, source for writes, new UUID for rename
00107                 S32 mOffset;    // offset into file, -1 = append (WRITE only)
00108                 S32 mBytes;             // bytes to read from file, -1 = all (new mFileType for rename)
00109                 S32     mBytesRead;     // bytes read from file
00110         };
00111 
00112         //------------------------------------------------------------------------
00113 public:
00114         static std::string sDataPath;
00115         static LLVFSThread* sLocal;             // Default worker thread
00116         
00117 public:
00118         LLVFSThread(bool threaded = TRUE);
00119         ~LLVFSThread(); 
00120 
00121         // Return a Request handle
00122         handle_t read(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,    /* Flawfinder: ignore */
00123                                   U8* buffer, S32 offset, S32 numbytes, U32 pri=PRIORITY_NORMAL, U32 flags = 0);
00124         handle_t write(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
00125                                    U8* buffer, S32 offset, S32 numbytes, U32 flags);
00126         // SJB: rename seems to have issues, especially when threaded
00127 //      handle_t rename(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
00128 //                                      const LLUUID &new_id, const LLAssetType::EType new_type, U32 flags);
00129         // Return number of bytes read
00130         S32 readImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
00131                                           U8* buffer, S32 offset, S32 numbytes);
00132         S32 writeImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
00133                                            U8* buffer, S32 offset, S32 numbytes);
00134 
00135         /*virtual*/ bool processRequest(QueuedRequest* req);
00136 
00137 public:
00138         static void initClass(bool local_is_threaded = TRUE); // Setup sLocal
00139         static S32 updateClass(U32 ms_elapsed);
00140         static void cleanupClass();             // Delete sLocal
00141         static void setDataPath(const std::string& path) { sDataPath = path; }
00142 };
00143 
00144 //============================================================================
00145 
00146 
00147 #endif // LL_LLVFSTHREAD_H

Generated on Fri May 16 08:33:02 2008 for SecondLife by  doxygen 1.5.5