PageRenderTime 30ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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