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