PageRenderTime 295ms CodeModel.GetById 151ms app.highlight 18ms RepoModel.GetById 123ms app.codeStats 0ms

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