PageRenderTime 58ms CodeModel.GetById 2ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llgroupmgr.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 378 lines | 281 code | 72 blank | 25 comment | 3 complexity | 9a6a3c1c150447e121f26acda32712e0 MD5 | raw file
  1/** 
  2 * @file llgroupmgr.h
  3 * @brief Manager for aggregating all client knowledge for specific groups
  4 *
  5 * $LicenseInfo:firstyear=2004&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_LLGROUPMGR_H
 28#define LL_LLGROUPMGR_H
 29
 30#include "lluuid.h"
 31#include "roles_constants.h"
 32#include <vector>
 33#include <string>
 34#include <map>
 35
 36class LLMessageSystem;
 37
 38class LLGroupMgrObserver
 39{
 40public:
 41	LLGroupMgrObserver(const LLUUID& id) : mID(id){};
 42	LLGroupMgrObserver() : mID(LLUUID::null){};
 43	virtual ~LLGroupMgrObserver(){};
 44	virtual void changed(LLGroupChange gc) = 0;
 45	const LLUUID& getID() { return mID; }
 46protected:
 47	LLUUID	mID;
 48};
 49
 50class LLParticularGroupObserver
 51{
 52public:
 53	virtual ~LLParticularGroupObserver(){}
 54	virtual void changed(const LLUUID& group_id, LLGroupChange gc) = 0;
 55};
 56
 57class LLGroupRoleData;
 58
 59class LLGroupMemberData
 60{
 61friend class LLGroupMgrGroupData;
 62
 63public:
 64	typedef std::map<LLUUID,LLGroupRoleData*> role_list_t;
 65	
 66	LLGroupMemberData(const LLUUID& id, 
 67						S32 contribution,
 68						U64 agent_powers,
 69						const std::string& title,
 70						const std::string& online_status,
 71						BOOL is_owner);
 72
 73	~LLGroupMemberData();
 74
 75	const LLUUID& getID() const { return mID; }
 76	S32 getContribution() const { return mContribution; }
 77	U64	getAgentPowers() const { return mAgentPowers; }
 78	BOOL isOwner() const { return mIsOwner; }
 79	const std::string& getTitle() const { return mTitle; }
 80	const std::string& getOnlineStatus() const { return mOnlineStatus; }
 81	void addRole(const LLUUID& role, LLGroupRoleData* rd);
 82	bool removeRole(const LLUUID& role);
 83	void clearRoles() { mRolesList.clear(); };
 84	role_list_t::iterator roleBegin() { return mRolesList.begin(); }
 85	role_list_t::iterator roleEnd() { return mRolesList.end(); }
 86
 87	BOOL isInRole(const LLUUID& role_id) { return (mRolesList.find(role_id) != mRolesList.end()); }
 88
 89protected:
 90	LLUUID	mID;
 91	S32		mContribution;
 92	U64		mAgentPowers;
 93	std::string	mTitle;
 94	std::string	mOnlineStatus;
 95	BOOL	mIsOwner;
 96	role_list_t mRolesList;
 97};
 98
 99struct LLRoleData
100{
101	LLRoleData() : mRolePowers(0), mChangeType(RC_UPDATE_NONE) { }
102	LLRoleData(const LLRoleData& rd)
103	: 	mRoleName(rd.mRoleName),
104		mRoleTitle(rd.mRoleTitle),
105		mRoleDescription(rd.mRoleDescription),
106		mRolePowers(rd.mRolePowers),
107		mChangeType(rd.mChangeType) { }
108
109	std::string mRoleName;
110	std::string mRoleTitle;
111	std::string mRoleDescription;
112	U64	mRolePowers;
113	LLRoleChangeType mChangeType;
114};
115
116class LLGroupRoleData
117{
118friend class LLGroupMgrGroupData;
119
120public:
121	LLGroupRoleData(const LLUUID& role_id, 
122					const std::string& role_name,
123					const std::string& role_title,
124					const std::string& role_desc,
125					const U64 role_powers,
126					const S32 member_count);
127	
128	LLGroupRoleData(const LLUUID& role_id, 
129					LLRoleData role_data,
130					const S32 member_count);
131
132	~LLGroupRoleData();
133
134	const LLUUID& getID() const { return mRoleID; }
135
136	const uuid_vec_t& getRoleMembers() const { return mMemberIDs; }
137	S32 getMembersInRole(uuid_vec_t members, BOOL needs_sort = TRUE);
138	S32 getTotalMembersInRole() { return mMemberIDs.size(); }
139
140	LLRoleData getRoleData() const { return mRoleData; }
141	void setRoleData(LLRoleData data) { mRoleData = data; }
142	
143	void addMember(const LLUUID& member);
144	bool removeMember(const LLUUID& member);
145	void clearMembers();
146
147	const uuid_vec_t::const_iterator getMembersBegin() const
148	{ return mMemberIDs.begin(); }
149
150	const uuid_vec_t::const_iterator getMembersEnd() const
151	{ return mMemberIDs.end(); }
152
153
154protected:
155	LLGroupRoleData()
156	: mMemberCount(0), mMembersNeedsSort(FALSE) {}
157
158	LLUUID mRoleID;
159	LLRoleData	mRoleData;
160
161	uuid_vec_t mMemberIDs;
162	S32	mMemberCount;
163
164private:
165	BOOL mMembersNeedsSort;
166};
167
168struct LLRoleMemberChange
169{
170	LLRoleMemberChange() : mChange(RMC_NONE) { }
171	LLRoleMemberChange(const LLUUID& role, const LLUUID& member, LLRoleMemberChangeType change)
172		: mRole(role), mMember(member), mChange(change) { }
173	LLRoleMemberChange(const LLRoleMemberChange& rc)
174		: mRole(rc.mRole), mMember(rc.mMember), mChange(rc.mChange) { }
175	LLUUID mRole;
176	LLUUID mMember;
177	LLRoleMemberChangeType mChange;
178};
179
180typedef std::pair<LLUUID,LLUUID> lluuid_pair;
181
182struct lluuid_pair_less
183{
184	bool operator()(const lluuid_pair& lhs, const lluuid_pair& rhs) const
185	{
186		if (lhs.first == rhs.first)
187			return lhs.second < rhs.second;
188		else
189			return lhs.first < rhs.first;
190	}
191};
192
193struct LLGroupTitle
194{
195	std::string mTitle;
196	LLUUID		mRoleID;
197	BOOL		mSelected;
198};
199
200class LLGroupMgr;
201
202class LLGroupMgrGroupData
203{
204friend class LLGroupMgr;
205
206public:
207	LLGroupMgrGroupData(const LLUUID& id);
208	~LLGroupMgrGroupData();
209
210	const LLUUID& getID() { return mID; }
211
212	BOOL getRoleData(const LLUUID& role_id, LLRoleData& role_data);
213	void setRoleData(const LLUUID& role_id, LLRoleData role_data);
214	void createRole(const LLUUID& role_id, LLRoleData role_data);
215	void deleteRole(const LLUUID& role_id);
216	BOOL pendingRoleChanges();
217
218	void addRolePower(const LLUUID& role_id, U64 power);
219	void removeRolePower(const LLUUID& role_id, U64 power);
220	U64  getRolePowers(const LLUUID& role_id);
221
222	void removeData();
223	void removeRoleData();
224	void removeMemberData();
225	void removeRoleMemberData();
226
227	bool changeRoleMember(const LLUUID& role_id, const LLUUID& member_id, LLRoleMemberChangeType rmc);
228	void recalcAllAgentPowers();
229	void recalcAgentPowers(const LLUUID& agent_id);
230
231	BOOL isMemberDataComplete() { return mMemberDataComplete; }
232	BOOL isRoleDataComplete() { return mRoleDataComplete; }
233	BOOL isRoleMemberDataComplete() { return mRoleMemberDataComplete; }
234	BOOL isGroupPropertiesDataComplete() { return mGroupPropertiesDataComplete; }
235
236public:
237	typedef	std::map<LLUUID,LLGroupMemberData*> member_list_t;
238	typedef	std::map<LLUUID,LLGroupRoleData*> role_list_t;
239	typedef std::map<lluuid_pair,LLRoleMemberChange,lluuid_pair_less> change_map_t;
240	typedef std::map<LLUUID,LLRoleData> role_data_map_t;
241	member_list_t		mMembers;
242	role_list_t			mRoles;
243
244	
245	change_map_t		mRoleMemberChanges;
246	role_data_map_t		mRoleChanges;
247
248	std::vector<LLGroupTitle> mTitles;
249
250	LLUUID				mID;
251	LLUUID				mOwnerRole;
252	std::string			mName;
253	std::string			mCharter;
254	BOOL				mShowInList;
255	LLUUID				mInsigniaID;
256	LLUUID				mFounderID;
257	BOOL				mOpenEnrollment;
258	S32					mMembershipFee;
259	BOOL				mAllowPublish;
260	BOOL				mListInProfile;
261	BOOL				mMaturePublish;
262	BOOL				mChanged;
263	S32					mMemberCount;
264	S32					mRoleCount;
265
266protected:
267	void sendRoleChanges();
268	void cancelRoleChanges();
269
270private:
271	LLUUID				mMemberRequestID;
272	LLUUID				mRoleDataRequestID;
273	LLUUID				mRoleMembersRequestID;
274	LLUUID				mTitlesRequestID;
275	U32					mReceivedRoleMemberPairs;
276
277	BOOL				mMemberDataComplete;
278	BOOL				mRoleDataComplete;
279	BOOL				mRoleMemberDataComplete;
280	BOOL				mGroupPropertiesDataComplete;
281
282	BOOL				mPendingRoleMemberRequest;
283};
284
285struct LLRoleAction
286{
287	std::string mName;
288	std::string mDescription;
289	std::string mLongDescription;
290	U64 mPowerBit;
291};
292
293struct LLRoleActionSet
294{
295	LLRoleActionSet();
296	~LLRoleActionSet();
297	LLRoleAction* mActionSetData;
298	std::vector<LLRoleAction*> mActions;
299};
300
301class LLGroupMgr : public LLSingleton<LLGroupMgr>
302{
303	LOG_CLASS(LLGroupMgr);
304	
305public:
306	LLGroupMgr();
307	~LLGroupMgr();
308
309	void addObserver(LLGroupMgrObserver* observer);
310	void addObserver(const LLUUID& group_id, LLParticularGroupObserver* observer);
311	void removeObserver(LLGroupMgrObserver* observer);
312	void removeObserver(const LLUUID& group_id, LLParticularGroupObserver* observer);
313	LLGroupMgrGroupData* getGroupData(const LLUUID& id);
314
315	void sendGroupPropertiesRequest(const LLUUID& group_id);
316	void sendGroupRoleDataRequest(const LLUUID& group_id);
317	void sendGroupRoleMembersRequest(const LLUUID& group_id);
318	void sendGroupMembersRequest(const LLUUID& group_id);
319	void sendGroupTitlesRequest(const LLUUID& group_id);
320	void sendGroupTitleUpdate(const LLUUID& group_id, const LLUUID& title_role_id);
321	void sendUpdateGroupInfo(const LLUUID& group_id);
322	void sendGroupRoleMemberChanges(const LLUUID& group_id);
323	void sendGroupRoleChanges(const LLUUID& group_id);
324
325	static void sendCreateGroupRequest(const std::string& name,
326									   const std::string& charter,
327									   U8 show_in_list,
328									   const LLUUID& insignia,
329									   S32 membership_fee,
330									   BOOL open_enrollment,
331									   BOOL allow_publish,
332									   BOOL mature_publish);
333
334	static void sendGroupMemberJoin(const LLUUID& group_id);
335	static void sendGroupMemberInvites(const LLUUID& group_id, std::map<LLUUID,LLUUID>& role_member_pairs);
336	static void sendGroupMemberEjects(const LLUUID& group_id,
337									  uuid_vec_t& member_ids);
338
339	void cancelGroupRoleChanges(const LLUUID& group_id);
340
341	static void processGroupPropertiesReply(LLMessageSystem* msg, void** data);
342	static void processGroupMembersReply(LLMessageSystem* msg, void** data);
343	static void processGroupRoleDataReply(LLMessageSystem* msg, void** data);
344	static void processGroupRoleMembersReply(LLMessageSystem* msg, void** data);
345	static void processGroupTitlesReply(LLMessageSystem* msg, void** data);
346	static void processCreateGroupReply(LLMessageSystem* msg, void** data);
347	static void processJoinGroupReply(LLMessageSystem* msg, void ** data);
348	static void processEjectGroupMemberReply(LLMessageSystem* msg, void ** data);
349	static void processLeaveGroupReply(LLMessageSystem* msg, void ** data);
350
351	static bool parseRoleActions(const std::string& xml_filename);
352
353	std::vector<LLRoleActionSet*> mRoleActionSets;
354
355	static void debugClearAllGroups(void*);
356	void clearGroups();
357	void clearGroupData(const LLUUID& group_id);
358
359private:
360	void notifyObservers(LLGroupChange gc);
361	void notifyObserver(const LLUUID& group_id, LLGroupChange gc);
362	void addGroup(LLGroupMgrGroupData* group_datap);
363	LLGroupMgrGroupData* createGroupData(const LLUUID &id);
364
365	typedef std::multimap<LLUUID,LLGroupMgrObserver*> observer_multimap_t;
366	observer_multimap_t mObservers;
367
368	typedef std::map<LLUUID, LLGroupMgrGroupData*> group_map_t;
369	group_map_t mGroups;
370
371	typedef std::set<LLParticularGroupObserver*> observer_set_t;
372	typedef std::map<LLUUID,observer_set_t> observer_map_t;
373	observer_map_t mParticularObservers;
374};
375
376
377#endif
378