/indra/newview/llcallingcard.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 267 lines · 142 code · 44 blank · 81 comment · 0 complexity · 563c30cd6bac6d7077dfe2b68d251e7f MD5 · raw file

  1. /**
  2. * @file llcallingcard.h
  3. * @brief Definition of the LLPreviewCallingCard class
  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_LLCALLINGCARD_H
  27. #define LL_LLCALLINGCARD_H
  28. #include <map>
  29. #include <set>
  30. #include <string>
  31. #include <vector>
  32. #include "lluserrelations.h"
  33. #include "lluuid.h"
  34. #include "v3dmath.h"
  35. //class LLInventoryModel;
  36. //class LLInventoryObserver;
  37. class LLMessageSystem;
  38. class LLTrackingData;
  39. class LLFriendObserver
  40. {
  41. public:
  42. // This enumeration is a way to refer to what changed in a more
  43. // human readable format. You can mask the value provided by
  44. // changed() to see if the observer is interested in the change.
  45. enum
  46. {
  47. NONE = 0,
  48. ADD = 1,
  49. REMOVE = 2,
  50. ONLINE = 4,
  51. POWERS = 8,
  52. ALL = 0xffffffff
  53. };
  54. virtual ~LLFriendObserver() {}
  55. virtual void changed(U32 mask) = 0;
  56. };
  57. /*
  58. struct LLBuddyInfo
  59. {
  60. bool mIsOnline;
  61. bool mIsEmpowered;
  62. LLBuddyInfo() : mIsOnline(false), mIsEmpowered(false) {}
  63. };
  64. */
  65. // This is used as a base class for doing operations on all buddies.
  66. class LLRelationshipFunctor
  67. {
  68. public:
  69. virtual ~LLRelationshipFunctor() {}
  70. virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy) = 0;
  71. };
  72. class LLAvatarTracker
  73. {
  74. public:
  75. static LLAvatarTracker& instance() { return sInstance; }
  76. void track(const LLUUID& avatar_id, const std::string& name);
  77. void untrack(const LLUUID& avatar_id);
  78. bool isTrackedAgentValid() { return mTrackedAgentValid; }
  79. void setTrackedAgentValid(bool valid) { mTrackedAgentValid = valid; }
  80. void findAgent();
  81. // coarse update information
  82. void setTrackedCoarseLocation(const LLVector3d& global_pos);
  83. // dealing with the tracked agent location
  84. bool haveTrackingInfo();
  85. void getDegreesAndDist(F32& rot, F64& horiz_dist, F64& vert_dist);
  86. LLVector3d getGlobalPos();
  87. // Get the name passed in, returns null string if uninitialized.
  88. const std::string& getName();
  89. // Get the avatar being tracked, returns LLUUID::null if uninitialized
  90. const LLUUID& getAvatarID();
  91. // Deal with inventory
  92. //void observe(LLInventoryModel* model);
  93. //void inventoryChanged();
  94. // add or remove agents from buddy list. Each method takes a set
  95. // of buddies and returns how many were actually added or removed.
  96. typedef std::map<LLUUID, LLRelationship*> buddy_map_t;
  97. S32 addBuddyList(const buddy_map_t& buddies);
  98. //S32 removeBuddyList(const buddy_list_t& exes);
  99. void copyBuddyList(buddy_map_t& buddies) const;
  100. // deal with termination of friendhsip
  101. void terminateBuddy(const LLUUID& id);
  102. // get full info
  103. const LLRelationship* getBuddyInfo(const LLUUID& id) const;
  104. // Is this person a friend/buddy/calling card holder?
  105. bool isBuddy(const LLUUID& id) const;
  106. // online status
  107. void setBuddyOnline(const LLUUID& id, bool is_online);
  108. bool isBuddyOnline(const LLUUID& id) const;
  109. // simple empowered status
  110. void setBuddyEmpowered(const LLUUID& id, bool is_empowered);
  111. bool isBuddyEmpowered(const LLUUID& id) const;
  112. // set the empower bit & message the server.
  113. void empowerList(const buddy_map_t& list, bool grant);
  114. void empower(const LLUUID& id, bool grant); // wrapper for above
  115. // register callbacks
  116. void registerCallbacks(LLMessageSystem* msg);
  117. // Add/remove an observer. If the observer is destroyed, be sure
  118. // to remove it. On destruction of the tracker, it will delete any
  119. // observers left behind.
  120. void addObserver(LLFriendObserver* observer);
  121. void removeObserver(LLFriendObserver* observer);
  122. void notifyObservers();
  123. // Observers interested in updates of a particular avatar.
  124. // On destruction these observers are NOT deleted.
  125. void addParticularFriendObserver(const LLUUID& buddy_id, LLFriendObserver* observer);
  126. void removeParticularFriendObserver(const LLUUID& buddy_id, LLFriendObserver* observer);
  127. void notifyParticularFriendObservers(const LLUUID& buddy_id);
  128. /**
  129. * Stores flag for change and id of object change applies to
  130. *
  131. * This allows outsiders to tell the AvatarTracker if something has
  132. * been changed 'under the hood',
  133. * and next notification will have exact avatar IDs have been changed.
  134. */
  135. void addChangedMask(U32 mask, const LLUUID& referent);
  136. const std::set<LLUUID>& getChangedIDs() { return mChangedBuddyIDs; }
  137. // Apply the functor to every buddy. Do not actually modify the
  138. // buddy list in the functor or bad things will happen.
  139. void applyFunctor(LLRelationshipFunctor& f);
  140. static void formFriendship(const LLUUID& friend_id);
  141. protected:
  142. void deleteTrackingData();
  143. void agentFound(const LLUUID& prey,
  144. const LLVector3d& estimated_global_pos);
  145. // Message system functionality
  146. static void processAgentFound(LLMessageSystem* msg, void**);
  147. static void processOnlineNotification(LLMessageSystem* msg, void**);
  148. static void processOfflineNotification(LLMessageSystem* msg, void**);
  149. //static void processGrantedProxies(LLMessageSystem* msg, void**);
  150. static void processTerminateFriendship(LLMessageSystem* msg, void**);
  151. static void processChangeUserRights(LLMessageSystem* msg, void**);
  152. void processNotify(LLMessageSystem* msg, bool online);
  153. void processChange(LLMessageSystem* msg);
  154. protected:
  155. static LLAvatarTracker sInstance;
  156. LLTrackingData* mTrackingData;
  157. bool mTrackedAgentValid;
  158. U32 mModifyMask;
  159. //LLInventoryModel* mInventory;
  160. //LLInventoryObserver* mInventoryObserver;
  161. buddy_map_t mBuddyInfo;
  162. typedef std::set<LLUUID> changed_buddy_t;
  163. changed_buddy_t mChangedBuddyIDs;
  164. typedef std::vector<LLFriendObserver*> observer_list_t;
  165. observer_list_t mObservers;
  166. typedef std::set<LLFriendObserver*> observer_set_t;
  167. typedef std::map<LLUUID, observer_set_t> observer_map_t;
  168. observer_map_t mParticularFriendObserverMap;
  169. private:
  170. // do not implement
  171. LLAvatarTracker(const LLAvatarTracker&);
  172. bool operator==(const LLAvatarTracker&);
  173. public:
  174. // don't you dare create or delete this object
  175. LLAvatarTracker();
  176. ~LLAvatarTracker();
  177. };
  178. // collect set of LLUUIDs we're a proxy for
  179. class LLCollectProxyBuddies : public LLRelationshipFunctor
  180. {
  181. public:
  182. LLCollectProxyBuddies() {}
  183. virtual ~LLCollectProxyBuddies() {}
  184. virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
  185. typedef std::set<LLUUID> buddy_list_t;
  186. buddy_list_t mProxy;
  187. };
  188. // collect dictionary sorted map of name -> agent_id for every online buddy
  189. class LLCollectMappableBuddies : public LLRelationshipFunctor
  190. {
  191. public:
  192. LLCollectMappableBuddies() {}
  193. virtual ~LLCollectMappableBuddies() {}
  194. virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
  195. typedef std::map<std::string, LLUUID, LLDictionaryLess> buddy_map_t;
  196. buddy_map_t mMappable;
  197. std::string mFullName;
  198. };
  199. // collect dictionary sorted map of name -> agent_id for every online buddy
  200. class LLCollectOnlineBuddies : public LLRelationshipFunctor
  201. {
  202. public:
  203. LLCollectOnlineBuddies() {}
  204. virtual ~LLCollectOnlineBuddies() {}
  205. virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
  206. typedef std::map<std::string, LLUUID, LLDictionaryLess> buddy_map_t;
  207. buddy_map_t mOnline;
  208. std::string mFullName;
  209. };
  210. // collect dictionary sorted map of name -> agent_id for every buddy,
  211. // one map is offline and the other map is online.
  212. class LLCollectAllBuddies : public LLRelationshipFunctor
  213. {
  214. public:
  215. LLCollectAllBuddies() {}
  216. virtual ~LLCollectAllBuddies() {}
  217. virtual bool operator()(const LLUUID& buddy_id, LLRelationship* buddy);
  218. typedef std::map<std::string, LLUUID, LLDictionaryLess> buddy_map_t;
  219. buddy_map_t mOnline;
  220. buddy_map_t mOffline;
  221. std::string mFullName;
  222. };
  223. #endif // LL_LLCALLINGCARD_H