PageRenderTime 42ms CodeModel.GetById 16ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llvfs/llvfsthread.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 142 lines | 84 code | 23 blank | 35 comment | 0 complexity | d89ef4ed1445234ed2b1f37311e208d7 MD5 | raw file
  1/** 
  2 * @file llvfsthread.h
  3 * @brief LLVFSThread definition
  4 *
  5 * $LicenseInfo:firstyear=2001&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_LLVFSTHREAD_H
 28#define LL_LLVFSTHREAD_H
 29
 30#include <queue>
 31#include <string>
 32#include <map>
 33#include <set>
 34
 35#include "llapr.h"
 36
 37#include "llqueuedthread.h"
 38
 39#include "llvfs.h"
 40
 41//============================================================================
 42
 43class LLVFSThread : public LLQueuedThread
 44{
 45	//------------------------------------------------------------------------
 46public:
 47	enum operation_t {
 48		FILE_READ,
 49		FILE_WRITE,
 50		FILE_RENAME
 51	};
 52
 53	//------------------------------------------------------------------------
 54public:
 55
 56	class Request : public QueuedRequest
 57	{
 58	protected:
 59		~Request() {}; // use deleteRequest()
 60		
 61	public:
 62		Request(handle_t handle, U32 priority, U32 flags,
 63				operation_t op, LLVFS* vfs,
 64				const LLUUID &file_id, const LLAssetType::EType file_type,
 65				U8* buffer, S32 offset, S32 numbytes);
 66
 67		S32 getBytesRead()
 68		{
 69			return mBytesRead;
 70		}
 71		S32 getOperation()
 72		{
 73			return mOperation;
 74		}
 75		U8* getBuffer()
 76		{
 77			return mBuffer;
 78		}
 79		LLVFS* getVFS()
 80		{
 81			return mVFS;
 82		}
 83		std::string getFilename()
 84		{
 85			std::string tstring;
 86			mFileID.toString(tstring);
 87			return tstring;
 88		}
 89		
 90		/*virtual*/ bool processRequest();
 91		/*virtual*/ void finishRequest(bool completed);
 92		/*virtual*/ void deleteRequest();
 93		
 94	private:
 95		operation_t mOperation;
 96		
 97		LLVFS* mVFS;
 98		LLUUID mFileID;
 99		LLAssetType::EType mFileType;
100		
101		U8* mBuffer;	// dest for reads, source for writes, new UUID for rename
102		S32 mOffset;	// offset into file, -1 = append (WRITE only)
103		S32 mBytes;		// bytes to read from file, -1 = all (new mFileType for rename)
104		S32	mBytesRead;	// bytes read from file
105	};
106
107	//------------------------------------------------------------------------
108public:
109	static std::string sDataPath;
110	static LLVFSThread* sLocal;		// Default worker thread
111	
112public:
113	LLVFSThread(bool threaded = TRUE);
114	~LLVFSThread();	
115
116	// Return a Request handle
117	handle_t read(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,	/* Flawfinder: ignore */
118				  U8* buffer, S32 offset, S32 numbytes, U32 pri=PRIORITY_NORMAL, U32 flags = 0);
119	handle_t write(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
120				   U8* buffer, S32 offset, S32 numbytes, U32 flags);
121	// SJB: rename seems to have issues, especially when threaded
122// 	handle_t rename(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
123// 					const LLUUID &new_id, const LLAssetType::EType new_type, U32 flags);
124	// Return number of bytes read
125	S32 readImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
126					  U8* buffer, S32 offset, S32 numbytes);
127	S32 writeImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
128					   U8* buffer, S32 offset, S32 numbytes);
129
130	/*virtual*/ bool processRequest(QueuedRequest* req);
131
132public:
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	static void setDataPath(const std::string& path) { sDataPath = path; }
137};
138
139//============================================================================
140
141
142#endif // LL_LLVFSTHREAD_H