* Applying Mantis #1852 - Plugin Provider refactoring. Courtesy of Ryan/Sempuki.

0.6.0-stable
Adam Frisby 2008-07-30 08:17:19 +00:00
parent 92e7f88a30
commit 2f8acdbe50
13 changed files with 70 additions and 34 deletions

View File

@ -27,6 +27,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Xml;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using log4net; using log4net;
@ -61,7 +62,7 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
public interface IPluginFilter public interface IPluginFilter
{ {
bool Apply (ExtensionNode plugin); bool Apply (PluginExtensionNode plugin);
} }
/// <summary> /// <summary>
@ -152,7 +153,7 @@ namespace OpenSim.Framework
if (filters.ContainsKey (ext)) if (filters.ContainsKey (ext))
filter = filters [ext]; filter = filters [ext];
foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (ext)) foreach (PluginExtensionNode node in AddinManager.GetExtensionNodes (ext))
{ {
log.Info("[PLUGINS]: Trying plugin " + node.Path); log.Info("[PLUGINS]: Trying plugin " + node.Path);
@ -197,9 +198,13 @@ namespace OpenSim.Framework
private void on_addinloaderror_(object sender, AddinErrorEventArgs args) private void on_addinloaderror_(object sender, AddinErrorEventArgs args)
{ {
log.Error ("[PLUGINS]: Plugin Error: " + args.Message if (args.Exception == null)
+ ": " + args.Exception.Message log.Error ("[PLUGINS]: Plugin Error: "
+ "\n"+ args.Exception.StackTrace); + args.Message);
else
log.Error ("[PLUGINS]: Plugin Error: "
+ args.Exception.Message + "\n"
+ args.Exception.StackTrace);
} }
private void clear_registry_ () private void clear_registry_ ()
@ -230,6 +235,39 @@ namespace OpenSim.Framework
} }
} }
public class PluginExtensionNode : ExtensionNode
{
[NodeAttribute]
string provider;
[NodeAttribute]
string type;
Type typeobj;
public string Provider { get { return provider; } }
public string TypeName { get { return type; } }
public Type TypeObject
{
get
{
if (typeobj != null)
return typeobj;
if (type.Length == 0)
throw new InvalidOperationException ("Type name not specified.");
return typeobj = Addin.GetType (type, true);
}
}
public object CreateInstance ()
{
return Activator.CreateInstance (TypeObject);
}
}
/// <summary> /// <summary>
/// Constraint that bounds the number of plugins to be loaded. /// Constraint that bounds the number of plugins to be loaded.
/// </summary> /// </summary>
@ -271,25 +309,20 @@ namespace OpenSim.Framework
} }
/// <summary> /// <summary>
/// Filters out which plugin to load based on its "Id", which is name given by the namespace or by Mono.Addins. /// Filters out which plugin to load based on its "Provider", which is name given by in the addin.xml
/// </summary> /// </summary>
public class PluginIdFilter : IPluginFilter public class PluginProviderFilter : IPluginFilter
{ {
private string id; private string provider;
public PluginIdFilter (string id) public PluginProviderFilter (string p)
{ {
this.id = id; provider = p;
} }
public bool Apply (ExtensionNode plugin) public bool Apply (PluginExtensionNode plugin)
{ {
System.Console.WriteLine ("[WTF]: " + plugin.Path); return (plugin.Provider == provider);
if (plugin.HasId == false)
return false;
return (plugin.Id == id);
} }
} }
} }

View File

@ -71,9 +71,9 @@ namespace OpenSim.Grid.GridServer
logloader.AddExtensionPoint ("/OpenSim/LogData"); logloader.AddExtensionPoint ("/OpenSim/LogData");
// loader will try to load all providers (MySQL, MSSQL, etc) // loader will try to load all providers (MySQL, MSSQL, etc)
// unless it is constrainted to the correct "id" // unless it is constrainted to the correct "Provider" entry in the addin.xml
gridloader.AddFilter ("/OpenSim/GridData", new PluginIdFilter (provider)); gridloader.AddFilter ("/OpenSim/GridData", new PluginProviderFilter (provider));
logloader.AddFilter ("/OpenSim/LogData", new PluginIdFilter (provider)); logloader.AddFilter ("/OpenSim/LogData", new PluginProviderFilter (provider));
gridloader.Load(); gridloader.Load();
logloader.Load(); logloader.Load();

View File

@ -6,6 +6,6 @@
<Addin id="OpenSim" version="0.5" /> <Addin id="OpenSim" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/Startup"> <Extension path = "/OpenSim/Startup">
<Type type="OpenSim.ApplicationPlugins.GridInfo.GridInfoPlugin" /> <Plugin type="OpenSim.ApplicationPlugins.GridInfo.GridInfoPlugin" />
</Extension> </Extension>
</Addin> </Addin>

View File

@ -6,6 +6,6 @@
<Addin id="OpenSim" version="0.5" /> <Addin id="OpenSim" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/Startup"> <Extension path = "/OpenSim/Startup">
<Type type="OpenSim.ApplicationPlugins.LoadRegions.LoadRegionsPlugin" /> <Plugin type="OpenSim.ApplicationPlugins.LoadRegions.LoadRegionsPlugin" />
</Extension> </Extension>
</Addin> </Addin>

View File

@ -6,9 +6,9 @@
<Addin id="OpenSim.Data" version="0.5" /> <Addin id="OpenSim.Data" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/GridData"> <Extension path = "/OpenSim/GridData">
<Type id="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLGridData" /> <Plugin provider="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLGridData" />
</Extension> </Extension>
<Extension path = "/OpenSim/LogData"> <Extension path = "/OpenSim/LogData">
<Type id="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLLogData" /> <Plugin provider="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLLogData" />
</Extension> </Extension>
</Addin> </Addin>

