llcallingcard.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLCALLINGCARD_H
00033 #define LL_LLCALLINGCARD_H
00034 
00035 #include <map>
00036 #include <set>
00037 #include <string>
00038 #include <vector>
00039 #include "lluserrelations.h"
00040 #include "lluuid.h"
00041 #include "v3dmath.h"
00042 
00043 //class LLInventoryModel;
00044 //class LLInventoryObserver;
00045 class LLMessageSystem;
00046 class LLTrackingData;
00047 class LLFriendObserver
00048 {
00049 public:
00050         // This enumeration is a way to refer to what changed in a more
00051         // human readable format. You can mask the value provided by
00052         // chaged() to see if the observer is interested in the change.
00053         enum 
00054         {
00055                 NONE = 0,
00056                 ADD = 1,
00057                 REMOVE = 2,
00058                 ONLINE = 4,
00059                 POWERS = 8,
00060                 ALL = 0xffffffff
00061         };
00062         virtual ~LLFriendObserver() {}
00063         virtual void changed(U32 mask) = 0;
00064 };
00065 
00066 /*
00067 struct LLBuddyInfo
00068 {
00069         bool mIsOnline;
00070         bool mIsEmpowered;
00071         LLBuddyInfo() : mIsOnline(false), mIsEmpowered(false) {}
00072 };
00073 */
00074 
00075 // This is used as a base class for doing operations on all buddies.
00076 class LLRelationshipFunctor
00077 {
00078 public:
00079         virtual ~LLRelationshipFunctor() {}
00080         virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy) = 0;
00081 };
00082         
00083 
00084 class LLAvatarTracker
00085 {
00086 public:
00087         static LLAvatarTracker& instance() { return sInstance; }
00088         
00089         void track(const LLUUID& avatar_id, const std::string& name);
00090         void untrack(const LLUUID& avatar_id);
00091         bool isTrackedAgentValid() { return mTrackedAgentValid; }
00092         void setTrackedAgentValid(bool valid) { mTrackedAgentValid = valid; }
00093         void findAgent();
00094 
00095         // coarse update information
00096         void setTrackedCoarseLocation(const LLVector3d& global_pos);
00097 
00098         // dealing with the tracked agent location
00099         bool haveTrackingInfo();
00100         void getDegreesAndDist(F32& rot, F64& horiz_dist, F64& vert_dist);
00101         LLVector3d getGlobalPos();
00102 
00103         // Get the name passed in, returns null string if uninitialized.
00104         const LLString& getName();
00105 
00106         // Get the avatar being tracked, returns LLUUID::null if uninitialized
00107         const LLUUID& getAvatarID();
00108 
00109         // Deal with inventory
00110         //void observe(LLInventoryModel* model);
00111         //void inventoryChanged();
00112 
00113         // add or remove agents from buddy list. Each method takes a set
00114         // of buddies and returns how many were actually added or removed.
00115         typedef std::map<LLUUID, LLRelationship*> buddy_map_t;
00116 
00117         S32 addBuddyList(const buddy_map_t& buddies);
00118         //S32 removeBuddyList(const buddy_list_t& exes);
00119         void copyBuddyList(buddy_map_t& buddies) const;
00120 
00121         // deal with termination of friendhsip
00122         void terminateBuddy(const LLUUID& id);
00123 
00124         // get full info
00125         const LLRelationship* getBuddyInfo(const LLUUID& id) const;
00126 
00127         // online status
00128         void setBuddyOnline(const LLUUID& id, bool is_online);
00129         bool isBuddyOnline(const LLUUID& id) const;
00130 
00131         // simple empowered status
00132         void setBuddyEmpowered(const LLUUID& id, bool is_empowered);
00133         bool isBuddyEmpowered(const LLUUID& id) const;
00134 
00135         // set the empower bit & message the server.
00136         void empowerList(const buddy_map_t& list, bool grant);
00137         void empower(const LLUUID& id, bool grant); // wrapper for above
00138 
00139         // register callbacks
00140         void registerCallbacks(LLMessageSystem* msg);
00141 
00142         // Add/remove an observer. If the observer is destroyed, be sure
00143         // to remove it. On destruction of the tracker, it will delete any
00144         // observers left behind.
00145         void addObserver(LLFriendObserver* observer);
00146         void removeObserver(LLFriendObserver* observer);
00147         void notifyObservers();
00148 
00149         // Apply the functor to every buddy. Do not actually modify the
00150         // buddy list in the functor or bad things will happen.
00151         void applyFunctor(LLRelationshipFunctor& f);
00152 
00153         static void formFriendship(const LLUUID& friend_id);
00154 
00155 protected:
00156         void deleteTrackingData();
00157         void agentFound(const LLUUID& prey,
00158                                         const LLVector3d& estimated_global_pos);
00159 
00160         // Message system functionality
00161         static void processAgentFound(LLMessageSystem* msg, void**);
00162         static void processOnlineNotification(LLMessageSystem* msg, void**);
00163         static void processOfflineNotification(LLMessageSystem* msg, void**);
00164         //static void processGrantedProxies(LLMessageSystem* msg, void**);
00165         static void processTerminateFriendship(LLMessageSystem* msg, void**);
00166         static void processChangeUserRights(LLMessageSystem* msg, void**);
00167 
00168         void processNotify(LLMessageSystem* msg, bool online);
00169         void processChange(LLMessageSystem* msg);
00170 
00171 protected:
00172         static LLAvatarTracker sInstance;
00173         LLTrackingData* mTrackingData;
00174         bool mTrackedAgentValid;
00175         U32 mModifyMask;
00176         //LLInventoryModel* mInventory;
00177         //LLInventoryObserver* mInventoryObserver;
00178 
00179         buddy_map_t mBuddyInfo;
00180 
00181         typedef std::vector<LLFriendObserver*> observer_list_t;
00182         observer_list_t mObservers;
00183 
00184 private:
00185         // do not implement
00186         LLAvatarTracker(const LLAvatarTracker&);
00187         bool operator==(const LLAvatarTracker&);
00188 
00189 public:
00190         // don't you dare create or delete this object
00191         LLAvatarTracker();
00192         ~LLAvatarTracker();
00193 };
00194 
00195 // collect set of LLUUIDs we're a proxy for
00196 class LLCollectProxyBuddies : public LLRelationshipFunctor
00197 {
00198 public:
00199         LLCollectProxyBuddies() {}
00200         virtual ~LLCollectProxyBuddies() {}
00201         virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
00202         typedef std::set<LLUUID> buddy_list_t;
00203         buddy_list_t mProxy;
00204 };
00205 
00206 // collect dictionary sorted map of name -> agent_id for every online buddy
00207 class LLCollectMappableBuddies : public LLRelationshipFunctor
00208 {
00209 public:
00210         LLCollectMappableBuddies() {}
00211         virtual ~LLCollectMappableBuddies() {}
00212         virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
00213         typedef std::map<std::string, LLUUID, LLDictionaryLess> buddy_map_t;
00214         buddy_map_t mMappable;
00215         char mFirst[DB_FIRST_NAME_BUF_SIZE];    /* Flawfinder: ignore */
00216         char mLast[DB_LAST_NAME_BUF_SIZE];      /* Flawfinder: ignore */
00217 };
00218 
00219 // collect dictionary sorted map of name -> agent_id for every online buddy
00220 class LLCollectOnlineBuddies : public LLRelationshipFunctor
00221 {
00222 public:
00223         LLCollectOnlineBuddies() {}
00224         virtual ~LLCollectOnlineBuddies() {}
00225         virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
00226         typedef std::map<std::string, LLUUID, LLDictionaryLess> buddy_map_t;
00227         buddy_map_t mOnline;
00228         char mFirst[DB_FIRST_NAME_BUF_SIZE];            /*Flawfinder: ignore*/
00229         char mLast[DB_LAST_NAME_BUF_SIZE];              /*Flawfinder: ignore*/  
00230 };
00231 
00232 // collect dictionary sorted map of name -> agent_id for every buddy,
00233 // one map is offline and the other map is online.
00234 class LLCollectAllBuddies : public LLRelationshipFunctor
00235 {
00236 public:
00237         LLCollectAllBuddies() {}
00238         virtual ~LLCollectAllBuddies() {}
00239         virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
00240         typedef std::map<std::string, LLUUID, LLDictionaryLess> buddy_map_t;
00241         buddy_map_t mOnline;
00242         buddy_map_t mOffline;
00243         char mFirst[DB_FIRST_NAME_BUF_SIZE];    /*Flawfinder: ignore*/  
00244         char mLast[DB_LAST_NAME_BUF_SIZE];              /*Flawfinder: ignore*/
00245 };
00246 
00247 #endif // LL_LLCALLINGCARD_H

Generated on Thu Jul 1 06:08:20 2010 for Second Life Viewer by  doxygen 1.4.7