[Opensim-dev] Module/Plugin Loading
Ryan McDougall
sempuki1 at gmail.com
Tue Jun 24 08:53:41 UTC 2008
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?
More information about the Opensim-dev
mailing list