* 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();
0.6.5-rc1
Adam Frisby 2009-04-21 04:55:53 +00:00
parent 01a22d940f
commit 594c7c3eb1
6 changed files with 81 additions and 3 deletions

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
class ExtensionHandler : IExtension
{
private readonly Dictionary<Type, object> m_instances;
public ExtensionHandler(Dictionary<Type, object> instances)
{
m_instances = instances;
}
public T Get<T>()
{
return (T) m_instances[typeof (T)];
}
public bool TryGet<T>(out T extension)
{
if (!m_instances.ContainsKey(typeof(T)))
{
extension = default(T);
return false;
}
extension = Get<T>();
return true;
}
public bool Has<T>()
{
return m_instances.ContainsKey(typeof (T));
}
}
}

View File

@ -28,6 +28,7 @@
using System.Reflection;
using log4net;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
@ -36,11 +37,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
private readonly IObject m_obj;
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly IGraphics m_graphics;
private readonly IExtension m_extend;
//private Scene m_scene;
public Host(IObject m_obj, Scene m_scene)
public Host(IObject m_obj, Scene m_scene, IExtension m_extend)
{
this.m_obj = m_obj;
this.m_extend = m_extend;
//this.m_scene = m_scene;
m_graphics = new Graphics(m_scene);
@ -60,5 +63,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
get { return m_graphics; }
}
public IExtension Extensions
{
get { return m_extend; }
}
}
}

View File

@ -0,0 +1,7 @@
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
public interface IMRMModule
{
void RegisterExtension<T>(T instance);
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces
{
public interface IExtension
{
T Get<T>();
bool TryGet<T>(out T extension);
bool Has<T>();
}
}

View File

@ -29,6 +29,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
@ -37,5 +38,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
IObject Object { get; }
ILog Console { get; }
IGraphics Graphics { get; }
IExtension Extensions { get; }
}
}

View File

@ -41,15 +41,22 @@ using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
public class MRMModule : IRegionModule
public class MRMModule : IRegionModule, IMRMModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_scene;
private readonly Dictionary<UUID,MRMBase> m_scripts = new Dictionary<UUID, MRMBase>();
private readonly Dictionary<Type,object> m_extensions = new Dictionary<Type, object>();
private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
public void RegisterExtension<T>(T instance)
{
m_extensions[typeof (T)] = instance;
}
public void Initialise(Scene scene, IConfigSource source)
{
if (source.Configs["MRM"] != null)
@ -59,6 +66,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
m_log.Info("[MRM] Enabling MRM Module");
m_scene = scene;
scene.EventManager.OnRezScript += EventManager_OnRezScript;
scene.RegisterModuleInterface<IMRMModule>(this);
}
else
{
@ -82,7 +91,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
m_log.Info("[MRM] Found C# MRM");
IWorld m_world = new World(m_scene);
IHost m_host = new Host(new SOPObject(m_scene, localID), m_scene);
IHost m_host = new Host(new SOPObject(m_scene, localID), m_scene, new ExtensionHandler(m_extensions));
MRMBase mmb = (MRMBase)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(
CompileFromDotNetText(script, itemID.ToString()),