[Opensim-dev] Module/Plugin Loading
Melanie
melanie at t-data.com
Tue Jun 24 09:11:05 UTC 2008
It's called _Mono_ addins... does it work in .NET?
Melanie
Ryan McDougall wrote:
> I've started looking at module/plugin loading in OpenSim. Some have
> commented that the current situation where things are loaded and
> initialized ad hoc should be replaced by a greater use of Mono.Addins.
>
> In my survey of the code I've identified a lot of copy-paste code, which
> minimally I can remove by consolidating that code into a common class or
> method. However I'd like to try and do a little better, and provide a
> framework for all the ad hoc loading.
>
> I've identified the following Interfaces which appear to be loaded
> dynamically somewhere:
>
>
> ILogData
> IUserData
> IAssetProvider
> IInventoryData
> IApplicationPlugin
> IRegionModule
> IRegionDataStore
> IGridPlugin
> IGridData
> IGenericConfig
> IDataNode
> IDataSnapshotProvider
> IClientNetworkServer
> IPhysicsPlugin
> IMeshingPlugin
> ITerrainEffect
> ITerrainLoader
> ITarget
>
> Does that look like a comprehensive list?
> Whats the difference between a Plugin and a Module?
>
> I suggest wrapping Mono.Addins into a simple common loader class as
> follows:
>
> Extend IPlugin to the following:
>
> public class PluginInitData {}
>
> public interface IPlugin : IDispose
> {
> string Version { get; }
> string Name { get; }
> void Initialise (PluginInitData);
> }
>
> and create:
>
> PluginLoader : IDispose
> {
> List<IPlugin> plugins = new List<IPlugin>();
>
> PluginLoader (string dir)
> {
> AddPluginDir (dir);
> }
>
> void AddPluginDir (string dir)
> {
> AddinManager.Initialize (dir);
> }
>
> void Load (string extpoint, PluginInitData data)
> {
> LoadUninitialized (extpoint);
> Initialize (data);
> }
>
> void LoadUninitialized <T> (string extpoint) where T : IPlugin
> {
> AddinManager.Registry.Update (null);
> ExtensionNodeList ns = AddinManager.GetExtensionNodes(extpoint);
> foreach (TypeExtensionNode n in ns)
> {
> log.Info("[PLUGINS]: Loading plugin " + n.Path);
> plugins.Add ((T) n.CreateInstance());
> }
> }
>
> void Initialize (PluginInitData data)
> {
> foreach (IPlugin p in plugins)
> p.Initialize (data);
> }
>
> void Dispose ()
> {
> foreach (IPlugin p in plugins)
> p.Dispose ();
> }
> }
>
> Which would be used in the following way:
>
> 1. Plugins would be created this way
>
> class MyPluginInitData : PluginInitData
> {
> int foo;
> string bar;
> };
>
> class MyPlugin : IPlugin
> {
> Initialize (PluginInitData data)
> {
> MyPluginInitData d = data as MyPluginInitData;
> //...
> }
> //...
> }
>
> 2. And would be loaded this way:
>
> PluginLoader loader = new PluginLoader ("my/plugin/dir");
> MyPluginInitData data = new MyPluginInitData (42, "huzzah");
>
> loader.load ("/OpenSim/MyPlugins", data);
>
> Whozit w = new Whozit();
> w.lart (loader.plugins); // does stuff with plugins
>
> What do you think?
>
>
> _______________________________________________
> Opensim-dev mailing list
> Opensim-dev at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/opensim-dev
>
>
More information about the Opensim-dev
mailing list