From 35fa8b454dab41fd54f846a3e58b79c13dd11fce Mon Sep 17 00:00:00 2001 From: BlueWall Date: Mon, 9 Apr 2012 17:53:55 -0400 Subject: [PATCH] Working on run-time init Working on build-up and tear-down for loading/unloading pluggins --- .../IntegrationServiceBase.cs | 54 +++++++++++++++++-- .../IntegrationService/PluginManager.cs | 30 ++++++++++- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs b/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs index 6d6c777229..55d8c5446c 100644 --- a/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs +++ b/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs @@ -52,19 +52,28 @@ namespace OpenSim.Services.IntegrationService string DefaultConfig { get; } } - public class IntegrationServiceBase : ServiceBase + // Hide the nasty stuff in here, let the IntegrationService be clean for + // our command and request handlers + public class IntegrationServiceBase : ServiceBase { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private string m_ConfigName = "IntegrationService"; - protected IPresenceService m_PresenceService; - protected IGridService m_GridService; + // protected IPresenceService m_PresenceService; + // protected IGridService m_GridService; protected IHttpServer m_Server; + protected string m_IntegrationConfig; protected PluginManager m_PluginManager; - IConfig m_IntegrationServerConfig; - string m_IntegrationConfigLoc; + AddinManager am; + + // Our individual pluggin configs + protected IConfig m_IntegrationServerConfig; + protected string m_IntegrationConfigLoc; + + // Our server config + IConfigSource m_ConfigSource; public IntegrationServiceBase(IConfigSource config, IHttpServer server) : base(config) @@ -77,6 +86,7 @@ namespace OpenSim.Services.IntegrationService // defaults to the ./bin directory string RegistryLocation = serverConfig.GetString("PluginRegistryLocation", "."); + AddinRegistry registry = new AddinRegistry(RegistryLocation, "."); m_PluginManager = new PluginManager(registry); @@ -88,6 +98,7 @@ namespace OpenSim.Services.IntegrationService AddinManager.AddinLoaded += on_addinloaded_; AddinManager.AddinLoadError += on_addinloaderror_; AddinManager.AddinUnloaded += HandleAddinManagerAddinUnloaded; + AddinManager.AddinEngine.ExtensionChanged += HandleAddinManagerAddinEngineExtensionChanged; m_Server = server; m_IntegrationServerConfig = config.Configs["IntegrationService"]; @@ -102,6 +113,10 @@ namespace OpenSim.Services.IntegrationService AddinManager.Registry.Update (); suppress_console_output_(false); + + AddinManager.AddExtensionNodeHandler ("/OpenSim/IntegrationService", OnExtensionChanged); + + foreach (IntegrationPlugin cmd in AddinManager.GetExtensionObjects("/OpenSim/IntegrationService")) { string ConfigPath = String.Format("{0}/(1)", m_IntegrationConfigLoc,cmd.ConfigName); @@ -148,6 +163,11 @@ namespace OpenSim.Services.IntegrationService } } + void HandleAddinManagerAddinEngineExtensionChanged (object sender, ExtensionEventArgs args) + { + MainConsole.Instance.Output("Plugin Extension Change"); + } + private IConfigSource GetConfig(string configName) { return new IniConfigSource(); @@ -169,6 +189,30 @@ namespace OpenSim.Services.IntegrationService + args.Exception.StackTrace); } + // This is out init + // We can do build-up and tear-down of our plugin + void OnExtensionChanged (object s, ExtensionNodeEventArgs args) + { + IntegrationPlugin ip = (IntegrationPlugin) args.ExtensionObject; + + m_log.Info ("[INTEGRATION SERVICE]: Plugin Change"); + + switch (args.Change) + { + // Build up + case ExtensionChange.Add: + + m_log.InfoFormat("[INTEGRATION SERVICE]: Plugin Added {0}", ip.Name); + return; + + // Tear down + case ExtensionChange.Remove: + + m_log.InfoFormat("[INTEGRATION SERVICE]: Plugin Remove {0}", ip.Name); + return; + } + } + private void on_addinloaded_(object sender, AddinEventArgs args) { m_log.Info ("[INTEGRATION SERVICE]: Plugin Loaded: " + args.AddinId); diff --git a/OpenSim/Services/IntegrationService/PluginManager.cs b/OpenSim/Services/IntegrationService/PluginManager.cs index c226fa77ea..ecfee9842f 100644 --- a/OpenSim/Services/IntegrationService/PluginManager.cs +++ b/OpenSim/Services/IntegrationService/PluginManager.cs @@ -27,6 +27,7 @@ using System; using System.Text; +using System.Linq; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -260,11 +261,19 @@ namespace OpenSim.Services.IntegrationService m_Registry.Update(); } + // Show plugin info public string AddinInfo(string[] args) { + Addin[] addins = GetSortedAddinList("IntegrationPlugin"); - string id = args[2]; - Addin addin = Registry.GetAddin(id, true); + int n = Convert.ToInt16(args[2]); + if (n > (addins.Length -1)) + { + MainConsole.Instance.Output("Selection out of range"); + return "XXX"; + } + + Addin addin = addins[n]; MainConsole.Instance.OutputFormat("Name: {0}\nURL: {1}\n{2}", addin.Name, addin.Description.Url, addin.Description.FileName); @@ -304,16 +313,33 @@ namespace OpenSim.Services.IntegrationService Addin addin = addins[n]; addin.Enabled = true; + AddinManager.Registry.EnableAddin(addin.Id); + AddinManager.Registry.Update(); + AddinManager.AddinEngine.LoadAddin(null, addin.Id); return; } #region Util + private void Testing() + { + Addin[] list = Registry.GetAddins(); + + var addins = list.Where( a => a.Description.Category == "IntegrationPlugin"); + + foreach (Addin addin in addins) + { + MainConsole.Instance.OutputFormat("Addin {0}", addin.Name); + } + } + private Addin[] GetSortedAddinList(string category) { ArrayList list = new ArrayList(); list.AddRange(m_Registry.GetAddins()); ArrayList xlist = new ArrayList(); + + foreach (Addin addin in list) { if (addin.Description.Category == category)