aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorAdam Frisby2009-04-21 04:55:53 +0000
committerAdam Frisby2009-04-21 04:55:53 +0000
commit594c7c3eb13695304c755ec1bc65c5f239754222 (patch)
tree5de4d356929e3afa7efd0045167a92e44f710c21 /OpenSim/Region
parentChange a bad use of a type name as a variable. Thanks, Fly-Man (diff)
downloadopensim-SC_OLD-594c7c3eb13695304c755ec1bc65c5f239754222.zip
opensim-SC_OLD-594c7c3eb13695304c755ec1bc65c5f239754222.tar.gz
opensim-SC_OLD-594c7c3eb13695304c755ec1bc65c5f239754222.tar.bz2
opensim-SC_OLD-594c7c3eb13695304c755ec1bc65c5f239754222.tar.xz
* Implements Extensions to MRM. This allows Region Modules to insert new classes into OpenSim MRM's.
* Example in region module: Scene.GetModuleInterface<IMRMModule>.RegisterExtension<IMyInterface>(this); * In the MRM: //@DEPENDS:MyExtensionModule.dll ... Host.Extensions<IMyInterface>.DoStuff();
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs39
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs10
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/IMRMModule.cs7
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IExtension.cs13
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs13
6 files changed, 81 insertions, 3 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs
new file mode 100644
index 0000000..bc159eb
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs
@@ -0,0 +1,39 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;
5
6namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
7{
8 class ExtensionHandler : IExtension
9 {
10 private readonly Dictionary<Type, object> m_instances;
11
12 public ExtensionHandler(Dictionary<Type, object> instances)
13 {
14 m_instances = instances;
15 }
16
17 public T Get<T>()
18 {
19 return (T) m_instances[typeof (T)];
20 }
21
22 public bool TryGet<T>(out T extension)
23 {
24 if (!m_instances.ContainsKey(typeof(T)))
25 {
26 extension = default(T);
27 return false;
28 }
29
30 extension = Get<T>();
31 return true;
32 }
33
34 public bool Has<T>()
35 {
36 return m_instances.ContainsKey(typeof (T));
37 }
38 }
39}
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs
index b7f67dd..94796e4 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs
@@ -28,6 +28,7 @@
28using System.Reflection; 28using System.Reflection;
29using log4net; 29using log4net;
30using OpenSim.Region.Framework.Scenes; 30using OpenSim.Region.Framework.Scenes;
31using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;
31 32
32namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 33namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
33{ 34{
@@ -36,11 +37,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
36 private readonly IObject m_obj; 37 private readonly IObject m_obj;
37 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 38 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
38 private readonly IGraphics m_graphics; 39 private readonly IGraphics m_graphics;
40 private readonly IExtension m_extend;
39 //private Scene m_scene; 41 //private Scene m_scene;
40 42
41 public Host(IObject m_obj, Scene m_scene) 43 public Host(IObject m_obj, Scene m_scene, IExtension m_extend)
42 { 44 {
43 this.m_obj = m_obj; 45 this.m_obj = m_obj;
46 this.m_extend = m_extend;
44 //this.m_scene = m_scene; 47 //this.m_scene = m_scene;
45 48
46 m_graphics = new Graphics(m_scene); 49 m_graphics = new Graphics(m_scene);
@@ -60,5 +63,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
60 { 63 {
61 get { return m_graphics; } 64 get { return m_graphics; }
62 } 65 }
66
67 public IExtension Extensions
68 {
69 get { return m_extend; }
70 }
63 } 71 }
64} 72}
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IMRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IMRMModule.cs
new file mode 100644
index 0000000..4c37a44
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IMRMModule.cs
@@ -0,0 +1,7 @@
1namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
2{
3 public interface IMRMModule
4 {
5 void RegisterExtension<T>(T instance);
6 }
7} \ No newline at end of file
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IExtension.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IExtension.cs
new file mode 100644
index 0000000..b58e600
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IExtension.cs
@@ -0,0 +1,13 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces
6{
7 public interface IExtension
8 {
9 T Get<T>();
10 bool TryGet<T>(out T extension);
11 bool Has<T>();
12 }
13}
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs
index 6c76919..fd73ffd 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs
@@ -29,6 +29,7 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text; 30using System.Text;
31using log4net; 31using log4net;
32using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;
32 33
33namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 34namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
34{ 35{
@@ -37,5 +38,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
37 IObject Object { get; } 38 IObject Object { get; }
38 ILog Console { get; } 39 ILog Console { get; }
39 IGraphics Graphics { get; } 40 IGraphics Graphics { get; }
41 IExtension Extensions { get; }
40 } 42 }
41} 43}
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs
index 0572fc7..b0fe222 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs
@@ -41,15 +41,22 @@ using OpenSim.Region.Framework.Scenes;
41 41
42namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 42namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
43{ 43{
44 public class MRMModule : IRegionModule 44 public class MRMModule : IRegionModule, IMRMModule
45 { 45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private Scene m_scene; 47 private Scene m_scene;
48 48
49 private readonly Dictionary<UUID,MRMBase> m_scripts = new Dictionary<UUID, MRMBase>(); 49 private readonly Dictionary<UUID,MRMBase> m_scripts = new Dictionary<UUID, MRMBase>();
50 50
51 private readonly Dictionary<Type,object> m_extensions = new Dictionary<Type, object>();
52
51 private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); 53 private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
52 54
55 public void RegisterExtension<T>(T instance)
56 {
57 m_extensions[typeof (T)] = instance;
58 }
59
53 public void Initialise(Scene scene, IConfigSource source) 60 public void Initialise(Scene scene, IConfigSource source)
54 { 61 {
55 if (source.Configs["MRM"] != null) 62 if (source.Configs["MRM"] != null)
@@ -59,6 +66,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
59 m_log.Info("[MRM] Enabling MRM Module"); 66 m_log.Info("[MRM] Enabling MRM Module");
60 m_scene = scene; 67 m_scene = scene;
61 scene.EventManager.OnRezScript += EventManager_OnRezScript; 68 scene.EventManager.OnRezScript += EventManager_OnRezScript;
69
70 scene.RegisterModuleInterface<IMRMModule>(this);
62 } 71 }
63 else 72 else
64 { 73 {
@@ -82,7 +91,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
82 { 91 {
83 m_log.Info("[MRM] Found C# MRM"); 92 m_log.Info("[MRM] Found C# MRM");
84 IWorld m_world = new World(m_scene); 93 IWorld m_world = new World(m_scene);
85 IHost m_host = new Host(new SOPObject(m_scene, localID), m_scene); 94 IHost m_host = new Host(new SOPObject(m_scene, localID), m_scene, new ExtensionHandler(m_extensions));
86 95
87 MRMBase mmb = (MRMBase)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( 96 MRMBase mmb = (MRMBase)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(
88 CompileFromDotNetText(script, itemID.ToString()), 97 CompileFromDotNetText(script, itemID.ToString()),