diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/lltransfertargetvfile.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmessage/lltransfertargetvfile.cpp | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/linden/indra/llmessage/lltransfertargetvfile.cpp b/linden/indra/llmessage/lltransfertargetvfile.cpp new file mode 100644 index 0000000..ce21605 --- /dev/null +++ b/linden/indra/llmessage/lltransfertargetvfile.cpp | |||
@@ -0,0 +1,257 @@ | |||
1 | /** | ||
2 | * @file lltransfertargetvfile.cpp | ||
3 | * @brief Transfer system for receiving a vfile. | ||
4 | * | ||
5 | * Copyright (c) 2006-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "linden_common.h" | ||
29 | |||
30 | #include "lltransfertargetvfile.h" | ||
31 | |||
32 | #include "lldatapacker.h" | ||
33 | #include "llerror.h" | ||
34 | #include "llvfile.h" | ||
35 | |||
36 | //static | ||
37 | std::list<LLTransferTargetParamsVFile*> LLTransferTargetVFile::sCallbackQueue; | ||
38 | |||
39 | //static | ||
40 | void LLTransferTargetVFile::updateQueue(bool shutdown) | ||
41 | { | ||
42 | for(std::list<LLTransferTargetParamsVFile*>::iterator iter = sCallbackQueue.begin(); | ||
43 | iter != sCallbackQueue.end(); ) | ||
44 | { | ||
45 | std::list<LLTransferTargetParamsVFile*>::iterator curiter = iter++; | ||
46 | LLTransferTargetParamsVFile* params = *curiter; | ||
47 | LLVFSThread::status_t s = LLVFile::getVFSThread()->getRequestStatus(params->mHandle); | ||
48 | if (s == LLVFSThread::STATUS_COMPLETE || s == LLVFSThread::STATUS_EXPIRED) | ||
49 | { | ||
50 | params->mCompleteCallback( | ||
51 | params->mErrCode, | ||
52 | params->getAssetID(), | ||
53 | params->getAssetType(), | ||
54 | params->mUserDatap); | ||
55 | delete params; | ||
56 | iter = sCallbackQueue.erase(curiter); | ||
57 | } | ||
58 | else if (shutdown) | ||
59 | { | ||
60 | delete params; | ||
61 | iter = sCallbackQueue.erase(curiter); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | |||
67 | LLTransferTargetParamsVFile::LLTransferTargetParamsVFile() : | ||
68 | LLTransferTargetParams(LLTTT_VFILE), | ||
69 | mAssetType(LLAssetType::AT_NONE), | ||
70 | mCompleteCallback(NULL), | ||
71 | mUserDatap(NULL), | ||
72 | mErrCode(0), | ||
73 | mHandle(LLVFSThread::nullHandle()) | ||
74 | { | ||
75 | } | ||
76 | |||
77 | void LLTransferTargetParamsVFile::setAsset( | ||
78 | const LLUUID& asset_id, | ||
79 | LLAssetType::EType asset_type) | ||
80 | { | ||
81 | mAssetID = asset_id; | ||
82 | mAssetType = asset_type; | ||
83 | } | ||
84 | |||
85 | void LLTransferTargetParamsVFile::setCallback(LLTTVFCompleteCallback cb, void *user_data) | ||
86 | { | ||
87 | mCompleteCallback = cb; | ||
88 | mUserDatap = user_data; | ||
89 | } | ||
90 | |||
91 | bool LLTransferTargetParamsVFile::unpackParams(LLDataPacker& dp) | ||
92 | { | ||
93 | // if the source provided a new key, assign that to the asset id. | ||
94 | if(dp.hasNext()) | ||
95 | { | ||
96 | LLUUID dummy_id; | ||
97 | dp.unpackUUID(dummy_id, "AgentID"); | ||
98 | dp.unpackUUID(dummy_id, "SessionID"); | ||
99 | dp.unpackUUID(dummy_id, "OwnerID"); | ||
100 | dp.unpackUUID(dummy_id, "TaskID"); | ||
101 | dp.unpackUUID(dummy_id, "ItemID"); | ||
102 | dp.unpackUUID(mAssetID, "AssetID"); | ||
103 | S32 dummy_type; | ||
104 | dp.unpackS32(dummy_type, "AssetType"); | ||
105 | } | ||
106 | |||
107 | // if we never got an asset id, this will always fail. | ||
108 | if(mAssetID.isNull()) | ||
109 | { | ||
110 | return false; | ||
111 | } | ||
112 | return true; | ||
113 | } | ||
114 | |||
115 | |||
116 | LLTransferTargetVFile::LLTransferTargetVFile( | ||
117 | const LLUUID& uuid, | ||
118 | LLTransferSourceType src_type) : | ||
119 | LLTransferTarget(LLTTT_VFILE, uuid, src_type), | ||
120 | mNeedsCreate(TRUE) | ||
121 | { | ||
122 | mTempID.generate(); | ||
123 | } | ||
124 | |||
125 | |||
126 | LLTransferTargetVFile::~LLTransferTargetVFile() | ||
127 | { | ||
128 | } | ||
129 | |||
130 | |||
131 | // virtual | ||
132 | bool LLTransferTargetVFile::unpackParams(LLDataPacker& dp) | ||
133 | { | ||
134 | if(LLTST_SIM_INV_ITEM == mSourceType) | ||
135 | { | ||
136 | return mParams.unpackParams(dp); | ||
137 | } | ||
138 | return true; | ||
139 | } | ||
140 | |||
141 | void LLTransferTargetVFile::applyParams(const LLTransferTargetParams ¶ms) | ||
142 | { | ||
143 | if (params.getType() != mType) | ||
144 | { | ||
145 | llwarns << "Target parameter type doesn't match!" << llendl; | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | mParams = (LLTransferTargetParamsVFile &)params; | ||
150 | } | ||
151 | |||
152 | |||
153 | LLTSCode LLTransferTargetVFile::dataCallback(const S32 packet_id, U8 *in_datap, const S32 in_size) | ||
154 | { | ||
155 | //llinfos << "LLTransferTargetFile::dataCallback" << llendl; | ||
156 | //llinfos << "Packet: " << packet_id << llendl; | ||
157 | |||
158 | LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND); | ||
159 | if (mNeedsCreate) | ||
160 | { | ||
161 | vf.setMaxSize(mSize); | ||
162 | mNeedsCreate = FALSE; | ||
163 | } | ||
164 | |||
165 | if (!in_size) | ||
166 | { | ||
167 | return LLTS_OK; | ||
168 | } | ||
169 | |||
170 | if (!vf.write(in_datap, in_size)) | ||
171 | { | ||
172 | llwarns << "Failure in LLTransferTargetVFile::dataCallback!" << llendl; | ||
173 | return LLTS_ERROR; | ||
174 | } | ||
175 | return LLTS_OK; | ||
176 | } | ||
177 | |||
178 | |||
179 | void LLTransferTargetVFile::completionCallback(const LLTSCode status) | ||
180 | { | ||
181 | //llinfos << "LLTransferTargetVFile::completionCallback" << llendl; | ||
182 | |||
183 | if (!gAssetStorage) | ||
184 | { | ||
185 | llwarns << "Aborting vfile transfer after asset storage shut down!" << llendl; | ||
186 | return; | ||
187 | } | ||
188 | LLVFSThread::handle_t handle = LLVFSThread::nullHandle(); | ||
189 | |||
190 | // Still need to gracefully handle error conditions. | ||
191 | S32 err_code = 0; | ||
192 | switch (status) | ||
193 | { | ||
194 | case LLTS_DONE: | ||
195 | if (!mNeedsCreate) | ||
196 | { | ||
197 | handle = LLVFile::getVFSThread()->rename( | ||
198 | gAssetStorage->mVFS, | ||
199 | mTempID, mParams.getAssetType(), | ||
200 | mParams.getAssetID(), mParams.getAssetType(), | ||
201 | LLVFSThread::AUTO_DELETE); | ||
202 | } | ||
203 | err_code = LL_ERR_NOERR; | ||
204 | lldebugs << "LLTransferTargetVFile::completionCallback for " | ||
205 | << mParams.getAssetID() << "," | ||
206 | << LLAssetType::lookup(mParams.getAssetType()) | ||
207 | << " with temp id " << mTempID << llendl; | ||
208 | break; | ||
209 | case LLTS_ERROR: | ||
210 | case LLTS_ABORT: | ||
211 | case LLTS_UNKNOWN_SOURCE: | ||
212 | default: | ||
213 | { | ||
214 | // We're aborting this transfer, we don't want to keep this file. | ||
215 | llwarns << "Aborting vfile transfer for " << mParams.getAssetID() << llendl; | ||
216 | LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND); | ||
217 | vf.remove(); | ||
218 | } | ||
219 | break; | ||
220 | } | ||
221 | |||
222 | switch (status) | ||
223 | { | ||
224 | case LLTS_DONE: | ||
225 | err_code = LL_ERR_NOERR; | ||
226 | break; | ||
227 | case LLTS_UNKNOWN_SOURCE: | ||
228 | err_code = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE; | ||
229 | break; | ||
230 | case LLTS_INSUFFICIENT_PERMISSIONS: | ||
231 | err_code = LL_ERR_INSUFFICIENT_PERMISSIONS; | ||
232 | break; | ||
233 | case LLTS_ERROR: | ||
234 | case LLTS_ABORT: | ||
235 | default: | ||
236 | err_code = LL_ERR_ASSET_REQUEST_FAILED; | ||
237 | break; | ||
238 | } | ||
239 | if (mParams.mCompleteCallback) | ||
240 | { | ||
241 | if (handle != LLVFSThread::nullHandle()) | ||
242 | { | ||
243 | LLTransferTargetParamsVFile* params = new LLTransferTargetParamsVFile(mParams); | ||
244 | params->mErrCode = err_code; | ||
245 | params->mHandle = handle; | ||
246 | sCallbackQueue.push_back(params); | ||
247 | } | ||
248 | else | ||
249 | { | ||
250 | mParams.mCompleteCallback( | ||
251 | err_code, | ||
252 | mParams.getAssetID(), | ||
253 | mParams.getAssetType(), | ||
254 | mParams.mUserDatap); | ||
255 | } | ||
256 | } | ||
257 | } | ||