diff options
author | James Cook <james@lindenlab.com> | 2010-02-17 16:55:58 -0800 |
---|---|---|
committer | James Cook <james@lindenlab.com> | 2010-02-17 16:55:58 -0800 |
commit | 55bfb4435e1a2ffc34578bf30877eb24a5edaa29 (patch) | |
tree | 7c58fde08cdf596b50604e5b2a28a23eea86fc11 | |
parent | 53ff6652f08f70fe924398f65b0e289e009d1e8c (diff) |
Look up display names via a web service
Also removed unused LLComboBox globals to reduce llappviewer.cpp
include file burden.
Review pending
-rw-r--r-- | indra/llmessage/llavatarnamecache.cpp | 212 | ||||
-rw-r--r-- | indra/llmessage/llavatarnamecache.h | 2 | ||||
-rw-r--r-- | indra/llui/llcombobox.cpp | 2 | ||||
-rw-r--r-- | indra/llui/llcombobox.h | 3 | ||||
-rw-r--r-- | indra/newview/llappviewer.cpp | 7 |
5 files changed, 180 insertions, 46 deletions
diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp index dbcb0d0c03..a7ed20ac9b 100644 --- a/indra/llmessage/llavatarnamecache.cpp +++ b/indra/llmessage/llavatarnamecache.cpp @@ -35,15 +35,92 @@ #include "llavatarnamecache.h" #include "llcachename.h" // until we get our own web service +#include "llframetimer.h" +#include "llhttpclient.h" +#include "llsdserialize.h" // JAMESDEBUG #include <cctype> // tolower() +#include <set> namespace LLAvatarNameCache { - std::map<LLUUID, LLAvatarName> sCache; + // base URL for name lookup service + std::string sNameServiceURL; + + // accumulated agent IDs for next query against service + typedef std::set<LLUUID> ask_queue_t; + ask_queue_t sAskQueue; + + // agent IDs that have been requested, but with no reply + // maps agent ID to frame time request was made + typedef std::map<LLUUID, F32> pending_queue_t; + pending_queue_t sPendingQueue; + + // names we know about + typedef std::map<LLUUID, LLAvatarName> cache_t; + cache_t sCache; + + // only need per-frame timing resolution + LLFrameTimer sRequestTimer; + + bool isRequestPending(const LLUUID& agent_id); } -// JAMESDEBUG re-enable when display names are turned on +class LLAvatarNameResponder : public LLHTTPClient::Responder +{ +public: + /*virtual*/ void result(const LLSD& content); + /*virtual*/ void error(U32 status, const std::string& reason); +}; + +void LLAvatarNameResponder::result(const LLSD& content) +{ + //std::ostringstream debug; + //LLSDSerialize::toPrettyXML(content, debug); + //llinfos << "JAMESDEBUG " << debug.str() << llendl; + + U32 now = (U32)LLFrameTimer::getTotalSeconds(); + LLSD::array_const_iterator it = content.beginArray(); + for ( ; it != content.endArray(); ++it) + { + const LLSD& row = *it; + + LLAvatarName av_name; + av_name.mSLID = row["slid"]; + av_name.mDisplayName = row["display_name"]; + av_name.mLastUpdate = now; + + // HACK for pretty stars + if (row["last_name"].asString() == "Linden") + { + av_name.mBadge = "Person_Star"; + } + + // Some avatars don't have explicit display names set + if (av_name.mDisplayName.empty()) + { + // make up a display name + std::string first_name = row["first_name"]; + std::string last_name = row["last_name"]; + av_name.mDisplayName = + LLCacheName::buildFullName(first_name, last_name); + } + + LLUUID agent_id = row["agent_id"]; + LLAvatarNameCache::sCache[agent_id] = av_name; + + LLAvatarNameCache::sPendingQueue.erase(agent_id); + + llinfos << "JAMESDEBUG fetched " << av_name.mDisplayName << llendl; + } +} + +void LLAvatarNameResponder::error(U32 status, const std::string& reason) +{ + llinfos << "JAMESDEBUG error " << status << " " << reason << llendl; +} + +// JAMESDEBUG re-enable when display names are turned on??? //static std::string slid_from_full_name(const std::string& full_name) //{ // std::string id = full_name; @@ -73,11 +150,6 @@ void LLAvatarNameCache::initClass() name.mBadge = "Person_Check"; sCache[LLUUID("27888d5f-4ddb-4df3-ad36-a1483ce0b3d9")] = name; - name.mSLID = "jim.linden"; - name.mDisplayName = "Jim Jenkins"; - name.mBadge = "Person_Star"; - sCache[LLUUID("3e5bf676-3577-c9ee-9fac-10df430015a1")] = name; - name.mSLID = "james.linden"; const unsigned char jose_sanchez[] = { 'J','o','s',0xC3,0xA9,' ','S','a','n','c','h','e','z', '\0' }; @@ -90,35 +162,41 @@ void LLAvatarNameCache::initClass() name.mBadge = ""; sCache[LLUUID("a23fff6c-80ae-4997-9253-48272fd01d3c")] = name; - name.mSLID = "hamilton.linden"; - name.mDisplayName = "Hamilton Hitchings"; - name.mBadge = "Person_Star"; - sCache[LLUUID("3f7ced39-5e38-4fdd-90f2-423560b1e6e2")] = name; - - name.mSLID = "rome.linden"; - name.mDisplayName = "Rome Portlock"; - name.mBadge = "Person_Star"; - sCache[LLUUID("537da1e1-a89f-4f9b-9056-b1f0757ccdd0")] = name; - - name.mSLID = "m.linden"; - name.mDisplayName = "Mark Kingdon"; - name.mBadge = "Person_Star"; - sCache[LLUUID("244195d6-c9b7-4fd6-9229-c3a8b2e60e81")] = name; - - name.mSLID = "t.linden"; - name.mDisplayName = "Tom Hale"; - name.mBadge = "Person_Star"; - sCache[LLUUID("49856302-98d4-4e32-b5e9-035e5b4e83a4")] = name; - - name.mSLID = "callen.linden"; - name.mDisplayName = "Christina Allen"; - name.mBadge = "Person_Star"; - sCache[LLUUID("e6ed7825-708f-4c6b-b6a7-f3fe921a9176")] = name; - - name.mSLID = "crimp.linden"; - name.mDisplayName = "Chris Rimple"; - name.mBadge = "Person_Star"; - sCache[LLUUID("a7f0ac18-205f-41d2-b5b4-f75f096ae511")] = name; + // These are served by the web service now + //name.mSLID = "jim.linden"; + //name.mDisplayName = "Jim Jenkins"; + //name.mBadge = "Person_Star"; + //sCache[LLUUID("3e5bf676-3577-c9ee-9fac-10df430015a1")] = name; + + //name.mSLID = "hamilton.linden"; + //name.mDisplayName = "Hamilton Hitchings"; + //name.mBadge = "Person_Star"; + //sCache[LLUUID("3f7ced39-5e38-4fdd-90f2-423560b1e6e2")] = name; + + //name.mSLID = "rome.linden"; + //name.mDisplayName = "Rome Portlock"; + //name.mBadge = "Person_Star"; + //sCache[LLUUID("537da1e1-a89f-4f9b-9056-b1f0757ccdd0")] = name; + + //name.mSLID = "m.linden"; + //name.mDisplayName = "Mark Kingdon"; + //name.mBadge = "Person_Star"; + //sCache[LLUUID("244195d6-c9b7-4fd6-9229-c3a8b2e60e81")] = name; + + //name.mSLID = "t.linden"; + //name.mDisplayName = "Tom Hale"; + //name.mBadge = "Person_Star"; + //sCache[LLUUID("49856302-98d4-4e32-b5e9-035e5b4e83a4")] = name; + + //name.mSLID = "callen.linden"; + //name.mDisplayName = "Christina Allen"; + //name.mBadge = "Person_Star"; + //sCache[LLUUID("e6ed7825-708f-4c6b-b6a7-f3fe921a9176")] = name; + + //name.mSLID = "crimp.linden"; + //name.mDisplayName = "Chris Rimple"; + //name.mBadge = "Person_Star"; + //sCache[LLUUID("a7f0ac18-205f-41d2-b5b4-f75f096ae511")] = name; } void LLAvatarNameCache::cleanupClass() @@ -135,6 +213,57 @@ void LLAvatarNameCache::exportFile(std::ostream& ostr) void LLAvatarNameCache::idle() { + const F32 SECS_BETWEEN_REQUESTS = 0.5f; // JAMESDEBUG set to 0.1? + if (sRequestTimer.checkExpirationAndReset(SECS_BETWEEN_REQUESTS)) + { + return; + } + + if (sAskQueue.empty()) + { + return; + } + + LLSD body; + body["agent_ids"] = LLSD::emptyArray(); + LLSD& agent_ids = body["agent_ids"]; + + ask_queue_t::const_iterator it = sAskQueue.begin(); + for ( ; it != sAskQueue.end(); ++it) + { + agent_ids.append( LLSD( *it ) ); + } + + //std::ostringstream debug; + //LLSDSerialize::toPrettyXML(body, debug); + //LL_INFOS("JAMESDEBUG") << debug.str() << LL_ENDL; + + // *TODO: configure the base URL for this + std::string url = "http://pdp15.lindenlab.com:8050/my-service/agent/display-names/"; + LLHTTPClient::post(url, body, new LLAvatarNameResponder()); + + // Move requests from Ask queue to Pending queue + U32 now = (U32)LLFrameTimer::getTotalSeconds(); + for (it = sAskQueue.begin(); it != sAskQueue.end(); ++it) + { + sPendingQueue[*it] = now; + } + sAskQueue.clear(); +} + +bool LLAvatarNameCache::isRequestPending(const LLUUID& agent_id) +{ + const U32 PENDING_TIMEOUT_SECS = 5 * 60; + U32 now = (U32)LLFrameTimer::getTotalSeconds(); + U32 expire_time = now - PENDING_TIMEOUT_SECS; + + pending_queue_t::const_iterator it = sPendingQueue.find(agent_id); + if (it != sPendingQueue.end()) + { + bool expired = (it->second < expire_time); + return !expired; + } + return false; } bool LLAvatarNameCache::get(const LLUUID& agent_id, LLAvatarName *av_name) @@ -146,7 +275,7 @@ bool LLAvatarNameCache::get(const LLUUID& agent_id, LLAvatarName *av_name) return true; } - // JAMESDEBUG Enable when we turn on display names. + // JAMESDEBUG Enable when we turn on display names??? //std::string full_name; //if (gCacheName->getFullName(agent_id, full_name)) //{ @@ -156,6 +285,15 @@ bool LLAvatarNameCache::get(const LLUUID& agent_id, LLAvatarName *av_name) // return true; //} + if (!isRequestPending(agent_id)) + { + std::pair<ask_queue_t::iterator,bool> found = sAskQueue.insert(agent_id); + if (found.second) + { + LL_INFOS("JAMESDEBUG") << "added to ask queue " << agent_id << LL_ENDL; + } + } + return false; } diff --git a/indra/llmessage/llavatarnamecache.h b/indra/llmessage/llavatarnamecache.h index adf12bbbc6..a0e6abf303 100644 --- a/indra/llmessage/llavatarnamecache.h +++ b/indra/llmessage/llavatarnamecache.h @@ -43,6 +43,8 @@ namespace LLAvatarNameCache void importFile(std::istream& istr); void exportFile(std::ostream& ostr); + // Periodically makes a batch request for display names not already in + // cache. Call once per frame. void idle(); // If name is in cache, returns true and fills in provided LLAvatarName diff --git a/indra/llui/llcombobox.cpp b/indra/llui/llcombobox.cpp index 9d23daf56d..1aa44f6b96 100644 --- a/indra/llui/llcombobox.cpp +++ b/indra/llui/llcombobox.cpp @@ -58,8 +58,6 @@ #include "lltooltip.h" // Globals -S32 LLCOMBOBOX_HEIGHT = 0; -S32 LLCOMBOBOX_WIDTH = 0; S32 MAX_COMBO_WIDTH = 500; static LLDefaultChildRegistry::Register<LLComboBox> register_combo_box("combo_box"); diff --git a/indra/llui/llcombobox.h b/indra/llui/llcombobox.h index 4f27588467..58e29dcb30 100644 --- a/indra/llui/llcombobox.h +++ b/indra/llui/llcombobox.h @@ -49,9 +49,6 @@ class LLFontGL; class LLViewBorder; -extern S32 LLCOMBOBOX_HEIGHT; -extern S32 LLCOMBOBOX_WIDTH; - class LLComboBox : public LLUICtrl, public LLCtrlListInterface { diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index ba2e13da9d..62b8b972b6 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -85,6 +85,7 @@ #include "llsecondlifeurls.h" // Linden library includes +#include "llavatarnamecache.h" #include "llimagej2c.h" #include "llmemory.h" #include "llprimitive.h" @@ -157,7 +158,6 @@ // Included so that constants/settings might be initialized // in save_settings_to_globals() #include "llbutton.h" -#include "llcombobox.h" #include "llstatusbar.h" #include "llsurface.h" #include "llvosky.h" @@ -399,9 +399,6 @@ static void settings_to_globals() MENU_BAR_HEIGHT = gSavedSettings.getS32("MenuBarHeight"); MENU_BAR_WIDTH = gSavedSettings.getS32("MenuBarWidth"); - LLCOMBOBOX_HEIGHT = BTN_HEIGHT - 2; - LLCOMBOBOX_WIDTH = 128; - LLSurface::setTextureSize(gSavedSettings.getU32("RegionTextureSize")); LLImageGL::sGlobalUseAnisotropic = gSavedSettings.getBOOL("RenderAnisotropic"); @@ -3897,6 +3894,8 @@ void LLAppViewer::idleNetwork() // deal with any queued name requests and replies. gCacheName->processPending(); + LLAvatarNameCache::idle(); + llpushcallstacks ; LLTimer check_message_timer; // Read all available packets from network |