aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
diff options
context:
space:
mode:
authorTedd Hansen2008-11-08 17:35:48 +0000
committerTedd Hansen2008-11-08 17:35:48 +0000
commit9511a8c76370f21e839114007dcd2b25c69b009a (patch)
treeb63323dfd96ecd1cc3cd560939bd66bb43ec9c1c /OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
parent* Added IClientIM to IClientCore interfaces (diff)
downloadopensim-SC_OLD-9511a8c76370f21e839114007dcd2b25c69b009a.zip
opensim-SC_OLD-9511a8c76370f21e839114007dcd2b25c69b009a.tar.gz
opensim-SC_OLD-9511a8c76370f21e839114007dcd2b25c69b009a.tar.bz2
opensim-SC_OLD-9511a8c76370f21e839114007dcd2b25c69b009a.tar.xz
Work in progress on SECS stuff. Have been holding it off until after 0.6 release. Still messy as hell and doesn't really work yet. Will undergo dramatic changes. AND MOST IMPORTANTLY: Will be conformed to work in coop with todays DNE and XEngine, hopefully one day providing a common interface for all components.
Diffstat (limited to 'OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs')
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs134
1 files changed, 123 insertions, 11 deletions
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs b/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
index 32c7748..f81b848 100644
--- a/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
+++ b/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
@@ -26,29 +26,143 @@
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.IO;
29using System.Reflection; 30using System.Reflection;
30using System.Text; 31using System.Text;
32using System.Threading;
33using OpenSim.ScriptEngine.Shared;
31using log4net; 34using log4net;
32 35
33namespace OpenSim.ApplicationPlugins.ScriptEngine 36namespace OpenSim.ApplicationPlugins.ScriptEngine
34{ 37{
38 /// <summary>
39 /// Loads all Script Engine Components
40 /// </summary>
35 public class ScriptEnginePlugin : IApplicationPlugin 41 public class ScriptEnginePlugin : IApplicationPlugin
36 { 42 {
37 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
38 internal OpenSimBase m_OpenSim; 44 internal OpenSimBase m_OpenSim;
39 private ComponentLoader pluginLoader; 45
46 // Component providers are registered here wit a name (string)
47 // When a script engine is created the components are instanciated
48 public static Dictionary<string, Type> providers = new Dictionary<string, Type>();
49 public static Dictionary<string, Type> scriptEngines = new Dictionary<string, Type>();
50
51
52 public ScriptEnginePlugin()
53 {
54 // Application startup
55#if DEBUG
56 m_log.InfoFormat("[{0}] ##################################", Name);
57 m_log.InfoFormat("[{0}] # Script Engine Component System #", Name);
58 m_log.InfoFormat("[{0}] ##################################", Name);
59#else
60 m_log.InfoFormat("[{0}] Script Engine Component System", Name);
61#endif
62
63 // Load all modules from current directory
64 // We only want files named OpenSim.ScriptEngine.*.dll
65 Load(".", "OpenSim.ScriptEngine.*.dll");
66 }
40 67
41 public void Initialise(OpenSimBase openSim) 68 public void Initialise(OpenSimBase openSim)
42 { 69 {
70
43 // Our objective: Load component .dll's 71 // Our objective: Load component .dll's
44 m_OpenSim = openSim; 72 m_OpenSim = openSim;
45 pluginLoader = new ComponentLoader(this); 73 //m_OpenSim.Shutdown();
74 }
75
76 private readonly static string nameIScriptEngineComponent = typeof(IScriptEngineComponent).Name; // keep interface name in managed code
77 private readonly static string nameIScriptEngine = typeof(IScriptEngine).Name; // keep interface name in managed code
78 /// <summary>
79 /// Load components from directory
80 /// </summary>
81 /// <param name="directory"></param>
82 public void Load(string directory, string filter)
83 {
84 // We may want to change how this functions as currently it required unique class names for each component
85
86 foreach (string file in Directory.GetFiles(directory, filter))
87 {
88 //m_log.DebugFormat("[ScriptEngine]: Loading: [{0}].", file);
89 Assembly componentAssembly = null;
90 try
91 {
92 componentAssembly = Assembly.LoadFrom(file);
93 } catch (Exception e)
94 {
95 m_log.ErrorFormat("[{0}] Error loading: \"{1}\".", Name, file);
96 }
97 if (componentAssembly != null)
98 {
99 try
100 {
101 // Go through all types in the assembly
102 foreach (Type componentType in componentAssembly.GetTypes())
103 {
104 if (componentType.IsPublic
105 && !componentType.IsAbstract)
106 {
107 //if (componentType.IsSubclassOf(typeof(ComponentBase)))
108 if (componentType.GetInterface(nameIScriptEngineComponent) != null)
109 {
110 // We have found an type which is derived from ProdiverBase, add it to provider list
111 m_log.InfoFormat("[{0}] Adding component: {1}", Name, componentType.Name);
112 lock (providers)
113 {
114 providers.Add(componentType.Name, componentType);
115 }
116 }
117 //if (componentType.IsSubclassOf(typeof(ScriptEngineBase)))
118 if (componentType.GetInterface(nameIScriptEngine) != null)
119 {
120 // We have found an type which is derived from RegionScriptEngineBase, add it to engine list
121 m_log.InfoFormat("[{0}] Adding script engine: {1}", Name, componentType.Name);
122 lock (scriptEngines)
123 {
124 scriptEngines.Add(componentType.Name, componentType);
125 }
126 }
127 }
128 }
129 }
130 catch
131 (ReflectionTypeLoadException re)
132 {
133 m_log.ErrorFormat("[{0}] Could not load component \"{1}\": {2}", Name, componentAssembly.FullName, re.ToString());
134 int c = 0;
135 foreach (Exception e in re.LoaderExceptions)
136 {
137 c++;
138 m_log.ErrorFormat("[{0}] LoaderException {1}: {2}", Name, c, e.ToString());
139 }
140 }
141 } //if
142 } //foreach
143 }
144
145 public static IScriptEngineComponent GetComponentInstance(string name, params Object[] args)
146 {
147 if (!providers.ContainsKey(name))
148 throw new Exception("ScriptEngine requested component named \"" + name +
149 "\" that does not exist.");
46 150
47 m_log.Info("[" + Name + "]: Script Engine Component System"); 151 return Activator.CreateInstance(providers[name], args) as IScriptEngineComponent;
48 m_log.Info("[" + Name + "]: Loading Script Engine Components");
49 pluginLoader.Load("ScriptEngines");
50
51 } 152 }
153
154 private readonly static string nameIScriptEngineRegionComponent = typeof(IScriptEngineRegionComponent).Name; // keep interface name in managed code
155 public static IScriptEngineComponent GetComponentInstance(RegionInfoStructure info, string name, params Object[] args)
156 {
157 IScriptEngineComponent c = GetComponentInstance(name, args);
158
159 // If module is IScriptEngineRegionComponent then it will have one instance per region and we will initialize it
160 if (c.GetType().GetInterface(nameIScriptEngineRegionComponent) != null)
161 ((IScriptEngineRegionComponent)c).Initialize(info);
162
163 return c;
164 }
165
52 #region IApplicationPlugin stuff 166 #region IApplicationPlugin stuff
53 /// <summary> 167 /// <summary>
54 /// Returns the plugin version 168 /// Returns the plugin version
@@ -65,16 +179,13 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine
65 /// <returns>Plugin name, eg MySQL User Provider</returns> 179 /// <returns>Plugin name, eg MySQL User Provider</returns>
66 public string Name 180 public string Name
67 { 181 {
68 get { return "ScriptEngine"; } 182 get { return "SECS"; }
69 } 183 }
70 184
71 /// <summary> 185 /// <summary>
72 /// Default-initialises the plugin 186 /// Default-initialises the plugin
73 /// </summary> 187 /// </summary>
74 public void Initialise() 188 public void Initialise() { }
75 {
76 //throw new NotImplementedException();
77 }
78 189
79 ///<summary> 190 ///<summary>
80 ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. 191 ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
@@ -85,5 +196,6 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine
85 //throw new NotImplementedException(); 196 //throw new NotImplementedException();
86 } 197 }
87 #endregion 198 #endregion
199
88 } 200 }
89} 201}