View File

@ -6,9 +6,9 @@
<Addin id="OpenSim.Data" version="0.5" /> <Addin id="OpenSim.Data" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/GridData"> <Extension path = "/OpenSim/GridData">
<Type id="OpenSim.Data.MySQL.dll" type="OpenSim.Data.MySQL.MySQLGridData" /> <Plugin provider="OpenSim.Data.MySQL.dll" type="OpenSim.Data.MySQL.MySQLGridData" />
</Extension> </Extension>
<Extension path = "/OpenSim/LogData"> <Extension path = "/OpenSim/LogData">
<Type id="OpenSim.Data.MySQL.dll" type="OpenSim.Data.MySQL.MySQLLogData" /> <Plugin provider="OpenSim.Data.MySQL.dll" type="OpenSim.Data.MySQL.MySQLLogData" />
</Extension> </Extension>
</Addin> </Addin>

View File

@ -6,6 +6,6 @@
<Addin id="OpenSim.Data" version="0.5" /> <Addin id="OpenSim.Data" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/GridData"> <Extension path = "/OpenSim/GridData">
<Type id="OpenSim.Data.SQLite.dll" type="OpenSim.Data.SQLite.SQLiteGridData" /> <Plugin provider="OpenSim.Data.SQLite.dll" type="OpenSim.Data.SQLite.SQLiteGridData" />
</Extension> </Extension>
</Addin> </Addin>

View File

@ -2,11 +2,12 @@
<Runtime> <Runtime>
<Import assembly="OpenSim.Grid.GridServer.exe"/> <Import assembly="OpenSim.Grid.GridServer.exe"/>
<Import assembly="OpenSim.Data.dll"/> <Import assembly="OpenSim.Data.dll"/>
<Import assembly="OpenSim.Framework.dll"/>
</Runtime> </Runtime>
<ExtensionPoint path = "/OpenSim/GridData"> <ExtensionPoint path = "/OpenSim/GridData">
<ExtensionNode objectType="OpenSim.Data.IGridDataPlugin"/> <ExtensionNode name="Plugin" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.Data.IGridDataPlugin"/>
</ExtensionPoint> </ExtensionPoint>
<ExtensionPoint path = "/OpenSim/LogData"> <ExtensionPoint path = "/OpenSim/LogData">
<ExtensionNode objectType="OpenSim.Data.ILogDataPlugin"/> <ExtensionNode name="Plugin" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.Data.ILogDataPlugin"/>
</ExtensionPoint> </ExtensionPoint>
</Addin> </Addin>

View File

@ -1,8 +1,9 @@
<Addin id="OpenSim.Grid.GridServer" isroot="true" version="0.5"> <Addin id="OpenSim.Grid.GridServer" isroot="true" version="0.5">
<Runtime> <Runtime>
<Import assembly="OpenSim.Grid.GridServer.exe"/> <Import assembly="OpenSim.Grid.GridServer.exe"/>
<Import assembly="OpenSim.Framework.dll"/>
</Runtime> </Runtime>
<ExtensionPoint path = "/OpenSim/GridServer"> <ExtensionPoint path = "/OpenSim/GridServer">
<ExtensionNode objectType="OpenSim.Grid.GridServer.IGridPlugin"/> <ExtensionNode name="Plugin" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.Grid.GridServer.IGridPlugin"/>
</ExtensionPoint> </ExtensionPoint>
</Addin> </Addin>

View File

@ -1,8 +1,9 @@
<Addin id="OpenSim" isroot="true" version="0.5"> <Addin id="OpenSim" isroot="true" version="0.5">
<Runtime> <Runtime>
<Import assembly="OpenSim.exe"/> <Import assembly="OpenSim.exe"/>
<Import assembly="OpenSim.Framework.dll"/>
</Runtime> </Runtime>
<ExtensionPoint path = "/OpenSim/Startup"> <ExtensionPoint path = "/OpenSim/Startup">
<ExtensionNode objectType="OpenSim.IApplicationPlugin"/> <ExtensionNode name="Plugin" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.IApplicationPlugin"/>
</ExtensionPoint> </ExtensionPoint>
</Addin> </Addin>

View File

@ -6,6 +6,6 @@
<Addin id="OpenSim" version="0.5" /> <Addin id="OpenSim" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/Startup"> <Extension path = "/OpenSim/Startup">
<Type type="OpenSim.ApplicationPlugins.RemoteController.RemoteAdminPlugin" /> <Plugin type="OpenSim.ApplicationPlugins.RemoteController.RemoteAdminPlugin" />
</Extension> </Extension>
</Addin> </Addin>

View File

@ -6,6 +6,6 @@
<Addin id="OpenSim" version="0.5" /> <Addin id="OpenSim" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/Startup"> <Extension path = "/OpenSim/Startup">
<Type type="OpenSim.ApplicationPlugins.Rest.Inventory.RestHandler" /> <Plugin type="OpenSim.ApplicationPlugins.Rest.Inventory.RestHandler" />
</Extension> </Extension>
</Addin> </Addin>

View File

@ -6,6 +6,6 @@
<Addin id="OpenSim" version="0.5" /> <Addin id="OpenSim" version="0.5" />
</Dependencies> </Dependencies>
<Extension path = "/OpenSim/Startup"> <Extension path = "/OpenSim/Startup">
<Type type="OpenSim.ApplicationPlugins.Rest.Regions.RestRegionPlugin" /> <Plugin type="OpenSim.ApplicationPlugins.Rest.Regions.RestRegionPlugin" />
</Extension> </Extension>
</Addin> </Addin>