X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=sidebyside;f=PluginManager.cs;h=551d5fdf56d4f88afa4b5018a7ce6841767f2d0a;hb=02acfc22dbfa3d145d265157fdf616a950fa30c6;hp=051c6ab13d43873986e2d0ff213a023d55aebd5c;hpb=ac127998500aa775484054cffa889098b3fd6a7b;p=WebThing.git diff --git a/PluginManager.cs b/PluginManager.cs index 051c6ab..551d5fd 100644 --- a/PluginManager.cs +++ b/PluginManager.cs @@ -6,11 +6,13 @@ using WebKit; namespace bytex64.WebThing { public class PluginManager { public Dictionary Plugins; + public List PluginOrder; private WebThing wt; public PluginManager(WebThing wt) { Plugins = new Dictionary(); + PluginOrder = new List(); this.wt = wt; } @@ -29,20 +31,54 @@ namespace bytex64.WebThing { p.Init(wt); Plugins[t.FullName] = p; Console.WriteLine("Successfully loaded {0}", t.FullName); + PluginOrder.Add(t.FullName); } } } public void WebViewSetup(WebView view) { - foreach (string key in Plugins.Keys) { + foreach (string key in PluginOrder) { Plugins[key].InitWebView(view); } } public void Deinit() { - foreach (WebThingPlugin p in Plugins.Values) { - p.Deinit(wt); + // This reverses the plugin order on the assumption that it + // will only be called once on program shutdown + PluginOrder.Reverse(); + foreach (string key in PluginOrder) { + Plugins[key].Deinit(wt); } } + + public bool Call(string funcname, params object[] args) { + bool found = false; + if (args.Length > 0) { + foreach (string key in PluginOrder) { + WebThingPlugin plugin = Plugins[key]; + Type ptype = plugin.GetType(); + + List types = new List(); + foreach (object o in args) + types.Add(o.GetType()); + + MethodInfo method = ptype.GetMethod(funcname, types.ToArray()); + if (method == null) continue; + method.Invoke(plugin, args); + found = true; + } + } else { + foreach (string key in PluginOrder) { + WebThingPlugin plugin = Plugins[key]; + Type ptype = plugin.GetType(); + + MethodInfo method = ptype.GetMethod(funcname, new Type[] {}); + if (method == null) continue; + method.Invoke(plugin, null); + found = true; + } + } + return found; + } } }