IScriptInstance.cs 7.3 KB

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