PageRenderTime 29ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llassetuploadqueue.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 211 lines | 154 code | 25 blank | 32 comment | 11 complexity | f2f1b8aacac2a93fac1c71f729e71c36 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llassetupload.cpp
  3. * @brief Serializes asset upload request
  4. *
  5. * $LicenseInfo:firstyear=2007&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 "llviewerprecompiledheaders.h"
  27. #include "llassetuploadqueue.h"
  28. #include "llviewerregion.h"
  29. #include "llviewerobjectlist.h"
  30. #include "llassetuploadresponders.h"
  31. #include "llsd.h"
  32. #include <iostream>
  33. class LLAssetUploadChainResponder : public LLUpdateTaskInventoryResponder
  34. {
  35. public:
  36. LLAssetUploadChainResponder(const LLSD& post_data,
  37. const std::string& file_name,
  38. const LLUUID& queue_id,
  39. U8* data,
  40. U32 data_size,
  41. std::string script_name,
  42. LLAssetUploadQueueSupplier *supplier) :
  43. LLUpdateTaskInventoryResponder(post_data, file_name, queue_id, LLAssetType::AT_LSL_TEXT),
  44. mSupplier(supplier),
  45. mData(data),
  46. mDataSize(data_size),
  47. mScriptName(script_name)
  48. {
  49. }
  50. virtual ~LLAssetUploadChainResponder()
  51. {
  52. if(mSupplier)
  53. {
  54. LLAssetUploadQueue *queue = mSupplier->get();
  55. if (queue)
  56. {
  57. // Give ownership of supplier back to queue.
  58. queue->mSupplier = mSupplier;
  59. mSupplier = NULL;
  60. }
  61. }
  62. delete mSupplier;
  63. delete mData;
  64. }
  65. virtual void error(U32 statusNum, const std::string& reason)
  66. {
  67. llwarns << "Error: " << reason << llendl;
  68. LLUpdateTaskInventoryResponder::error(statusNum, reason);
  69. LLAssetUploadQueue *queue = mSupplier->get();
  70. if (queue)
  71. {
  72. queue->request(&mSupplier);
  73. }
  74. }
  75. virtual void result(const LLSD& content)
  76. {
  77. LLUpdateTaskInventoryResponder::result(content);
  78. LLAssetUploadQueue *queue = mSupplier->get();
  79. if (queue)
  80. {
  81. // Responder is reused across 2 phase upload,
  82. // so only start next upload after 2nd phase complete.
  83. std::string state = content["state"];
  84. if(state == "complete")
  85. {
  86. queue->request(&mSupplier);
  87. }
  88. }
  89. }
  90. virtual void uploadUpload(const LLSD& content)
  91. {
  92. std::string uploader = content["uploader"];
  93. mSupplier->log(std::string("Compiling " + mScriptName).c_str());
  94. llinfos << "Compiling " << llendl;
  95. // postRaw takes ownership of mData and will delete it.
  96. LLHTTPClient::postRaw(uploader, mData, mDataSize, this);
  97. mData = NULL;
  98. mDataSize = 0;
  99. }
  100. virtual void uploadComplete(const LLSD& content)
  101. {
  102. // Bytecode save completed
  103. if (content["compiled"])
  104. {
  105. mSupplier->log("Compilation succeeded");
  106. llinfos << "Compiled!" << llendl;
  107. }
  108. else
  109. {
  110. LLSD compile_errors = content["errors"];
  111. for(LLSD::array_const_iterator line = compile_errors.beginArray();
  112. line < compile_errors.endArray(); line++)
  113. {
  114. mSupplier->log(line->asString());
  115. llinfos << content["errors"] << llendl;
  116. }
  117. }
  118. LLUpdateTaskInventoryResponder::uploadComplete(content);
  119. }
  120. LLAssetUploadQueueSupplier *mSupplier;
  121. U8* mData;
  122. U32 mDataSize;
  123. std::string mScriptName;
  124. };
  125. LLAssetUploadQueue::LLAssetUploadQueue(LLAssetUploadQueueSupplier *supplier) :
  126. mSupplier(supplier)
  127. {
  128. }
  129. //virtual
  130. LLAssetUploadQueue::~LLAssetUploadQueue()
  131. {
  132. delete mSupplier;
  133. }
  134. // Takes ownership of supplier.
  135. void LLAssetUploadQueue::request(LLAssetUploadQueueSupplier** supplier)
  136. {
  137. if (mQueue.empty())
  138. return;
  139. UploadData data = mQueue.front();
  140. mQueue.pop_front();
  141. LLSD body;
  142. body["task_id"] = data.mTaskId;
  143. body["item_id"] = data.mItemId;
  144. body["is_script_running"] = data.mIsRunning;
  145. body["target"] = data.mIsTargetMono? "mono" : "lsl2";
  146. std::string url = "";
  147. LLViewerObject* object = gObjectList.findObject(data.mTaskId);
  148. if (object)
  149. {
  150. url = object->getRegion()->getCapability("UpdateScriptTask");
  151. LLHTTPClient::post(url, body,
  152. new LLAssetUploadChainResponder(
  153. body, data.mFilename, data.mQueueId,
  154. data.mData, data.mDataSize, data.mScriptName, *supplier));
  155. }
  156. *supplier = NULL;
  157. }
  158. void LLAssetUploadQueue::queue(const std::string& filename,
  159. const LLUUID& task_id,
  160. const LLUUID& item_id,
  161. BOOL is_running,
  162. BOOL is_target_mono,
  163. const LLUUID& queue_id,
  164. U8* script_data,
  165. U32 data_size,
  166. std::string script_name)
  167. {
  168. UploadData data;
  169. data.mTaskId = task_id;
  170. data.mItemId = item_id;
  171. data.mIsRunning = is_running;
  172. data.mIsTargetMono = is_target_mono;
  173. data.mQueueId = queue_id;
  174. data.mFilename = filename;
  175. data.mData = script_data;
  176. data.mDataSize = data_size;
  177. data.mScriptName = script_name;
  178. mQueue.push_back(data);
  179. if(mSupplier)
  180. {
  181. request(&mSupplier);
  182. }
  183. }
  184. LLAssetUploadQueueSupplier::~LLAssetUploadQueueSupplier()
  185. {
  186. }