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         virtual void copy(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(FILE* fp);
00105         virtual BOOL exportFile(FILE* 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         enum
00139         {
00140                 // The meaning of LLInventoryItem::mFlags is distinct for each
00141                 // inventory type.
00142                 II_FLAGS_NONE = 0,
00143 
00144                 // landmark flags
00145                 II_FLAGS_LANDMARK_VISITED = 1,
00146 
00147                 // flag to indicate that object permissions should have next
00148                 // owner perm be more restrictive on rez. We bump this into
00149                 // the second byte of the flags since the low byte is used to
00150                 // track attachment points.
00151                 II_FLAGS_OBJECT_SLAM_PERM = 0x100,
00152 
00153                 // These flags specify which permissions masks to overwrite
00154                 // upon rez.  Normally, if no permissions slam (above) or
00155                 // overwrite flags are set, the asset's permissions are
00156                 // used and the inventory's permissions are ignored.  If
00157                 // any of these flags are set, the inventory's permissions
00158                 // take precedence.
00159                 II_FLAGS_OBJECT_PERM_OVERWRITE_BASE                     = 0x010000,
00160                 II_FLAGS_OBJECT_PERM_OVERWRITE_OWNER            = 0x020000,
00161                 II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP            = 0x040000,
00162                 II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE         = 0x080000,
00163                 II_FLAGS_OBJECT_PERM_OVERWRITE_NEXT_OWNER       = 0x100000,
00164 
00165                 // flag to indicate whether an object that is returned is composed 
00166                 // of muiltiple items or not.
00167                 II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS                      = 0x200000,
00168 
00169                 // wearables use the low order byte of flags to store the
00170                 // EWearableType enumeration found in newview/llwearable.h
00171         };
00172 
00173 protected:
00174         ~LLInventoryItem(); // ref counted
00175 
00176 public:
00177         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00178         LLInventoryItem(const LLUUID& uuid,
00179                                         const LLUUID& parent_uuid,
00180                                         const LLPermissions& permissions,
00181                                         const LLUUID& asset_uuid,
00182                                         LLAssetType::EType type,
00183                                         LLInventoryType::EType inv_type,
00184                                         const LLString& name, 
00185                                         const LLString& desc,
00186                                         const LLSaleInfo& sale_info,
00187                                         U32 flags,
00188                                         S32 creation_date_utc);
00189         LLInventoryItem();
00190         // Create a copy of an inventory item from a pointer to another item
00191         // Note: Because InventoryItems are ref counted, reference copy (a = b)
00192         // is prohibited
00193         LLInventoryItem(const LLInventoryItem* other);
00194         virtual void copy(const LLInventoryItem* other); // LLRefCount requires custom copy
00195 
00196         // As a constructor alternative, the clone() method works like a
00197         // copy constructor, but gens a new UUID.
00198         // It is up to the caller to delete (unref) the item.
00199         virtual void clone(LLPointer<LLInventoryItem>& newitem) const;
00200         
00201         // accessors
00202         const LLPermissions& getPermissions() const;
00203         const LLUUID& getCreatorUUID() const;
00204         const LLUUID& getAssetUUID() const;
00205         const LLString& getDescription() const;
00206         const LLSaleInfo& getSaleInfo() const;
00207         LLInventoryType::EType getInventoryType() const;
00208         U32 getFlags() const;
00209         S32 getCreationDate() const;
00210         U32 getCRC32() const; // really more of a checksum.
00211         
00212         // mutators - will not call updateServer(), and will never fail
00213         // (though it may correct to sane values)
00214         void setAssetUUID(const LLUUID& asset_id);
00215         void setDescription(const LLString& new_desc);
00216         void setSaleInfo(const LLSaleInfo& sale_info);
00217         void setPermissions(const LLPermissions& perm);
00218         void setInventoryType(LLInventoryType::EType inv_type);
00219         void setFlags(U32 flags);
00220         void setCreationDate(S32 creation_date_utc);
00221 
00222         // Put this inventory item onto the current outgoing mesage. It
00223         // assumes you have already called nextBlock().
00224         virtual void packMessage(LLMessageSystem* msg) const;
00225 
00226         // unpack returns TRUE if the inventory item came through the
00227         // network ok. It uses a simple crc check which is defeatable, but
00228         // we want to detect network mangling somehow.
00229         virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
00230 
00231         // file support
00232         virtual BOOL importFile(FILE* fp);
00233         virtual BOOL exportFile(FILE* fp, BOOL include_asset_key = TRUE) const;
00234 
00235         virtual BOOL importLegacyStream(std::istream& input_stream);
00236         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00237 
00238         virtual LLXMLNode *exportFileXML(BOOL include_asset_key = TRUE) const;
00239         BOOL importXML(LLXMLNode* node);
00240 
00241         // helper functions
00242 
00243         // pack all information needed to reconstruct this item into the given binary bucket.
00244         // perm_override is optional
00245         S32 packBinaryBucket(U8* bin_bucket, LLPermissions* perm_override = NULL) const;
00246         void unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size);
00247         LLSD asLLSD() const;
00248         bool fromLLSD(LLSD& sd);
00249 
00250 };
00251 
00252 BOOL item_dictionary_sort(LLInventoryItem* a,LLInventoryItem* b);
00253 BOOL item_date_sort(LLInventoryItem* a, LLInventoryItem* b);
00254 
00255 
00256 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00257 // Class LLInventoryCategory
00258 //
00259 // An instance of this class represents a category of inventory
00260 // items. Users come with a set of default categories, and can create
00261 // new ones as needed.
00262 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00263 
00264 class LLInventoryCategory : public LLInventoryObject
00265 {
00266 public:
00267         typedef LLDynamicArray<LLPointer<LLInventoryCategory> > cat_array_t;
00268 
00269 protected:
00270         ~LLInventoryCategory();
00271         
00272 public:
00273         MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
00274         LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
00275                                                 LLAssetType::EType preferred_type,
00276                                                 const LLString& name);
00277         LLInventoryCategory();
00278         LLInventoryCategory(const LLInventoryCategory* other);
00279         virtual void copy(const LLInventoryCategory* other); // LLRefCount requires custom copy
00280 
00281         // accessors and mutators
00282         LLAssetType::EType getPreferredType() const;
00283         void setPreferredType(LLAssetType::EType type);
00284         // For messaging system support
00285         virtual void packMessage(LLMessageSystem* msg) const;
00286         virtual void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
00287 
00288         // file support
00289         virtual BOOL importFile(FILE* fp);
00290         virtual BOOL exportFile(FILE* fp, BOOL include_asset_key = TRUE) const;
00291 
00292         virtual BOOL importLegacyStream(std::istream& input_stream);
00293         virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
00294 
00295 protected:
00296         // The type of asset that this category was "meant" to hold
00297         // (although it may in fact hold any type).
00298         LLAssetType::EType      mPreferredType;         
00299 
00300 };
00301 
00302 
00303 //-----------------------------------------------------------------------------
00304 // Useful bits
00305 //-----------------------------------------------------------------------------
00306 
00307 // This functor tests if an item is transferrable and returns true if
00308 // it is. Derived from unary_function<> so that the object can be used
00309 // in stl-compliant adaptable predicates (eg, not1<>). You might want
00310 // to use this in std::partition() or similar logic.
00311 struct IsItemTransferable : public std::unary_function<LLInventoryItem*, bool>
00312 {
00313         LLUUID mDestID;
00314         IsItemTransferable(const LLUUID& dest_id) : mDestID(dest_id) {}
00315         bool operator()(const LLInventoryItem* item) const
00316         {
00317                 return (item->getPermissions().allowTransferTo(mDestID)) ? true:false;
00318         }
00319 };
00320 
00321 // This functor is used to set the owner and group of inventory items,
00322 // for example, in a simple std::for_each() loop. Note that the call
00323 // to setOwnerAndGroup can fail if authority_id != LLUUID::null.
00324 struct SetItemOwnerAndGroup
00325 {
00326         LLUUID mAuthorityID;
00327         LLUUID mOwnerID;
00328         LLUUID mGroupID;
00329         SetItemOwnerAndGroup(const LLUUID& authority_id,
00330                                                  const LLUUID& owner_id,
00331                                                  const LLUUID& group_id) :
00332                 mAuthorityID(authority_id), mOwnerID(owner_id), mGroupID(group_id) {}
00333         void operator()(LLInventoryItem* item) const
00334         {
00335                 LLPermissions perm = item->getPermissions();
00336                 bool is_atomic = (LLAssetType::AT_OBJECT == item->getType()) ? false : true;
00337                 perm.setOwnerAndGroup(mAuthorityID, mOwnerID, mGroupID, is_atomic);
00338                 // If no owner id is set, this is equivalent to a deed action.
00339                 // Clear 'share with group'.
00340                 if (mOwnerID.isNull())
00341                 {
00342                         perm.setMaskGroup(PERM_NONE);
00343                 }
00344                 item->setPermissions(perm);
00345         }
00346 };
00347 
00348 // This functor is used to unset the share with group, everyone perms, and
00349 // for sale info for objects being sold through contents.
00350 struct SetNotForSale
00351 {
00352         LLUUID mAgentID;
00353         LLUUID mGroupID;
00354         SetNotForSale(const LLUUID& agent_id,
00355                                   const LLUUID& group_id) :
00356                         mAgentID(agent_id), mGroupID(group_id) {}
00357         void operator()(LLInventoryItem* item) const
00358         {
00359                 // Clear group & everyone permissions.
00360                 LLPermissions perm = item->getPermissions();
00361                 perm.setGroupBits(mAgentID, mGroupID, FALSE, PERM_MODIFY | PERM_MOVE | PERM_COPY);
00362                 perm.setEveryoneBits(mAgentID, mGroupID, FALSE, PERM_MOVE | PERM_COPY);
00363                 item->setPermissions(perm);
00364 
00365                 // Mark group & everyone permissions for overwrite on the next
00366                 // rez if it is an object.
00367                 if(LLAssetType::AT_OBJECT == item->getType())
00368                 {
00369                         U32 flags = item->getFlags();
00370                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
00371                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
00372                         item->setFlags(flags);
00373                 }
00374 
00375                 // Clear for sale info.
00376                 item->setSaleInfo(LLSaleInfo::DEFAULT);
00377         }
00378 };
00379 
00380 typedef std::list<LLPointer<LLInventoryObject> > InventoryObjectList;
00381 
00382 // These functions convert between structured data and an inventroy
00383 // item, appropriate for serialization.
00384 LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item);
00385 LLPointer<LLInventoryItem> ll_create_item_from_sd(const LLSD& sd_item);
00386 LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat);
00387 LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat);
00388 
00389 #endif // LL_LLINVENTORY_H

Generated on Thu Jul 1 06:08:44 2010 for Second Life Viewer by  doxygen 1.4.7