/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. #ifndef LL_LLCACHENAME_H
  27. #define LL_LLCACHENAME_H
  28. #include <boost/bind.hpp>
  29. #include <boost/signals2.hpp>
  30. class LLMessageSystem;
  31. class LLHost;
  32. class LLUUID;
  33. typedef boost::signals2::signal<void (const LLUUID& id,
  34. const std::string& name,
  35. bool is_group)> LLCacheNameSignal;
  36. typedef LLCacheNameSignal::slot_type LLCacheNameCallback;
  37. // Old callback with user data for compatability
  38. typedef void (*old_callback_t)(const LLUUID&, const std::string&, bool, void*);
  39. // Here's the theory:
  40. // If you request a name that isn't in the cache, it returns "waiting"
  41. // and requests the data. After the data arrives, you get that on
  42. // subsequent calls.
  43. // If the data hasn't been updated in an hour, it requests it again,
  44. // but keeps giving you the old value until new data arrives.
  45. // If you haven't requested the data in an hour, it releases it.
  46. class LLCacheName
  47. {
  48. public:
  49. LLCacheName(LLMessageSystem* msg);
  50. LLCacheName(LLMessageSystem* msg, const LLHost& upstream_host);
  51. ~LLCacheName();
  52. // registers the upstream host
  53. // for viewers, this is the currently connected simulator
  54. // for simulators, this is the data server
  55. void setUpstream(const LLHost& upstream_host);
  56. boost::signals2::connection addObserver(const LLCacheNameCallback& callback);
  57. // storing cache on disk; for viewer, in name.cache
  58. bool importFile(std::istream& istr);
  59. void exportFile(std::ostream& ostr);
  60. // If available, copies name ("bobsmith123" or "James Linden") into string
  61. // If not available, copies the string "waiting".
  62. // Returns TRUE iff available.
  63. BOOL getFullName(const LLUUID& id, std::string& full_name);
  64. // Reverse lookup of UUID from name
  65. BOOL getUUID(const std::string& first, const std::string& last, LLUUID& id);
  66. BOOL getUUID(const std::string& fullname, LLUUID& id);
  67. // IDEVO Temporary code
  68. // Clean up new-style "bobsmith123 Resident" names to "bobsmith123" for display
  69. static std::string buildFullName(const std::string& first, const std::string& last);
  70. // Clean up legacy "bobsmith123 Resident" to "bobsmith123"
  71. // If name does not contain "Resident" returns it unchanged.
  72. static std::string cleanFullName(const std::string& full_name);
  73. // Converts a standard legacy name to a username
  74. // "bobsmith123 Resident" -> "bobsmith"
  75. // "Random Linden" -> "random.linden"
  76. static std::string buildUsername(const std::string& name);
  77. // Converts a complete display name to a legacy name
  78. // if possible, otherwise returns the input
  79. // "Alias (random.linden)" -> "Random Linden"
  80. // "Something random" -> "Something random"
  81. static std::string buildLegacyName(const std::string& name);
  82. // If available, this method copies the group name into the string
  83. // provided. The caller must allocate at least
  84. // DB_GROUP_NAME_BUF_SIZE characters. If not available, this
  85. // method copies the string "waiting". Returns TRUE iff available.
  86. BOOL getGroupName(const LLUUID& id, std::string& group);
  87. // Call the callback with the group or avatar name.
  88. // If the data is currently available, may call the callback immediatly
  89. // otherwise, will request the data, and will call the callback when
  90. // available. There is no garuntee the callback will ever be called.
  91. boost::signals2::connection get(const LLUUID& id, bool is_group, const LLCacheNameCallback& callback);
  92. // Convenience method for looking up a group name, so you can
  93. // tell the difference between avatar lookup and group lookup
  94. // in global searches
  95. boost::signals2::connection getGroup(const LLUUID& group_id, const LLCacheNameCallback& callback);
  96. // LEGACY
  97. boost::signals2::connection get(const LLUUID& id, bool is_group, old_callback_t callback, void* user_data);
  98. // This method needs to be called from time to time to send out
  99. // requests.
  100. void processPending();
  101. // Expire entries created more than "secs" seconds ago.
  102. void deleteEntriesOlderThan(S32 secs);
  103. // Debugging
  104. void dump(); // Dumps the contents of the cache
  105. void dumpStats(); // Dumps the sizes of the cache and associated queues.
  106. void clear(); // Deletes all entries from the cache
  107. static std::string getDefaultName();
  108. // Returns "Resident", the default last name for SLID-based accounts
  109. // that have no last name.
  110. static std::string getDefaultLastName();
  111. static void localizeCacheName(std::string key, std::string value);
  112. static std::map<std::string, std::string> sCacheName;
  113. private:
  114. class Impl;
  115. Impl& impl;
  116. };
  117. extern LLCacheName* gCacheName;
  118. #endif