PageRenderTime 23ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llinventory/llinventory.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 298 lines | 154 code | 30 blank | 114 comment | 0 complexity | 53e09e2ef656bd2eb5e13866d8a05c9d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llinventory.h
  3. * @brief LLInventoryItem and LLInventoryCategory class declaration.
  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. #ifndef LL_LLINVENTORY_H
  27. #define LL_LLINVENTORY_H
  28. #include "lldarray.h"
  29. #include "llfoldertype.h"
  30. #include "llinventorytype.h"
  31. #include "llmemtype.h"
  32. #include "llpermissions.h"
  33. #include "llrefcount.h"
  34. #include "llsaleinfo.h"
  35. #include "llsd.h"
  36. #include "lluuid.h"
  37. class LLMessageSystem;
  38. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. // Class LLInventoryObject
  40. //
  41. // Base class for anything in the user's inventory. Handles the common code
  42. // between items and categories.
  43. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. class LLInventoryObject : public LLRefCount
  45. {
  46. public:
  47. typedef std::list<LLPointer<LLInventoryObject> > object_list_t;
  48. //--------------------------------------------------------------------
  49. // Initialization
  50. //--------------------------------------------------------------------
  51. public:
  52. MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
  53. LLInventoryObject();
  54. LLInventoryObject(const LLUUID& uuid,
  55. const LLUUID& parent_uuid,
  56. LLAssetType::EType type,
  57. const std::string& name);
  58. void copyObject(const LLInventoryObject* other); // LLRefCount requires custom copy
  59. protected:
  60. virtual ~LLInventoryObject();
  61. //--------------------------------------------------------------------
  62. // Accessors
  63. //--------------------------------------------------------------------
  64. public:
  65. virtual const LLUUID& getUUID() const; // inventoryID that this item points to
  66. virtual const LLUUID& getLinkedUUID() const; // inventoryID that this item points to, else this item's inventoryID
  67. const LLUUID& getParentUUID() const;
  68. virtual const std::string& getName() const;
  69. virtual LLAssetType::EType getType() const;
  70. LLAssetType::EType getActualType() const; // bypasses indirection for linked items
  71. BOOL getIsLinkType() const;
  72. //--------------------------------------------------------------------
  73. // Mutators
  74. // Will not call updateServer
  75. //--------------------------------------------------------------------
  76. public:
  77. void setUUID(const LLUUID& new_uuid);
  78. virtual void rename(const std::string& new_name);
  79. void setParent(const LLUUID& new_parent);
  80. void setType(LLAssetType::EType type);
  81. private:
  82. // in place correction for inventory name string
  83. void correctInventoryName(std::string& name);
  84. //--------------------------------------------------------------------
  85. // File Support
  86. // Implemented here so that a minimal information set can be transmitted
  87. // between simulator and viewer.
  88. //--------------------------------------------------------------------
  89. public:
  90. // virtual BOOL importFile(LLFILE* fp);
  91. virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
  92. virtual BOOL importLegacyStream(std::istream& input_stream);
  93. virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
  94. virtual void removeFromServer();
  95. virtual void updateParentOnServer(BOOL) const;
  96. virtual void updateServer(BOOL) const;
  97. //--------------------------------------------------------------------
  98. // Member Variables
  99. //--------------------------------------------------------------------
  100. protected:
  101. LLUUID mUUID;
  102. LLUUID mParentUUID; // Parent category. Root categories have LLUUID::NULL.
  103. LLAssetType::EType mType;
  104. std::string mName;
  105. };
  106. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. // Class LLInventoryItem
  108. //
  109. // An item in the current user's inventory.
  110. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. class LLInventoryItem : public LLInventoryObject
  112. {
  113. public:
  114. typedef LLDynamicArray<LLPointer<LLInventoryItem> > item_array_t;
  115. //--------------------------------------------------------------------
  116. // Initialization
  117. //--------------------------------------------------------------------
  118. public:
  119. MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
  120. LLInventoryItem(const LLUUID& uuid,
  121. const LLUUID& parent_uuid,
  122. const LLPermissions& permissions,
  123. const LLUUID& asset_uuid,
  124. LLAssetType::EType type,
  125. LLInventoryType::EType inv_type,
  126. const std::string& name,
  127. const std::string& desc,
  128. const LLSaleInfo& sale_info,
  129. U32 flags,
  130. S32 creation_date_utc);
  131. LLInventoryItem();
  132. // Create a copy of an inventory item from a pointer to another item
  133. // Note: Because InventoryItems are ref counted, reference copy (a = b)
  134. // is prohibited
  135. LLInventoryItem(const LLInventoryItem* other);
  136. virtual void copyItem(const LLInventoryItem* other); // LLRefCount requires custom copy
  137. void generateUUID() { mUUID.generate(); }
  138. protected:
  139. ~LLInventoryItem(); // ref counted
  140. //--------------------------------------------------------------------
  141. // Accessors
  142. //--------------------------------------------------------------------
  143. public:
  144. virtual const LLUUID& getLinkedUUID() const;
  145. virtual const LLPermissions& getPermissions() const;
  146. virtual const LLUUID& getCreatorUUID() const;
  147. virtual const LLUUID& getAssetUUID() const;
  148. virtual const std::string& getDescription() const;
  149. virtual const LLSaleInfo& getSaleInfo() const;
  150. virtual LLInventoryType::EType getInventoryType() const;
  151. virtual U32 getFlags() const;
  152. virtual time_t getCreationDate() const;
  153. virtual U32 getCRC32() const; // really more of a checksum.
  154. //--------------------------------------------------------------------
  155. // Mutators
  156. // Will not call updateServer and will never fail
  157. // (though it may correct to sane values)
  158. //--------------------------------------------------------------------
  159. public:
  160. void setAssetUUID(const LLUUID& asset_id);
  161. void setDescription(const std::string& new_desc);
  162. void setSaleInfo(const LLSaleInfo& sale_info);
  163. void setPermissions(const LLPermissions& perm);
  164. void setInventoryType(LLInventoryType::EType inv_type);
  165. void setFlags(U32 flags);
  166. void setCreationDate(time_t creation_date_utc);
  167. void setCreator(const LLUUID& creator); // only used for calling cards
  168. // Check for changes in permissions masks and sale info
  169. // and set the corresponding bits in mFlags.
  170. void accumulatePermissionSlamBits(const LLInventoryItem& old_item);
  171. // Put this inventory item onto the current outgoing mesage.
  172. // Assumes you have already called nextBlock().
  173. virtual void packMessage(LLMessageSystem* msg) const;
  174. // Returns TRUE if the inventory item came through the network correctly.
  175. // Uses a simple crc check which is defeatable, but we want to detect
  176. // network mangling somehow.
  177. virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
  178. //--------------------------------------------------------------------
  179. // File Support
  180. //--------------------------------------------------------------------
  181. public:
  182. virtual BOOL importFile(LLFILE* fp);
  183. virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
  184. virtual BOOL importLegacyStream(std::istream& input_stream);
  185. virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
  186. //--------------------------------------------------------------------
  187. // Helper Functions
  188. //--------------------------------------------------------------------
  189. public:
  190. // Pack all information needed to reconstruct this item into the given binary bucket.
  191. S32 packBinaryBucket(U8* bin_bucket, LLPermissions* perm_override = NULL) const;
  192. void unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size);
  193. LLSD asLLSD() const;
  194. void asLLSD( LLSD& sd ) const;
  195. bool fromLLSD(const LLSD& sd);
  196. //--------------------------------------------------------------------
  197. // Member Variables
  198. //--------------------------------------------------------------------
  199. protected:
  200. LLPermissions mPermissions;
  201. LLUUID mAssetUUID;
  202. std::string mDescription;
  203. LLSaleInfo mSaleInfo;
  204. LLInventoryType::EType mInventoryType;
  205. U32 mFlags;
  206. time_t mCreationDate; // seconds from 1/1/1970, UTC
  207. };
  208. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. // Class LLInventoryCategory
  210. //
  211. // A category/folder of inventory items. Users come with a set of default
  212. // categories, and can create new ones as needed.
  213. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  214. class LLInventoryCategory : public LLInventoryObject
  215. {
  216. public:
  217. typedef LLDynamicArray<LLPointer<LLInventoryCategory> > cat_array_t;
  218. //--------------------------------------------------------------------
  219. // Initialization
  220. //--------------------------------------------------------------------
  221. public:
  222. MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
  223. LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
  224. LLFolderType::EType preferred_type,
  225. const std::string& name);
  226. LLInventoryCategory();
  227. LLInventoryCategory(const LLInventoryCategory* other);
  228. void copyCategory(const LLInventoryCategory* other); // LLRefCount requires custom copy
  229. protected:
  230. ~LLInventoryCategory();
  231. //--------------------------------------------------------------------
  232. // Accessors And Mutators
  233. //--------------------------------------------------------------------
  234. public:
  235. LLFolderType::EType getPreferredType() const;
  236. void setPreferredType(LLFolderType::EType type);
  237. LLSD asLLSD() const;
  238. bool fromLLSD(const LLSD& sd);
  239. //--------------------------------------------------------------------
  240. // Messaging
  241. //--------------------------------------------------------------------
  242. public:
  243. virtual void packMessage(LLMessageSystem* msg) const;
  244. virtual void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
  245. //--------------------------------------------------------------------
  246. // File Support
  247. //--------------------------------------------------------------------
  248. public:
  249. virtual BOOL importFile(LLFILE* fp);
  250. virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
  251. virtual BOOL importLegacyStream(std::istream& input_stream);
  252. virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
  253. //--------------------------------------------------------------------
  254. // Member Variables
  255. //--------------------------------------------------------------------
  256. protected:
  257. LLFolderType::EType mPreferredType; // Type that this category was "meant" to hold (although it may hold any type).
  258. };
  259. //-----------------------------------------------------------------------------
  260. // Convertors
  261. //
  262. // These functions convert between structured data and an inventory
  263. // item, appropriate for serialization.
  264. //-----------------------------------------------------------------------------
  265. LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item);
  266. LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat);
  267. LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat);
  268. #endif // LL_LLINVENTORY_H