llcachename.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * @file llcachename.h
  3. * @brief A cache of names from UUIDs.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLCACHENAME_H
  33. #define LL_LLCACHENAME_H
  34. #include <map>
  35. #include "llavatarnamecache.h"
  36. class LLMessageSystem;
  37. class LLHost;
  38. class LLUUID;
  39. typedef boost::signals2::signal<void(const LLUUID& id, const std::string& name,
  40. bool is_group)> LLCacheNameSignal;
  41. typedef LLCacheNameSignal::slot_type LLCacheNameCallback;
  42. // Here is the theory: if you request a name which is not in the cache, it
  43. // returns "waiting" and requests the data. After the data arrives, you get
  44. // that on subsequent calls. If the data has not been updated in an hour, it
  45. // requests it again, but keeps giving you the old value until new data
  46. // arrives. If you have not requested the data in an hour, it releases it.
  47. class LLCacheName
  48. {
  49. protected:
  50. LOG_CLASS(LLCacheName);
  51. public:
  52. LLCacheName(LLMessageSystem* msgp, const std::string& loading,
  53. const std::string& nobody, const std::string& none);
  54. ~LLCacheName();
  55. // Registers the upstream host, i.e. the currently connected simulator
  56. void setUpstream(const LLHost& upstream_host);
  57. boost::signals2::connection addObserver(const LLCacheNameCallback& callback);
  58. // Storing cache on disk; for viewer, in name.cache
  59. bool importFile(std::istream& istr);
  60. void exportFile(std::ostream& ostr);
  61. // If available, copies name ("bobsmith123" or "James Linden") into string
  62. // If not available, copies the string "waiting".
  63. // Returns true if available.
  64. bool getName(const LLUUID& id, std::string& first, std::string& last);
  65. bool getFullName(const LLUUID& id, std::string& full_name);
  66. // Reverse lookup of UUID from name
  67. bool getUUID(const std::string& first, const std::string& last,
  68. LLUUID& id);
  69. bool getUUID(const std::string& fullname, LLUUID& id);
  70. // If available, this method copies the group name into the string
  71. // provided. If not available, this method copies the string "waiting".
  72. // Returns true if available.
  73. bool getGroupName(const LLUUID& id, std::string& group);
  74. // Call the callback with the group or avatar name.
  75. // If the data is currently available, may call the callback immediately
  76. // otherwise, will request the data, and will call the callback when
  77. // available. There is no guarantee the callback will ever be called.
  78. boost::signals2::connection get(const LLUUID& id, bool is_group,
  79. const LLCacheNameCallback& callback);
  80. // This method needs to be called from time to time to send out requests.
  81. void processPending();
  82. // Expire entries created more than "secs" seconds ago.
  83. void deleteEntriesOlderThan(S32 secs);
  84. // Debugging
  85. void dump(); // Dumps the contents of the cache
  86. void dumpStats(); // Dumps the sizes of the cache and associated queues.
  87. void clear(); // Deletes all entries from the cache
  88. const std::string& getDefaultName() const;
  89. // Clean up new-style "bobsmith123 Resident" names to "bobsmith123" for
  90. // display
  91. static std::string buildFullName(const std::string& first,
  92. const std::string& last);
  93. // Clean up legacy "bobsmith123 Resident" to "bobsmith123".
  94. // If the name does not contain "Resident", returns it unchanged.
  95. static std::string cleanFullName(const std::string& full_name);
  96. // Converts a standard legacy name to a username
  97. // "bobsmith123 Resident" -> "bobsmith"
  98. // "Random Linden" -> "random.linden"
  99. static std::string buildUsername(const std::string& name);
  100. // Converts a complete display name to a legacy name
  101. // if possible, otherwise returns the input
  102. // "Alias (random.linden)" -> "Random Linden"
  103. // "Something random" -> "Something random"
  104. static std::string buildLegacyName(const std::string& name);
  105. private:
  106. class Impl;
  107. Impl& impl;
  108. };
  109. extern LLCacheName* gCacheNamep;
  110. #endif