diff options
author | dolphin@dolphin-THINK.lindenlab.com <dolphin@dolphin-THINK.lindenlab.com> | 2012-11-19 08:06:42 -0800 |
---|---|---|
committer | dolphin@dolphin-THINK.lindenlab.com <dolphin@dolphin-THINK.lindenlab.com> | 2012-11-19 08:06:42 -0800 |
commit | 2cde962d5db94baf860eb94fecaf9671548b2c53 (patch) | |
tree | e0be2ff2ec0a6812ed4bcff88bada3dae85adec8 /indra/llmessage | |
parent | 723ab8b108beb7fc140b8be163d59b5dfa896ca8 (diff) |
Test populating the experience keys UI with avatar name data.
Diffstat (limited to 'indra/llmessage')
-rw-r--r-- | indra/llmessage/llexperiencecache.cpp | 138 | ||||
-rw-r--r-- | indra/llmessage/llexperiencecache.h | 21 |
2 files changed, 148 insertions, 11 deletions
diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 8667ae8981..0d8f76c7e2 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -25,24 +25,20 @@ */ #include "linden_common.h" +#include "llavatarname.h" #include "llframetimer.h" #include "llhttpclient.h" +#include "llsdserialize.h" #include <set> #include <map> #include "llexperiencecache.h" -class LLExperienceData -{ -public: - std::string mDisplayName; -}; - namespace LLExperienceCache { - bool sRunning = true; + bool sRunning = false; std::string sLookupURL; typedef std::set<LLUUID> ask_queue_t; @@ -52,19 +48,122 @@ namespace LLExperienceCache pending_queue_t sPendingQueue; - typedef std::map<LLUUID, LLExperienceData> cache_t; cache_t sCache; LLFrameTimer sRequestTimer; + + void processExperience( const LLUUID& agent_id, const LLExperienceData& experience, bool add_to_cache ) + { + if(add_to_cache) + { + sCache[agent_id]=experience; + + sPendingQueue.erase(agent_id); + + + //signal + } + } + + void initClass( bool running ) + { + sRunning = false; + } + + const cache_t& getCached() + { + return sCache; + } + + + + void importFile(std::istream& istr) + { + LLSD data; + S32 parse_count = LLSDSerialize::fromXMLDocument(data, istr); + if(parse_count < 1) return; + + LLSD agents = data["agents"]; + + LLUUID agent_id; + LLExperienceData experience; + LLSD::map_const_iterator it = agents.beginMap(); + for(; it != agents.endMap() ; ++it) + { + agent_id.set(it->first); + experience.fromLLSD( it->second); + sCache[agent_id]=experience; + } + + LL_INFOS("ExperienceCache") << "loaded " << sCache.size() << LL_ENDL; + } + + void exportFile(std::ostream& ostr) + { + LLSD agents; + + cache_t::const_iterator it =sCache.begin(); + for( ; it != sCache.end() ; ++it) + { + agents[it->first.asString()] = it->second.asLLSD(); + } + + LLSD data; + data["agents"] = agents; + + LLSDSerialize::toPrettyXML(data, ostr); + } + class LLExperienceResponder : public LLHTTPClient::Responder { public: - LLExperienceResponder(std::vector<LLUUID> agent_ids) + LLExperienceResponder(const std::vector<LLUUID>& agent_ids) + :mAgentIds(agent_ids) { } + + virtual void completedHeader(U32 status, const std::string& reason, const LLSD& content) + { + mHeaders = content; + } + + virtual void result(const LLSD& content) + { + LLSD agents = content["agents"]; + LLSD::array_const_iterator it = agents.beginArray(); + for( /**/ ; it != agents.endArray(); ++it) + { + const LLSD& row = *it; + LLUUID agent_id = row["id"].asUUID(); + + LLExperienceData experience; + + if(experience.fromLLSD(row)) + { + LL_DEBUGS("ExperienceCache") << __FUNCTION__ << "Received result for " << agent_id + << "display '" << experience.mDisplayName << "'" << LL_ENDL ; + + processExperience(agent_id, experience, true); + } + } + + LLSD unresolved_agents = content["bad_ids"]; + S32 num_unresolved = unresolved_agents.size(); + if(num_unresolved > 0) + { + LL_DEBUGS("ExperienceCache") << __FUNCTION__ << "Ignoreing " << num_unresolved + << " bad ids" << LL_ENDL ; + } + + LL_DEBUGS("ExperienceCache") << __FUNCTION__ << sCache.size() << " cached experiences" << LL_ENDL; + } + + private: + std::vector<LLUUID> mAgentIds; + LLSD mHeaders; }; void requestExperiences() @@ -171,7 +270,7 @@ namespace LLExperienceCache bool get( const LLUUID& agent_id, LLExperienceData* experience_data ) { - if(!sRunning) + if(sRunning) { cache_t::const_iterator it = sCache.find(agent_id); @@ -193,3 +292,22 @@ namespace LLExperienceCache } + +bool LLExperienceData::fromLLSD( const LLSD& sd ) +{ + mDisplayName = sd["display_name"].asString(); + mDescription = sd["username"].asString(); + + if(mDisplayName.empty() || mDescription.empty()) return false; + + mDescription += " % Hey, this is a description!"; + return true; +} + +LLSD LLExperienceData::asLLSD() const +{ + LLSD sd; + sd["display_name"] = mDisplayName; + sd["username"] = mDescription.substr(0, llmin(mDescription.size(),mDescription.find(" %"))); + return sd; +} diff --git a/indra/llmessage/llexperiencecache.h b/indra/llmessage/llexperiencecache.h index 6be51b039e..799cdea13a 100644 --- a/indra/llmessage/llexperiencecache.h +++ b/indra/llmessage/llexperiencecache.h @@ -32,7 +32,20 @@ #include <string> class LLUUID; -class LLExperienceData; + + +class LLExperienceData +{ +public: + bool fromLLSD(const LLSD& sd); + LLSD asLLSD() const; + + + std::string mDisplayName; + std::string mDescription; +}; + + namespace LLExperienceCache { @@ -41,12 +54,18 @@ namespace LLExperienceCache void idle(); + void exportFile(std::ostream& ostr); + void importFile(std::istream& istr); + void initClass(bool running); void erase(const LLUUID& agent_id); void fetch(const LLUUID& agent_id); void insert(const LLUUID& agent_id, const LLExperienceData& experience_data); bool get(const LLUUID& agent_id, LLExperienceData* experience_data); + typedef std::map<LLUUID, LLExperienceData> cache_t; + + const cache_t& getCached(); }; #endif // LL_LLEXPERIENCECACHE_H |