DotNetEngine.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.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.Framework.Interfaces;
  37. using OpenSim.Region.Framework.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. }
  93. public void Initialise(Scene scene, IConfigSource source)
  94. {
  95. RegionInfo.Scene = scene;
  96. RegionInfo.ConfigSource = source;
  97. m_log.DebugFormat("[{0}] Initializing components", Name);
  98. InitializeComponents();
  99. }
  100. public void PostInitialise() { }
  101. /// <summary>
  102. /// Called on region close
  103. /// </summary>
  104. public void Close()
  105. {
  106. ComponentClose();
  107. }
  108. #region Initialize the Script Engine Components we need
  109. public void InitializeComponents()
  110. {
  111. string cname = "";
  112. m_log.DebugFormat("[{0}] Component initialization", Name);
  113. // Initialize an instance of all module we want
  114. try
  115. {
  116. cname = "ScriptManager";
  117. m_log.DebugFormat("[{0}] Executor: {1}", Name, cname);
  118. RegionInfo.Executors.Add(cname,
  119. ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptExecutor);
  120. cname = "ScriptLoader";
  121. m_log.DebugFormat("[{0}] ScriptLoader: {1}", Name, cname);
  122. RegionInfo.ScriptLoader =
  123. ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptExecutor as ScriptLoader;
  124. // CommandProviders
  125. foreach (string cn in commandNames)
  126. {
  127. cname = cn;
  128. m_log.DebugFormat("[{0}] CommandProvider: {1}", Name, cname);
  129. RegionInfo.CommandProviders.Add(cname,
  130. ComponentFactory.GetComponentInstance(RegionInfo, cname) as
  131. IScriptCommandProvider);
  132. }
  133. // Compilers
  134. foreach (string cn in compilerNames)
  135. {
  136. cname = cn;
  137. m_log.DebugFormat("[{0}] Compiler: {1}", Name, cname);
  138. RegionInfo.Compilers.Add(cname,
  139. ComponentFactory.GetComponentInstance(RegionInfo, cname) as
  140. IScriptCompiler);
  141. }
  142. // Schedulers
  143. foreach (string cn in schedulerNames)
  144. {
  145. cname = cn;
  146. m_log.DebugFormat("[{0}] Scheduler: {1}", Name, cname);
  147. RegionInfo.Schedulers.Add(cname,
  148. ComponentFactory.GetComponentInstance(RegionInfo, cname) as
  149. IScriptScheduler);
  150. }
  151. // Event provider
  152. cname = "LSLEventProvider";
  153. m_log.DebugFormat("[{0}] EventProvider: {1}", Name, cname);
  154. IScriptEventProvider sep = ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptEventProvider;
  155. RegionInfo.EventProviders.Add(cname, sep);
  156. m_LSLEventProvider = sep as LSLEventProvider;
  157. // Hook up events
  158. m_LSLEventProvider.RezScript += Events_RezScript;
  159. m_LSLEventProvider.RemoveScript += Events_RemoveScript;
  160. }
  161. catch (Exception e)
  162. {
  163. m_log.ErrorFormat("[{0}] Exception while loading \"{1}\": {2}", Name, cname, e.ToString());
  164. }
  165. }
  166. private void ComponentClose()
  167. {
  168. // Close schedulers
  169. foreach (IScriptScheduler scheduler in RegionInfo.Schedulers.Values)
  170. {
  171. scheduler.Close();
  172. }
  173. }
  174. #endregion
  175. }
  176. }