[Opensim-dev] Module/Plugin Loading

Sean Dague sean at dague.net
Tue Jun 24 13:09:06 UTC 2008


On Tue, Jun 24, 2008 at 05:53:41PM +0900, 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?

List looks good.

> 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);
> }

Why bother with that wrapping?  Don't we get all those from the addin
structure already.

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

The loader approach looks very good.  +1 in moving forward on that.

Something to think about down the road is that Addins have online
repository support built in.  It would be great to have that reasonably
integrated with OpenSim so that we could move some modules out of the
core and into online repositories.

    -Sean

-- 
__________________________________________________________________

Sean Dague                                       Mid-Hudson Valley
sean at dague dot net                            Linux Users Group
http://dague.net                                 http://mhvlug.org

There is no silver bullet.  Plus, werewolves make better neighbors
than zombies, and they tend to keep the vampire population down.
__________________________________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://opensimulator.org/pipermail/opensim-dev/attachments/20080624/bccbfa3d/attachment-0001.pgp>


More information about the Opensim-dev mailing list