DotNetEngine.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.Reflection;
  30. using System.Text;
  31. using System.Text.RegularExpressions;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.ApplicationPlugins.ScriptEngine;
  36. using OpenSim.Region.Environment.Interfaces;
  37. using OpenSim.Region.Environment.Scenes;
  38. using OpenSim.ScriptEngine.Components.DotNetEngine.Events;
  39. using OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler;
  40. using OpenSim.ScriptEngine.Shared;
  41. using ComponentFactory = OpenSim.ApplicationPlugins.ScriptEngine.ComponentFactory;
  42. namespace OpenSim.ScriptEngine.Engines.DotNetEngine
  43. {
  44. // This is a sample engine
  45. public partial class DotNetEngine : IScriptEngine
  46. {
  47. //private string[] _ComponentNames = new string[] {
  48. // "Commands_LSL",
  49. // "Commands_OSSL",
  50. // "Compiler_CS",
  51. // "Compiler_JS",
  52. // "Compiler_LSL",
  53. // "Compiler_VB",
  54. // "LSLEventProvider",
  55. // "Scheduler"
  56. // };
  57. internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  58. public string Name { get { return "SECS.DotNetEngine"; } }
  59. //public bool IsSharedModule { get { return true; } }
  60. internal RegionInfoStructure RegionInfo;
  61. private string[] commandNames = new string[]
  62. {
  63. "Commands_LSL"
  64. };
  65. private string[] compilerNames = new string[]
  66. {
  67. "Compiler_CS",
  68. "Compiler_JS",
  69. "Compiler_LSL",
  70. "Compiler_YP",
  71. "Compiler_VB"
  72. };
  73. private string[] schedulerNames = new string[]
  74. {
  75. "Scheduler"
  76. };
  77. //internal IScriptLoader m_ScriptLoader;
  78. internal LSLEventProvider m_LSLEventProvider;
  79. //internal IScriptExecutor m_Executor;
  80. //internal Dictionary<string, IScriptCompiler> Compilers = new Dictionary<string, IScriptCompiler>();
  81. internal Dictionary<string, IScriptScheduler> Schedulers = new Dictionary<string, IScriptScheduler>();
  82. public static Dictionary<string, IScriptCompiler> Compilers = new Dictionary<string, IScriptCompiler>();
  83. // private static bool haveInitialized = false;
  84. public DotNetEngine()
  85. {
  86. RegionInfo = new RegionInfoStructure();
  87. RegionInfo.Compilers = Compilers;
  88. RegionInfo.Schedulers = Schedulers;
  89. RegionInfo.Executors = new Dictionary<string, IScriptExecutor>();
  90. RegionInfo.CommandProviders = new Dictionary<string, IScriptCommandProvider>();
  91. RegionInfo.EventProviders = new Dictionary<string, IScriptEventProvider>();
  92. RegionInfo.Logger = LogManager.GetLogger("SECS.DotNetEngine.RegionInfo");
  93. }
  94. public void Initialise(Scene scene, IConfigSource source)
  95. {
  96. RegionInfo.Scene = scene;
  97. RegionInfo.ConfigSource = source;
  98. m_log.DebugFormat("[{0}] Initializing components", Name);
  99. InitializeComponents();
  100. }
  101. public void PostInitialise() { }
  102. /// <summary>
  103. /// Called on region close
  104. /// </summary>
  105. public void Close()
  106. {
  107. ComponentClose();
  108. }
  109. #region Initialize the Script Engine Components we need
  110. public void InitializeComponents()
  111. {
  112. string cname = "";
  113. m_log.DebugFormat("[{0}] Component initialization", Name);
  114. // Initialize an instance of all module we want
  115. try
  116. {
  117. cname = "ScriptManager";
  118. m_log.DebugFormat("[{0}] Executor: {1}", Name, cname);
  119. RegionInfo.Executors.Add(cname,
  120. ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptExecutor);
  121. cname = "ScriptLoader";
  122. m_log.DebugFormat("[{0}] ScriptLoader: {1}", Name, cname);
  123. RegionInfo.ScriptLoader =
  124. ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptExecutor as ScriptLoader;
  125. // CommandProviders
  126. foreach (string cn in commandNames)
  127. {
  128. cname = cn;
  129. m_log.DebugFormat("[{0}] CommandProvider: {1}", Name, cname);
  130. RegionInfo.CommandProviders.Add(cname,
  131. ComponentFactory.GetComponentInstance(RegionInfo, cname) as
  132. IScriptCommandProvider);
  133. }
  134. // Compilers
  135. foreach (string cn in compilerNames)
  136. {
  137. cname = cn;
  138. m_log.DebugFormat("[{0}] Compiler: {1}", Name, cname);
  139. RegionInfo.Compilers.Add(cname,
  140. ComponentFactory.GetComponentInstance(RegionInfo, cname) as
  141. IScriptCompiler);
  142. }
  143. // Schedulers
  144. foreach (string cn in schedulerNames)
  145. {
  146. cname = cn;
  147. m_log.DebugFormat("[{0}] Scheduler: {1}", Name, cname);
  148. RegionInfo.Schedulers.Add(cname,
  149. ComponentFactory.GetComponentInstance(RegionInfo, cname) as
  150. IScriptScheduler);
  151. }
  152. // Event provider
  153. cname = "LSLEventProvider";
  154. m_log.DebugFormat("[{0}] EventProvider: {1}", Name, cname);
  155. IScriptEventProvider sep = ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptEventProvider;
  156. RegionInfo.EventProviders.Add(cname, sep);
  157. m_LSLEventProvider = sep as LSLEventProvider;
  158. // Hook up events
  159. m_LSLEventProvider.RezScript += Events_RezScript;
  160. m_LSLEventProvider.RemoveScript += Events_RemoveScript;
  161. }
  162. catch (Exception e)
  163. {
  164. m_log.ErrorFormat("[{0}] Exception while loading \"{1}\": {2}", Name, cname, e.ToString());
  165. }
  166. }
  167. private void ComponentClose()
  168. {
  169. // Close schedulers
  170. foreach (IScriptScheduler scheduler in RegionInfo.Schedulers.Values)
  171. {
  172. scheduler.Close();
  173. }
  174. }
  175. #endregion
  176. }
  177. }