lltransfertargetvfile.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "lltransfertargetvfile.h"
00035 
00036 #include "lldatapacker.h"
00037 #include "llerror.h"
00038 #include "llvfile.h"
00039 
00040 //static
00041 void LLTransferTargetVFile::updateQueue(bool shutdown)
00042 {
00043 }
00044 
00045 
00046 LLTransferTargetParamsVFile::LLTransferTargetParamsVFile() :
00047         LLTransferTargetParams(LLTTT_VFILE),
00048         mAssetType(LLAssetType::AT_NONE),
00049         mCompleteCallback(NULL),
00050         mUserDatap(NULL),
00051         mErrCode(0)
00052 {
00053 }
00054 
00055 void LLTransferTargetParamsVFile::setAsset(
00056         const LLUUID& asset_id,
00057         LLAssetType::EType asset_type)
00058 {
00059         mAssetID = asset_id;
00060         mAssetType = asset_type;
00061 }
00062 
00063 void LLTransferTargetParamsVFile::setCallback(LLTTVFCompleteCallback cb, void *user_data)
00064 {
00065         mCompleteCallback = cb;
00066         mUserDatap = user_data;
00067 }
00068 
00069 bool LLTransferTargetParamsVFile::unpackParams(LLDataPacker& dp)
00070 {
00071         // if the source provided a new key, assign that to the asset id.
00072         if(dp.hasNext())
00073         {
00074                 LLUUID dummy_id;
00075                 dp.unpackUUID(dummy_id, "AgentID");
00076                 dp.unpackUUID(dummy_id, "SessionID");
00077                 dp.unpackUUID(dummy_id, "OwnerID");
00078                 dp.unpackUUID(dummy_id, "TaskID");
00079                 dp.unpackUUID(dummy_id, "ItemID");
00080                 dp.unpackUUID(mAssetID, "AssetID");
00081                 S32 dummy_type;
00082                 dp.unpackS32(dummy_type, "AssetType");
00083         }
00084 
00085         // if we never got an asset id, this will always fail.
00086         if(mAssetID.isNull())
00087         {
00088                 return false;
00089         }
00090         return true;
00091 }
00092 
00093 
00094 LLTransferTargetVFile::LLTransferTargetVFile(
00095         const LLUUID& uuid,
00096         LLTransferSourceType src_type) :
00097         LLTransferTarget(LLTTT_VFILE, uuid, src_type),
00098         mNeedsCreate(TRUE)
00099 {
00100         mTempID.generate();
00101 }
00102 
00103 
00104 LLTransferTargetVFile::~LLTransferTargetVFile()
00105 {
00106 }
00107 
00108 
00109 // virtual
00110 bool LLTransferTargetVFile::unpackParams(LLDataPacker& dp)
00111 {
00112         if(LLTST_SIM_INV_ITEM == mSourceType)
00113         {
00114                 return mParams.unpackParams(dp);
00115         }
00116         return true;
00117 }
00118 
00119 void LLTransferTargetVFile::applyParams(const LLTransferTargetParams &params)
00120 {
00121         if (params.getType() != mType)
00122         {
00123                 llwarns << "Target parameter type doesn't match!" << llendl;
00124                 return;
00125         }
00126         
00127         mParams = (LLTransferTargetParamsVFile &)params;
00128 }
00129 
00130 
00131 LLTSCode LLTransferTargetVFile::dataCallback(const S32 packet_id, U8 *in_datap, const S32 in_size)
00132 {
00133         //llinfos << "LLTransferTargetFile::dataCallback" << llendl;
00134         //llinfos << "Packet: " << packet_id << llendl;
00135 
00136         LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND);
00137         if (mNeedsCreate)
00138         {
00139                 vf.setMaxSize(mSize);
00140                 mNeedsCreate = FALSE;
00141         }
00142 
00143         if (!in_size)
00144         {
00145                 return LLTS_OK;
00146         }
00147 
00148         if (!vf.write(in_datap, in_size))
00149         {
00150                 llwarns << "Failure in LLTransferTargetVFile::dataCallback!" << llendl;
00151                 return LLTS_ERROR;
00152         }
00153         return LLTS_OK;
00154 }
00155 
00156 
00157 void LLTransferTargetVFile::completionCallback(const LLTSCode status)
00158 {
00159         //llinfos << "LLTransferTargetVFile::completionCallback" << llendl;
00160 
00161         if (!gAssetStorage)
00162         {
00163                 llwarns << "Aborting vfile transfer after asset storage shut down!" << llendl;
00164                 return;
00165         }
00166         
00167         // Still need to gracefully handle error conditions.
00168         S32 err_code = 0;
00169         switch (status)
00170         {
00171           case LLTS_DONE:
00172                 if (!mNeedsCreate)
00173                 {
00174                         LLVFile file(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::WRITE);
00175                         if (!file.rename(mParams.getAssetID(), mParams.getAssetType()))
00176                         {
00177                                 llerrs << "LLTransferTargetVFile: rename failed" << llendl;
00178                         }
00179                 }
00180                 err_code = LL_ERR_NOERR;
00181                 lldebugs << "LLTransferTargetVFile::completionCallback for "
00182                          << mParams.getAssetID() << ","
00183                          << LLAssetType::lookup(mParams.getAssetType())
00184                          << " with temp id " << mTempID << llendl;
00185                 break;
00186           case LLTS_ERROR:
00187           case LLTS_ABORT:
00188           case LLTS_UNKNOWN_SOURCE:
00189           default:
00190           {
00191                   // We're aborting this transfer, we don't want to keep this file.
00192                   llwarns << "Aborting vfile transfer for " << mParams.getAssetID() << llendl;
00193                   LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND);
00194                   vf.remove();
00195           }
00196           break;
00197         }
00198 
00199         switch (status)
00200         {
00201         case LLTS_DONE:
00202                 err_code = LL_ERR_NOERR;
00203                 break;
00204         case LLTS_UNKNOWN_SOURCE:
00205                 err_code = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE;
00206                 break;
00207         case LLTS_INSUFFICIENT_PERMISSIONS:
00208                 err_code = LL_ERR_INSUFFICIENT_PERMISSIONS;
00209                 break;
00210         case LLTS_ERROR:
00211         case LLTS_ABORT:
00212         default:
00213                 err_code = LL_ERR_ASSET_REQUEST_FAILED;
00214                 break;
00215         }
00216         if (mParams.mCompleteCallback)
00217         {
00218                 mParams.mCompleteCallback(err_code,
00219                                                                   mParams.getAssetID(),
00220                                                                   mParams.getAssetType(),
00221                                                                   mParams.mUserDatap,
00222                                                                   LL_EXSTAT_NONE);
00223         }
00224 }

Generated on Thu Jul 1 06:09:23 2010 for Second Life Viewer by  doxygen 1.4.7