diff options
author | Adam Frisby | 2008-07-30 08:17:19 +0000 |
---|---|---|
committer | Adam Frisby | 2008-07-30 08:17:19 +0000 |
commit | 2f8acdbe5073c21ab49ac0865eecd10db401eb32 (patch) | |
tree | d44b914e5e8103d93ea1cca8707b88b792d8ec04 /OpenSim/Framework | |
parent | cleanups and refactoring to make it more readable. (diff) | |
download | opensim-SC_OLD-2f8acdbe5073c21ab49ac0865eecd10db401eb32.zip opensim-SC_OLD-2f8acdbe5073c21ab49ac0865eecd10db401eb32.tar.gz opensim-SC_OLD-2f8acdbe5073c21ab49ac0865eecd10db401eb32.tar.bz2 opensim-SC_OLD-2f8acdbe5073c21ab49ac0865eecd10db401eb32.tar.xz |
* Applying Mantis #1852 - Plugin Provider refactoring. Courtesy of Ryan/Sempuki.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/PluginLoader.cs | 67 |
1 files changed, 50 insertions, 17 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 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Xml; | ||
30 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
31 | using System.Reflection; | 32 | using System.Reflection; |
32 | using log4net; | 33 | using log4net; |
@@ -61,7 +62,7 @@ namespace OpenSim.Framework | |||
61 | /// </summary> | 62 | /// </summary> |
62 | public interface IPluginFilter | 63 | public interface IPluginFilter |
63 | { | 64 | { |
64 | bool Apply (ExtensionNode plugin); | 65 | bool Apply (PluginExtensionNode plugin); |
65 | } | 66 | } |
66 | 67 | ||
67 | /// <summary> | 68 | /// <summary> |
@@ -152,7 +153,7 @@ namespace OpenSim.Framework | |||
152 | if (filters.ContainsKey (ext)) | 153 | if (filters.ContainsKey (ext)) |
153 | filter = filters [ext]; | 154 | filter = filters [ext]; |
154 | 155 | ||
155 | foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (ext)) | 156 | foreach (PluginExtensionNode node in AddinManager.GetExtensionNodes (ext)) |
156 | { | 157 | { |
157 | log.Info("[PLUGINS]: Trying plugin " + node.Path); | 158 | log.Info("[PLUGINS]: Trying plugin " + node.Path); |
158 | 159 | ||
@@ -197,9 +198,13 @@ namespace OpenSim.Framework | |||
197 | 198 | ||
198 | private void on_addinloaderror_(object sender, AddinErrorEventArgs args) | 199 | private void on_addinloaderror_(object sender, AddinErrorEventArgs args) |
199 | { | 200 | { |
200 | log.Error ("[PLUGINS]: Plugin Error: " + args.Message | 201 | if (args.Exception == null) |
201 | + ": " + args.Exception.Message | 202 | log.Error ("[PLUGINS]: Plugin Error: " |
202 | + "\n"+ args.Exception.StackTrace); | 203 | + args.Message); |
204 | else | ||
205 | log.Error ("[PLUGINS]: Plugin Error: " | ||
206 | + args.Exception.Message + "\n" | ||
207 | + args.Exception.StackTrace); | ||
203 | } | 208 | } |
204 | 209 | ||
205 | private void clear_registry_ () | 210 | private void clear_registry_ () |
@@ -230,6 +235,39 @@ namespace OpenSim.Framework | |||
230 | } | 235 | } |
231 | } | 236 | } |
232 | 237 | ||
238 | public class PluginExtensionNode : ExtensionNode | ||
239 | { | ||
240 | [NodeAttribute] | ||
241 | string provider; | ||
242 | |||
243 | [NodeAttribute] | ||
244 | string type; | ||
245 | |||
246 | Type typeobj; | ||
247 | |||
248 | public string Provider { get { return provider; } } | ||
249 | public string TypeName { get { return type; } } | ||
250 | |||
251 | public Type TypeObject | ||
252 | { | ||
253 | get | ||
254 | { | ||
255 | if (typeobj != null) | ||
256 | return typeobj; | ||
257 | |||
258 | if (type.Length == 0) | ||
259 | throw new InvalidOperationException ("Type name not specified."); | ||
260 | |||
261 | return typeobj = Addin.GetType (type, true); | ||
262 | } | ||
263 | } | ||
264 | |||
265 | public object CreateInstance () | ||
266 | { | ||
267 | return Activator.CreateInstance (TypeObject); | ||
268 | } | ||
269 | } | ||
270 | |||
233 | /// <summary> | 271 | /// <summary> |
234 | /// Constraint that bounds the number of plugins to be loaded. | 272 | /// Constraint that bounds the number of plugins to be loaded. |
235 | /// </summary> | 273 | /// </summary> |
@@ -271,25 +309,20 @@ namespace OpenSim.Framework | |||
271 | } | 309 | } |
272 | 310 | ||
273 | /// <summary> | 311 | /// <summary> |
274 | /// Filters out which plugin to load based on its "Id", which is name given by the namespace or by Mono.Addins. | 312 | /// Filters out which plugin to load based on its "Provider", which is name given by in the addin.xml |
275 | /// </summary> | 313 | /// </summary> |
276 | public class PluginIdFilter : IPluginFilter | 314 | public class PluginProviderFilter : IPluginFilter |
277 | { | 315 | { |
278 | private string id; | 316 | private string provider; |
279 | 317 | ||
280 | public PluginIdFilter (string id) | 318 | public PluginProviderFilter (string p) |
281 | { | 319 | { |
282 | this.id = id; | 320 | provider = p; |
283 | } | 321 | } |
284 | 322 | ||
285 | public bool Apply (ExtensionNode plugin) | 323 | public bool Apply (PluginExtensionNode plugin) |
286 | { | 324 | { |
287 | System.Console.WriteLine ("[WTF]: " + plugin.Path); | 325 | return (plugin.Provider == provider); |
288 | |||
289 | if (plugin.HasId == false) | ||
290 | return false; | ||
291 | |||
292 | return (plugin.Id == id); | ||
293 | } | 326 | } |
294 | } | 327 | } |
295 | } | 328 | } |