llassetstorage.h

Go to the documentation of this file.
00001 
00033 #ifndef LL_LLASSETSTORAGE_H
00034 #define LL_LLASSETSTORAGE_H
00035 
00036 #include <string>
00037 
00038 #include "lluuid.h"
00039 #include "lltimer.h"
00040 #include "llnamevalue.h"
00041 #include "llhost.h"
00042 #include "stdenums.h"   // for EDragAndDropType
00043 #include "lltransfermanager.h" // For LLTSCode enum
00044 #include "llassettype.h"
00045 #include "llstring.h"
00046 #include "llextendedstatus.h"
00047 
00048 // Forward declarations
00049 class LLMessageSystem;
00050 class LLXferManager;
00051 class LLAssetStorage;
00052 class LLVFS;
00053 class LLSD;
00054 
00055 // anything that takes longer than this to download will abort.
00056 // HTTP Uploads also timeout if they take longer than this.
00057 const F32 LL_ASSET_STORAGE_TIMEOUT = 5 * 60.0f;  
00058 
00059 class LLAssetInfo
00060 {
00061 protected:
00062         std::string             mDescription;
00063         std::string             mName;
00064 
00065 public:
00066         LLUUID                  mUuid;
00067         LLTransactionID mTransactionID;
00068         LLUUID                  mCreatorID;
00069         LLAssetType::EType      mType;
00070 
00071         LLAssetInfo( void );
00072         LLAssetInfo( const LLUUID& object_id, const LLUUID& creator_id,
00073                                  LLAssetType::EType type, const char* name, const char* desc );
00074         LLAssetInfo( const LLNameValue& nv );
00075         
00076         const std::string& getName( void ) const { return mName; }
00077         const std::string& getDescription( void ) const { return mDescription; } 
00078         void setName( const std::string& name );
00079         void setDescription( const std::string& desc );
00080 
00081         // Assets (aka potential inventory items) can be applied to an
00082         // object in the world. We'll store that as a string name value
00083         // pair where the name encodes part of asset info, and the value
00084         // the rest.  LLAssetInfo objects will be responsible for parsing
00085         // the meaning out froman LLNameValue object. See the inventory
00086         // design docs for details.
00087         void setFromNameValue( const LLNameValue& nv );
00088 };
00089 
00090 
00091 class LLAssetRequest
00092 {
00093 public:
00094         LLAssetRequest(const LLUUID &uuid, const LLAssetType::EType at);
00095         virtual ~LLAssetRequest();
00096         
00097         LLUUID getUUID() const                                  { return mUUID; }
00098         LLAssetType::EType getType() const              { return mType; }
00099 
00100         void setUUID(const LLUUID& id) { mUUID = id; }
00101         void setType(LLAssetType::EType type) { mType = type; }
00102         void setTimeout (F64 timeout) { mTimeout = timeout; }
00103 
00104 protected:
00105         LLUUID  mUUID;
00106         LLAssetType::EType mType;
00107 
00108 public:
00109         void    (*mDownCallback)(LLVFS*, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat);
00110         void    (*mUpCallback)(const LLUUID&, void *, S32, LLExtStat);
00111         void    (*mInfoCallback)(LLAssetInfo *, void *, S32);
00112 
00113         void    *mUserData;
00114         LLHost  mHost;
00115         BOOL    mIsTemp;
00116         BOOL    mIsLocal;
00117         BOOL    mIsUserWaiting;         // We don't want to try forever if a user is waiting for a result.
00118         F64             mTime;                          // Message system time
00119         F64             mTimeout;                       // Amount of time before timing out.
00120         BOOL    mIsPriority;
00121         BOOL    mDataSentInFirstPacket;
00122         BOOL    mDataIsInVFS;
00123         LLUUID  mRequestingAgentID;     // Only valid for uploads from an agent
00124 
00125         virtual LLSD getTerseDetails() const;
00126         virtual LLSD getFullDetails() const;
00127 };
00128 
00129 template <class T>
00130 struct ll_asset_request_equal : public std::equal_to<T>
00131 {
00132         bool operator()(const T& x, const T& y) const 
00133         { 
00134                 return (        x->getType() == y->getType()
00135                                 &&      x->getUUID() == y->getUUID() );
00136         }
00137 };
00138 
00139 
00140 class LLInvItemRequest
00141 {
00142 public:
00143         LLInvItemRequest(const LLUUID &uuid, const LLAssetType::EType at);
00144         virtual ~LLInvItemRequest();
00145 
00146         LLUUID getUUID() const                                  { return mUUID; }
00147         LLAssetType::EType getType() const              { return mType; }
00148 
00149         void setUUID(const LLUUID& id) { mUUID = id; }
00150         void setType(LLAssetType::EType type) { mType = type; }
00151 
00152 protected:
00153         LLUUID  mUUID;
00154         LLAssetType::EType mType;
00155 
00156 public:
00157         void    (*mDownCallback)(LLVFS*, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat);
00158 
00159         void    *mUserData;
00160         LLHost  mHost;
00161         BOOL    mIsTemp;
00162         F64             mTime;                          // Message system time
00163         BOOL    mIsPriority;
00164         BOOL    mDataSentInFirstPacket;
00165         BOOL    mDataIsInVFS;
00166 
00167 };
00168 
00169 class LLEstateAssetRequest
00170 {
00171 public:
00172         LLEstateAssetRequest(const LLUUID &uuid, const LLAssetType::EType at, EstateAssetType et);
00173         virtual ~LLEstateAssetRequest();
00174 
00175         LLUUID getUUID() const                                  { return mUUID; }
00176         LLAssetType::EType getAType() const             { return mAType; }
00177 
00178         void setUUID(const LLUUID& id) { mUUID = id; }
00179         void setType(LLAssetType::EType type) { mAType = type; }
00180 
00181 protected:
00182         LLUUID  mUUID;
00183         LLAssetType::EType mAType;
00184         EstateAssetType mEstateAssetType;
00185 
00186 public:
00187         void    (*mDownCallback)(LLVFS*, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat);
00188 
00189         void    *mUserData;
00190         LLHost  mHost;
00191         BOOL    mIsTemp;
00192         F64             mTime;                          // Message system time
00193         BOOL    mIsPriority;
00194         BOOL    mDataSentInFirstPacket;
00195         BOOL    mDataIsInVFS;
00196 
00197 };
00198 
00199 
00200 
00201 
00202 typedef void (*LLGetAssetCallback)(LLVFS *vfs, const LLUUID &asset_id,
00203                                                                                  LLAssetType::EType asset_type, void *user_data, S32 status, LLExtStat ext_status);
00204 
00205 class LLAssetStorage
00206 {
00207 public:
00208         // VFS member is public because static child methods need it :(
00209         LLVFS *mVFS;
00210         typedef void (*LLStoreAssetCallback)(const LLUUID &asset_id, void *user_data, S32 status, LLExtStat ext_status);
00211 
00212         enum ERequestType
00213         {
00214                 RT_INVALID = -1,
00215                 RT_DOWNLOAD = 0,
00216                 RT_UPLOAD = 1,
00217                 RT_LOCALUPLOAD = 2,
00218                 RT_COUNT = 3
00219         };
00220 
00221 protected:
00222         BOOL mShutDown;
00223         LLHost mUpstreamHost;
00224         
00225         LLMessageSystem *mMessageSys;
00226         LLXferManager   *mXferManager;
00227 
00228 
00229         typedef std::list<LLAssetRequest*> request_list_t;
00230         request_list_t mPendingDownloads;
00231         request_list_t mPendingUploads;
00232         request_list_t mPendingLocalUploads;
00233         
00234 public:
00235         LLAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
00236                                    LLVFS *vfs, const LLHost &upstream_host);
00237 
00238         LLAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
00239                                    LLVFS *vfs);
00240         virtual ~LLAssetStorage();
00241 
00242         void setUpstream(const LLHost &upstream_host);
00243 
00244         virtual BOOL hasLocalAsset(const LLUUID &uuid, LLAssetType::EType type);
00245 
00246         // public interface methods
00247         // note that your callback may get called BEFORE the function returns
00248 
00249         virtual void getAssetData(const LLUUID uuid, LLAssetType::EType atype, LLGetAssetCallback cb, void *user_data, BOOL is_priority = FALSE);
00250 
00251         /*
00252          * TransactionID version
00253          * Viewer needs the store_local
00254          */
00255         virtual void storeAssetData(
00256                 const LLTransactionID& tid,
00257                 LLAssetType::EType atype,
00258                 LLStoreAssetCallback callback,
00259                 void* user_data,
00260                 bool temp_file = false,
00261                 bool is_priority = false,
00262                 bool store_local = false,
00263                 bool user_waiting= false,
00264                 F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
00265 
00266         /*
00267          * AssetID version
00268          * Sim needs both store_local and requesting_agent_id.
00269          */
00270         virtual void storeAssetData(
00271                 const LLUUID& asset_id,
00272                 LLAssetType::EType asset_type,
00273                 LLStoreAssetCallback callback,
00274                 void* user_data,
00275                 bool temp_file = false,
00276                 bool is_priority = false,
00277                 bool store_local = false,
00278                 const LLUUID& requesting_agent_id = LLUUID::null,
00279                 bool user_waiting= false,
00280                 F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
00281 
00282         virtual void checkForTimeouts();
00283 
00284         void getEstateAsset(const LLHost &object_sim, const LLUUID &agent_id, const LLUUID &session_id,
00285                                                                         const LLUUID &asset_id, LLAssetType::EType atype, EstateAssetType etype,
00286                                                                          LLGetAssetCallback callback, void *user_data, BOOL is_priority);
00287 
00288         void getInvItemAsset(const LLHost &object_sim,
00289                                                  const LLUUID &agent_id, const LLUUID &session_id,
00290                                                  const LLUUID &owner_id, const LLUUID &task_id, const LLUUID &item_id,
00291                                                  const LLUUID &asset_id, LLAssetType::EType atype,
00292                                                  LLGetAssetCallback cb, void *user_data, BOOL is_priority = FALSE); // Get a particular inventory item.
00293 
00294 protected:
00295         virtual LLSD getPendingDetails(const request_list_t* requests,
00296                                         LLAssetType::EType asset_type,
00297                                         const std::string& detail_prefix) const;
00298 
00299         virtual LLSD getPendingRequest(const request_list_t* requests,
00300                                                         LLAssetType::EType asset_type,
00301                                                         const LLUUID& asset_id) const;
00302 
00303         virtual bool deletePendingRequest(request_list_t* requests,
00304                                                         LLAssetType::EType asset_type,
00305                                                         const LLUUID& asset_id);
00306 
00307 public:
00308         static const LLAssetRequest* findRequest(const request_list_t* requests,
00309                                                                                 LLAssetType::EType asset_type,
00310                                                                                 const LLUUID& asset_id);
00311         static LLAssetRequest* findRequest(request_list_t* requests,
00312                                                                                 LLAssetType::EType asset_type,
00313                                                                                 const LLUUID& asset_id);
00314 
00315         request_list_t* getRequestList(ERequestType rt);
00316         const request_list_t* getRequestList(ERequestType rt) const;
00317         static std::string getRequestName(ERequestType rt);
00318 
00319         S32 getNumPendingDownloads() const;
00320         S32 getNumPendingUploads() const;
00321         S32 getNumPendingLocalUploads();
00322         S32 getNumPending(ERequestType rt) const;
00323 
00324         virtual LLSD getPendingDetails(ERequestType rt,
00325                                         LLAssetType::EType asset_type,
00326                                         const std::string& detail_prefix) const;
00327 
00328         virtual LLSD getPendingRequest(ERequestType rt,
00329                                                         LLAssetType::EType asset_type,
00330                                                         const LLUUID& asset_id) const;
00331 
00332         virtual bool deletePendingRequest(ERequestType rt,
00333                                                         LLAssetType::EType asset_type,
00334                                                         const LLUUID& asset_id);
00335 
00336 
00337         // download process callbacks
00338         static void downloadCompleteCallback(
00339                 S32 result,
00340                 const LLUUID& file_id,
00341                 LLAssetType::EType file_type,
00342                 void* user_data, LLExtStat ext_status);
00343         static void downloadEstateAssetCompleteCallback(
00344                 S32 result,
00345                 const LLUUID& file_id,
00346                 LLAssetType::EType file_type,
00347                 void* user_data, LLExtStat ext_status);
00348         static void downloadInvItemCompleteCallback(
00349                 S32 result,
00350                 const LLUUID& file_id,
00351                 LLAssetType::EType file_type,
00352                 void* user_data, LLExtStat ext_status);
00353 
00354         // upload process callbacks
00355         static void uploadCompleteCallback(const LLUUID&, void *user_data, S32 result, LLExtStat ext_status);
00356         static void processUploadComplete(LLMessageSystem *msg, void **this_handle);
00357 
00358         // debugging
00359         static const char* getErrorString( S32 status );
00360 
00361         // deprecated file-based methods
00362         void getAssetData(const LLUUID uuid, LLAssetType::EType type, void (*callback)(const char*, const LLUUID&, void *, S32, LLExtStat), void *user_data, BOOL is_priority = FALSE);
00363 
00364         /*
00365          * AssetID version.
00366          */
00367         virtual void storeAssetData(
00368                 const char* filename,
00369                 const LLUUID& asset_id,
00370                 LLAssetType::EType type,
00371                 LLStoreAssetCallback callback,
00372                 void* user_data,
00373                 bool temp_file = false,
00374                 bool is_priority = false,
00375                 bool user_waiting = false,
00376                 F64 timeout  = LL_ASSET_STORAGE_TIMEOUT);
00377 
00378         /*
00379          * TransactionID version
00380          */
00381         virtual void storeAssetData(
00382                 const char * filename,
00383                 const LLTransactionID &transaction_id,
00384                 LLAssetType::EType type,
00385                 LLStoreAssetCallback callback,
00386                 void *user_data,
00387                 bool temp_file = false,
00388                 bool is_priority = false,
00389                 bool user_waiting = false,
00390                 F64 timeout  = LL_ASSET_STORAGE_TIMEOUT);
00391 
00392         static void legacyGetDataCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::EType, void *user_data, S32 status, LLExtStat ext_status);
00393         static void legacyStoreDataCallback(const LLUUID &uuid, void *user_data, S32 status, LLExtStat ext_status);
00394 
00395         // Temp assets are stored on sim nodes, they have agent ID and location data associated with them.
00396         // This is a no-op for non-http asset systems
00397         virtual void addTempAssetData(const LLUUID& asset_id, const LLUUID& agent_id, const std::string& host_name);
00398         virtual BOOL hasTempAssetData(const LLUUID& texture_id) const;
00399         virtual std::string getTempAssetHostName(const LLUUID& texture_id) const;
00400         virtual LLUUID getTempAssetAgentID(const LLUUID& texture_id) const;
00401         virtual void removeTempAssetData(const LLUUID& asset_id);
00402         virtual void removeTempAssetDataByAgentID(const LLUUID& agent_id);
00403         // Pass LLUUID::null for all
00404         virtual void dumpTempAssetData(const LLUUID& avatar_id) const;
00405         virtual void clearTempAssetData();
00406 
00407         // add extra methods to handle metadata
00408 
00409 protected:
00410         void _cleanupRequests(BOOL all, S32 error);
00411         void _callUploadCallbacks(const LLUUID &uuid, const LLAssetType::EType asset_type, BOOL success, LLExtStat ext_status);
00412 
00413         virtual void _queueDataRequest(const LLUUID& uuid, LLAssetType::EType type,
00414                                                                    void (*callback)(LLVFS *vfs, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat),
00415                                                                    void *user_data, BOOL duplicate,
00416                                                                    BOOL is_priority);
00417 
00418 private:
00419         void _init(LLMessageSystem *msg,
00420                            LLXferManager *xfer,
00421                            LLVFS *vfs,
00422                            const LLHost &upstream_host);
00423 };
00424 
00426 // Wrappers to replicate deprecated API
00428 
00429 class LLLegacyAssetRequest
00430 {
00431 public:
00432         void    (*mDownCallback)(const char *, const LLUUID&, void *, S32, LLExtStat);
00433         LLAssetStorage::LLStoreAssetCallback mUpCallback;
00434 
00435         void    *mUserData;
00436 };
00437 
00438 extern LLAssetStorage *gAssetStorage;
00439 extern const LLUUID CATEGORIZE_LOST_AND_FOUND_ID;
00440 #endif  

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