Fix upload snapshot to inventory callback mechanism.

This commit is contained in:
Aleric Inglewood
2013-01-12 17:27:33 +01:00
parent 024c62aed4
commit 57228fa208
5 changed files with 74 additions and 15 deletions

View File

@@ -317,8 +317,10 @@ void LLAssetUploadResponder::uploadComplete(const LLSD& content)
LLNewAgentInventoryResponder::LLNewAgentInventoryResponder( LLNewAgentInventoryResponder::LLNewAgentInventoryResponder(
const LLSD& post_data, const LLSD& post_data,
const LLUUID& vfile_id, const LLUUID& vfile_id,
LLAssetType::EType asset_type) LLAssetType::EType asset_type,
: LLAssetUploadResponder(post_data, vfile_id, asset_type) void (*callback)(bool, void*),
void* user_data)
: LLAssetUploadResponder(post_data, vfile_id, asset_type), mCallBack(callback), mUserData(user_data)
{ {
} }
@@ -326,13 +328,17 @@ LLNewAgentInventoryResponder::LLNewAgentInventoryResponder(
const LLSD& post_data, const LLSD& post_data,
const std::string& file_name, const std::string& file_name,
LLAssetType::EType asset_type) LLAssetType::EType asset_type)
: LLAssetUploadResponder(post_data, file_name, asset_type) : LLAssetUploadResponder(post_data, file_name, asset_type), mCallBack(NULL), mUserData(NULL)
{ {
} }
// virtual // virtual
void LLNewAgentInventoryResponder::error(U32 statusNum, const std::string& reason) void LLNewAgentInventoryResponder::error(U32 statusNum, const std::string& reason)
{ {
if (mCallBack)
{
(*mCallBack)(false, mUserData);
}
LLAssetUploadResponder::error(statusNum, reason); LLAssetUploadResponder::error(statusNum, reason);
//LLImportColladaAssetCache::getInstance()->assetUploaded(mVFileID, LLUUID(), FALSE); //LLImportColladaAssetCache::getInstance()->assetUploaded(mVFileID, LLUUID(), FALSE);
} }
@@ -340,6 +346,10 @@ void LLNewAgentInventoryResponder::error(U32 statusNum, const std::string& reaso
//virtual //virtual
void LLNewAgentInventoryResponder::uploadFailure(const LLSD& content) void LLNewAgentInventoryResponder::uploadFailure(const LLSD& content)
{ {
if (mCallBack)
{
(*mCallBack)(false, mUserData);
}
LLAssetUploadResponder::uploadFailure(content); LLAssetUploadResponder::uploadFailure(content);
//LLImportColladaAssetCache::getInstance()->assetUploaded(mVFileID, content["new_asset"], FALSE); //LLImportColladaAssetCache::getInstance()->assetUploaded(mVFileID, content["new_asset"], FALSE);
} }
@@ -349,6 +359,11 @@ void LLNewAgentInventoryResponder::uploadComplete(const LLSD& content)
{ {
lldebugs << "LLNewAgentInventoryResponder::result from capabilities" << llendl; lldebugs << "LLNewAgentInventoryResponder::result from capabilities" << llendl;
if (mCallBack)
{
(*mCallBack)(true, mUserData);
}
//std::ostringstream llsdxml; //std::ostringstream llsdxml;
//LLSDSerialize::toXML(content, llsdxml); //LLSDSerialize::toXML(content, llsdxml);
//llinfos << "upload complete content:\n " << llsdxml.str() << llendl; //llinfos << "upload complete content:\n " << llsdxml.str() << llendl;

View File

@@ -78,11 +78,15 @@ protected:
class LLNewAgentInventoryResponder : public LLAssetUploadResponder class LLNewAgentInventoryResponder : public LLAssetUploadResponder
{ {
void (*mCallBack)(bool, void*);
void* mUserData;
public: public:
LLNewAgentInventoryResponder( LLNewAgentInventoryResponder(
const LLSD& post_data, const LLSD& post_data,
const LLUUID& vfile_id, const LLUUID& vfile_id,
LLAssetType::EType asset_type); LLAssetType::EType asset_type,
void (*callback)(bool, void*) = NULL,
void* user_data = NULL);
LLNewAgentInventoryResponder( LLNewAgentInventoryResponder(
const LLSD& post_data, const LLSD& post_data,
const std::string& file_name, const std::string& file_name,

View File

@@ -64,6 +64,7 @@
#include "llviewerwindow.h" #include "llviewerwindow.h"
#include "llwindow.h" #include "llwindow.h"
#include "llviewermenufile.h" // upload_new_resource() #include "llviewermenufile.h" // upload_new_resource()
#include "llresourcedata.h"
#include "llfloaterpostcard.h" #include "llfloaterpostcard.h"
#include "llfloaterfeed.h" #include "llfloaterfeed.h"
#include "llcheckboxctrl.h" #include "llcheckboxctrl.h"
@@ -183,6 +184,7 @@ public:
LLFloaterPostcard* savePostcard(); LLFloaterPostcard* savePostcard();
void saveTexture(); void saveTexture();
static void saveTextureDone(LLUUID const& asset_id, void* user_data, S32 status, LLExtStat ext_status); static void saveTextureDone(LLUUID const& asset_id, void* user_data, S32 status, LLExtStat ext_status);
static void saveTextureDone2(bool success, void* user_data);
void saveLocal(); void saveLocal();
void saveStart(int index); void saveStart(int index);
void saveDone(ESnapshotType type, bool success, int index); void saveDone(ESnapshotType type, bool success, int index);
@@ -1383,9 +1385,10 @@ LLFloaterPostcard* LLSnapshotLivePreview::savePostcard()
class saveTextureUserData { class saveTextureUserData {
public: public:
saveTextureUserData(LLSnapshotLivePreview* self, int index) : mSelf(self), mSnapshotIndex(index) { } saveTextureUserData(LLSnapshotLivePreview* self, int index, bool temporary) : mSelf(self), mSnapshotIndex(index), mTemporary(temporary) { }
LLSnapshotLivePreview* mSelf; LLSnapshotLivePreview* mSelf;
int mSnapshotIndex; int mSnapshotIndex;
bool mTemporary;
}; };
void LLSnapshotLivePreview::saveTexture() void LLSnapshotLivePreview::saveTexture()
@@ -1412,7 +1415,8 @@ void LLSnapshotLivePreview::saveTexture()
LLAgentUI::buildFullname(who_took_it); LLAgentUI::buildFullname(who_took_it);
LLAssetStorage::LLStoreAssetCallback callback = &LLSnapshotLivePreview::saveTextureDone; LLAssetStorage::LLStoreAssetCallback callback = &LLSnapshotLivePreview::saveTextureDone;
S32 expected_upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(); S32 expected_upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload();
upload_new_resource(tid, // tid saveTextureUserData* user_data = new saveTextureUserData(this, sSnapshotIndex, gSavedSettings.getBOOL("TemporaryUpload"));
if (!upload_new_resource(tid, // tid
LLAssetType::AT_TEXTURE, LLAssetType::AT_TEXTURE,
"Snapshot : " + pos_string, "Snapshot : " + pos_string,
"Taken by " + who_took_it + " at " + pos_string, "Taken by " + who_took_it + " at " + pos_string,
@@ -1423,7 +1427,12 @@ void LLSnapshotLivePreview::saveTexture()
LLFloaterPerms::getGroupPerms(), // that is more permissive than other uploads LLFloaterPerms::getGroupPerms(), // that is more permissive than other uploads
LLFloaterPerms::getEveryonePerms(), LLFloaterPerms::getEveryonePerms(),
"Snapshot : " + pos_string, "Snapshot : " + pos_string,
callback, expected_upload_cost, new saveTextureUserData(this, sSnapshotIndex)); callback, expected_upload_cost, user_data, &LLSnapshotLivePreview::saveTextureDone2))
{
// Something went wrong.
delete user_data;
saveDone(SNAPSHOT_TEXTURE, false, sSnapshotIndex);
}
gViewerWindow->playSnapshotAnimAndSound(); gViewerWindow->playSnapshotAnimAndSound();
LLViewerStats::getInstance()->incStat(LLViewerStats::ST_SNAPSHOT_COUNT ); LLViewerStats::getInstance()->incStat(LLViewerStats::ST_SNAPSHOT_COUNT );
@@ -1509,16 +1518,36 @@ void LLSnapshotLivePreview::saveDone(ESnapshotType type, bool success, int index
} }
} }
// This callback is only used for the *legacy* LLViewerAssetStorage::storeAssetData
// (when the cap NewFileAgentInventory is not available) and temporaries.
// See upload_new_resource.
//static //static
void LLSnapshotLivePreview::saveTextureDone(LLUUID const& asset_id, void* user_data, S32 status, LLExtStat ext_status) void LLSnapshotLivePreview::saveTextureDone(LLUUID const& asset_id, void* user_data, S32 status, LLExtStat ext_status)
{ {
bool success = status != LL_ERR_NOERR; LLResourceData* resource_data = (LLResourceData*)user_data;
bool success = status == LL_ERR_NOERR;
if (!success) if (!success)
{ {
LLSD args; LLSD args;
args["REASON"] = std::string(LLAssetStorage::getErrorString(status)); args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
LLNotificationsUtil::add("UploadSnapshotFail", args); LLNotificationsUtil::add("UploadSnapshotFail", args);
} }
saveTextureUserData* data = (saveTextureUserData*)resource_data->mUserData;
bool temporary = data->mTemporary;
data->mSelf->saveDone(SNAPSHOT_TEXTURE, success, data->mSnapshotIndex);
delete data;
// Call the default call back.
LLAssetStorage::LLStoreAssetCallback asset_callback = temporary ? &temp_upload_callback : &upload_done_callback;
(*asset_callback)(asset_id, user_data, status, ext_status);
}
// This callback used when the capability NewFileAgentInventory is available and it wasn't a temporary.
// See upload_new_resource.
//static
void LLSnapshotLivePreview::saveTextureDone2(bool success, void* user_data)
{
saveTextureUserData* data = (saveTextureUserData*)user_data; saveTextureUserData* data = (saveTextureUserData*)user_data;
data->mSelf->saveDone(SNAPSHOT_TEXTURE, success, data->mSnapshotIndex); data->mSelf->saveDone(SNAPSHOT_TEXTURE, success, data->mSnapshotIndex);
delete data; delete data;

View File

@@ -1155,7 +1155,7 @@ LLSD generate_new_resource_upload_capability_body(LLAssetType::EType asset_type,
return body; return body;
} }
void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_type, bool upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_type,
std::string name, std::string name,
std::string desc, S32 compression_info, std::string desc, S32 compression_info,
LLFolderType::EType destination_folder_type, LLFolderType::EType destination_folder_type,
@@ -1166,11 +1166,12 @@ void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_ty
const std::string& display_name, const std::string& display_name,
LLAssetStorage::LLStoreAssetCallback callback, LLAssetStorage::LLStoreAssetCallback callback,
S32 expected_upload_cost, S32 expected_upload_cost,
void *userdata) void *userdata,
void (*callback2)(bool, void*))
{ {
if(gDisconnected) if(gDisconnected)
{ {
return ; return false;
} }
@@ -1207,7 +1208,7 @@ void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_ty
body["expected_upload_cost"] = LLSD::Integer(expected_upload_cost); body["expected_upload_cost"] = LLSD::Integer(expected_upload_cost);
LLHTTPClient::post(url, body, LLHTTPClient::post(url, body,
new LLNewAgentInventoryResponder(body, uuid, asset_type)); new LLNewAgentInventoryResponder(body, uuid, asset_type, callback2, userdata));
} }
else else
{ {
@@ -1230,7 +1231,7 @@ void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_ty
args["[CURRENCY]"] = gHippoGridManager->getConnectedGrid()->getCurrencySymbol(); args["[CURRENCY]"] = gHippoGridManager->getConnectedGrid()->getCurrencySymbol();
args["[AMOUNT]"] = llformat("%d", expected_upload_cost); args["[AMOUNT]"] = llformat("%d", expected_upload_cost);
LLFloaterBuyCurrency::buyCurrency( LLTrans::getString("UploadingCosts", args), expected_upload_cost ); LLFloaterBuyCurrency::buyCurrency( LLTrans::getString("UploadingCosts", args), expected_upload_cost );
return; return false;
} }
} }
} }
@@ -1260,6 +1261,9 @@ void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_ty
TRUE, TRUE,
temporary); temporary);
} }
// Return true when a call to a callback function will follow.
return true;
} }
LLAssetID generate_asset_id_for_new_upload(const LLTransactionID& tid) LLAssetID generate_asset_id_for_new_upload(const LLTransactionID& tid)

