aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/PluginLoader.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-07-30 08:17:19 +0000
committerAdam Frisby2008-07-30 08:17:19 +0000
commit2f8acdbe5073c21ab49ac0865eecd10db401eb32 (patch)
treed44b914e5e8103d93ea1cca8707b88b792d8ec04 /OpenSim/Framework/PluginLoader.cs
parentcleanups and refactoring to make it more readable. (diff)
downloadopensim-SC-2f8acdbe5073c21ab49ac0865eecd10db401eb32.zip
opensim-SC-2f8acdbe5073c21ab49ac0865eecd10db401eb32.tar.gz
opensim-SC-2f8acdbe5073c21ab49ac0865eecd10db401eb32.tar.bz2
opensim-SC-2f8acdbe5073c21ab49ac0865eecd10db401eb32.tar.xz
* Applying Mantis #1852 - Plugin Provider refactoring. Courtesy of Ryan/Sempuki.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/PluginLoader.cs67
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
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Xml;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.Reflection; 32using System.Reflection;
32using log4net; 33using 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}