diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/newview/llassetuploadqueue.cpp | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2 meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz |
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/newview/llassetuploadqueue.cpp')
-rw-r--r-- | linden/indra/newview/llassetuploadqueue.cpp | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/linden/indra/newview/llassetuploadqueue.cpp b/linden/indra/newview/llassetuploadqueue.cpp new file mode 100644 index 0000000..f645828 --- /dev/null +++ b/linden/indra/newview/llassetuploadqueue.cpp | |||
@@ -0,0 +1,216 @@ | |||
1 | /** | ||
2 | * @file llassetupload.cpp | ||
3 | * @brief Serializes asset upload request | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-2008, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | * $/LicenseInfo$ | ||
30 | */ | ||
31 | |||
32 | #include "llviewerprecompiledheaders.h" | ||
33 | |||
34 | #include "llassetuploadqueue.h" | ||
35 | #include "llviewerregion.h" | ||
36 | #include "llviewerobjectlist.h" | ||
37 | |||
38 | #include "llassetuploadresponders.h" | ||
39 | #include "llsd.h" | ||
40 | #include <iostream> | ||
41 | |||
42 | class LLAssetUploadChainResponder : public LLUpdateTaskInventoryResponder | ||
43 | { | ||
44 | public: | ||
45 | |||
46 | LLAssetUploadChainResponder(const LLSD& post_data, | ||
47 | const std::string& file_name, | ||
48 | const LLUUID& queue_id, | ||
49 | U8* data, | ||
50 | U32 data_size, | ||
51 | std::string script_name, | ||
52 | LLAssetUploadQueueSupplier *supplier) : | ||
53 | LLUpdateTaskInventoryResponder(post_data, file_name, queue_id, LLAssetType::AT_LSL_TEXT), | ||
54 | mSupplier(supplier), | ||
55 | mData(data), | ||
56 | mDataSize(data_size), | ||
57 | mScriptName(script_name) | ||
58 | { | ||
59 | } | ||
60 | |||
61 | virtual ~LLAssetUploadChainResponder() | ||
62 | { | ||
63 | if(mSupplier) | ||
64 | { | ||
65 | LLAssetUploadQueue *queue = mSupplier->get(); | ||
66 | if (queue) | ||
67 | { | ||
68 | // Give ownership of supplier back to queue. | ||
69 | queue->mSupplier = mSupplier; | ||
70 | mSupplier = NULL; | ||
71 | } | ||
72 | } | ||
73 | delete mSupplier; | ||
74 | delete mData; | ||
75 | } | ||
76 | |||
77 | virtual void error(U32 statusNum, const std::string& reason) | ||
78 | { | ||
79 | llwarns << "Error: " << reason << llendl; | ||
80 | LLUpdateTaskInventoryResponder::error(statusNum, reason); | ||
81 | LLAssetUploadQueue *queue = mSupplier->get(); | ||
82 | if (queue) | ||
83 | { | ||
84 | queue->request(&mSupplier); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | virtual void result(const LLSD& content) | ||
89 | { | ||
90 | LLUpdateTaskInventoryResponder::result(content); | ||
91 | LLAssetUploadQueue *queue = mSupplier->get(); | ||
92 | if (queue) | ||
93 | { | ||
94 | // Responder is reused across 2 phase upload, | ||
95 | // so only start next upload after 2nd phase complete. | ||
96 | std::string state = content["state"]; | ||
97 | if(state == "complete") | ||
98 | { | ||
99 | queue->request(&mSupplier); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | virtual void uploadUpload(const LLSD& content) | ||
105 | { | ||
106 | std::string uploader = content["uploader"]; | ||
107 | |||
108 | mSupplier->log(std::string("Compiling " + mScriptName).c_str()); | ||
109 | llinfos << "Compiling " << llendl; | ||
110 | |||
111 | // postRaw takes ownership of mData and will delete it. | ||
112 | LLHTTPClient::postRaw(uploader, mData, mDataSize, this); | ||
113 | mData = NULL; | ||
114 | mDataSize = 0; | ||
115 | } | ||
116 | |||
117 | virtual void uploadComplete(const LLSD& content) | ||
118 | { | ||
119 | // Bytecode save completed | ||
120 | if (content["compiled"]) | ||
121 | { | ||
122 | mSupplier->log("Compilation succeeded"); | ||
123 | llinfos << "Compiled!" << llendl; | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | LLSD compile_errors = content["errors"]; | ||
128 | for(LLSD::array_const_iterator line = compile_errors.beginArray(); | ||
129 | line < compile_errors.endArray(); line++) | ||
130 | { | ||
131 | mSupplier->log(line->asString()); | ||
132 | llinfos << content["errors"] << llendl; | ||
133 | } | ||
134 | } | ||
135 | LLUpdateTaskInventoryResponder::uploadComplete(content); | ||
136 | } | ||
137 | |||
138 | LLAssetUploadQueueSupplier *mSupplier; | ||
139 | U8* mData; | ||
140 | U32 mDataSize; | ||
141 | std::string mScriptName; | ||
142 | }; | ||
143 | |||
144 | |||
145 | LLAssetUploadQueue::LLAssetUploadQueue(LLAssetUploadQueueSupplier *supplier) : | ||
146 | mSupplier(supplier) | ||
147 | { | ||
148 | } | ||
149 | |||
150 | //virtual | ||
151 | LLAssetUploadQueue::~LLAssetUploadQueue() | ||
152 | { | ||
153 | delete mSupplier; | ||
154 | } | ||
155 | |||
156 | // Takes ownership of supplier. | ||
157 | void LLAssetUploadQueue::request(LLAssetUploadQueueSupplier** supplier) | ||
158 | { | ||
159 | if (mQueue.empty()) | ||
160 | return; | ||
161 | |||
162 | UploadData data = mQueue.front(); | ||
163 | mQueue.pop_front(); | ||
164 | |||
165 | LLSD body; | ||
166 | body["task_id"] = data.mTaskId; | ||
167 | body["item_id"] = data.mItemId; | ||
168 | body["is_script_running"] = data.mIsRunning; | ||
169 | body["target"] = data.mIsTargetMono? "mono" : "lsl2"; | ||
170 | |||
171 | std::string url = ""; | ||
172 | LLViewerObject* object = gObjectList.findObject(data.mTaskId); | ||
173 | if (object) | ||
174 | { | ||
175 | url = object->getRegion()->getCapability("UpdateScriptTask"); | ||
176 | LLHTTPClient::post(url, body, | ||
177 | new LLAssetUploadChainResponder( | ||
178 | body, data.mFilename, data.mQueueId, | ||
179 | data.mData, data.mDataSize, data.mScriptName, *supplier)); | ||
180 | } | ||
181 | |||
182 | *supplier = NULL; | ||
183 | } | ||
184 | |||
185 | void LLAssetUploadQueue::queue(const std::string& filename, | ||
186 | const LLUUID& task_id, | ||
187 | const LLUUID& item_id, | ||
188 | BOOL is_running, | ||
189 | BOOL is_target_mono, | ||
190 | const LLUUID& queue_id, | ||
191 | U8* script_data, | ||
192 | U32 data_size, | ||
193 | std::string script_name) | ||
194 | { | ||
195 | UploadData data; | ||
196 | data.mTaskId = task_id; | ||
197 | data.mItemId = item_id; | ||
198 | data.mIsRunning = is_running; | ||
199 | data.mIsTargetMono = is_target_mono; | ||
200 | data.mQueueId = queue_id; | ||
201 | data.mFilename = filename; | ||
202 | data.mData = script_data; | ||
203 | data.mDataSize = data_size; | ||
204 | data.mScriptName = script_name; | ||
205 | |||
206 | mQueue.push_back(data); | ||
207 | |||
208 | if(mSupplier) | ||
209 | { | ||
210 | request(&mSupplier); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | LLAssetUploadQueueSupplier::~LLAssetUploadQueueSupplier() | ||
215 | { | ||
216 | } | ||