aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs222
1 files changed, 65 insertions, 157 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
index f6dd5af..4cedfe6 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
@@ -49,75 +49,39 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 50
51 /// <summary> 51 /// <summary>
52 /// Upload state.
53 /// </summary>
54 /// <remarks>
55 /// New -> Uploading -> Complete
56 /// </remarks>
57 private enum UploadState
58 {
59 New,
60 Uploading,
61 Complete
62 }
63
64 /// <summary>
65 /// Reference to the object that holds this uploader. Used to remove ourselves from it's list if we 52 /// Reference to the object that holds this uploader. Used to remove ourselves from it's list if we
66 /// are performing a delayed update. 53 /// are performing a delayed update.
67 /// </summary> 54 /// </summary>
68 AgentAssetTransactions m_transactions; 55 AgentAssetTransactions m_transactions;
69 56
70 private UploadState m_uploadState = UploadState.New;
71
72 private AssetBase m_asset; 57 private AssetBase m_asset;
73 private UUID InventFolder = UUID.Zero; 58 private UUID InventFolder = UUID.Zero;
74 private sbyte invType = 0; 59 private sbyte invType = 0;
75 60
76 private bool m_createItem; 61 private bool m_createItem = false;
77 private uint m_createItemCallback; 62 private uint m_createItemCallback = 0;
78 63 private bool m_updateItem = false;
79 private bool m_updateItem;
80 private InventoryItemBase m_updateItemData; 64 private InventoryItemBase m_updateItemData;
81 65
82 private bool m_updateTaskItem;
83 private TaskInventoryItem m_updateTaskItemData;
84
85 private string m_description = String.Empty; 66 private string m_description = String.Empty;
86 private bool m_dumpAssetToFile; 67 private bool m_dumpAssetToFile;
68 private bool m_finished = false;
87 private string m_name = String.Empty; 69 private string m_name = String.Empty;
88// private bool m_storeLocal; 70 private bool m_storeLocal;
89 private uint nextPerm = 0; 71 private uint nextPerm = 0;
90 private IClientAPI ourClient; 72 private IClientAPI ourClient;
91 73 private UUID TransactionID = UUID.Zero;
92 private UUID m_transactionID;
93
94 private sbyte type = 0; 74 private sbyte type = 0;
95 private byte wearableType = 0; 75 private byte wearableType = 0;
96 private byte[] m_oldData = null; 76 private byte[] m_oldData = null;
97 public ulong XferID; 77 public ulong XferID;
98 private Scene m_Scene; 78 private Scene m_Scene;
99 79
100 /// <summary> 80 public AssetXferUploader(AgentAssetTransactions transactions, Scene scene, UUID assetID, bool dumpAssetToFile)
101 /// AssetXferUploader constructor
102 /// </summary>
103 /// <param name='transactions'>/param>
104 /// <param name='scene'></param>
105 /// <param name='transactionID'></param>
106 /// <param name='dumpAssetToFile'>
107 /// If true then when the asset is uploaded it is dumped to a file with the format
108 /// String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat",
109 /// now.Year, now.Month, now.Day, now.Hour, now.Minute,
110 /// now.Second, m_asset.Name, m_asset.Type);
111 /// for debugging purposes.
112 /// </param>
113 public AssetXferUploader(
114 AgentAssetTransactions transactions, Scene scene, UUID transactionID, bool dumpAssetToFile)
115 { 81 {
116 m_asset = new AssetBase();
117
118 m_transactions = transactions; 82 m_transactions = transactions;
119 m_transactionID = transactionID;
120 m_Scene = scene; 83 m_Scene = scene;
84 m_asset = new AssetBase() { FullID = assetID };
121 m_dumpAssetToFile = dumpAssetToFile; 85 m_dumpAssetToFile = dumpAssetToFile;
122 } 86 }
123 87
@@ -163,50 +127,30 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
163 } 127 }
164 128
165 /// <summary> 129 /// <summary>
166 /// Start asset transfer from the client 130 /// Initialise asset transfer from the client
167 /// </summary> 131 /// </summary>
168 /// <param name="remoteClient"></param> 132 /// <param name="xferID"></param>
169 /// <param name="assetID"></param> 133 /// <param name="packetID"></param>
170 /// <param name="transaction"></param> 134 /// <param name="data"></param>
171 /// <param name="type"></param> 135 public void Initialise(IClientAPI remoteClient, UUID assetID,
172 /// <param name="data"> 136 UUID transaction, sbyte type, byte[] data, bool storeLocal,
173 /// Optional data. If present then the asset is created immediately with this data 137 bool tempFile)
174 /// rather than requesting an upload from the client. The data must be longer than 2 bytes.
175 /// </param>
176 /// <param name="storeLocal"></param>
177 /// <param name="tempFile"></param>
178 public void StartUpload(
179 IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, byte[] data, bool storeLocal,
180 bool tempFile)
181 { 138 {
182// m_log.DebugFormat( 139// m_log.DebugFormat(
183// "[ASSET XFER UPLOADER]: Initialised xfer from {0}, asset {1}, transaction {2}, type {3}, storeLocal {4}, tempFile {5}, already received data length {6}", 140// "[ASSET XFER UPLOADER]: Initialised xfer from {0}, asset {1}, transaction {2}, type {3}, storeLocal {4}, tempFile {5}, already received data length {6}",
184// remoteClient.Name, assetID, transaction, type, storeLocal, tempFile, data.Length); 141// remoteClient.Name, assetID, transaction, type, storeLocal, tempFile, data.Length);
185 142
186 lock (this)
187 {
188 if (m_uploadState != UploadState.New)
189 {
190 m_log.WarnFormat(
191 "[ASSET XFER UPLOADER]: Tried to start upload of asset {0}, transaction {1} for {2} but this is already in state {3}. Aborting.",
192 assetID, transaction, remoteClient.Name, m_uploadState);
193
194 return;
195 }
196
197 m_uploadState = UploadState.Uploading;
198 }
199
200 ourClient = remoteClient; 143 ourClient = remoteClient;
201 144 m_asset.Name = "blank";
202 m_asset.FullID = assetID; 145 m_asset.Description = "empty";
203 m_asset.Type = type; 146 m_asset.Type = type;
204 m_asset.CreatorID = remoteClient.AgentId.ToString(); 147 m_asset.CreatorID = remoteClient.AgentId.ToString();
205 m_asset.Data = data; 148 m_asset.Data = data;
206 m_asset.Local = storeLocal; 149 m_asset.Local = storeLocal;
207 m_asset.Temporary = tempFile; 150 m_asset.Temporary = tempFile;
208 151
209// m_storeLocal = storeLocal; 152 TransactionID = transaction;
153 m_storeLocal = storeLocal;
210 154
211 if (m_asset.Data.Length > 2) 155 if (m_asset.Data.Length > 2)
212 { 156 {
@@ -231,35 +175,36 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
231 175
232 protected void SendCompleteMessage() 176 protected void SendCompleteMessage()
233 { 177 {
178 ourClient.SendAssetUploadCompleteMessage(m_asset.Type, true,
179 m_asset.FullID);
180
234 // We must lock in order to avoid a race with a separate thread dealing with an inventory item or create 181 // We must lock in order to avoid a race with a separate thread dealing with an inventory item or create
235 // message from other client UDP. 182 // message from other client UDP.
236 lock (this) 183 lock (this)
237 { 184 {
238 m_uploadState = UploadState.Complete; 185 m_finished = true;
239
240 ourClient.SendAssetUploadCompleteMessage(m_asset.Type, true, m_asset.FullID);
241
242 if (m_createItem) 186 if (m_createItem)
243 { 187 {
244 CompleteCreateItem(m_createItemCallback); 188 DoCreateItem(m_createItemCallback);
245 } 189 }
246 else if (m_updateItem) 190 else if (m_updateItem)
247 { 191 {
248 CompleteItemUpdate(m_updateItemData); 192 StoreAssetForItemUpdate(m_updateItemData);
193
194 // Remove ourselves from the list of transactions if completion was delayed until the transaction
195 // was complete.
196 // TODO: Should probably do the same for create item.
197 m_transactions.RemoveXferUploader(TransactionID);
249 } 198 }
250 else if (m_updateTaskItem) 199 else if (m_storeLocal)
251 { 200 {
252 CompleteTaskItemUpdate(m_updateTaskItemData); 201 m_Scene.AssetService.Store(m_asset);
253 } 202 }
254// else if (m_storeLocal)
255// {
256// m_Scene.AssetService.Store(m_asset);
257// }
258 } 203 }
259 204
260 m_log.DebugFormat( 205 m_log.DebugFormat(
261 "[ASSET XFER UPLOADER]: Uploaded asset {0} for transaction {1}", 206 "[ASSET XFER UPLOADER]: Uploaded asset {0} for transaction {1}",
262 m_asset.FullID, m_transactionID); 207 m_asset.FullID, TransactionID);
263 208
264 if (m_dumpAssetToFile) 209 if (m_dumpAssetToFile)
265 { 210 {
@@ -287,37 +232,40 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
287 } 232 }
288 233
289 public void RequestCreateInventoryItem(IClientAPI remoteClient, 234 public void RequestCreateInventoryItem(IClientAPI remoteClient,
290 UUID folderID, uint callbackID, 235 UUID transactionID, UUID folderID, uint callbackID,
291 string description, string name, sbyte invType, 236 string description, string name, sbyte invType,
292 sbyte type, byte wearableType, uint nextOwnerMask) 237 sbyte type, byte wearableType, uint nextOwnerMask)
293 { 238 {
294 InventFolder = folderID; 239 if (TransactionID == transactionID)
295 m_name = name;
296 m_description = description;
297 this.type = type;
298 this.invType = invType;
299 this.wearableType = wearableType;
300 nextPerm = nextOwnerMask;
301 m_asset.Name = name;
302 m_asset.Description = description;
303 m_asset.Type = type;
304
305 // We must lock to avoid a race with a separate thread uploading the asset.
306 lock (this)
307 { 240 {
308 if (m_uploadState == UploadState.Complete) 241 InventFolder = folderID;
242 m_name = name;
243 m_description = description;
244 this.type = type;
245 this.invType = invType;
246 this.wearableType = wearableType;
247 nextPerm = nextOwnerMask;
248 m_asset.Name = name;
249 m_asset.Description = description;
250 m_asset.Type = type;
251
252 // We must lock to avoid a race with a separate thread uploading the asset.
253 lock (this)
309 { 254 {
310 CompleteCreateItem(callbackID); 255 if (m_finished)
311 } 256 {
312 else 257 DoCreateItem(callbackID);
313 { 258 }
314 m_createItem = true; //set flag so the inventory item is created when upload is complete 259 else
315 m_createItemCallback = callbackID; 260 {
261 m_createItem = true; //set flag so the inventory item is created when upload is complete
262 m_createItemCallback = callbackID;
263 }
316 } 264 }
317 } 265 }
318 } 266 }
319 267
320 public void RequestUpdateInventoryItem(IClientAPI remoteClient, InventoryItemBase item) 268 public void RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item)
321 { 269 {
322 // We must lock to avoid a race with a separate thread uploading the asset. 270 // We must lock to avoid a race with a separate thread uploading the asset.
323 lock (this) 271 lock (this)
@@ -332,9 +280,9 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
332 item.AssetID = m_asset.FullID; 280 item.AssetID = m_asset.FullID;
333 m_Scene.InventoryService.UpdateItem(item); 281 m_Scene.InventoryService.UpdateItem(item);
334 282
335 if (m_uploadState == UploadState.Complete) 283 if (m_finished)
336 { 284 {
337 CompleteItemUpdate(item); 285 StoreAssetForItemUpdate(item);
338 } 286 }
339 else 287 else
340 { 288 {
@@ -348,59 +296,20 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
348 } 296 }
349 } 297 }
350 298
351 public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient, TaskInventoryItem taskItem)
352 {
353 // We must lock to avoid a race with a separate thread uploading the asset.
354 lock (this)
355 {
356 m_asset.Name = taskItem.Name;
357 m_asset.Description = taskItem.Description;
358 m_asset.Type = (sbyte)taskItem.Type;
359 taskItem.AssetID = m_asset.FullID;
360
361 if (m_uploadState == UploadState.Complete)
362 {
363 CompleteTaskItemUpdate(taskItem);
364 }
365 else
366 {
367 m_updateTaskItem = true;
368 m_updateTaskItemData = taskItem;
369 }
370 }
371 }
372
373 /// <summary> 299 /// <summary>
374 /// Store the asset for the given item when it has been uploaded. 300 /// Store the asset for the given item.
375 /// </summary> 301 /// </summary>
376 /// <param name="item"></param> 302 /// <param name="item"></param>
377 private void CompleteItemUpdate(InventoryItemBase item) 303 private void StoreAssetForItemUpdate(InventoryItemBase item)
378 { 304 {
379// m_log.DebugFormat( 305// m_log.DebugFormat(
380// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier item update for {1} for {2}", 306// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier item update for {1} for {2}",
381// m_asset.FullID, item.Name, ourClient.Name); 307// m_asset.FullID, item.Name, ourClient.Name);
382 308
383 m_Scene.AssetService.Store(m_asset); 309 m_Scene.AssetService.Store(m_asset);
384
385 m_transactions.RemoveXferUploader(m_transactionID);
386 }
387
388 /// <summary>
389 /// Store the asset for the given task item when it has been uploaded.
390 /// </summary>
391 /// <param name="taskItem"></param>
392 private void CompleteTaskItemUpdate(TaskInventoryItem taskItem)
393 {
394// m_log.DebugFormat(
395// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier task item update for {1} for {2}",
396// m_asset.FullID, taskItem.Name, ourClient.Name);
397
398 m_Scene.AssetService.Store(m_asset);
399
400 m_transactions.RemoveXferUploader(m_transactionID);
401 } 310 }
402 311
403 private void CompleteCreateItem(uint callbackID) 312 private void DoCreateItem(uint callbackID)
404 { 313 {
405 ValidateAssets(); 314 ValidateAssets();
406 m_Scene.AssetService.Store(m_asset); 315 m_Scene.AssetService.Store(m_asset);
@@ -430,8 +339,6 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
430 ourClient.SendInventoryItemCreateUpdate(item, callbackID); 339 ourClient.SendInventoryItemCreateUpdate(item, callbackID);
431 else 340 else
432 ourClient.SendAlertMessage("Unable to create inventory item"); 341 ourClient.SendAlertMessage("Unable to create inventory item");
433
434 m_transactions.RemoveXferUploader(m_transactionID);
435 } 342 }
436 343
437 private void ValidateAssets() 344 private void ValidateAssets()
@@ -509,7 +416,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
509 /// <returns>null if the asset has not finished uploading</returns> 416 /// <returns>null if the asset has not finished uploading</returns>
510 public AssetBase GetAssetData() 417 public AssetBase GetAssetData()
511 { 418 {
512 if (m_uploadState == UploadState.Complete) 419 if (m_finished)
513 { 420 {
514 ValidateAssets(); 421 ValidateAssets();
515 return m_asset; 422 return m_asset;
@@ -562,3 +469,4 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
562 } 469 }
563 } 470 }
564} 471}
472