1
0

IScriptInstance.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright (c) Contributors, 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 OpenSimulator 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;
  29. using System.Collections.Generic;
  30. using System.Threading;
  31. using OpenMetaverse;
  32. using log4net;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Region.ScriptEngine.Shared;
  36. using OpenSim.Region.ScriptEngine.Interfaces;
  37. namespace OpenSim.Region.ScriptEngine.Interfaces
  38. {
  39. public enum StateSource
  40. {
  41. RegionStart = 0,
  42. NewRez = 1,
  43. PrimCrossing = 2,
  44. ScriptedRez = 3,
  45. AttachedRez = 4,
  46. Teleporting = 5
  47. }
  48. public interface IScriptWorkItem
  49. {
  50. bool Cancel();
  51. bool Abort();
  52. /// <summary>
  53. /// Wait for the work item to complete.
  54. /// </summary>
  55. /// <param name='t'>The number of milliseconds to wait. Must be >= -1 (Timeout.Infinite).</param>
  56. bool Wait(int t);
  57. }
  58. /// <summary>
  59. /// Interface for interaction with a particular script instance
  60. /// </summary>
  61. public interface IScriptInstance
  62. {
  63. /// <summary>
  64. /// Debug level for this script instance.
  65. /// </summary>
  66. /// <remarks>
  67. /// Level == 0, no extra data is logged.
  68. /// Level >= 1, state changes are logged.
  69. /// Level >= 2, event firing is logged.
  70. /// <value>
  71. /// The debug level.
  72. /// </value>
  73. int DebugLevel { get; set; }
  74. /// <summary>
  75. /// Is the script currently running?
  76. /// </summary>
  77. bool Running { get; set; }
  78. /// <summary>
  79. /// Is the script suspended?
  80. /// </summary>
  81. bool Suspended { get; set; }
  82. /// <summary>
  83. /// Is the script shutting down?
  84. /// </summary>
  85. bool ShuttingDown { get; set; }
  86. /// <summary>
  87. /// Script state
  88. /// </summary>
  89. string State { get; set; }
  90. /// <summary>
  91. /// Time the script was last started
  92. /// </summary>
  93. DateTime TimeStarted { get; }
  94. /// <summary>
  95. /// Tick the last measurement period was started.
  96. /// </summary>
  97. long MeasurementPeriodTickStart { get; }
  98. /// <summary>
  99. /// Ticks spent executing in the last measurement period.
  100. /// </summary>
  101. long MeasurementPeriodExecutionTime { get; }
  102. /// <summary>
  103. /// Scene part in which this script instance is contained.
  104. /// </summary>
  105. SceneObjectPart Part { get; }
  106. IScriptEngine Engine { get; }
  107. UUID AppDomain { get; set; }
  108. string PrimName { get; }
  109. string ScriptName { get; }
  110. UUID ItemID { get; }
  111. UUID ObjectID { get; }
  112. /// <summary>
  113. /// UUID of the root object for the linkset that the script is in.
  114. /// </summary>
  115. UUID RootObjectID { get; }
  116. /// <summary>
  117. /// Local id of the root object for the linkset that the script is in.
  118. /// </summary>
  119. uint RootLocalID { get; }
  120. uint LocalID { get; }
  121. UUID AssetID { get; }
  122. /// <summary>
  123. /// Inventory item containing the script used.
  124. /// </summary>
  125. TaskInventoryItem ScriptTask { get; }
  126. Queue EventQueue { get; }
  127. /// <summary>
  128. /// Number of events queued for processing.
  129. /// </summary>
  130. long EventsQueued { get; }
  131. /// <summary>
  132. /// Number of events processed by this script instance.
  133. /// </summary>
  134. long EventsProcessed { get; }
  135. void ClearQueue();
  136. int StartParam { get; set; }
  137. void RemoveState();
  138. void Init();
  139. void Start();
  140. /// <summary>
  141. /// Stop the script instance.
  142. /// </summary>
  143. /// <remarks>
  144. /// This must not be called by a thread that is in the process of handling an event for this script. Otherwise
  145. /// there is a danger that it will self-abort and not complete the reset.
  146. /// </remarks>
  147. /// <param name="timeout"></param>
  148. /// How many milliseconds we will wait for an existing script event to finish before
  149. /// forcibly aborting that event.
  150. /// <returns>true if the script was successfully stopped, false otherwise</returns>
  151. bool Stop(int timeout);
  152. void SetState(string state);
  153. /// <summary>
  154. /// Post an event to this script instance.
  155. /// </summary>
  156. /// <param name="data"></param>
  157. void PostEvent(EventParams data);
  158. void Suspend();
  159. void Resume();
  160. /// <summary>
  161. /// Process the next event queued for this script instance.
  162. /// </summary>
  163. /// <returns></returns>
  164. object EventProcessor();
  165. int EventTime();
  166. /// <summary>
  167. /// Reset the script.
  168. /// </summary>
  169. /// <remarks>
  170. /// This must not be called by a thread that is in the process of handling an event for this script. Otherwise
  171. /// there is a danger that it will self-abort and not complete the reset. Such a thread must call
  172. /// ApiResetScript() instead.
  173. /// </remarks>
  174. /// <param name='timeout'>
  175. /// How many milliseconds we will wait for an existing script event to finish before
  176. /// forcibly aborting that event prior to script reset.
  177. /// </param>
  178. void ResetScript(int timeout);
  179. /// <summary>
  180. /// Reset the script.
  181. /// </summary>
  182. /// <remarks>
  183. /// This must not be called by any thread other than the one executing the scripts current event. This is
  184. /// because there is no wait or abort logic if another thread is in the middle of processing a script event.
  185. /// Such an external thread should use ResetScript() instead.
  186. /// </remarks>
  187. void ApiResetScript();
  188. Dictionary<string, object> GetVars();
  189. void SetVars(Dictionary<string, object> vars);
  190. DetectParams GetDetectParams(int idx);
  191. UUID GetDetectID(int idx);
  192. void SaveState(string assembly);
  193. void DestroyScriptInstance();
  194. IScriptApi GetApi(string name);
  195. Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap
  196. { get; set; }
  197. string GetAssemblyName();
  198. string GetXMLState();
  199. double MinEventDelay { set; }
  200. UUID RegionID { get; }
  201. }
  202. }