[Opensim-dev] Module/Plugin Loading

Justin Clark-Casey jjustincc at googlemail.com
Tue Jun 24 16:47:41 UTC 2008


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?

Probably just semantics in many cases, though in general I think we have 
been referring to application plugins, which apply at the application 
level and already use the Mono.addins framework, and region modules, 
which use our own framework.

> 
> 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

As Sean says, it would be nice if we could use Mono.Addins facilities 
directly.

On a more general note Ryan, I'd like to know what your impressions are 
of Mono.Addins and whether you think it's a good choice for OpenSim. 
Personally, I looked at it somewhat superficially a while back and I 
wasn't convinced about the quality of the code or the documentation 
(thogh this is the pot calling the kettle black), but things may have 
moved on.

> 
> What do you think?
> 

Definitely good that you're looking at this.  It might be needless to 
say this, but when you do produce patches, small incremental ones will 
be easier for us to take on board than a single large one.

Regards,

-- 
justincc
Justin Clark-Casey
http://justincc.wordpress.com



More information about the Opensim-dev mailing list