PageRenderTime 41ms CodeModel.GetById 32ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llavatarnamecache.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 106 lines | 33 code | 23 blank | 50 comment | 0 complexity | efc86fc9e411aea8155d9d0059d7e867 MD5 | raw file
  1/** 
  2 * @file llavatarnamecache.h
  3 * @brief Provides lookup of avatar SLIDs ("bobsmith123") and display names
  4 * ("James Cook") from avatar UUIDs.
  5 *
  6 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LLAVATARNAMECACHE_H
 29#define LLAVATARNAMECACHE_H
 30
 31#include "llavatarname.h"	// for convenience
 32
 33#include <boost/signals2.hpp>
 34
 35class LLSD;
 36class LLUUID;
 37
 38namespace LLAvatarNameCache
 39{
 40		
 41	typedef boost::signals2::signal<void (void)> use_display_name_signal_t;
 42
 43	// Until the cache is set running, immediate lookups will fail and
 44	// async lookups will be queued.  This allows us to block requests
 45	// until we know if the first region supports display names.
 46	void initClass(bool running);
 47	void cleanupClass();
 48
 49	void importFile(std::istream& istr);
 50	void exportFile(std::ostream& ostr);
 51
 52	// On the viewer, usually a simulator capabilitity
 53	// If empty, name cache will fall back to using legacy name
 54	// lookup system
 55	void setNameLookupURL(const std::string& name_lookup_url);
 56
 57	// Do we have a valid lookup URL, hence are we trying to use the
 58	// new display name lookup system?
 59	bool hasNameLookupURL();
 60	
 61	// Periodically makes a batch request for display names not already in
 62	// cache.  Call once per frame.
 63	void idle();
 64
 65	// If name is in cache, returns true and fills in provided LLAvatarName
 66	// otherwise returns false
 67	bool get(const LLUUID& agent_id, LLAvatarName *av_name);
 68
 69	// Callback types for get() below
 70	typedef boost::signals2::signal<
 71		void (const LLUUID& agent_id, const LLAvatarName& av_name)>
 72			callback_signal_t;
 73	typedef callback_signal_t::slot_type callback_slot_t;
 74
 75	// Fetches name information and calls callback.
 76	// If name information is in cache, callback will be called immediately.
 77	void get(const LLUUID& agent_id, callback_slot_t slot);
 78
 79	// Allow display names to be explicitly disabled for testing.
 80	void setUseDisplayNames(bool use);
 81	bool useDisplayNames();
 82
 83	void erase(const LLUUID& agent_id);
 84
 85    /// Provide some fallback for agents that return errors
 86	void handleAgentError(const LLUUID& agent_id);
 87
 88	// Force a re-fetch of the most recent data, but keep the current
 89	// data in cache
 90	void fetch(const LLUUID& agent_id);
 91
 92	void insert(const LLUUID& agent_id, const LLAvatarName& av_name);
 93
 94	// Compute name expiration time from HTTP Cache-Control header,
 95	// or return default value, in seconds from epoch.
 96	F64 nameExpirationFromHeaders(LLSD headers);
 97
 98	void addUseDisplayNamesCallback(const use_display_name_signal_t::slot_type& cb);
 99}
100
101// Parse a cache-control header to get the max-age delta-seconds.
102// Returns true if header has max-age param and it parses correctly.
103// Exported here to ease unit testing.
104bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age);
105
106#endif