Convert LSL syntax download to coroutine.
parent
7fb7e93a13
commit
aa47516e89
|
|
@ -34,66 +34,8 @@
|
|||
#include "llhttpclient.h"
|
||||
#include "llsdserialize.h"
|
||||
#include "llviewerregion.h"
|
||||
#include "llcorehttputil.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fetchKeywordsFileResponder
|
||||
//-----------------------------------------------------------------------------
|
||||
class fetchKeywordsFileResponder : public LLHTTPClient::Responder
|
||||
{
|
||||
public:
|
||||
fetchKeywordsFileResponder(const std::string& filespec)
|
||||
: mFileSpec(filespec)
|
||||
{
|
||||
LL_DEBUGS("SyntaxLSL") << "Instantiating with file saving to: '" << filespec << "'" << LL_ENDL;
|
||||
}
|
||||
|
||||
/* virtual */ void httpFailure()
|
||||
{
|
||||
LL_WARNS("SyntaxLSL") << "failed to fetch syntax file [status:" << getStatus() << "]: " << getContent() << LL_ENDL;
|
||||
}
|
||||
|
||||
/* virtual */ void httpSuccess()
|
||||
{
|
||||
// Continue only if a valid LLSD object was returned.
|
||||
const LLSD& content = getContent();
|
||||
if (content.isMap())
|
||||
{
|
||||
if (LLSyntaxIdLSL::getInstance()->isSupportedVersion(content))
|
||||
{
|
||||
LLSyntaxIdLSL::getInstance()->setKeywordsXml(content);
|
||||
|
||||
cacheFile(content);
|
||||
LLSyntaxIdLSL::getInstance()->handleFileFetched(mFileSpec);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_WARNS("SyntaxLSL") << "Unknown or unsupported version of syntax file." << LL_ENDL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_WARNS("SyntaxLSL") << "Syntax file '" << mFileSpec << "' contains invalid LLSD." << LL_ENDL;
|
||||
}
|
||||
}
|
||||
|
||||
void cacheFile(const LLSD& content_ref)
|
||||
{
|
||||
std::stringstream str;
|
||||
LLSDSerialize::toXML(content_ref, str);
|
||||
const std::string xml = str.str();
|
||||
|
||||
// save the str to disk, usually to the cache.
|
||||
llofstream file(mFileSpec.c_str(), std::ios_base::out);
|
||||
file.write(xml.c_str(), str.str().size());
|
||||
file.close();
|
||||
|
||||
LL_DEBUGS("SyntaxLSL") << "Syntax file received, saving as: '" << mFileSpec << "'" << LL_ENDL;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string mFileSpec;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// LLSyntaxIdLSL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -166,13 +108,72 @@ bool LLSyntaxIdLSL::syntaxIdChanged()
|
|||
//-----------------------------------------------------------------------------
|
||||
void LLSyntaxIdLSL::fetchKeywordsFile(const std::string& filespec)
|
||||
{
|
||||
mInflightFetches.push_back(filespec);
|
||||
LLHTTPClient::get(mCapabilityURL,
|
||||
new fetchKeywordsFileResponder(filespec),
|
||||
LLSD(), 30.f);
|
||||
LLCoros::instance().launch("LLSyntaxIdLSL::fetchKeywordsFileCoro",
|
||||
boost::bind(&LLSyntaxIdLSL::fetchKeywordsFileCoro, this, _1, mCapabilityURL, filespec));
|
||||
LL_DEBUGS("SyntaxLSL") << "LSLSyntaxId capability URL is: " << mCapabilityURL << ". Filename to use is: '" << filespec << "'." << LL_ENDL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fetchKeywordsFileCoro
|
||||
//-----------------------------------------------------------------------------
|
||||
void LLSyntaxIdLSL::fetchKeywordsFileCoro(LLCoros::self& self, std::string url, std::string fileSpec)
|
||||
{
|
||||
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
|
||||
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
|
||||
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoro", httpPolicy));
|
||||
LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
|
||||
|
||||
std::pair<std::set<std::string>::iterator, bool> insrt = mInflightFetches.insert(fileSpec);
|
||||
if (!insrt.second)
|
||||
{
|
||||
LL_WARNS("SyntaxLSL") << "Already downloading keyword file called \"" << fileSpec << "\"." << LL_ENDL;
|
||||
return;
|
||||
}
|
||||
|
||||
LLSD result = httpAdapter->getAndYield(self, httpRequest, url);
|
||||
|
||||
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
|
||||
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
|
||||
|
||||
mInflightFetches.erase(fileSpec);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
LL_WARNS("SyntaxLSL") << "Failed to fetch syntax file \"" << fileSpec << "\"" << LL_ENDL;
|
||||
return;
|
||||
}
|
||||
|
||||
result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
|
||||
|
||||
if (isSupportedVersion(result))
|
||||
{
|
||||
setKeywordsXml(result);
|
||||
cacheFile(fileSpec, result);
|
||||
loadKeywordsIntoLLSD();
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_WARNS("SyntaxLSL") << "Unknown or unsupported version of syntax file." << LL_ENDL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// cacheFile
|
||||
//-----------------------------------------------------------------------------
|
||||
void LLSyntaxIdLSL::cacheFile(const std::string &fileSpec, const LLSD& content_ref)
|
||||
{
|
||||
std::stringstream str;
|
||||
LLSDSerialize::toXML(content_ref, str);
|
||||
const std::string xml = str.str();
|
||||
|
||||
// save the str to disk, usually to the cache.
|
||||
llofstream file(fileSpec.c_str(), std::ios_base::out);
|
||||
file.write(xml.c_str(), str.str().size());
|
||||
file.close();
|
||||
|
||||
LL_DEBUGS("SyntaxLSL") << "Syntax file received, saving as: '" << fileSpec << "'" << LL_ENDL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// initialize
|
||||
|
|
@ -260,8 +261,8 @@ void LLSyntaxIdLSL::loadDefaultKeywordsIntoLLSD()
|
|||
// loadKeywordsFileIntoLLSD
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Load xml serialised LLSD
|
||||
* @desc Opens the specified filespec and attempts to deserialise the
|
||||
* @brief Load xml serialized LLSD
|
||||
* @desc Opens the specified filespec and attempts to deserializes the
|
||||
* contained data to the specified LLSD object. indicate success/failure with
|
||||
* sLoaded/sLoadFailed members.
|
||||
*/
|
||||
|
|
@ -276,7 +277,7 @@ void LLSyntaxIdLSL::loadKeywordsIntoLLSD()
|
|||
{
|
||||
if (isSupportedVersion(content))
|
||||
{
|
||||
LL_DEBUGS("SyntaxLSL") << "Deserialised: " << mFullFileSpec << LL_ENDL;
|
||||
LL_DEBUGS("SyntaxLSL") << "Deserialized: " << mFullFileSpec << LL_ENDL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -317,12 +318,6 @@ void LLSyntaxIdLSL::handleCapsReceived(const LLUUID& region_uuid)
|
|||
}
|
||||
}
|
||||
|
||||
void LLSyntaxIdLSL::handleFileFetched(const std::string& filepath)
|
||||
{
|
||||
mInflightFetches.remove(filepath);
|
||||
loadKeywordsIntoLLSD();
|
||||
}
|
||||
|
||||
boost::signals2::connection LLSyntaxIdLSL::addSyntaxIDCallback(const syntax_id_changed_signal_t::slot_type& cb)
|
||||
{
|
||||
return mSyntaxIDChangedSignal.connect(cb);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
#include "llviewerprecompiledheaders.h"
|
||||
|
||||
#include "llsingleton.h"
|
||||
#include "lleventcoro.h"
|
||||
#include "llcoros.h"
|
||||
|
||||
class fetchKeywordsFileResponder;
|
||||
|
||||
|
|
@ -40,7 +42,7 @@ class LLSyntaxIdLSL : public LLSingleton<LLSyntaxIdLSL>
|
|||
friend class fetchKeywordsFileResponder;
|
||||
|
||||
private:
|
||||
std::list<std::string> mInflightFetches;
|
||||
std::set<std::string> mInflightFetches;
|
||||
typedef boost::signals2::signal<void()> syntax_id_changed_signal_t;
|
||||
syntax_id_changed_signal_t mSyntaxIDChangedSignal;
|
||||
boost::signals2::connection mRegionChangedCallback;
|
||||
|
|
@ -49,13 +51,15 @@ private:
|
|||
bool isSupportedVersion(const LLSD& content);
|
||||
void handleRegionChanged();
|
||||
void handleCapsReceived(const LLUUID& region_uuid);
|
||||
void handleFileFetched(const std::string& filepath);
|
||||
void setKeywordsXml(const LLSD& content) { mKeywordsXml = content; };
|
||||
void buildFullFileSpec();
|
||||
void fetchKeywordsFile(const std::string& filespec);
|
||||
void loadDefaultKeywordsIntoLLSD();
|
||||
void loadKeywordsIntoLLSD();
|
||||
|
||||
|
||||
void fetchKeywordsFileCoro(LLCoros::self& self, std::string url, std::string fileSpec);
|
||||
void cacheFile(const std::string &fileSpec, const LLSD& content_ref);
|
||||
|
||||
std::string mCapabilityURL;
|
||||
std::string mFullFileSpec;
|
||||
ELLPath mFilePath;
|
||||
|
|
|
|||
Loading…
Reference in New Issue