aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/ScriptEngine
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
parent* Added IClientIM to IClientCore interfaces (diff)
downloadopensim-SC-9511a8c76370f21e839114007dcd2b25c69b009a.zip
opensim-SC-9511a8c76370f21e839114007dcd2b25c69b009a.tar.gz
opensim-SC-9511a8c76370f21e839114007dcd2b25c69b009a.tar.bz2
opensim-SC-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')
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/ComponentLoader.cs101
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/ComponentRegistry.cs68
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/Components/CommandBase.cs45
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/Components/CompilerBase.cs45
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/Components/ComponentBase.cs53
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/Components/EventBase.cs45
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/Components/SchedulerBase.cs45
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/RegionEngineLoader.cs (renamed from OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEnginePlugin.cs)72
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs182
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEngine.addin.xml12
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEnginePlugin.addin.xml11
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs134
12 files changed, 181 insertions, 632 deletions
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/ComponentLoader.cs b/OpenSim/ApplicationPlugins/ScriptEngine/ComponentLoader.cs
deleted file mode 100644
index d2e3cd0..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/ComponentLoader.cs
+++ /dev/null
@@ -1,101 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.IO;
30using System.Reflection;
31using System.Text;
32using log4net;
33using OpenSim.ApplicationPlugins.ScriptEngine.Components;
34
35namespace OpenSim.ApplicationPlugins.ScriptEngine
36{
37 /// <summary>
38 /// Used to load ScriptEngine component .dll's
39 /// </summary>
40 internal class ComponentLoader
41 {
42 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 //private ScriptEnginePlugin scriptEnginePlugin;
44 public ComponentLoader(ScriptEnginePlugin sep)
45 {
46 //scriptEnginePlugin = sep;
47 }
48
49 /// <summary>
50 /// Load components from directory
51 /// </summary>
52 /// <param name="directory"></param>
53 public void Load(string directory)
54 {
55 // We may want to change how this functions as currently it required unique class names for each component
56
57 foreach (string file in Directory.GetFiles(directory, "*.dll"))
58 {
59 //m_log.DebugFormat("[ScriptEngine]: Loading: [{0}].", file);
60 Assembly componentAssembly = Assembly.LoadFrom(file);
61 if (componentAssembly != null)
62 {
63 try
64 {
65 // Go through all types in the assembly
66 foreach (Type componentType in componentAssembly.GetTypes())
67 {
68 if (componentType.IsPublic
69 && !componentType.IsAbstract)
70 {
71 if (componentType.IsSubclassOf(typeof (ComponentBase)))
72 {
73 // We have found an type which is derived from ProdiverBase, add it to provider list
74 m_log.InfoFormat("[ScriptEngine]: Adding component: {0}", componentType.Name);
75 lock (ComponentRegistry.providers)
76 {
77 ComponentRegistry.providers.Add(componentType.Name, componentType);
78 }
79 }
80 if (componentType.IsSubclassOf(typeof(RegionScriptEngineBase)))
81 {
82 // We have found an type which is derived from RegionScriptEngineBase, add it to engine list
83 m_log.InfoFormat("[ScriptEngine]: Adding script engine: {0}", componentType.Name);
84 lock (ComponentRegistry.scriptEngines)
85 {
86 ComponentRegistry.scriptEngines.Add(componentType.Name, componentType);
87 }
88 }
89 }
90 }
91 }
92 catch
93 (ReflectionTypeLoadException)
94 {
95 m_log.InfoFormat("[ScriptEngine]: Could not load types for [{0}].", componentAssembly.FullName);
96 }
97 } //if
98 } //foreach
99 }
100 }
101} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/ComponentRegistry.cs b/OpenSim/ApplicationPlugins/ScriptEngine/ComponentRegistry.cs
deleted file mode 100644
index 5ffa490..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/ComponentRegistry.cs
+++ /dev/null
@@ -1,68 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30using OpenSim.ApplicationPlugins.ScriptEngine;
31using OpenSim.ApplicationPlugins.ScriptEngine.Components;
32
33namespace OpenSim.ApplicationPlugins.ScriptEngine
34{
35 /// <summary>
36 /// Component providers
37 /// This is where any component (any part) of the Script Engine Component System (SECS) registers.
38 /// Nothing is instanciated at this point. The modules just need to register here to be available for any script engine.
39 /// </summary>
40 public static class ComponentRegistry
41 {
42 // Component providers are registered here wit a name (string)
43 // When a script engine is created the components are instanciated
44 public static Dictionary<string, Type> providers = new Dictionary<string, Type>();
45 public static Dictionary<string, Type> scriptEngines = new Dictionary<string, Type>();
46
47 ///// <summary>
48 ///// Returns a list of ProviderBase objects which has been instanciated by their name
49 ///// </summary>
50 ///// <param name="Providers">List of Script Engine Components</param>
51 ///// <returns></returns>
52 //public static List<ComponentBase> GetComponents(string[] Providers)
53 //{
54 // List<ComponentBase> pbl = new List<ComponentBase>();
55 // if (Providers != null)
56 // {
57 // foreach (string p in Providers)
58 // {
59 // if (providers.ContainsKey(p))
60 // pbl.Add(Activator.CreateInstance(providers[p]) as ComponentBase);
61 // }
62 // }
63
64 // return pbl;
65 //}
66
67 }
68} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CommandBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/Components/CommandBase.cs
deleted file mode 100644
index 4708554..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CommandBase.cs
+++ /dev/null
@@ -1,45 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace OpenSim.ApplicationPlugins.ScriptEngine.Components
32{
33 public abstract class CommandBase: ComponentBase
34 {
35 //public override iProviderBase CreateInstance()
36 //{
37 // throw new NotImplementedException();
38 //}
39
40 //public override void Start()
41 //{
42 // throw new NotImplementedException();
43 //}
44 }
45} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CompilerBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/Components/CompilerBase.cs
deleted file mode 100644
index e62d1f2..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CompilerBase.cs
+++ /dev/null
@@ -1,45 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace OpenSim.ApplicationPlugins.ScriptEngine.Components
32{
33 public abstract class CompilerBase: ComponentBase
34 {
35 //public override iProviderBase CreateInstance()
36 //{
37 // throw new NotImplementedException();
38 //}
39
40 //public override void Start()
41 //{
42 // throw new NotImplementedException();
43 //}
44 }
45} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/ComponentBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/Components/ComponentBase.cs
deleted file mode 100644
index 48c6bfe..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/ComponentBase.cs
+++ /dev/null
@@ -1,53 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace OpenSim.ApplicationPlugins.ScriptEngine.Components
32{
33 /// <summary>
34 /// Generic baseclass for component providers
35 /// </summary>
36 public abstract class ComponentBase //: iProviderBase
37 {
38 //public abstract iProviderBase CreateInstance();
39 public abstract void Start();
40 public abstract void Close();
41 public RegionScriptEngineBase scriptEngine;
42 public void Initialize(RegionScriptEngineBase ScriptEngine)
43 {
44 scriptEngine = ScriptEngine;
45 }
46
47 static ComponentBase()
48 {
49 // We got loaded -- should we register now?
50 //OpenSim.ApplicationPlugins.ScriptEngine.ComponentProviders.providers.Add(GetType());
51 }
52 }
53} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/EventBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/Components/EventBase.cs
deleted file mode 100644
index 1c0fd52..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/EventBase.cs
+++ /dev/null
@@ -1,45 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace OpenSim.ApplicationPlugins.ScriptEngine.Components
32{
33 public abstract class EventBase : ComponentBase
34 {
35 //public override iProviderBase CreateInstance()
36 //{
37 // throw new NotImplementedException();
38 //}
39
40 //public override void Start()
41 //{
42 // throw new NotImplementedException();
43 //}
44 }
45} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/SchedulerBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/Components/SchedulerBase.cs
deleted file mode 100644
index 9d5aff0..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/SchedulerBase.cs
+++ /dev/null
@@ -1,45 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace OpenSim.ApplicationPlugins.ScriptEngine.Components
32{
33 public abstract class SchedulerBase: ComponentBase
34 {
35 //public override iProviderBase CreateInstance()
36 //{
37 // throw new NotImplementedException();
38 //}
39
40 //public override void Start()
41 //{
42 // throw new NotImplementedException();
43 //}
44 }
45} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEnginePlugin.cs b/OpenSim/ApplicationPlugins/ScriptEngine/RegionEngineLoader.cs
index e6def85..115d237 100644
--- a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEnginePlugin.cs
+++ b/OpenSim/ApplicationPlugins/ScriptEngine/RegionEngineLoader.cs
@@ -26,45 +26,51 @@
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection;
29using System.Text; 30using System.Text;
31using log4net;
30using Nini.Config; 32using Nini.Config;
31using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
32using OpenSim.Region.Environment.Scenes; 34using OpenSim.Region.Environment.Scenes;
35using OpenSim.ScriptEngine.Shared;
33 36
34namespace OpenSim.ApplicationPlugins.ScriptEngine 37namespace OpenSim.ApplicationPlugins.ScriptEngine
35{ 38{
36 public class RegionScriptEnginePlugin : IRegionModule 39 public class RegionEngineLoader : IRegionModule
37 { 40 {
38 // This is a region module. 41 // This is a region module.
39 // This means: Every time a new region is created, a new instance of this module is also created. 42 // This means: Every time a new region is created, a new instance of this module is also created.
40 // This module is responsible for starting the script engine for this region. 43 // This module is responsible for starting the script engine for this region.
44 public string Name { get { return "SECS.DotNetEngine.Scheduler.RegionLoader"; } }
45 public bool IsSharedModule { get { return true; } }
41 46
47 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 private string tempScriptEngineName = "DotNetEngine"; 48 private string tempScriptEngineName = "DotNetEngine";
43 public RegionScriptEngineBase scriptEngine; 49 public IScriptEngine scriptEngine;
50 public IConfigSource ConfigSource;
51 public IConfig ScriptConfigSource;
44 public void Initialise(Scene scene, IConfigSource source) 52 public void Initialise(Scene scene, IConfigSource source)
45 { 53 {
46 return;
47 // New region is being created 54 // New region is being created
48 // Create a new script engine 55 // Create a new script engine
49// try 56 // Make sure we have config
50// { 57 if (ConfigSource.Configs["SECS"] == null)
51// lock (ComponentRegistry.scriptEngines) 58 ConfigSource.AddConfig("SECS");
52// { 59 ScriptConfigSource = ConfigSource.Configs["SECS"];
53// scriptEngine = 60
54// Activator.CreateInstance(ComponentRegistry.scriptEngines[tempScriptEngineName]) as 61 // Is SECS enabled?
55// RegionScriptEngineBase; 62 if (ScriptConfigSource.GetBoolean("Enabled", false))
56// } 63 {
57// scriptEngine.Initialize(scene, source); 64 LoadEngine();
58// } 65 if (scriptEngine != null)
59// catch (Exception ex) 66 scriptEngine.Initialise(scene, source);
60// { 67 }
61// scriptEngine.m_log.Error("[ScriptEngine]: Unable to load engine \"" + tempScriptEngineName + "\": " + ex.ToString());
62// }
63 } 68 }
64 69
65 public void PostInitialise() 70 public void PostInitialise()
66 { 71 {
67 // Nothing 72 if (scriptEngine != null)
73 scriptEngine.PostInitialise();
68 } 74 }
69 75
70 public void Close() 76 public void Close()
@@ -76,18 +82,34 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine
76 } 82 }
77 catch (Exception ex) 83 catch (Exception ex)
78 { 84 {
79 scriptEngine.m_log.Error("[ScriptEngine]: Unable to close engine \"" + tempScriptEngineName + "\": " + ex.ToString()); 85 m_log.ErrorFormat("[{0}] Unable to close engine \"{1}\": {2}", Name, tempScriptEngineName, ex.ToString());
80 } 86 }
81 } 87 }
82 88
83 public string Name 89 private void LoadEngine()
84 { 90 {
85 get { return "ScriptEngine Region Loader"; } 91 m_log.DebugFormat("[{0}] Loading region script engine engine \"{1}\".", Name, tempScriptEngineName);
92 try
93 {
94 lock (ScriptEnginePlugin.scriptEngines)
95 {
96 if (!ScriptEnginePlugin.scriptEngines.ContainsKey(tempScriptEngineName))
97 {
98 m_log.ErrorFormat("[{0}] Unable to load region script engine: Script engine \"{1}\" does not exist.", Name, tempScriptEngineName);
99 }
100 else
101 {
102 scriptEngine =
103 Activator.CreateInstance(ScriptEnginePlugin.scriptEngines[tempScriptEngineName]) as
104 IScriptEngine;
105 }
106 }
107 }
108 catch (Exception ex)
109 {
110 m_log.ErrorFormat("[{0}] Internal error loading region script engine \"{1}\": {2}", Name, tempScriptEngineName, ex.ToString());
111 }
86 } 112 }
87 113
88 public bool IsSharedModule
89 {
90 get { return true; }
91 }
92 } 114 }
93} 115}
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs
deleted file mode 100644
index 89a90ae..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs
+++ /dev/null
@@ -1,182 +0,0 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using System.Text;
31using log4net;
32using Nini.Config;
33using OpenSim.ApplicationPlugins.ScriptEngine.Components;
34using OpenSim.Region.Environment.Scenes;
35
36namespace OpenSim.ApplicationPlugins.ScriptEngine
37{
38 public abstract class RegionScriptEngineBase
39 {
40
41 /// <summary>
42 /// Called on region initialize
43 /// </summary>
44 public abstract void Initialize();
45 public abstract string Name { get; }
46 /// <summary>
47 /// Called before components receive Close()
48 /// </summary>
49 public abstract void PreClose();
50 // Hold list of all the different components we have working for us
51 public List<ComponentBase> Components = new List<ComponentBase>();
52
53 public Scene m_Scene;
54 public IConfigSource m_ConfigSource;
55 public readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56
57 public void Initialize(Scene scene, IConfigSource source)
58 {
59 // Region started
60 m_Scene = scene;
61 m_ConfigSource = source;
62 Initialize();
63 }
64
65 /// <summary>
66 /// Creates instances of script engine components inside "components" List
67 /// </summary>
68 /// <param name="ComponentList">Array of comonent names to initialize</param>
69 public void InitializeComponents(string[] ComponentList)
70 {
71 // Take list of providers to initialize and make instances of them
72 foreach (string c in ComponentList)
73 {
74 m_log.Info("[" + Name + "]: Loading: " + c);
75 lock (Components)
76 {
77 lock (ComponentRegistry.providers)
78 {
79 try
80 {
81 if (ComponentRegistry.providers.ContainsKey(c))
82 Components.Add(Activator.CreateInstance(ComponentRegistry.providers[c]) as ComponentBase);
83 else
84 m_log.Error("[" + Name + "]: Component \"" + c + "\" not found, can not load");
85 }
86 catch (Exception ex)
87 {
88 m_log.Error("[" + Name + "]: Exception loading \"" + c + "\": " + ex.ToString());
89 }
90 }
91 }
92 }
93
94
95 // Run Initialize on all our providers, hand over a reference of ourself.
96 foreach (ComponentBase p in Components.ToArray())
97 {
98 try
99 {
100 p.Initialize(this);
101 }
102 catch (Exception ex)
103 {
104 lock (Components)
105 {
106 m_log.Error("[" + Name + "]: Error initializing \"" + p.GetType().FullName + "\": " +
107 ex.ToString());
108 if (Components.Contains(p))
109 Components.Remove(p);
110 }
111 }
112 }
113 // All modules has been initialized, call Start() on them.
114 foreach (ComponentBase p in Components.ToArray())
115 {
116 try
117 {
118 p.Start();
119 }
120 catch (Exception ex)
121 {
122 lock (Components)
123 {
124 m_log.Error("[" + Name + "]: Error starting \"" + p.GetType().FullName + "\": " + ex.ToString());
125 if (Components.Contains(p))
126 Components.Remove(p);
127 }
128 }
129 }
130
131 }
132
133 #region Functions to return lists based on type
134 // Predicate for searching List for a certain type
135 private static bool FindType<T>(ComponentBase pb)
136 {
137 if (pb.GetType() is T)
138 return true;
139 return false;
140 }
141 public List<ComponentBase> GetCommandComponentList()
142 {
143 return Components.FindAll(FindType<CommandBase>);
144 }
145 public List<ComponentBase> GetCompilerComponentList()
146 {
147 return Components.FindAll(FindType<CompilerBase>);
148 }
149 public List<ComponentBase> GetEventComponentList()
150 {
151 return Components.FindAll(FindType<EventBase>);
152 }
153 public List<ComponentBase> GetScheduleComponentList()
154 {
155 return Components.FindAll(FindType<SchedulerBase>);
156 }
157
158 #endregion
159
160 public void Close()
161 {
162 // We need to shut down
163
164 // First call abstracted PreClose()
165 PreClose();
166
167 // Then Call Close() on all components
168 foreach (ComponentBase p in Components.ToArray())
169 {
170 try
171 {
172 p.Close();
173 }
174 catch (Exception)
175 {
176 // TODO: Print error to console
177 }
178 }
179 }
180 }
181}
182
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEngine.addin.xml b/OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEngine.addin.xml
deleted file mode 100644
index 38f6eb0..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEngine.addin.xml
+++ /dev/null
@@ -1,12 +0,0 @@
1<Addin id="ScriptEngine" version="0.1">
2 <Runtime>
3 <Import assembly="OpenSim.ApplicationPlugins.ScriptEngine.dll" />
4 </Runtime>
5 <Dependencies>
6 <Addin id="OpenSim" version="0.5" />
7 <Addin id="RegionProxy" version="0.1" />
8 </Dependencies>
9 <Extension path="/OpenSim/Startup">
10 <Plugin id="ScriptEngine" type="OpenSim.ApplicationPlugins.ScriptEngine.ScriptEnginePlugin" />
11 </Extension>
12</Addin>
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEnginePlugin.addin.xml b/OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEnginePlugin.addin.xml
new file mode 100644
index 0000000..f067bf4
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/ScriptEngine/Resources/ScriptEnginePlugin.addin.xml
@@ -0,0 +1,11 @@
1<Addin id="OpenSim.ApplicationPlugins.ScriptEngine" version="0.1">
2 <Runtime>
3 <Import assembly="OpenSim.ApplicationPlugins.ScriptEngine.dll" />
4 </Runtime>
5 <Dependencies>
6 <Addin id="OpenSim" version="0.5" />
7 </Dependencies>
8 <Extension path = "/OpenSim/Startup">
9 <Plugin id="ScriptEnginePlugin" type="OpenSim.ApplicationPlugins.ScriptEngine.ScriptEnginePlugin" />
10 </Extension>
11</Addin>
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}