PageRenderTime 38ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/lltransfertargetvfile.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 219 lines | 157 code | 28 blank | 34 comment | 15 complexity | de3db9f1d35015e1229f92b93f092ec1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltransfertargetvfile.cpp
  3. * @brief Transfer system for receiving a vfile.
  4. *
  5. * $LicenseInfo:firstyear=2006&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. #include "linden_common.h"
  27. #include "lltransfertargetvfile.h"
  28. #include "lldatapacker.h"
  29. #include "llerror.h"
  30. #include "llvfile.h"
  31. //static
  32. void LLTransferTargetVFile::updateQueue(bool shutdown)
  33. {
  34. }
  35. LLTransferTargetParamsVFile::LLTransferTargetParamsVFile() :
  36. LLTransferTargetParams(LLTTT_VFILE),
  37. mAssetType(LLAssetType::AT_NONE),
  38. mCompleteCallback(NULL),
  39. mUserDatap(NULL),
  40. mErrCode(0)
  41. {
  42. }
  43. void LLTransferTargetParamsVFile::setAsset(
  44. const LLUUID& asset_id,
  45. LLAssetType::EType asset_type)
  46. {
  47. mAssetID = asset_id;
  48. mAssetType = asset_type;
  49. }
  50. void LLTransferTargetParamsVFile::setCallback(LLTTVFCompleteCallback cb, void *user_data)
  51. {
  52. mCompleteCallback = cb;
  53. mUserDatap = user_data;
  54. }
  55. bool LLTransferTargetParamsVFile::unpackParams(LLDataPacker& dp)
  56. {
  57. // if the source provided a new key, assign that to the asset id.
  58. if(dp.hasNext())
  59. {
  60. LLUUID dummy_id;
  61. dp.unpackUUID(dummy_id, "AgentID");
  62. dp.unpackUUID(dummy_id, "SessionID");
  63. dp.unpackUUID(dummy_id, "OwnerID");
  64. dp.unpackUUID(dummy_id, "TaskID");
  65. dp.unpackUUID(dummy_id, "ItemID");
  66. dp.unpackUUID(mAssetID, "AssetID");
  67. S32 dummy_type;
  68. dp.unpackS32(dummy_type, "AssetType");
  69. }
  70. // if we never got an asset id, this will always fail.
  71. if(mAssetID.isNull())
  72. {
  73. return false;
  74. }
  75. return true;
  76. }
  77. LLTransferTargetVFile::LLTransferTargetVFile(
  78. const LLUUID& uuid,
  79. LLTransferSourceType src_type) :
  80. LLTransferTarget(LLTTT_VFILE, uuid, src_type),
  81. mNeedsCreate(TRUE)
  82. {
  83. mTempID.generate();
  84. }
  85. LLTransferTargetVFile::~LLTransferTargetVFile()
  86. {
  87. }
  88. // virtual
  89. bool LLTransferTargetVFile::unpackParams(LLDataPacker& dp)
  90. {
  91. if(LLTST_SIM_INV_ITEM == mSourceType)
  92. {
  93. return mParams.unpackParams(dp);
  94. }
  95. return true;
  96. }
  97. void LLTransferTargetVFile::applyParams(const LLTransferTargetParams &params)
  98. {
  99. if (params.getType() != mType)
  100. {
  101. llwarns << "Target parameter type doesn't match!" << llendl;
  102. return;
  103. }
  104. mParams = (LLTransferTargetParamsVFile &)params;
  105. }
  106. LLTSCode LLTransferTargetVFile::dataCallback(const S32 packet_id, U8 *in_datap, const S32 in_size)
  107. {
  108. //llinfos << "LLTransferTargetFile::dataCallback" << llendl;
  109. //llinfos << "Packet: " << packet_id << llendl;
  110. LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND);
  111. if (mNeedsCreate)
  112. {
  113. vf.setMaxSize(mSize);
  114. mNeedsCreate = FALSE;
  115. }
  116. if (!in_size)
  117. {
  118. return LLTS_OK;
  119. }
  120. if (!vf.write(in_datap, in_size))
  121. {
  122. llwarns << "Failure in LLTransferTargetVFile::dataCallback!" << llendl;
  123. return LLTS_ERROR;
  124. }
  125. return LLTS_OK;
  126. }
  127. void LLTransferTargetVFile::completionCallback(const LLTSCode status)
  128. {
  129. //llinfos << "LLTransferTargetVFile::completionCallback" << llendl;
  130. if (!gAssetStorage)
  131. {
  132. llwarns << "Aborting vfile transfer after asset storage shut down!" << llendl;
  133. return;
  134. }
  135. // Still need to gracefully handle error conditions.
  136. S32 err_code = 0;
  137. switch (status)
  138. {
  139. case LLTS_DONE:
  140. if (!mNeedsCreate)
  141. {
  142. LLVFile file(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::WRITE);
  143. if (!file.rename(mParams.getAssetID(), mParams.getAssetType()))
  144. {
  145. llerrs << "LLTransferTargetVFile: rename failed" << llendl;
  146. }
  147. }
  148. err_code = LL_ERR_NOERR;
  149. lldebugs << "LLTransferTargetVFile::completionCallback for "
  150. << mParams.getAssetID() << ","
  151. << LLAssetType::lookup(mParams.getAssetType())
  152. << " with temp id " << mTempID << llendl;
  153. break;
  154. case LLTS_ERROR:
  155. case LLTS_ABORT:
  156. case LLTS_UNKNOWN_SOURCE:
  157. default:
  158. {
  159. // We're aborting this transfer, we don't want to keep this file.
  160. llwarns << "Aborting vfile transfer for " << mParams.getAssetID() << llendl;
  161. LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND);
  162. vf.remove();
  163. }
  164. break;
  165. }
  166. switch (status)
  167. {
  168. case LLTS_DONE:
  169. err_code = LL_ERR_NOERR;
  170. break;
  171. case LLTS_UNKNOWN_SOURCE:
  172. err_code = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE;
  173. break;
  174. case LLTS_INSUFFICIENT_PERMISSIONS:
  175. err_code = LL_ERR_INSUFFICIENT_PERMISSIONS;
  176. break;
  177. case LLTS_ERROR:
  178. case LLTS_ABORT:
  179. default:
  180. err_code = LL_ERR_ASSET_REQUEST_FAILED;
  181. break;
  182. }
  183. if (mParams.mCompleteCallback)
  184. {
  185. mParams.mCompleteCallback(err_code,
  186. mParams.getAssetID(),
  187. mParams.getAssetType(),
  188. mParams.mUserDatap,
  189. LL_EXSTAT_NONE);
  190. }
  191. }