ExecutorBase.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 OpenSim 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 System.Runtime.Remoting.Lifetime;
  30. using OpenSim.Region.ScriptEngine.Shared;
  31. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  32. using OpenSim.Region.ScriptEngine.Interfaces;
  33. namespace OpenSim.Region.ScriptEngine.XEngine
  34. {
  35. public abstract class ExecutorBase : MarshalByRefObject
  36. {
  37. /// <summary>
  38. /// Contains the script to execute functions in.
  39. /// </summary>
  40. protected IScript m_Script;
  41. protected Dictionary<string, scriptEvents> m_eventFlagsMap = new Dictionary<string, scriptEvents>();
  42. [Flags]
  43. public enum scriptEvents : int
  44. {
  45. None = 0,
  46. attach = 1,
  47. collision = 15,
  48. collision_end = 32,
  49. collision_start = 64,
  50. control = 128,
  51. dataserver = 256,
  52. email = 512,
  53. http_response = 1024,
  54. land_collision = 2048,
  55. land_collision_end = 4096,
  56. land_collision_start = 8192,
  57. at_target = 16384,
  58. listen = 32768,
  59. money = 65536,
  60. moving_end = 131072,
  61. moving_start = 262144,
  62. not_at_rot_target = 524288,
  63. not_at_target = 1048576,
  64. remote_data = 8388608,
  65. run_time_permissions = 268435456,
  66. state_entry = 1073741824,
  67. state_exit = 2,
  68. timer = 4,
  69. touch = 8,
  70. touch_end = 536870912,
  71. touch_start = 2097152,
  72. object_rez = 4194304
  73. }
  74. /// <summary>
  75. /// Create a new instance of ExecutorBase
  76. /// </summary>
  77. /// <param name="Script"></param>
  78. public ExecutorBase(IScript Script)
  79. {
  80. m_Script = Script;
  81. initEventFlags();
  82. }
  83. /// <summary>
  84. /// Make sure our object does not timeout when in AppDomain. (Called by ILease base class)
  85. /// </summary>
  86. /// <returns></returns>
  87. public override Object InitializeLifetimeService()
  88. {
  89. //Console.WriteLine("Executor: InitializeLifetimeService()");
  90. // return null;
  91. ILease lease = (ILease)base.InitializeLifetimeService();
  92. if (lease.CurrentState == LeaseState.Initial)
  93. {
  94. lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1);
  95. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
  96. // lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
  97. }
  98. return lease;
  99. }
  100. /// <summary>
  101. /// Get current AppDomain
  102. /// </summary>
  103. /// <returns>Current AppDomain</returns>
  104. public AppDomain GetAppDomain()
  105. {
  106. return AppDomain.CurrentDomain;
  107. }
  108. /// <summary>
  109. /// Execute a specific function/event in script.
  110. /// </summary>
  111. /// <param name="FunctionName">Name of function to execute</param>
  112. /// <param name="args">Arguments to pass to function</param>
  113. public void ExecuteEvent(string state, string FunctionName, object[] args)
  114. {
  115. DoExecuteEvent(state, FunctionName, args);
  116. }
  117. protected abstract void DoExecuteEvent(string state, string FunctionName, object[] args);
  118. /// <summary>
  119. /// Compute the events handled by the current state of the script
  120. /// </summary>
  121. /// <returns>state mask</returns>
  122. public scriptEvents GetStateEventFlags(string state)
  123. {
  124. return DoGetStateEventFlags(state);
  125. }
  126. protected abstract scriptEvents DoGetStateEventFlags(string state);
  127. protected void initEventFlags()
  128. {
  129. // Initialize the table if it hasn't already been done
  130. if (m_eventFlagsMap.Count > 0)
  131. {
  132. return;
  133. }
  134. m_eventFlagsMap.Add("attach", scriptEvents.attach);
  135. // m_eventFlagsMap.Add("at_rot_target",(long)scriptEvents.at_rot_target);
  136. m_eventFlagsMap.Add("at_target", scriptEvents.at_target);
  137. // m_eventFlagsMap.Add("changed",(long)scriptEvents.changed);
  138. m_eventFlagsMap.Add("collision", scriptEvents.collision);
  139. m_eventFlagsMap.Add("collision_end", scriptEvents.collision_end);
  140. m_eventFlagsMap.Add("collision_start", scriptEvents.collision_start);
  141. m_eventFlagsMap.Add("control", scriptEvents.control);
  142. m_eventFlagsMap.Add("dataserver", scriptEvents.dataserver);
  143. m_eventFlagsMap.Add("email", scriptEvents.email);
  144. m_eventFlagsMap.Add("http_response", scriptEvents.http_response);
  145. m_eventFlagsMap.Add("land_collision", scriptEvents.land_collision);
  146. m_eventFlagsMap.Add("land_collision_end", scriptEvents.land_collision_end);
  147. m_eventFlagsMap.Add("land_collision_start", scriptEvents.land_collision_start);
  148. // m_eventFlagsMap.Add("link_message",scriptEvents.link_message);
  149. m_eventFlagsMap.Add("listen", scriptEvents.listen);
  150. m_eventFlagsMap.Add("money", scriptEvents.money);
  151. m_eventFlagsMap.Add("moving_end", scriptEvents.moving_end);
  152. m_eventFlagsMap.Add("moving_start", scriptEvents.moving_start);
  153. m_eventFlagsMap.Add("not_at_rot_target", scriptEvents.not_at_rot_target);
  154. m_eventFlagsMap.Add("not_at_target", scriptEvents.not_at_target);
  155. // m_eventFlagsMap.Add("no_sensor",(long)scriptEvents.no_sensor);
  156. // m_eventFlagsMap.Add("on_rez",(long)scriptEvents.on_rez);
  157. m_eventFlagsMap.Add("remote_data", scriptEvents.remote_data);
  158. m_eventFlagsMap.Add("run_time_permissions", scriptEvents.run_time_permissions);
  159. // m_eventFlagsMap.Add("sensor",(long)scriptEvents.sensor);
  160. m_eventFlagsMap.Add("state_entry", scriptEvents.state_entry);
  161. m_eventFlagsMap.Add("state_exit", scriptEvents.state_exit);
  162. m_eventFlagsMap.Add("timer", scriptEvents.timer);
  163. m_eventFlagsMap.Add("touch", scriptEvents.touch);
  164. m_eventFlagsMap.Add("touch_end", scriptEvents.touch_end);
  165. m_eventFlagsMap.Add("touch_start", scriptEvents.touch_start);
  166. m_eventFlagsMap.Add("object_rez", scriptEvents.object_rez);
  167. }
  168. }
  169. }