From 2f8acdbe5073c21ab49ac0865eecd10db401eb32 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Wed, 30 Jul 2008 08:17:19 +0000 Subject: * Applying Mantis #1852 - Plugin Provider refactoring. Courtesy of Ryan/Sempuki. --- OpenSim/Framework/PluginLoader.cs | 67 +++++++++++++++++++++++++--------- OpenSim/Grid/GridServer/GridManager.cs | 6 +-- bin/GridInfoPlugin.addin.xml | 2 +- bin/LoadRegionsPlugin.addin.xml | 2 +- bin/OpenSim.Data.MSSQL.addin.xml | 4 +- bin/OpenSim.Data.MySQL.addin.xml | 4 +- bin/OpenSim.Data.SQLite.addin.xml | 2 +- bin/OpenSim.Data.addin.xml | 5 ++- bin/OpenSim.Grid.GridServer.addin.xml | 3 +- bin/OpenSim.addin.xml | 3 +- bin/RemoteAdminPlugin.addin.xml | 2 +- bin/RestHandler.addin.xml | 2 +- bin/RestRegionPlugin.addin.xml | 2 +- 13 files changed, 70 insertions(+), 34 deletions(-) diff --git a/OpenSim/Framework/PluginLoader.cs b/OpenSim/Framework/PluginLoader.cs index c4602a8..616fa3e 100644 --- a/OpenSim/Framework/PluginLoader.cs +++ b/OpenSim/Framework/PluginLoader.cs @@ -27,6 +27,7 @@ using System; using System.IO; +using System.Xml; using System.Collections.Generic; using System.Reflection; using log4net; @@ -61,7 +62,7 @@ namespace OpenSim.Framework /// public interface IPluginFilter { - bool Apply (ExtensionNode plugin); + bool Apply (PluginExtensionNode plugin); } /// @@ -152,7 +153,7 @@ namespace OpenSim.Framework if (filters.ContainsKey (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); @@ -197,9 +198,13 @@ namespace OpenSim.Framework private void on_addinloaderror_(object sender, AddinErrorEventArgs args) { - log.Error ("[PLUGINS]: Plugin Error: " + args.Message - + ": " + args.Exception.Message - + "\n"+ args.Exception.StackTrace); + if (args.Exception == null) + log.Error ("[PLUGINS]: Plugin Error: " + + args.Message); + else + log.Error ("[PLUGINS]: Plugin Error: " + + args.Exception.Message + "\n" + + args.Exception.StackTrace); } 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); + } + } + /// /// Constraint that bounds the number of plugins to be loaded. /// @@ -271,25 +309,20 @@ namespace OpenSim.Framework } /// - /// 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 /// - 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); - - if (plugin.HasId == false) - return false; - - return (plugin.Id == id); + return (plugin.Provider == provider); } } } diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs index ec3ca19..98e670f 100644 --- a/OpenSim/Grid/GridServer/GridManager.cs +++ b/OpenSim/Grid/GridServer/GridManager.cs @@ -71,9 +71,9 @@ namespace OpenSim.Grid.GridServer logloader.AddExtensionPoint ("/OpenSim/LogData"); // loader will try to load all providers (MySQL, MSSQL, etc) - // unless it is constrainted to the correct "id" - gridloader.AddFilter ("/OpenSim/GridData", new PluginIdFilter (provider)); - logloader.AddFilter ("/OpenSim/LogData", new PluginIdFilter (provider)); + // unless it is constrainted to the correct "Provider" entry in the addin.xml + gridloader.AddFilter ("/OpenSim/GridData", new PluginProviderFilter (provider)); + logloader.AddFilter ("/OpenSim/LogData", new PluginProviderFilter (provider)); gridloader.Load(); logloader.Load(); diff --git a/bin/GridInfoPlugin.addin.xml b/bin/GridInfoPlugin.addin.xml index ee75817..67cf604 100644 --- a/bin/GridInfoPlugin.addin.xml +++ b/bin/GridInfoPlugin.addin.xml @@ -6,6 +6,6 @@ - + diff --git a/bin/LoadRegionsPlugin.addin.xml b/bin/LoadRegionsPlugin.addin.xml index 7fc3876..a12f91a 100644 --- a/bin/LoadRegionsPlugin.addin.xml +++ b/bin/LoadRegionsPlugin.addin.xml @@ -6,6 +6,6 @@ - + diff --git a/bin/OpenSim.Data.MSSQL.addin.xml b/bin/OpenSim.Data.MSSQL.addin.xml index b85c792..9b05e59 100644 --- a/bin/OpenSim.Data.MSSQL.addin.xml +++ b/bin/OpenSim.Data.MSSQL.addin.xml @@ -6,9 +6,9 @@ - + - + diff --git a/bin/OpenSim.Data.MySQL.addin.xml b/bin/OpenSim.Data.MySQL.addin.xml index 6dd4d75..f7372e6 100644 --- a/bin/OpenSim.Data.MySQL.addin.xml +++ b/bin/OpenSim.Data.MySQL.addin.xml @@ -6,9 +6,9 @@ - + - + diff --git a/bin/OpenSim.Data.SQLite.addin.xml b/bin/OpenSim.Data.SQLite.addin.xml index ef254dc..1d2f29e 100644 --- a/bin/OpenSim.Data.SQLite.addin.xml +++ b/bin/OpenSim.Data.SQLite.addin.xml @@ -6,6 +6,6 @@ - + diff --git a/bin/OpenSim.Data.addin.xml b/bin/OpenSim.Data.addin.xml index c70c3f7..991f652 100644 --- a/bin/OpenSim.Data.addin.xml +++ b/bin/OpenSim.Data.addin.xml @@ -2,11 +2,12 @@ + - + - + diff --git a/bin/OpenSim.Grid.GridServer.addin.xml b/bin/OpenSim.Grid.GridServer.addin.xml index 0d44082..85742a1 100644 --- a/bin/OpenSim.Grid.GridServer.addin.xml +++ b/bin/OpenSim.Grid.GridServer.addin.xml @@ -1,8 +1,9 @@ + - + diff --git a/bin/OpenSim.addin.xml b/bin/OpenSim.addin.xml index 7f8b258..122a1a8 100644 --- a/bin/OpenSim.addin.xml +++ b/bin/OpenSim.addin.xml @@ -1,8 +1,9 @@ + - + diff --git a/bin/RemoteAdminPlugin.addin.xml b/bin/RemoteAdminPlugin.addin.xml index cb82ee0..a0b8bee 100644 --- a/bin/RemoteAdminPlugin.addin.xml +++ b/bin/RemoteAdminPlugin.addin.xml @@ -6,6 +6,6 @@ - + diff --git a/bin/RestHandler.addin.xml b/bin/RestHandler.addin.xml index 1727c3b..33a1484 100644 --- a/bin/RestHandler.addin.xml +++ b/bin/RestHandler.addin.xml @@ -6,6 +6,6 @@ - + diff --git a/bin/RestRegionPlugin.addin.xml b/bin/RestRegionPlugin.addin.xml index 91a6dd6..9fc8e6b 100644 --- a/bin/RestRegionPlugin.addin.xml +++ b/bin/RestRegionPlugin.addin.xml @@ -6,6 +6,6 @@ - + -- cgit v1.1