lluserrelations.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * @file lluserrelations.h
  3. * @author Phoenix
  4. * @date 2006-10-12
  5. * @brief Class for handling granted rights.
  6. *
  7. * $LicenseInfo:firstyear=2006&license=viewergpl$
  8. *
  9. * Copyright (c) 2006-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. #ifndef LL_LLUSERRELAIONS_H
  35. #define LL_LLUSERRELAIONS_H
  36. #include "stdtypes.h"
  37. #include "llpreprocessor.h"
  38. // This class represents a relationship between two agents, where the related
  39. // agent is stored and the other agent is the relationship is implicit by
  40. // container ownership. This is merely a cache of this information used by the
  41. // sim and viewer.
  42. class LLRelationship
  43. {
  44. public:
  45. LL_INLINE LLRelationship()
  46. : mGrantToAgent(0),
  47. mGrantFromAgent(0),
  48. mChangeSerialNum(0),
  49. mIsOnline(false)
  50. {
  51. }
  52. LL_INLINE LLRelationship(S32 grant_to, S32 grant_from, bool is_online)
  53. : mGrantToAgent(grant_to),
  54. mGrantFromAgent(grant_from),
  55. mChangeSerialNum(0),
  56. mIsOnline(is_online)
  57. {
  58. }
  59. // Does this instance believe the related agent is currently online or
  60. // available.
  61. // This call does not check any kind of central store or make any deep
  62. // information calls - it simply checks a cache of online status.
  63. LL_INLINE bool isOnline() const { return mIsOnline; }
  64. // Sets the online status.
  65. LL_INLINE void online(bool is_online)
  66. {
  67. mIsOnline = is_online;
  68. ++mChangeSerialNum;
  69. }
  70. // Granted rights. Anonymous enumeration for specifying rights.
  71. enum
  72. {
  73. GRANT_NONE = 0x0,
  74. GRANT_ONLINE_STATUS = 0x1,
  75. GRANT_MAP_LOCATION = 0x2,
  76. GRANT_MODIFY_OBJECTS = 0x4,
  77. };
  78. // Checks for a set of rights granted to agent. 'rights' is a bitfield to
  79. // check for rights. Returns true if all rights have been granted.
  80. LL_INLINE bool isRightGrantedTo(S32 rights) const
  81. {
  82. return (mGrantToAgent & rights) == rights;
  83. }
  84. // Checks for a set of rights granted from an agent. 'rights' is a bitfield
  85. // to check for rights. Returns true if all rights have been granted.
  86. LL_INLINE bool isRightGrantedFrom(S32 rights) const
  87. {
  88. return (mGrantFromAgent & rights) == rights;
  89. }
  90. // Gets the rights granted to the other agent. Returns the bitmask of
  91. // granted rights.
  92. LL_INLINE S32 getRightsGrantedTo() const { return mGrantToAgent; }
  93. // Gets the rights granted from the other agent. Returns the bitmask of
  94. // granted rights.
  95. LL_INLINE S32 getRightsGrantedFrom() const { return mGrantFromAgent; }
  96. LL_INLINE void setRightsTo(S32 to_agent)
  97. {
  98. mGrantToAgent = to_agent;
  99. ++mChangeSerialNum;
  100. }
  101. LL_INLINE void setRightsFrom(S32 from_agent)
  102. {
  103. mGrantFromAgent = from_agent;
  104. ++mChangeSerialNum;
  105. }
  106. // Gets the change count for this agent. Every change to rights will
  107. // increment the serial number allowing listeners to determine when a
  108. // relationship value is actually new. Returns change serial number for
  109. // relationship
  110. LL_INLINE S32 getChangeSerialNum() const { return mChangeSerialNum; }
  111. // Grants a set of rights. Any bit which is set will grant that right if it
  112. // is set in the instance. You can pass in LLGrantedRights::NONE to not
  113. // change that field. 'to_agent' are the rights to grant to agent_id and
  114. // 'from_agent' the rights granted from agent_id.
  115. LL_INLINE void grantRights(S32 to_agent, S32 from_agent)
  116. {
  117. mGrantToAgent |= to_agent;
  118. mGrantFromAgent |= from_agent;
  119. ++mChangeSerialNum;
  120. }
  121. // Revokes a set of rights. Any bit which is set will revoke that right if
  122. // it is set in the instance. You can pass in LLGrantedRights::NONE to not
  123. // change that field.'to_agent' are the rights to grant to agent_id and
  124. // 'from_agent' the rights granted from agent_id.
  125. LL_INLINE void revokeRights(S32 to_agent, S32 from_agent)
  126. {
  127. mGrantToAgent &= ~to_agent;
  128. mGrantFromAgent &= ~from_agent;
  129. ++mChangeSerialNum;
  130. }
  131. private:
  132. S32 mGrantToAgent;
  133. S32 mGrantFromAgent;
  134. S32 mChangeSerialNum;
  135. bool mIsOnline;
  136. };
  137. #endif // LL_LLUSERRELAIONS_H