PageRenderTime 29ms CodeModel.GetById 18ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llvfs/lllfsthread.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 148 lines | 88 code | 25 blank | 35 comment | 0 complexity | c1d930feb263ebbaa45dea8ba39bc14a MD5 | raw file
  1/** 
  2 * @file lllfsthread.h
  3 * @brief LLLFSThread base class
  4 *
  5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLLFSTHREAD_H
 28#define LL_LLLFSTHREAD_H
 29
 30#include <queue>
 31#include <string>
 32#include <map>
 33#include <set>
 34
 35#include "llapr.h"
 36#include "llpointer.h"
 37#include "llqueuedthread.h"
 38
 39//============================================================================
 40// Threaded Local File System
 41//============================================================================
 42
 43class LLLFSThread : public LLQueuedThread
 44{
 45	//------------------------------------------------------------------------
 46public:
 47	enum operation_t {
 48		FILE_READ,
 49		FILE_WRITE,
 50		FILE_RENAME,
 51		FILE_REMOVE
 52	};
 53
 54	//------------------------------------------------------------------------
 55public:
 56
 57	class Responder : public LLThreadSafeRefCount
 58	{
 59	protected:
 60		~Responder();
 61	public:
 62		virtual void completed(S32 bytes) = 0;
 63	};
 64
 65	class Request : public QueuedRequest
 66	{
 67	protected:
 68		virtual ~Request(); // use deleteRequest()
 69		
 70	public:
 71		Request(LLLFSThread* thread,
 72				handle_t handle, U32 priority, 
 73				operation_t op, const std::string& filename,
 74				U8* buffer, S32 offset, S32 numbytes,
 75				Responder* responder);
 76
 77		S32 getBytes()
 78		{
 79			return mBytes;
 80		}
 81		S32 getBytesRead()
 82		{
 83			return mBytesRead;
 84		}
 85		S32 getOperation()
 86		{
 87			return mOperation;
 88		}
 89		U8* getBuffer()
 90		{
 91			return mBuffer;
 92		}
 93		const std::string& getFilename()
 94		{
 95			return mFileName;
 96		}
 97		
 98		/*virtual*/ bool processRequest();
 99		/*virtual*/ void finishRequest(bool completed);
100		/*virtual*/ void deleteRequest();
101		
102	private:
103		LLLFSThread* mThread;
104		operation_t mOperation;
105		
106		std::string mFileName;
107		
108		U8* mBuffer;	// dest for reads, source for writes, new UUID for rename
109		S32 mOffset;	// offset into file, -1 = append (WRITE only)
110		S32 mBytes;		// bytes to read from file, -1 = all
111		S32 mBytesRead;	// bytes read from file
112
113		LLPointer<Responder> mResponder;
114	};
115
116	//------------------------------------------------------------------------
117public:
118	LLLFSThread(bool threaded = TRUE);
119	~LLLFSThread();	
120
121	// Return a Request handle
122	handle_t read(const std::string& filename,	/* Flawfinder: ignore */ 
123				  U8* buffer, S32 offset, S32 numbytes,
124				  Responder* responder, U32 pri=0);
125	handle_t write(const std::string& filename,
126				   U8* buffer, S32 offset, S32 numbytes,
127				   Responder* responder, U32 pri=0);
128	
129	// Misc
130	U32 priorityCounter() { return mPriorityCounter-- & PRIORITY_LOWBITS; } // Use to order IO operations
131	
132	// static initializers
133	static void initClass(bool local_is_threaded = TRUE); // Setup sLocal
134	static S32 updateClass(U32 ms_elapsed);
135	static void cleanupClass();		// Delete sLocal
136
137	
138private:
139	U32 mPriorityCounter;
140	
141public:
142	static LLLFSThread* sLocal;		// Default local file thread
143};
144
145//============================================================================
146
147
148#endif // LL_LLLFSTHREAD_H