lllfsthread.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLLFSTHREAD_H
00033 #define LL_LLLFSTHREAD_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 //============================================================================
00045 // Threaded Local File System
00046 //============================================================================
00047 
00048 class LLLFSThread : public LLQueuedThread
00049 {
00050         //------------------------------------------------------------------------
00051 public:
00052         enum operation_t {
00053                 FILE_READ,
00054                 FILE_WRITE,
00055                 FILE_RENAME,
00056                 FILE_REMOVE
00057         };
00058 
00059         //------------------------------------------------------------------------
00060 public:
00061 
00062         class Responder : public LLThreadSafeRefCount
00063         {
00064         protected:
00065                 ~Responder();
00066         public:
00067                 virtual void completed(S32 bytes) = 0;
00068         };
00069 
00070         class Request : public QueuedRequest
00071         {
00072         protected:
00073                 virtual ~Request(); // use deleteRequest()
00074                 
00075         public:
00076                 Request(LLLFSThread* thread,
00077                                 handle_t handle, U32 priority, 
00078                                 operation_t op, const LLString& filename,
00079                                 U8* buffer, S32 offset, S32 numbytes,
00080                                 Responder* responder);
00081 
00082                 S32 getBytes()
00083                 {
00084                         return mBytes;
00085                 }
00086                 S32 getBytesRead()
00087                 {
00088                         return mBytesRead;
00089                 }
00090                 S32 getOperation()
00091                 {
00092                         return mOperation;
00093                 }
00094                 U8* getBuffer()
00095                 {
00096                         return mBuffer;
00097                 }
00098                 const LLString& getFilename()
00099                 {
00100                         return mFileName;
00101                 }
00102                 
00103                 /*virtual*/ bool processRequest();
00104                 /*virtual*/ void finishRequest(bool completed);
00105                 /*virtual*/ void deleteRequest();
00106                 
00107         private:
00108                 LLLFSThread* mThread;
00109                 operation_t mOperation;
00110                 
00111                 LLString mFileName;
00112                 
00113                 U8* mBuffer;    // dest for reads, source for writes, new UUID for rename
00114                 S32 mOffset;    // offset into file, -1 = append (WRITE only)
00115                 S32 mBytes;             // bytes to read from file, -1 = all
00116                 S32 mBytesRead; // bytes read from file
00117 
00118                 LLPointer<Responder> mResponder;
00119         };
00120 
00121         //------------------------------------------------------------------------
00122 public:
00123         LLLFSThread(bool threaded = TRUE);
00124         ~LLLFSThread(); 
00125 
00126         // Return a Request handle
00127         handle_t read(const LLString& filename, /* Flawfinder: ignore */ 
00128                                   U8* buffer, S32 offset, S32 numbytes,
00129                                   Responder* responder, U32 pri=0);
00130         handle_t write(const LLString& filename,
00131                                    U8* buffer, S32 offset, S32 numbytes,
00132                                    Responder* responder, U32 pri=0);
00133         
00134         // Misc
00135         U32 priorityCounter() { return mPriorityCounter-- & PRIORITY_LOWBITS; } // Use to order IO operations
00136         
00137         // static initializers
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 
00142         
00143 private:
00144         U32 mPriorityCounter;
00145         
00146 public:
00147         static LLLFSThread* sLocal;             // Default local file thread
00148 };
00149 
00150 //============================================================================
00151 
00152 
00153 #endif // LL_LLLFSTHREAD_H

Generated on Thu Jul 1 06:08:48 2010 for Second Life Viewer by  doxygen 1.4.7