/Aurora/AuroraDotNetEngine/ScriptPlugins/XmlRequest.cs

https://bitbucket.org/VirtualReality/software-testing · C# · 156 lines · 105 code · 23 blank · 28 comment · 11 complexity · 5135875591536a8e721dccb0a6f9d509 MD5 · raw file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.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;
  28. using System.Collections.Generic;
  29. using Aurora.Framework;
  30. using Aurora.Framework.Modules;
  31. using Aurora.Framework.SceneInfo;
  32. using OpenMetaverse;
  33. using OpenMetaverse.StructuredData;
  34. namespace Aurora.ScriptEngine.AuroraDotNetEngine.Plugins
  35. {
  36. public class XmlRequestPlugin : IScriptPlugin
  37. {
  38. private readonly List<IXMLRPC> m_modules = new List<IXMLRPC>();
  39. public ScriptEngine m_ScriptEngine;
  40. #region IScriptPlugin Members
  41. public bool RemoveOnStateChange
  42. {
  43. get { return false; }
  44. }
  45. public void Initialize(ScriptEngine ScriptEngine)
  46. {
  47. m_ScriptEngine = ScriptEngine;
  48. }
  49. public void AddRegion(IScene scene)
  50. {
  51. m_modules.Add(scene.RequestModuleInterface<IXMLRPC>());
  52. }
  53. public bool Check()
  54. {
  55. bool needToContinue = false;
  56. foreach (IXMLRPC xmlrpc in m_modules)
  57. {
  58. if (xmlrpc == null)
  59. continue;
  60. IXmlRpcRequestInfo rInfo = xmlrpc.GetNextCompletedRequest();
  61. ISendRemoteDataRequest srdInfo = (ISendRemoteDataRequest) xmlrpc.GetNextCompletedSRDRequest();
  62. if (!needToContinue)
  63. needToContinue = xmlrpc.hasRequests();
  64. if (rInfo == null && srdInfo == null)
  65. continue;
  66. while (rInfo != null)
  67. {
  68. xmlrpc.RemoveCompletedRequest(rInfo.GetMessageID());
  69. //Deliver data to prim's remote_data handler
  70. object[] resobj = new object[]
  71. {
  72. new LSL_Types.LSLInteger(2),
  73. new LSL_Types.LSLString(
  74. rInfo.GetChannelKey().ToString()),
  75. new LSL_Types.LSLString(
  76. rInfo.GetMessageID().ToString()),
  77. new LSL_Types.LSLString(String.Empty),
  78. new LSL_Types.LSLInteger(rInfo.GetIntValue()),
  79. new LSL_Types.LSLString(rInfo.GetStrVal())
  80. };
  81. m_ScriptEngine.PostScriptEvent(
  82. rInfo.GetItemID(), rInfo.GetPrimID(), new EventParams(
  83. "remote_data", resobj,
  84. new DetectParams[0]), EventPriority.Suspended);
  85. rInfo = xmlrpc.GetNextCompletedRequest();
  86. }
  87. while (srdInfo != null)
  88. {
  89. xmlrpc.RemoveCompletedSRDRequest(srdInfo.GetReqID());
  90. //Deliver data to prim's remote_data handler
  91. object[] resobj = new object[]
  92. {
  93. new LSL_Types.LSLInteger(3),
  94. new LSL_Types.LSLString(srdInfo.Channel),
  95. new LSL_Types.LSLString(srdInfo.GetReqID().ToString()),
  96. new LSL_Types.LSLString(String.Empty),
  97. new LSL_Types.LSLInteger(srdInfo.Idata),
  98. new LSL_Types.LSLString(srdInfo.Sdata)
  99. };
  100. m_ScriptEngine.PostScriptEvent(
  101. srdInfo.ItemID, srdInfo.PrimID, new EventParams(
  102. "remote_data", resobj,
  103. new DetectParams[0]), EventPriority.Suspended);
  104. srdInfo = (ISendRemoteDataRequest) xmlrpc.GetNextCompletedSRDRequest();
  105. }
  106. }
  107. return needToContinue;
  108. }
  109. public string Name
  110. {
  111. get { return "XmlRequest"; }
  112. }
  113. public OSD GetSerializationData(UUID itemID, UUID primID)
  114. {
  115. return "";
  116. }
  117. public void CreateFromData(UUID itemID, UUID objectID, OSD data)
  118. {
  119. }
  120. public void RemoveScript(UUID primID, UUID itemID)
  121. {
  122. foreach (IXMLRPC xmlrpc in m_modules)
  123. {
  124. xmlrpc.DeleteChannels(itemID);
  125. xmlrpc.CancelSRDRequests(itemID);
  126. }
  127. }
  128. #endregion
  129. public void Dispose()
  130. {
  131. }
  132. }
  133. }