PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Aurora/Framework/Services/ClassHelpers/Other/AuroraEventManager.cs

https://bitbucket.org/VirtualReality/software-testing
C# | 146 lines | 53 code | 6 blank | 87 comment | 6 complexity | 91cd301b0d38f21a2d05dc71e10bfa39 MD5 | raw file
  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.org/, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the Aurora-Sim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections.Generic;
  28. using System.Linq;
  29. namespace Aurora.Framework.Services.ClassHelpers.Other
  30. {
  31. /// <summary>
  32. /// Delegate to fire when a generic event comes in
  33. /// </summary>
  34. /// <param name="FunctionName">Name of the event being fired</param>
  35. /// <param name="parameters">Parameters that the event has, can be null</param>
  36. public delegate object OnGenericEventHandler(string FunctionName, object parameters);
  37. /// <summary>
  38. /// A generic event manager that fires one event for many generic events
  39. /// </summary>
  40. public class AuroraEventManager
  41. {
  42. private readonly Dictionary<string, List<OnGenericEventHandler>> m_events =
  43. new Dictionary<string, List<OnGenericEventHandler>>();
  44. /// <summary>
  45. /// Events so far:
  46. /// DrawDistanceChanged - Changed Draw Distance
  47. /// param is a ScenePresence
  48. /// BanUser - Added a new banned user to the estate bans
  49. /// param is a UUID of an agent
  50. /// UnBanUser - Removed a banned user from the estate bans
  51. /// param is a UUID of an agent
  52. /// SignficantCameraMovement - The Camera has moved a distance that has triggered this update
  53. /// param is a ScenePresence
  54. /// ObjectSelected - An object has been selected
  55. /// param is a SceneObjectPart
  56. /// ObjectDeselected - An object has been selected
  57. /// param is a SceneObjectPart
  58. /// ObjectChangedOwner - An object's owner was changed
  59. /// param is a SceneObjectGroup
  60. /// ObjectChangedPhysicalStatus - An object's physical status has changed
  61. /// param is a SceneObjectGroup
  62. /// ObjectEnteringNewParcel - An object has entered a new parcel
  63. /// param is an object[], with o[0] a SceneObjectGroup, o[1] the new parcel UUID, and o[2] the old parcel UUID
  64. /// UserStatusChange - User's status (logged in/out) has changed
  65. /// param is a object[], with o[0] the UUID of the user (as a string), o[1] whether they are logging in, o[2] the region they are entering (if logging in)
  66. /// PreRegisterRegion - A region is about to be registered
  67. /// param is a GridRegion
  68. /// NewUserConnection - A new user has been added to the scene (child or root)
  69. /// param is an object[], with o[0] OSDMap that will be returned to the server, and o[1] the AgentCircuitData that will be added to the region
  70. /// EstateUpdated - An estate has been updated
  71. /// param is the EstateSettings of the changed estate
  72. /// ObjectAddedFlag - An object in the Scene has added a prim flag
  73. /// param is an object[], with o[0] a ISceneChildEntity and o[1] the flag that was changed
  74. /// ObjectRemovedFlag - An object in the Scene has removed a prim flag
  75. /// param is an object[], with o[0] a ISceneChildEntity and o[1] the flag that was changed
  76. /// SetAppearance - An avatar has updated their appearance
  77. /// param is an object[], with o[0] the UUID of the avatar and o[1] the AvatarData that is to be updated
  78. /// GridRegionSuccessfullyRegistered - Aurora.Server, A region has registered with the grid service
  79. /// param is an object[], with o[0] the OSDMap which will be sent to the new region, o[1] the SessionID, o[2] the GridRegion that registered
  80. /// Backup - The 'backup' console command was triggered, everything should backup
  81. /// no params
  82. /// AssetRequested - This is fired when the asset is requested by the client
  83. /// params are IClientAPI and TransferRequestPacket
  84. /// DeleteUserInformation - The user is being deleted, remove all of their information from all databases
  85. /// params are the user's UUID
  86. /// CreateUserInformation - The user account is being created
  87. /// params are the user's UUID
  88. /// UpdateUserInformation - The user account is being updated
  89. /// params are the user's UUID
  90. /// </summary>
  91. public void RegisterEventHandler(string functionName, OnGenericEventHandler handler)
  92. {
  93. lock (m_events)
  94. {
  95. if (!m_events.ContainsKey(functionName))
  96. m_events.Add(functionName, new List<OnGenericEventHandler>());
  97. m_events[functionName].Add(handler);
  98. }
  99. }
  100. public void UnregisterEventHandler(string functionName, OnGenericEventHandler handler)
  101. {
  102. lock (m_events)
  103. {
  104. if (!m_events.ContainsKey(functionName))
  105. return;
  106. m_events[functionName].Remove(handler);
  107. }
  108. }
  109. /// <summary>
  110. /// Fire a generic event for all modules hooking onto it
  111. /// </summary>
  112. /// <param name="FunctionName">Name of event to trigger</param>
  113. /// <param name="Param">Any parameters to pass along with the event</param>
  114. public List<object> FireGenericEventHandler(string FunctionName, object Param)
  115. {
  116. List<object> retVal = new List<object>();
  117. lock (m_events)
  118. {
  119. //If not null, fire for all
  120. List<OnGenericEventHandler> events;
  121. if (m_events.TryGetValue(FunctionName, out events))
  122. {
  123. #if (!ISWIN)
  124. foreach (OnGenericEventHandler handler in new List<OnGenericEventHandler>(events))
  125. {
  126. object param = handler(FunctionName, Param);
  127. if (param != null)
  128. retVal.Add(param);
  129. }
  130. #else
  131. retVal.AddRange(
  132. new List<OnGenericEventHandler>(events).Select(handler => handler(FunctionName, Param))
  133. .Where(param => param != null));
  134. #endif
  135. }
  136. }
  137. return retVal;
  138. }
  139. }
  140. }