llinventory.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLINVENTORY_H
00033 #define LL_LLINVENTORY_H
00034 
00035 #include <functional>
00036 
00037 #include "llassetstorage.h"
00038 #include "lldarray.h"
00039 #include "llinventorytype.h"
00040 #include "llmemtype.h"
00041 #include "llpermissions.h"
00042 #include "llsaleinfo.h"
00043 #include "llsd.h"
00044 #include "lluuid.h"
00045 #include "llxmlnode.h"
00046 
00047 // consts for Key field in the task inventory update message
00048 extern const U8 TASK_INVENTORY_ITEM_KEY;
00049 extern const U8 TASK_INVENTORY_ASSET_KEY;
00050 
00051 // anonymous enumeration to specify a max inventory buffer size for
00052 // use in packBinaryBucket()
00053 enum
00054 {
00055         MAX_INVENTORY_BUFFER_SIZE = 1024
00056 };
00057 
00058 
00059 
00060 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00061 // Class LLInventoryObject
00062 //
00063 // This is the base class for inventory objects that handles the
00064 // common code between items and categories. The 'mParentUUID' member
00065 // means the parent category since all inventory objects except each
00066 // user's root category are in some category. Each user's root
00067 // category will have mParentUUID==LLUUID::null.
00068 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00069 
00070 class LLMessageSystem;
00071 
00072 class LLInventoryObject : public LLRefCount
00073 {
00074 protected:
00075         LLUUID mUUID;
00076         LLUUID mParentUUID;
00077         LLAssetType::EType mType;
00078         LLString mName;
00079 
00080 protected:
00081         virtual ~LLInventoryObject( void );
00082         
00083 public:
00084         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00085         LLInventoryObject(const LLUUID& uuid, const LLUUID& parent_uuid,
00086                                           LLAssetType::EType type, const LLString& name);
00087         LLInventoryObject();
00088         void copyObject(const LLInventoryObject* other); // LLRefCount requires custom copy
00089 
00090         // accessors
00091         const LLUUID& getUUID() const;
00092         const LLUUID& getParentUUID() const;
00093         const LLString& getName() const;
00094         LLAssetType::EType getType() const;
00095 
00096         // mutators - will not call updateServer();
00097         void setUUID(const LLUUID& new_uuid);
00098         void rename(const LLString& new_name);
00099         void setParent(const LLUUID& new_parent);
00100         void setType(LLAssetType::EType type);
00101 
00102         // file support - implemented here so that a minimal information
00103         // set can be transmitted between simulator and viewer.
00104 //      virtual BOOL importFile(LLFILE* fp);
00105         virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
00106 
00107         virtual BOOL importLegacyStream(std::istream& input_stream);
00108         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00109 
00110         // virtual methods
00111         virtual void removeFromServer();
00112         virtual void updateParentOnServer(BOOL) const;
00113         virtual void updateServer(BOOL) const;
00114 };
00115 
00116 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00117 // Class LLInventoryItem
00118 //
00119 // An inventory item represents something that the current user has in
00120 // their inventory.
00121 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00122 
00123 class LLInventoryItem : public LLInventoryObject
00124 {
00125 public:
00126         typedef LLDynamicArray<LLPointer<LLInventoryItem> > item_array_t;
00127         
00128 protected:
00129         LLPermissions mPermissions;
00130         LLUUID mAssetUUID;
00131         LLString mDescription;
00132         LLSaleInfo mSaleInfo;
00133         LLInventoryType::EType mInventoryType;
00134         U32 mFlags;
00135         S32 mCreationDate;      // seconds from 1/1/1970, UTC
00136 
00137 public:
00138 
00142         enum
00143         {
00144                 // The shared flags at the top are shared among all inventory
00145                 // types. After that section, all values of flags are type
00146                 // dependent.  The shared flags will start at 2^30 and work
00147                 // down while item type specific flags will start at 2^0 and
00148                 // work up.
00149                 II_FLAGS_NONE = 0,
00150 
00151 
00152                 //
00153                 // Shared flags
00154                 //
00155                 //
00156 
00157                 // This value means that the asset has only one reference in
00158                 // the system. If the inventory item is deleted, or the asset
00159                 // id updated, then we can remove the old reference.
00160                 II_FLAGS_SHARED_SINGLE_REFERENCE = 0x40000000,
00161 
00162 
00163                 //
00164                 // Landmark flags
00165                 //
00166                 II_FLAGS_LANDMARK_VISITED = 1,
00167 
00168                 //
00169                 // Object flags
00170                 //
00171 
00172                 // flag to indicate that object permissions should have next
00173                 // owner perm be more restrictive on rez. We bump this into
00174                 // the second byte of the flags since the low byte is used to
00175                 // track attachment points.
00176                 II_FLAGS_OBJECT_SLAM_PERM = 0x100,
00177 
00178                 // flag to indicate that the object sale information has been changed.
00179                 II_FLAGS_OBJECT_SLAM_SALE = 0x1000,
00180 
00181                 // These flags specify which permissions masks to overwrite
00182                 // upon rez.  Normally, if no permissions slam (above) or
00183                 // overwrite flags are set, the asset's permissions are
00184                 // used and the inventory's permissions are ignored.  If
00185                 // any of these flags are set, the inventory's permissions
00186                 // take precedence.
00187                 II_FLAGS_OBJECT_PERM_OVERWRITE_BASE                     = 0x010000,
00188                 II_FLAGS_OBJECT_PERM_OVERWRITE_OWNER            = 0x020000,
00189                 II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP            = 0x040000,
00190                 II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE         = 0x080000,
00191                 II_FLAGS_OBJECT_PERM_OVERWRITE_NEXT_OWNER       = 0x100000,
00192 
00193                 // flag to indicate whether an object that is returned is composed 
00194                 // of muiltiple items or not.
00195                 II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS                      = 0x200000,
00196 
00197                 //
00198                 // wearables use the low order byte of flags to store the
00199                 // EWearableType enumeration found in newview/llwearable.h
00200                 //
00201                 II_FLAGS_WEARABLES_MASK = 0xff,
00202         };
00203 
00204 protected:
00205         ~LLInventoryItem(); // ref counted
00206 
00207 public:
00208         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00209         LLInventoryItem(const LLUUID& uuid,
00210                                         const LLUUID& parent_uuid,
00211                                         const LLPermissions& permissions,
00212                                         const LLUUID& asset_uuid,
00213                                         LLAssetType::EType type,
00214                                         LLInventoryType::EType inv_type,
00215                                         const LLString& name, 
00216                                         const LLString& desc,
00217                                         const LLSaleInfo& sale_info,
00218                                         U32 flags,
00219                                         S32 creation_date_utc);
00220         LLInventoryItem();
00221         // Create a copy of an inventory item from a pointer to another item
00222         // Note: Because InventoryItems are ref counted, reference copy (a = b)
00223         // is prohibited
00224         LLInventoryItem(const LLInventoryItem* other);
00225         virtual void copyItem(const LLInventoryItem* other); // LLRefCount requires custom copy
00226 
00227         // As a constructor alternative, the clone() method works like a
00228         // copy constructor, but gens a new UUID.
00229         // It is up to the caller to delete (unref) the item.
00230         virtual void cloneItem(LLPointer<LLInventoryItem>& newitem) const;
00231         
00232         // accessors
00233         const LLPermissions& getPermissions() const;
00234         const LLUUID& getCreatorUUID() const;
00235         const LLUUID& getAssetUUID() const;
00236         const LLString& getDescription() const;
00237         const LLSaleInfo& getSaleInfo() const;
00238         LLInventoryType::EType getInventoryType() const;
00239         U32 getFlags() const;
00240         S32 getCreationDate() const;
00241         U32 getCRC32() const; // really more of a checksum.
00242         
00243         // mutators - will not call updateServer(), and will never fail
00244         // (though it may correct to sane values)
00245         void setAssetUUID(const LLUUID& asset_id);
00246         void setDescription(const LLString& new_desc);
00247         void setSaleInfo(const LLSaleInfo& sale_info);
00248         void setPermissions(const LLPermissions& perm);
00249         void setInventoryType(LLInventoryType::EType inv_type);
00250         void setFlags(U32 flags);
00251         void setCreationDate(S32 creation_date_utc);
00252 
00253         // Put this inventory item onto the current outgoing mesage. It
00254         // assumes you have already called nextBlock().
00255         virtual void packMessage(LLMessageSystem* msg) const;
00256 
00257         // unpack returns TRUE if the inventory item came through the
00258         // network ok. It uses a simple crc check which is defeatable, but
00259         // we want to detect network mangling somehow.
00260         virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
00261         // file support
00262         virtual BOOL importFile(LLFILE* fp);
00263         virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
00264 
00265         virtual BOOL importLegacyStream(std::istream& input_stream);
00266         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00267 
00268         virtual LLXMLNode *exportFileXML(BOOL include_asset_key = TRUE) const;
00269         BOOL importXML(LLXMLNode* node);
00270 
00271         // helper functions
00272 
00273         // pack all information needed to reconstruct this item into the given binary bucket.
00274         // perm_override is optional
00275         S32 packBinaryBucket(U8* bin_bucket, LLPermissions* perm_override = NULL) const;
00276         void unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size);
00277         LLSD asLLSD() const;
00278         bool fromLLSD(LLSD& sd);
00279 
00280 };
00281 
00282 BOOL item_dictionary_sort(LLInventoryItem* a,LLInventoryItem* b);
00283 BOOL item_date_sort(LLInventoryItem* a, LLInventoryItem* b);
00284 
00285 
00286 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00287 // Class LLInventoryCategory
00288 //
00289 // An instance of this class represents a category of inventory
00290 // items. Users come with a set of default categories, and can create
00291 // new ones as needed.
00292 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00293 
00294 class LLInventoryCategory : public LLInventoryObject
00295 {
00296 public:
00297         typedef LLDynamicArray<LLPointer<LLInventoryCategory> > cat_array_t;
00298 
00299 protected:
00300         ~LLInventoryCategory();
00301         
00302 public:
00303         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00304         LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
00305                                                 LLAssetType::EType preferred_type,
00306                                                 const LLString& name);
00307         LLInventoryCategory();
00308         LLInventoryCategory(const LLInventoryCategory* other);
00309         void copyCategory(const LLInventoryCategory* other); // LLRefCount requires custom copy
00310 
00311         // accessors and mutators
00312         LLAssetType::EType getPreferredType() const;
00313         void setPreferredType(LLAssetType::EType type);
00314         // For messaging system support
00315         virtual void packMessage(LLMessageSystem* msg) const;
00316         virtual void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
00317 
00318         LLSD asLLSD() const;
00319         bool fromLLSD(LLSD& sd);
00320 
00321         // file support
00322         virtual BOOL importFile(LLFILE* fp);
00323         virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
00324 
00325         virtual BOOL importLegacyStream(std::istream& input_stream);
00326         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00327 
00328 protected:
00329         // The type of asset that this category was "meant" to hold
00330         // (although it may in fact hold any type).
00331         LLAssetType::EType      mPreferredType;         
00332 
00333 };
00334 
00335 
00336 //-----------------------------------------------------------------------------
00337 // Useful bits
00338 //-----------------------------------------------------------------------------
00339 
00340 // This functor tests if an item is transferrable and returns true if
00341 // it is. Derived from unary_function<> so that the object can be used
00342 // in stl-compliant adaptable predicates (eg, not1<>). You might want
00343 // to use this in std::partition() or similar logic.
00344 struct IsItemTransferable : public std::unary_function<LLInventoryItem*, bool>
00345 {
00346         LLUUID mDestID;
00347         IsItemTransferable(const LLUUID& dest_id) : mDestID(dest_id) {}
00348         bool operator()(const LLInventoryItem* item) const
00349         {
00350                 return (item->getPermissions().allowTransferTo(mDestID)) ? true:false;
00351         }
00352 };
00353 
00354 // This functor is used to set the owner and group of inventory items,
00355 // for example, in a simple std::for_each() loop. Note that the call
00356 // to setOwnerAndGroup can fail if authority_id != LLUUID::null.
00357 struct SetItemOwnerAndGroup
00358 {
00359         LLUUID mAuthorityID;
00360         LLUUID mOwnerID;
00361         LLUUID mGroupID;
00362         SetItemOwnerAndGroup(const LLUUID& authority_id,
00363                                                  const LLUUID& owner_id,
00364                                                  const LLUUID& group_id) :
00365                 mAuthorityID(authority_id), mOwnerID(owner_id), mGroupID(group_id) {}
00366         void operator()(LLInventoryItem* item) const
00367         {
00368                 LLPermissions perm = item->getPermissions();
00369                 bool is_atomic = (LLAssetType::AT_OBJECT == item->getType()) ? false : true;
00370                 perm.setOwnerAndGroup(mAuthorityID, mOwnerID, mGroupID, is_atomic);
00371                 // If no owner id is set, this is equivalent to a deed action.
00372                 // Clear 'share with group'.
00373                 if (mOwnerID.isNull())
00374                 {
00375                         perm.setMaskGroup(PERM_NONE);
00376                 }
00377                 item->setPermissions(perm);
00378         }
00379 };
00380 
00381 // This functor is used to unset the share with group, everyone perms, and
00382 // for sale info for objects being sold through contents.
00383 struct SetNotForSale
00384 {
00385         LLUUID mAgentID;
00386         LLUUID mGroupID;
00387         SetNotForSale(const LLUUID& agent_id,
00388                                   const LLUUID& group_id) :
00389                         mAgentID(agent_id), mGroupID(group_id) {}
00390         void operator()(LLInventoryItem* item) const
00391         {
00392                 // Clear group & everyone permissions.
00393                 LLPermissions perm = item->getPermissions();
00394                 perm.setGroupBits(mAgentID, mGroupID, FALSE, PERM_MODIFY | PERM_MOVE | PERM_COPY);
00395                 perm.setEveryoneBits(mAgentID, mGroupID, FALSE, PERM_MOVE | PERM_COPY);
00396                 item->setPermissions(perm);
00397 
00398                 // Mark group & everyone permissions for overwrite on the next
00399                 // rez if it is an object.
00400                 if(LLAssetType::AT_OBJECT == item->getType())
00401                 {
00402                         U32 flags = item->getFlags();
00403                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
00404                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
00405                         item->setFlags(flags);
00406                 }
00407 
00408                 // Clear for sale info.
00409                 item->setSaleInfo(LLSaleInfo::DEFAULT);
00410         }
00411 };
00412 
00413 typedef std::list<LLPointer<LLInventoryObject> > InventoryObjectList;
00414 
00415 // These functions convert between structured data and an inventroy
00416 // item, appropriate for serialization.
00417 LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item);
00418 LLPointer<LLInventoryItem> ll_create_item_from_sd(const LLSD& sd_item);
00419 LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat);
00420 LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat);
00421 
00422 #endif // LL_LLINVENTORY_H

Generated on Fri May 16 08:32:12 2008 for SecondLife by  doxygen 1.5.5