PageRenderTime 27ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llcachename.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 148 lines | 48 code | 30 blank | 70 comment | 0 complexity | 51c252dd07d54b61a8bb0c9046888ba9 MD5 | raw file
  1/** 
  2 * @file llcachename.h
  3 * @brief A cache of names from UUIDs.
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLCACHENAME_H
 28#define LL_LLCACHENAME_H
 29
 30#include <boost/bind.hpp>
 31#include <boost/signals2.hpp>
 32
 33class LLMessageSystem;
 34class LLHost;
 35class LLUUID;
 36
 37
 38typedef boost::signals2::signal<void (const LLUUID& id,
 39                                      const std::string& name,
 40                                      bool is_group)> LLCacheNameSignal;
 41typedef LLCacheNameSignal::slot_type LLCacheNameCallback;
 42
 43// Old callback with user data for compatability
 44typedef void (*old_callback_t)(const LLUUID&, const std::string&, bool, void*);
 45
 46// Here's the theory:
 47// If you request a name that isn't in the cache, it returns "waiting"
 48// and requests the data.  After the data arrives, you get that on 
 49// subsequent calls.
 50// If the data hasn't been updated in an hour, it requests it again,
 51// but keeps giving you the old value until new data arrives.
 52// If you haven't requested the data in an hour, it releases it.
 53class LLCacheName
 54{
 55public:
 56	LLCacheName(LLMessageSystem* msg);
 57	LLCacheName(LLMessageSystem* msg, const LLHost& upstream_host);
 58	~LLCacheName();
 59
 60	// registers the upstream host
 61	// for viewers, this is the currently connected simulator
 62	// for simulators, this is the data server
 63	void setUpstream(const LLHost& upstream_host);
 64
 65	boost::signals2::connection addObserver(const LLCacheNameCallback& callback);
 66
 67	// storing cache on disk; for viewer, in name.cache
 68	bool importFile(std::istream& istr);
 69	void exportFile(std::ostream& ostr);
 70
 71	// If available, copies name ("bobsmith123" or "James Linden") into string
 72	// If not available, copies the string "waiting".
 73	// Returns TRUE iff available.
 74	BOOL getFullName(const LLUUID& id, std::string& full_name);
 75
 76	// Reverse lookup of UUID from name
 77	BOOL getUUID(const std::string& first, const std::string& last, LLUUID& id);
 78	BOOL getUUID(const std::string& fullname, LLUUID& id);
 79
 80	// IDEVO Temporary code
 81	// Clean up new-style "bobsmith123 Resident" names to "bobsmith123" for display
 82	static std::string buildFullName(const std::string& first, const std::string& last);
 83
 84	// Clean up legacy "bobsmith123 Resident" to "bobsmith123"
 85	// If name does not contain "Resident" returns it unchanged.
 86	static std::string cleanFullName(const std::string& full_name);
 87	
 88	// Converts a standard legacy name to a username
 89	// "bobsmith123 Resident" -> "bobsmith"
 90	// "Random Linden" -> "random.linden"
 91	static std::string buildUsername(const std::string& name);
 92	
 93	// Converts a complete display name to a legacy name
 94	// if possible, otherwise returns the input
 95	// "Alias (random.linden)" -> "Random Linden"
 96	// "Something random" -> "Something random"
 97	static std::string buildLegacyName(const std::string& name);
 98	
 99	// If available, this method copies the group name into the string
100	// provided. The caller must allocate at least
101	// DB_GROUP_NAME_BUF_SIZE characters. If not available, this
102	// method copies the string "waiting". Returns TRUE iff available.
103	BOOL getGroupName(const LLUUID& id, std::string& group);
104
105	// Call the callback with the group or avatar name.
106	// If the data is currently available, may call the callback immediatly
107	// otherwise, will request the data, and will call the callback when
108	// available.  There is no garuntee the callback will ever be called.
109	boost::signals2::connection get(const LLUUID& id, bool is_group, const LLCacheNameCallback& callback);
110
111	// Convenience method for looking up a group name, so you can
112	// tell the difference between avatar lookup and group lookup
113	// in global searches
114	boost::signals2::connection getGroup(const LLUUID& group_id, const LLCacheNameCallback& callback);
115
116	// LEGACY
117	boost::signals2::connection get(const LLUUID& id, bool is_group, old_callback_t callback, void* user_data);
118	// This method needs to be called from time to time to send out
119	// requests.
120	void processPending();
121
122	// Expire entries created more than "secs" seconds ago.
123	void deleteEntriesOlderThan(S32 secs);
124
125	// Debugging
126	void dump();		// Dumps the contents of the cache
127	void dumpStats();	// Dumps the sizes of the cache and associated queues.
128	void clear();		// Deletes all entries from the cache
129
130	static std::string getDefaultName();
131
132	// Returns "Resident", the default last name for SLID-based accounts
133	// that have no last name.
134	static std::string getDefaultLastName();
135
136	static void localizeCacheName(std::string key, std::string value);
137	static std::map<std::string, std::string> sCacheName;
138private:
139
140	class Impl;
141	Impl& impl;
142};
143
144
145
146extern LLCacheName* gCacheName;
147
148#endif