IScriptInstance.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. /// If true then the engine is responsible for persisted state. If false then some other component may
  92. /// persist state (e.g. attachments persisting in assets).
  93. /// </summary>
  94. bool StatePersistedHere { get; }
  95. /// <summary>
  96. /// Time the script was last started
  97. /// </summary>
  98. DateTime TimeStarted { get; }
  99. /// <summary>
  100. /// Tick the last measurement period was started.
  101. /// </summary>
  102. long MeasurementPeriodTickStart { get; }
  103. /// <summary>
  104. /// Ticks spent executing in the last measurement period.
  105. /// </summary>
  106. long MeasurementPeriodExecutionTime { get; }
  107. /// <summary>
  108. /// Scene part in which this script instance is contained.
  109. /// </summary>
  110. SceneObjectPart Part { get; }
  111. IScriptEngine Engine { get; }
  112. UUID AppDomain { get; set; }
  113. string PrimName { get; }
  114. string ScriptName { get; }
  115. UUID ItemID { get; }
  116. UUID ObjectID { get; }
  117. /// <summary>
  118. /// UUID of the root object for the linkset that the script is in.
  119. /// </summary>
  120. UUID RootObjectID { get; }
  121. /// <summary>
  122. /// Local id of the root object for the linkset that the script is in.
  123. /// </summary>
  124. uint RootLocalID { get; }
  125. uint LocalID { get; }
  126. UUID AssetID { get; }
  127. /// <summary>
  128. /// Inventory item containing the script used.
  129. /// </summary>
  130. TaskInventoryItem ScriptTask { get; }
  131. Queue EventQueue { get; }
  132. /// <summary>
  133. /// Number of events queued for processing.
  134. /// </summary>
  135. long EventsQueued { get; }
  136. /// <summary>
  137. /// Number of events processed by this script instance.
  138. /// </summary>
  139. long EventsProcessed { get; }
  140. void ClearQueue();
  141. int StartParam { get; set; }
  142. void RemoveState();
  143. void Init();
  144. void Start();
  145. /// <summary>
  146. /// Stop the script instance.
  147. /// </summary>
  148. /// <remarks>
  149. /// This must not be called by a thread that is in the process of handling an event for this script. Otherwise
  150. /// there is a danger that it will self-abort and not complete the reset.
  151. /// </remarks>
  152. /// <param name="timeout"></param>
  153. /// How many milliseconds we will wait for an existing script event to finish before
  154. /// forcibly aborting that event.
  155. /// <param name="clearEventQueue">If true then the event queue is also cleared</param>
  156. /// <returns>true if the script was successfully stopped, false otherwise</returns>
  157. bool Stop(int timeout, bool clearEventQueue = false);
  158. void SetState(string state);
  159. /// <summary>
  160. /// Post an event to this script instance.
  161. /// </summary>
  162. /// <param name="data"></param>
  163. void PostEvent(EventParams data);
  164. void Suspend();
  165. void Resume();
  166. /// <summary>
  167. /// Process the next event queued for this script instance.
  168. /// </summary>
  169. /// <returns></returns>
  170. object EventProcessor();
  171. int EventTime();
  172. /// <summary>
  173. /// Reset the script.
  174. /// </summary>
  175. /// <remarks>
  176. /// This must not be called by a thread that is in the process of handling an event for this script. Otherwise
  177. /// there is a danger that it will self-abort and not complete the reset. Such a thread must call
  178. /// ApiResetScript() instead.
  179. /// </remarks>
  180. /// <param name='timeout'>
  181. /// How many milliseconds we will wait for an existing script event to finish before
  182. /// forcibly aborting that event prior to script reset.
  183. /// </param>
  184. void ResetScript(int timeout);
  185. /// <summary>
  186. /// Reset the script.
  187. /// </summary>
  188. /// <remarks>
  189. /// This must not be called by any thread other than the one executing the scripts current event. This is
  190. /// because there is no wait or abort logic if another thread is in the middle of processing a script event.
  191. /// Such an external thread should use ResetScript() instead.
  192. /// </remarks>
  193. void ApiResetScript();
  194. Dictionary<string, object> GetVars();
  195. void SetVars(Dictionary<string, object> vars);
  196. DetectParams GetDetectParams(int idx);
  197. UUID GetDetectID(int idx);
  198. void SaveState();
  199. void DestroyScriptInstance();
  200. IScriptApi GetApi(string name);
  201. Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap
  202. { get; set; }
  203. string GetAssemblyName();
  204. string GetXMLState();
  205. double MinEventDelay { set; }
  206. UUID RegionID { get; }
  207. }
  208. }