PageRenderTime 124ms CodeModel.GetById 59ms app.highlight 60ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llmessage/llassetstorage.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 488 lines | 329 code | 89 blank | 70 comment | 2 complexity | 6183b250f26a4a26f09e112b8a3ef6dc MD5 | raw file
  1/** 
  2 * @file llassetstorage.h
  3 * @brief definition of LLAssetStorage class which allows simple
  4 * up/downloads of uuid,type asets
  5 *
  6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLASSETSTORAGE_H
 29#define LL_LLASSETSTORAGE_H
 30
 31#include <string>
 32
 33#include "lluuid.h"
 34#include "lltimer.h"
 35#include "llnamevalue.h"
 36#include "llhost.h"
 37#include "stdenums.h" 	// for EDragAndDropType
 38#include "lltransfermanager.h" // For LLTSCode enum
 39#include "llassettype.h"
 40#include "llstring.h"
 41#include "llextendedstatus.h"
 42
 43// Forward declarations
 44class LLMessageSystem;
 45class LLXferManager;
 46class LLAssetStorage;
 47class LLVFS;
 48class LLSD;
 49
 50// anything that takes longer than this to download will abort.
 51// HTTP Uploads also timeout if they take longer than this.
 52const F32 LL_ASSET_STORAGE_TIMEOUT = 5 * 60.0f;  
 53
 54class LLAssetInfo
 55{
 56protected:
 57	std::string		mDescription;
 58	std::string		mName;
 59
 60public:
 61	LLUUID			mUuid;
 62	LLTransactionID	mTransactionID;
 63	LLUUID			mCreatorID;
 64	LLAssetType::EType	mType;
 65
 66	LLAssetInfo( void );
 67	LLAssetInfo( const LLUUID& object_id, const LLUUID& creator_id,
 68				 LLAssetType::EType type, const char* name, const char* desc );
 69	LLAssetInfo( const LLNameValue& nv );
 70	
 71	const std::string& getName( void ) const { return mName; }
 72	const std::string& getDescription( void ) const { return mDescription; } 
 73	void setName( const std::string& name );
 74	void setDescription( const std::string& desc );
 75
 76	// Assets (aka potential inventory items) can be applied to an
 77	// object in the world. We'll store that as a string name value
 78	// pair where the name encodes part of asset info, and the value
 79	// the rest.  LLAssetInfo objects will be responsible for parsing
 80	// the meaning out froman LLNameValue object. See the inventory
 81	// design docs for details.
 82	void setFromNameValue( const LLNameValue& nv );
 83};
 84
 85
 86class LLAssetRequest
 87{
 88public:
 89	LLAssetRequest(const LLUUID &uuid, const LLAssetType::EType at);
 90	virtual ~LLAssetRequest();
 91	
 92	LLUUID getUUID() const					{ return mUUID; }
 93	LLAssetType::EType getType() const		{ return mType; }
 94
 95	void setUUID(const LLUUID& id) { mUUID = id; }
 96	void setType(LLAssetType::EType type) { mType = type; }
 97	void setTimeout (F64 timeout) { mTimeout = timeout; }
 98
 99protected:
100	LLUUID	mUUID;
101	LLAssetType::EType mType;
102
103public:
104	void	(*mDownCallback)(LLVFS*, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat);
105	void	(*mUpCallback)(const LLUUID&, void *, S32, LLExtStat);
106	void	(*mInfoCallback)(LLAssetInfo *, void *, S32);
107
108	void	*mUserData;
109	LLHost  mHost;
110	BOOL	mIsTemp;
111	BOOL	mIsLocal;
112	BOOL	mIsUserWaiting;		// We don't want to try forever if a user is waiting for a result.
113	F64		mTime;				// Message system time
114	F64		mTimeout;			// Amount of time before timing out.
115	BOOL    mIsPriority;
116	BOOL	mDataSentInFirstPacket;
117	BOOL	mDataIsInVFS;
118	LLUUID	mRequestingAgentID;	// Only valid for uploads from an agent
119
120	virtual LLSD getTerseDetails() const;
121	virtual LLSD getFullDetails() const;
122};
123
124template <class T>
125struct ll_asset_request_equal : public std::equal_to<T>
126{
127	bool operator()(const T& x, const T& y) const 
128	{ 
129		return (	x->getType() == y->getType()
130				&&	x->getUUID() == y->getUUID() );
131	}
132};
133
134
135class LLInvItemRequest
136{
137public:
138	LLInvItemRequest(const LLUUID &uuid, const LLAssetType::EType at);
139	virtual ~LLInvItemRequest();
140
141	LLUUID getUUID() const					{ return mUUID; }
142	LLAssetType::EType getType() const		{ return mType; }
143
144	void setUUID(const LLUUID& id) { mUUID = id; }
145	void setType(LLAssetType::EType type) { mType = type; }
146
147protected:
148	LLUUID	mUUID;
149	LLAssetType::EType mType;
150
151public:
152	void	(*mDownCallback)(LLVFS*, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat);
153
154	void	*mUserData;
155	LLHost  mHost;
156	BOOL	mIsTemp;
157	F64		mTime;				// Message system time
158	BOOL    mIsPriority;
159	BOOL	mDataSentInFirstPacket;
160	BOOL	mDataIsInVFS;
161
162};
163
164class LLEstateAssetRequest
165{
166public:
167	LLEstateAssetRequest(const LLUUID &uuid, const LLAssetType::EType at, EstateAssetType et);
168	virtual ~LLEstateAssetRequest();
169
170	LLUUID getUUID() const					{ return mUUID; }
171	LLAssetType::EType getAType() const		{ return mAType; }
172
173	void setUUID(const LLUUID& id) { mUUID = id; }
174	void setType(LLAssetType::EType type) { mAType = type; }
175
176protected:
177	LLUUID	mUUID;
178	LLAssetType::EType mAType;
179	EstateAssetType mEstateAssetType;
180
181public:
182	void	(*mDownCallback)(LLVFS*, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat);
183
184	void	*mUserData;
185	LLHost  mHost;
186	BOOL	mIsTemp;
187	F64		mTime;				// Message system time
188	BOOL    mIsPriority;
189	BOOL	mDataSentInFirstPacket;
190	BOOL	mDataIsInVFS;
191
192};
193
194
195// Map of known bad assets
196typedef std::map<LLUUID,U64,lluuid_less> toxic_asset_map_t;
197
198typedef void (*LLGetAssetCallback)(LLVFS *vfs, const LLUUID &asset_id,
199										 LLAssetType::EType asset_type, void *user_data, S32 status, LLExtStat ext_status);
200
201class LLTempAssetStorage
202{
203public:
204	virtual ~LLTempAssetStorage() =0;
205	virtual void addTempAssetData(const LLUUID& asset_id,
206								  const LLUUID& agent_id,
207								  const std::string& host_name) = 0;
208};
209
210class LLAssetStorage : public LLTempAssetStorage
211{
212public:
213	// VFS member is public because static child methods need it :(
214	LLVFS *mVFS;
215	LLVFS *mStaticVFS;
216	typedef void (*LLStoreAssetCallback)(const LLUUID &asset_id, void *user_data, S32 status, LLExtStat ext_status);
217
218	enum ERequestType
219	{
220		RT_INVALID = -1,
221		RT_DOWNLOAD = 0,
222		RT_UPLOAD = 1,
223		RT_LOCALUPLOAD = 2,
224		RT_COUNT = 3
225	};
226
227protected:
228	BOOL mShutDown;
229	LLHost mUpstreamHost;
230	
231	LLMessageSystem *mMessageSys;
232	LLXferManager	*mXferManager;
233
234
235	typedef std::list<LLAssetRequest*> request_list_t;
236	request_list_t mPendingDownloads;
237	request_list_t mPendingUploads;
238	request_list_t mPendingLocalUploads;
239	
240	// Map of toxic assets - these caused problems when recently rezzed, so avoid them
241	toxic_asset_map_t	mToxicAssetMap;		// Objects in this list are known to cause problems and are not loaded
242
243public:
244	LLAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
245				   LLVFS *vfs, LLVFS *static_vfs, const LLHost &upstream_host);
246
247	LLAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
248				   LLVFS *vfs, LLVFS *static_vfs);
249	virtual ~LLAssetStorage();
250
251	void setUpstream(const LLHost &upstream_host);
252
253	virtual BOOL hasLocalAsset(const LLUUID &uuid, LLAssetType::EType type);
254
255	// public interface methods
256	// note that your callback may get called BEFORE the function returns
257
258	virtual void getAssetData(const LLUUID uuid, LLAssetType::EType atype, LLGetAssetCallback cb, void *user_data, BOOL is_priority = FALSE);
259
260	/*
261	 * TransactionID version
262	 * Viewer needs the store_local
263	 */
264	virtual void storeAssetData(
265		const LLTransactionID& tid,
266		LLAssetType::EType atype,
267		LLStoreAssetCallback callback,
268		void* user_data,
269		bool temp_file = false,
270		bool is_priority = false,
271		bool store_local = false,
272		bool user_waiting= false,
273		F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
274
275	/*
276	 * AssetID version
277	 * Sim needs both store_local and requesting_agent_id.
278	 */
279	virtual	void storeAssetData(
280		const LLUUID& asset_id,
281		LLAssetType::EType asset_type,
282		LLStoreAssetCallback callback,
283		void* user_data,
284		bool temp_file = false,
285		bool is_priority = false,
286		bool store_local = false,
287		const LLUUID& requesting_agent_id = LLUUID::null,
288		bool user_waiting= false,
289		F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
290
291	virtual void checkForTimeouts();
292
293	void getEstateAsset(const LLHost &object_sim, const LLUUID &agent_id, const LLUUID &session_id,
294									const LLUUID &asset_id, LLAssetType::EType atype, EstateAssetType etype,
295									 LLGetAssetCallback callback, void *user_data, BOOL is_priority);
296
297	void getInvItemAsset(const LLHost &object_sim,
298						 const LLUUID &agent_id, const LLUUID &session_id,
299						 const LLUUID &owner_id, const LLUUID &task_id, const LLUUID &item_id,
300						 const LLUUID &asset_id, LLAssetType::EType atype,
301						 LLGetAssetCallback cb, void *user_data, BOOL is_priority = FALSE); // Get a particular inventory item.
302
303	// Check if an asset is in the toxic map.  If it is, the entry is updated
304	BOOL		isAssetToxic( const LLUUID& uuid );
305
306	// Clean the toxic asset list, remove old entries
307	void		flushOldToxicAssets( BOOL force_it );
308
309	// Add an item to the toxic asset map
310	void		markAssetToxic( const LLUUID& uuid );
311
312protected:
313	bool findInStaticVFSAndInvokeCallback(const LLUUID& uuid, LLAssetType::EType type,
314										  LLGetAssetCallback callback, void *user_data);
315
316	virtual LLSD getPendingDetailsImpl(const request_list_t* requests,
317	 				LLAssetType::EType asset_type,
318	 				const std::string& detail_prefix) const;
319
320	virtual LLSD getPendingRequestImpl(const request_list_t* requests,
321							LLAssetType::EType asset_type,
322							const LLUUID& asset_id) const;
323
324	virtual bool deletePendingRequestImpl(request_list_t* requests,
325							LLAssetType::EType asset_type,
326							const LLUUID& asset_id);
327
328public:
329	static const LLAssetRequest* findRequest(const request_list_t* requests,
330										LLAssetType::EType asset_type,
331										const LLUUID& asset_id);
332	static LLAssetRequest* findRequest(request_list_t* requests,
333										LLAssetType::EType asset_type,
334										const LLUUID& asset_id);
335
336	request_list_t* getRequestList(ERequestType rt);
337	const request_list_t* getRequestList(ERequestType rt) const;
338	static std::string getRequestName(ERequestType rt);
339
340	S32 getNumPendingDownloads() const;
341	S32 getNumPendingUploads() const;
342	S32 getNumPendingLocalUploads();
343	S32 getNumPending(ERequestType rt) const;
344
345	virtual LLSD getPendingDetails(ERequestType rt,
346	 				LLAssetType::EType asset_type,
347	 				const std::string& detail_prefix) const;
348
349	virtual LLSD getPendingRequest(ERequestType rt,
350							LLAssetType::EType asset_type,
351							const LLUUID& asset_id) const;
352
353	virtual bool deletePendingRequest(ERequestType rt,
354							LLAssetType::EType asset_type,
355							const LLUUID& asset_id);
356
357
358	// download process callbacks
359	static void downloadCompleteCallback(
360		S32 result,
361		const LLUUID& file_id,
362		LLAssetType::EType file_type,
363		void* user_data, LLExtStat ext_status);
364	static void downloadEstateAssetCompleteCallback(
365		S32 result,
366		const LLUUID& file_id,
367		LLAssetType::EType file_type,
368		void* user_data, LLExtStat ext_status);
369	static void downloadInvItemCompleteCallback(
370		S32 result,
371		const LLUUID& file_id,
372		LLAssetType::EType file_type,
373		void* user_data, LLExtStat ext_status);
374
375	// upload process callbacks
376	static void uploadCompleteCallback(const LLUUID&, void *user_data, S32 result, LLExtStat ext_status);
377	static void processUploadComplete(LLMessageSystem *msg, void **this_handle);
378
379	// debugging
380	static const char* getErrorString( S32 status );
381
382	// deprecated file-based methods
383	void getAssetData(const LLUUID uuid, LLAssetType::EType type, void (*callback)(const char*, const LLUUID&, void *, S32, LLExtStat), void *user_data, BOOL is_priority = FALSE);
384
385	/*
386	 * AssetID version.
387	 */
388	virtual void storeAssetData(
389		const std::string& filename,
390		const LLUUID& asset_id,
391		LLAssetType::EType type,
392		LLStoreAssetCallback callback,
393		void* user_data,
394		bool temp_file = false,
395		bool is_priority = false,
396		bool user_waiting = false,
397		F64 timeout  = LL_ASSET_STORAGE_TIMEOUT);
398
399	/*
400	 * TransactionID version
401	 */
402	virtual void storeAssetData(
403		const std::string& filename,
404		const LLTransactionID &transaction_id,
405		LLAssetType::EType type,
406		LLStoreAssetCallback callback,
407		void *user_data,
408		bool temp_file = false,
409		bool is_priority = false,
410		bool user_waiting = false,
411		F64 timeout  = LL_ASSET_STORAGE_TIMEOUT);
412
413	static void legacyGetDataCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::EType, void *user_data, S32 status, LLExtStat ext_status);
414	static void legacyStoreDataCallback(const LLUUID &uuid, void *user_data, S32 status, LLExtStat ext_status);
415
416	// Temp assets are stored on sim nodes, they have agent ID and location data associated with them.
417	// This is a no-op for non-http asset systems
418	virtual void addTempAssetData(const LLUUID& asset_id, const LLUUID& agent_id, const std::string& host_name);
419	virtual BOOL hasTempAssetData(const LLUUID& texture_id) const;
420	virtual std::string getTempAssetHostName(const LLUUID& texture_id) const;
421	virtual LLUUID getTempAssetAgentID(const LLUUID& texture_id) const;
422	virtual void removeTempAssetData(const LLUUID& asset_id);
423	virtual void removeTempAssetDataByAgentID(const LLUUID& agent_id);
424	// Pass LLUUID::null for all
425	virtual void dumpTempAssetData(const LLUUID& avatar_id) const;
426	virtual void clearTempAssetData();
427
428	// add extra methods to handle metadata
429
430protected:
431	void _cleanupRequests(BOOL all, S32 error);
432	void _callUploadCallbacks(const LLUUID &uuid, const LLAssetType::EType asset_type, BOOL success, LLExtStat ext_status);
433
434	virtual void _queueDataRequest(const LLUUID& uuid, LLAssetType::EType type,
435								   void (*callback)(LLVFS *vfs, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat),
436								   void *user_data, BOOL duplicate,
437								   BOOL is_priority);
438
439private:
440	void _init(LLMessageSystem *msg,
441			   LLXferManager *xfer,
442			   LLVFS *vfs,
443			   LLVFS *static_vfs,
444			   const LLHost &upstream_host);
445
446protected:
447	enum EMetricResult
448	{
449		// Static valued enums for #dw readability - please copy this
450		// declaration to them on updates -- source in llassetstorage.h
451		MR_INVALID			= -1,	// Makes no sense
452		MR_OKAY				= 0,	// Success - no metric normally
453		MR_ZERO_SIZE		= 1,	// Zero size asset
454		MR_BAD_FUNCTION		= 2,	// Tried to use a virtual base (PROGRAMMER ERROR)
455		MR_FILE_NONEXIST	= 3,	// Old format store call - source file does not exist
456		MR_NO_FILENAME		= 4,	// Old format store call - source filename is NULL/0-length
457		MR_NO_UPSTREAM		= 5,	// Upstream provider is missing
458		MR_VFS_CORRUPTION	= 6		// VFS is corrupt - too-large or mismatched stated/returned sizes
459	};
460
461	static class LLMetrics *metric_recipient;
462
463	static void reportMetric( const LLUUID& asset_id, const LLAssetType::EType asset_type, const std::string& filename,
464							  const LLUUID& agent_id, S32 asset_size, EMetricResult result,
465							  const char* file, const S32 line, const std::string& message ); 
466public:
467	static void setMetricRecipient( LLMetrics *recip )
468	{
469		metric_recipient = recip;
470	}
471};
472
473////////////////////////////////////////////////////////////////////////
474// Wrappers to replicate deprecated API
475////////////////////////////////////////////////////////////////////////
476
477class LLLegacyAssetRequest
478{
479public:
480	void	(*mDownCallback)(const char *, const LLUUID&, void *, S32, LLExtStat);
481	LLAssetStorage::LLStoreAssetCallback mUpCallback;
482
483	void	*mUserData;
484};
485
486extern LLAssetStorage *gAssetStorage;
487extern const LLUUID CATEGORIZE_LOST_AND_FOUND_ID;
488#endif