00001 00032 #ifndef LL_LLGROUPMGR_H 00033 #define LL_LLGROUPMGR_H 00034 00035 #include "lluuid.h" 00036 #include "roles_constants.h" 00037 #include <vector> 00038 #include <string> 00039 #include <map> 00040 00041 class LLMessageSystem; 00042 00043 class LLGroupMgrObserver 00044 { 00045 public: 00046 LLGroupMgrObserver(const LLUUID& id) : mID(id){}; 00047 virtual ~LLGroupMgrObserver(){}; 00048 virtual void changed(LLGroupChange gc) = 0; 00049 const LLUUID& getID() { return mID; } 00050 protected: 00051 LLUUID mID; 00052 }; 00053 00054 class LLGroupRoleData; 00055 00056 class LLGroupMemberData 00057 { 00058 friend class LLGroupMgrGroupData; 00059 00060 public: 00061 typedef std::map<LLUUID,LLGroupRoleData*> role_list_t; 00062 00063 LLGroupMemberData(const LLUUID& id, 00064 S32 contribution, 00065 U64 agent_powers, 00066 const std::string& title, 00067 const std::string& online_status, 00068 BOOL is_owner); 00069 00070 ~LLGroupMemberData(); 00071 00072 const LLUUID& getID() const { return mID; } 00073 S32 getContribution() const { return mContribution; } 00074 U64 getAgentPowers() const { return mAgentPowers; } 00075 BOOL isOwner() const { return mIsOwner; } 00076 const std::string& getTitle() const { return mTitle; } 00077 const std::string& getOnlineStatus() const { return mOnlineStatus; } 00078 void addRole(const LLUUID& role, LLGroupRoleData* rd); 00079 bool removeRole(const LLUUID& role); 00080 void clearRoles() { mRolesList.clear(); }; 00081 role_list_t::iterator roleBegin() { return mRolesList.begin(); } 00082 role_list_t::iterator roleEnd() { return mRolesList.end(); } 00083 00084 BOOL isInRole(const LLUUID& role_id) { return (mRolesList.find(role_id) != mRolesList.end()); } 00085 00086 protected: 00087 LLUUID mID; 00088 S32 mContribution; 00089 U64 mAgentPowers; 00090 std::string mTitle; 00091 std::string mOnlineStatus; 00092 BOOL mIsOwner; 00093 role_list_t mRolesList; 00094 }; 00095 00096 struct LLRoleData 00097 { 00098 LLRoleData() : mRolePowers(0), mChangeType(RC_UPDATE_NONE) { } 00099 LLRoleData(const LLRoleData& rd) 00100 : mRoleName(rd.mRoleName), 00101 mRoleTitle(rd.mRoleTitle), 00102 mRoleDescription(rd.mRoleDescription), 00103 mRolePowers(rd.mRolePowers), 00104 mChangeType(rd.mChangeType) { } 00105 00106 std::string mRoleName; 00107 std::string mRoleTitle; 00108 std::string mRoleDescription; 00109 U64 mRolePowers; 00110 LLRoleChangeType mChangeType; 00111 }; 00112 00113 class LLGroupRoleData 00114 { 00115 friend class LLGroupMgrGroupData; 00116 00117 public: 00118 LLGroupRoleData(const LLUUID& role_id, 00119 const std::string& role_name, 00120 const std::string& role_title, 00121 const std::string& role_desc, 00122 const U64 role_powers, 00123 const S32 member_count); 00124 00125 LLGroupRoleData(const LLUUID& role_id, 00126 LLRoleData role_data, 00127 const S32 member_count); 00128 00129 ~LLGroupRoleData(); 00130 00131 const LLUUID& getID() const { return mRoleID; } 00132 00133 const std::vector<LLUUID>& getRoleMembers() const { return mMemberIDs; } 00134 S32 getMembersInRole(std::vector<LLUUID> members, BOOL needs_sort = TRUE); 00135 S32 getTotalMembersInRole() { return mMemberIDs.size(); } 00136 00137 LLRoleData getRoleData() const { return mRoleData; } 00138 void setRoleData(LLRoleData data) { mRoleData = data; } 00139 00140 void addMember(const LLUUID& member); 00141 bool removeMember(const LLUUID& member); 00142 void clearMembers(); 00143 00144 const std::vector<LLUUID>::const_iterator getMembersBegin() const 00145 { return mMemberIDs.begin(); } 00146 00147 const std::vector<LLUUID>::const_iterator getMembersEnd() const 00148 { return mMemberIDs.end(); } 00149 00150 00151 protected: 00152 LLGroupRoleData() 00153 : mMemberCount(0), mMembersNeedsSort(FALSE) {} 00154 00155 LLUUID mRoleID; 00156 LLRoleData mRoleData; 00157 00158 std::vector<LLUUID> mMemberIDs; 00159 S32 mMemberCount; 00160 00161 private: 00162 BOOL mMembersNeedsSort; 00163 }; 00164 00165 struct LLRoleMemberChange 00166 { 00167 LLRoleMemberChange() : mChange(RMC_NONE) { } 00168 LLRoleMemberChange(const LLUUID& role, const LLUUID& member, LLRoleMemberChangeType change) 00169 : mRole(role), mMember(member), mChange(change) { } 00170 LLRoleMemberChange(const LLRoleMemberChange& rc) 00171 : mRole(rc.mRole), mMember(rc.mMember), mChange(rc.mChange) { } 00172 LLUUID mRole; 00173 LLUUID mMember; 00174 LLRoleMemberChangeType mChange; 00175 }; 00176 00177 typedef std::pair<LLUUID,LLUUID> lluuid_pair; 00178 00179 struct lluuid_pair_less 00180 { 00181 bool operator()(const lluuid_pair& lhs, const lluuid_pair& rhs) const 00182 { 00183 if (lhs.first == rhs.first) 00184 return lhs.second < rhs.second; 00185 else 00186 return lhs.first < rhs.first; 00187 } 00188 }; 00189 00190 struct LLGroupTitle 00191 { 00192 std::string mTitle; 00193 LLUUID mRoleID; 00194 BOOL mSelected; 00195 }; 00196 00197 class LLGroupMgr; 00198 00199 class LLGroupMgrGroupData 00200 { 00201 friend class LLGroupMgr; 00202 00203 public: 00204 LLGroupMgrGroupData(const LLUUID& id); 00205 ~LLGroupMgrGroupData(); 00206 00207 const LLUUID& getID() { return mID; } 00208 00209 BOOL getRoleData(const LLUUID& role_id, LLRoleData& role_data); 00210 void setRoleData(const LLUUID& role_id, LLRoleData role_data); 00211 void createRole(const LLUUID& role_id, LLRoleData role_data); 00212 void deleteRole(const LLUUID& role_id); 00213 BOOL pendingRoleChanges(); 00214 00215 void addRolePower(const LLUUID& role_id, U64 power); 00216 void removeRolePower(const LLUUID& role_id, U64 power); 00217 U64 getRolePowers(const LLUUID& role_id); 00218 00219 void removeData(); 00220 void removeRoleData(); 00221 void removeMemberData(); 00222 void removeRoleMemberData(); 00223 00224 bool changeRoleMember(const LLUUID& role_id, const LLUUID& member_id, LLRoleMemberChangeType rmc); 00225 void recalcAllAgentPowers(); 00226 void recalcAgentPowers(const LLUUID& agent_id); 00227 00228 BOOL isMemberDataComplete() { return mMemberDataComplete; } 00229 BOOL isRoleDataComplete() { return mRoleDataComplete; } 00230 BOOL isRoleMemberDataComplete() { return mRoleMemberDataComplete; } 00231 BOOL isGroupPropertiesDataComplete() { return mGroupPropertiesDataComplete; } 00232 00233 public: 00234 typedef std::map<LLUUID,LLGroupMemberData*> member_list_t; 00235 typedef std::map<LLUUID,LLGroupRoleData*> role_list_t; 00236 typedef std::map<lluuid_pair,LLRoleMemberChange,lluuid_pair_less> change_map_t; 00237 typedef std::map<LLUUID,LLRoleData> role_data_map_t; 00238 member_list_t mMembers; 00239 role_list_t mRoles; 00240 00241 00242 change_map_t mRoleMemberChanges; 00243 role_data_map_t mRoleChanges; 00244 00245 std::vector<LLGroupTitle> mTitles; 00246 00247 LLUUID mID; 00248 LLUUID mOwnerRole; 00249 std::string mName; 00250 std::string mCharter; 00251 BOOL mShowInList; 00252 LLUUID mInsigniaID; 00253 LLUUID mFounderID; 00254 BOOL mOpenEnrollment; 00255 S32 mMembershipFee; 00256 BOOL mAllowPublish; 00257 BOOL mListInProfile; 00258 BOOL mMaturePublish; 00259 BOOL mChanged; 00260 S32 mMemberCount; 00261 S32 mRoleCount; 00262 00263 protected: 00264 void sendRoleChanges(); 00265 void cancelRoleChanges(); 00266 00267 private: 00268 LLUUID mMemberRequestID; 00269 LLUUID mRoleDataRequestID; 00270 LLUUID mRoleMembersRequestID; 00271 LLUUID mTitlesRequestID; 00272 U32 mReceivedRoleMemberPairs; 00273 00274 BOOL mMemberDataComplete; 00275 BOOL mRoleDataComplete; 00276 BOOL mRoleMemberDataComplete; 00277 BOOL mGroupPropertiesDataComplete; 00278 00279 BOOL mPendingRoleMemberRequest; 00280 }; 00281 00282 struct LLRoleAction 00283 { 00284 std::string mName; 00285 std::string mDescription; 00286 std::string mLongDescription; 00287 U64 mPowerBit; 00288 }; 00289 00290 struct LLRoleActionSet 00291 { 00292 LLRoleActionSet(); 00293 ~LLRoleActionSet(); 00294 LLRoleAction* mActionSetData; 00295 std::vector<LLRoleAction*> mActions; 00296 }; 00297 00298 class LLGroupMgr : public LLSingleton<LLGroupMgr> 00299 { 00300 LOG_CLASS(LLGroupMgr); 00301 00302 public: 00303 LLGroupMgr(); 00304 ~LLGroupMgr(); 00305 00306 void addObserver(LLGroupMgrObserver* observer); 00307 void removeObserver(LLGroupMgrObserver* observer); 00308 LLGroupMgrGroupData* getGroupData(const LLUUID& id); 00309 00310 void sendGroupPropertiesRequest(const LLUUID& group_id); 00311 void sendGroupRoleDataRequest(const LLUUID& group_id); 00312 void sendGroupRoleMembersRequest(const LLUUID& group_id); 00313 void sendGroupMembersRequest(const LLUUID& group_id); 00314 void sendGroupTitlesRequest(const LLUUID& group_id); 00315 void sendGroupTitleUpdate(const LLUUID& group_id, const LLUUID& title_role_id); 00316 void sendUpdateGroupInfo(const LLUUID& group_id); 00317 void sendGroupRoleMemberChanges(const LLUUID& group_id); 00318 void sendGroupRoleChanges(const LLUUID& group_id); 00319 00320 static void sendCreateGroupRequest(const std::string& name, 00321 const std::string& charter, 00322 U8 show_in_list, 00323 const LLUUID& insignia, 00324 S32 membership_fee, 00325 BOOL open_enrollment, 00326 BOOL allow_publish, 00327 BOOL mature_publish); 00328 00329 static void sendGroupMemberJoin(const LLUUID& group_id); 00330 static void sendGroupMemberInvites(const LLUUID& group_id, std::map<LLUUID,LLUUID>& role_member_pairs); 00331 static void sendGroupMemberEjects(const LLUUID& group_id, 00332 std::vector<LLUUID>& member_ids); 00333 00334 void cancelGroupRoleChanges(const LLUUID& group_id); 00335 00336 static void processGroupPropertiesReply(LLMessageSystem* msg, void** data); 00337 static void processGroupMembersReply(LLMessageSystem* msg, void** data); 00338 static void processGroupRoleDataReply(LLMessageSystem* msg, void** data); 00339 static void processGroupRoleMembersReply(LLMessageSystem* msg, void** data); 00340 static void processGroupTitlesReply(LLMessageSystem* msg, void** data); 00341 static void processCreateGroupReply(LLMessageSystem* msg, void** data); 00342 static void processJoinGroupReply(LLMessageSystem* msg, void ** data); 00343 static void processEjectGroupMemberReply(LLMessageSystem* msg, void ** data); 00344 static void processLeaveGroupReply(LLMessageSystem* msg, void ** data); 00345 00346 static bool parseRoleActions(const LLString& xml_filename); 00347 00348 std::vector<LLRoleActionSet*> mRoleActionSets; 00349 00350 static void debugClearAllGroups(void*); 00351 void clearGroups(); 00352 void clearGroupData(const LLUUID& group_id); 00353 00354 private: 00355 void notifyObservers(LLGroupChange gc); 00356 void addGroup(LLGroupMgrGroupData* group_datap); 00357 LLGroupMgrGroupData* createGroupData(const LLUUID &id); 00358 00359 typedef std::multimap<LLUUID,LLGroupMgrObserver*> observer_multimap_t; 00360 observer_multimap_t mObservers; 00361 typedef std::map<LLUUID, LLGroupMgrGroupData*> group_map_t; 00362 group_map_t mGroups; 00363 }; 00364 00365 00366 #endif 00367