llcachename.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLCACHENAME_H
00033 #define LL_LLCACHENAME_H
00034 
00035 class LLMessageSystem;
00036 class LLHost;
00037 class LLUUID;
00038 
00039 // agent_id/group_id, first_name, last_name, is_group, user_data
00040 typedef void (*LLCacheNameCallback)(const LLUUID&, const char*, const char*, BOOL, void*);
00041 
00042 // Here's the theory:
00043 // If you request a name that isn't in the cache, it returns "waiting"
00044 // and requests the data.  After the data arrives, you get that on 
00045 // subsequent calls.
00046 // If the data hasn't been updated in an hour, it requests it again,
00047 // but keeps giving you the old value until new data arrives.
00048 // If you haven't requested the data in an hour, it releases it.
00049 class LLCacheName
00050 {
00051 public:
00052         LLCacheName(LLMessageSystem* msg);
00053         LLCacheName(LLMessageSystem* msg, const LLHost& upstream_host);
00054         ~LLCacheName();
00055 
00056         // registers the upstream host
00057         // for viewers, this is the currently connected simulator
00058         // for simulators, this is the data server
00059         void setUpstream(const LLHost& upstream_host);
00060 
00061         void addObserver(LLCacheNameCallback callback);
00062         void removeObserver(LLCacheNameCallback callback);
00063 
00064         void cancelCallback(const LLUUID& id, LLCacheNameCallback callback, void* user_data = NULL);
00065 
00066         // janky old format. Remove after a while. Phoenix. 2008-01-30
00067         void importFile(LLFILE* fp);
00068 
00069         // storing cache on disk; for viewer, in name.cache
00070         bool importFile(std::istream& istr);
00071         void exportFile(std::ostream& ostr);
00072 
00073         // If available, copies the first and last name into the strings provided.
00074         // first must be at least DB_FIRST_NAME_BUF_SIZE characters.
00075         // last must be at least DB_LAST_NAME_BUF_SIZE characters.
00076         // If not available, copies the string "waiting".
00077         // Returns TRUE iff available.
00078         BOOL getName(const LLUUID& id, char* first, char* last);
00079         BOOL getName(const LLUUID& id, std::string& first, std::string& last);
00080         BOOL getFullName(const LLUUID& id, std::string& fullname);
00081         
00082         // If available, this method copies the group name into the string
00083         // provided. The caller must allocate at least
00084         // DB_GROUP_NAME_BUF_SIZE characters. If not available, this
00085         // method copies the string "waiting". Returns TRUE iff available.
00086         BOOL getGroupName(const LLUUID& id, char* group);
00087         BOOL getGroupName(const LLUUID& id, std::string& group);
00088 
00089         // Call the callback with the group or avatar name.
00090         // If the data is currently available, may call the callback immediatly
00091         // otherwise, will request the data, and will call the callback when
00092         // available.  There is no garuntee the callback will ever be called.
00093         void get(const LLUUID& id, BOOL is_group, LLCacheNameCallback callback, void* user_data = NULL);
00094         
00095         // LEGACY
00096         void getName(const LLUUID& id, LLCacheNameCallback callback, void* user_data = NULL)
00097                         { get(id, FALSE, callback, user_data); }
00098 
00099         // This method needs to be called from time to time to send out
00100         // requests.
00101         void processPending();
00102 
00103         // Expire entries created more than "secs" seconds ago.
00104         void deleteEntriesOlderThan(S32 secs);
00105 
00106         // Debugging
00107         void dump();            // Dumps the contents of the cache
00108         void dumpStats();       // Dumps the sizes of the cache and associated queues.
00109 
00110         static LLString getDefaultName();
00111 
00112 private:
00113 
00114         class Impl;
00115         Impl& impl;
00116 };
00117 
00118 
00119 
00120 extern LLCacheName* gCacheName;
00121 
00122 #endif

Generated on Fri May 16 08:32:23 2008 for SecondLife by  doxygen 1.5.5