View File

@@ -66,7 +66,8 @@ void upload_new_resource(const std::string& src_filename,
S32 expected_upload_cost, S32 expected_upload_cost,
void *userdata); void *userdata);
void upload_new_resource(const LLTransactionID &tid, // Return false if no upload attempt was done (and the callback will not be called).
bool upload_new_resource(const LLTransactionID &tid,
LLAssetType::EType type, LLAssetType::EType type,
std::string name, std::string name,
std::string desc, std::string desc,
@@ -79,7 +80,13 @@ void upload_new_resource(const LLTransactionID &tid,
const std::string& display_name, const std::string& display_name,
LLAssetStorage::LLStoreAssetCallback callback, LLAssetStorage::LLStoreAssetCallback callback,
S32 expected_upload_cost, S32 expected_upload_cost,
void *userdata); void *userdata,
void (*callback2)(bool, void*) = NULL);
// The default callback functions, called when 'callback' == NULL (for normal and temporary uploads).
// user_data must be a LLResourceData allocated with new (or NULL).
void upload_done_callback(const LLUUID& uuid, void* user_data, S32 result, LLExtStat ext_status);
void temp_upload_callback(const LLUUID& uuid, void* user_data, S32 result, LLExtStat ext_status);
LLAssetID generate_asset_id_for_new_upload(const LLTransactionID& tid); LLAssetID generate_asset_id_for_new_upload(const LLTransactionID& tid);