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 LLGroupMemberData(const LLUUID& id,
00062 S32 contribution,
00063 U64 agent_powers,
00064 const std::string& title,
00065 const std::string& online_status,
00066 BOOL is_owner);
00067
00068 ~LLGroupMemberData();
00069
00070 const LLUUID& getID() const { return mID; }
00071 S32 getContribution() const { return mContribution; }
00072 U64 getAgentPowers() const { return mAgentPowers; }
00073 BOOL isOwner() const { return mIsOwner; }
00074 const std::string& getTitle() const { return mTitle; }
00075 const std::string& getOnlineStatus() const { return mOnlineStatus; }
00076 void addRole(const LLUUID& role, LLGroupRoleData* rd);
00077 bool removeRole(const LLUUID& role);
00078 void clearRoles() { mRoles.clear(); };
00079 std::map<LLUUID,LLGroupRoleData*>::iterator roleBegin() { return mRoles.begin(); }
00080 std::map<LLUUID,LLGroupRoleData*>::iterator roleEnd() { return mRoles.end(); }
00081
00082 BOOL isInRole(const LLUUID& role_id) { return (mRoles.find(role_id) != mRoles.end()); }
00083
00084 protected:
00085 LLUUID mID;
00086 S32 mContribution;
00087 U64 mAgentPowers;
00088 std::string mTitle;
00089 std::string mOnlineStatus;
00090 BOOL mIsOwner;
00091 std::map<LLUUID,LLGroupRoleData*> mRoles;
00092 };
00093
00094 struct LLRoleData
00095 {
00096 LLRoleData() : mRolePowers(0), mChangeType(RC_UPDATE_NONE) { }
00097 LLRoleData(const LLRoleData& rd)
00098 : mRoleName(rd.mRoleName),
00099 mRoleTitle(rd.mRoleTitle),
00100 mRoleDescription(rd.mRoleDescription),
00101 mRolePowers(rd.mRolePowers),
00102 mChangeType(rd.mChangeType) { }
00103
00104 std::string mRoleName;
00105 std::string mRoleTitle;
00106 std::string mRoleDescription;
00107 U64 mRolePowers;
00108 LLRoleChangeType mChangeType;
00109 };
00110
00111 class LLGroupRoleData
00112 {
00113 friend class LLGroupMgrGroupData;
00114
00115 public:
00116 LLGroupRoleData(const LLUUID& role_id,
00117 const std::string& role_name,
00118 const std::string& role_title,
00119 const std::string& role_desc,
00120 const U64 role_powers,
00121 const S32 member_count);
00122
00123 LLGroupRoleData(const LLUUID& role_id,
00124 LLRoleData role_data,
00125 const S32 member_count);
00126
00127 ~LLGroupRoleData();
00128
00129 const LLUUID& getID() const { return mRoleID; }
00130
00131 const std::vector<LLUUID>& getRoleMembers() const { return mMemberIDs; }
00132 S32 getMembersInRole(std::vector<LLUUID> members, BOOL needs_sort = TRUE);
00133 S32 getTotalMembersInRole() { return mMemberIDs.size(); }
00134
00135 LLRoleData getRoleData() const { return mRoleData; }
00136 void setRoleData(LLRoleData data) { mRoleData = data; }
00137
00138 void addMember(const LLUUID& member);
00139 bool removeMember(const LLUUID& member);
00140 void clearMembers();
00141
00142 const std::vector<LLUUID>::const_iterator getMembersBegin() const
00143 { return mMemberIDs.begin(); }
00144
00145 const std::vector<LLUUID>::const_iterator getMembersEnd() const
00146 { return mMemberIDs.end(); }
00147
00148
00149 protected:
00150 LLGroupRoleData()
00151 : mMemberCount(0), mMembersNeedsSort(FALSE) {}
00152
00153 LLUUID mRoleID;
00154 LLRoleData mRoleData;
00155
00156 std::vector<LLUUID> mMemberIDs;
00157 S32 mMemberCount;
00158
00159 private:
00160 BOOL mMembersNeedsSort;
00161 };
00162
00163 struct LLRoleMemberChange
00164 {
00165 LLRoleMemberChange() : mChange(RMC_NONE) { }
00166 LLRoleMemberChange(const LLUUID& role, const LLUUID& member, LLRoleMemberChangeType change)
00167 : mRole(role), mMember(member), mChange(change) { }
00168 LLRoleMemberChange(const LLRoleMemberChange& rc)
00169 : mRole(rc.mRole), mMember(rc.mMember), mChange(rc.mChange) { }
00170 LLUUID mRole;
00171 LLUUID mMember;
00172 LLRoleMemberChangeType mChange;
00173 };
00174
00175 typedef std::pair<LLUUID,LLUUID> lluuid_pair;
00176
00177 struct lluuid_pair_less
00178 {
00179 bool operator()(const lluuid_pair& lhs, const lluuid_pair& rhs) const
00180 {
00181 if (lhs.first == rhs.first)
00182 return lhs.second < rhs.second;
00183 else
00184 return lhs.first < rhs.first;
00185 }
00186 };
00187
00188 typedef std::map<lluuid_pair,LLRoleMemberChange,lluuid_pair_less> change_map;
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;
00235 typedef member_list::iterator member_iter;
00236 typedef std::map<LLUUID,LLGroupRoleData*> role_list;
00237 typedef role_list::iterator role_iter;
00238
00239 member_list mMembers;
00240 role_list mRoles;
00241
00242
00243 change_map mRoleMemberChanges;
00244 std::map<LLUUID,LLRoleData> mRoleChanges;
00245
00246 std::vector<LLGroupTitle> mTitles;
00247
00248 LLUUID mID;
00249 LLUUID mOwnerRole;
00250 std::string mName;
00251 std::string mCharter;
00252 BOOL mShowInList;
00253 LLUUID mInsigniaID;
00254 LLUUID mFounderID;
00255 BOOL mOpenEnrollment;
00256 S32 mMembershipFee;
00257 BOOL mAllowPublish;
00258 BOOL mListInProfile;
00259 BOOL mMaturePublish;
00260 BOOL mChanged;
00261 S32 mMemberCount;
00262 S32 mRoleCount;
00263
00264 protected:
00265 void sendRoleChanges();
00266 void cancelRoleChanges();
00267
00268 private:
00269 LLUUID mMemberRequestID;
00270 LLUUID mRoleDataRequestID;
00271 LLUUID mRoleMembersRequestID;
00272 LLUUID mTitlesRequestID;
00273 U32 mReceivedRoleMemberPairs;
00274
00275 BOOL mMemberDataComplete;
00276 BOOL mRoleDataComplete;
00277 BOOL mRoleMemberDataComplete;
00278 BOOL mGroupPropertiesDataComplete;
00279
00280 BOOL mPendingRoleMemberRequest;
00281 };
00282
00283 struct LLRoleAction
00284 {
00285 std::string mName;
00286 std::string mDescription;
00287 std::string mLongDescription;
00288 U64 mPowerBit;
00289 };
00290
00291 struct LLRoleActionSet
00292 {
00293 LLRoleActionSet();
00294 ~LLRoleActionSet();
00295 LLRoleAction* mActionSetData;
00296 std::vector<LLRoleAction*> mActions;
00297 };
00298
00299 class LLGroupMgr
00300 {
00301 public:
00302 LLGroupMgr();
00303 ~LLGroupMgr();
00304
00305 void addObserver(LLGroupMgrObserver* observer);
00306 void removeObserver(LLGroupMgrObserver* observer);
00307 LLGroupMgrGroupData* getGroupData(const LLUUID& id);
00308
00309 void sendGroupPropertiesRequest(const LLUUID& group_id);
00310 void sendGroupRoleDataRequest(const LLUUID& group_id);
00311 void sendGroupRoleMembersRequest(const LLUUID& group_id);
00312 void sendGroupMembersRequest(const LLUUID& group_id);
00313 void sendGroupTitlesRequest(const LLUUID& group_id);
00314 void sendGroupTitleUpdate(const LLUUID& group_id, const LLUUID& title_role_id);
00315 void sendUpdateGroupInfo(const LLUUID& group_id);
00316 void sendGroupRoleMemberChanges(const LLUUID& group_id);
00317 void sendGroupRoleChanges(const LLUUID& group_id);
00318
00319 static void sendCreateGroupRequest(const std::string& name,
00320 const std::string& charter,
00321 U8 show_in_list,
00322 const LLUUID& insignia,
00323 S32 membership_fee,
00324 BOOL open_enrollment,
00325 BOOL allow_publish,
00326 BOOL mature_publish);
00327
00328 static void sendGroupMemberJoin(const LLUUID& group_id);
00329 static void sendGroupMemberInvites(const LLUUID& group_id, std::map<LLUUID,LLUUID>& role_member_pairs);
00330 static void sendGroupMemberEjects(const LLUUID& group_id,
00331 std::vector<LLUUID>& member_ids);
00332
00333 void cancelGroupRoleChanges(const LLUUID& group_id);
00334
00335 static void processGroupPropertiesReply(LLMessageSystem* msg, void** data);
00336 static void processGroupMembersReply(LLMessageSystem* msg, void** data);
00337 static void processGroupRoleDataReply(LLMessageSystem* msg, void** data);
00338 static void processGroupRoleMembersReply(LLMessageSystem* msg, void** data);
00339 static void processGroupTitlesReply(LLMessageSystem* msg, void** data);
00340 static void processCreateGroupReply(LLMessageSystem* msg, void** data);
00341 static void processJoinGroupReply(LLMessageSystem* msg, void ** data);
00342 static void processEjectGroupMemberReply(LLMessageSystem* msg, void ** data);
00343 static void processLeaveGroupReply(LLMessageSystem* msg, void ** data);
00344
00345 static bool parseRoleActions(const LLString& xml_filename);
00346
00347 std::vector<LLRoleActionSet*> mRoleActionSets;
00348
00349 static void debugClearAllGroups(void*);
00350 void clearGroups();
00351 void clearGroupData(const LLUUID& group_id);
00352 protected:
00353 void notifyObservers(LLGroupChange gc);
00354 void addGroup(LLGroupMgrGroupData* group_datap);
00355 LLGroupMgrGroupData* createGroupData(const LLUUID &id);
00356
00357 protected:
00358 typedef std::multimap<LLUUID,LLGroupMgrObserver*>::iterator observer_iter;
00359 std::multimap<LLUUID,LLGroupMgrObserver*> mObservers;
00360 typedef std::map<LLUUID, LLGroupMgrGroupData*>::iterator group_iter;
00361 std::map<LLUUID, LLGroupMgrGroupData*> mGroups;
00362 };
00363
00364 extern LLGroupMgr* gGroupMgr;
00365
00366 #endif
00367