diff --git a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs index a8a3237389..fcb6991969 100644 --- a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs +++ b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs @@ -136,9 +136,6 @@ namespace OpenSim.ApplicationPlugins.LoadRegions } } } - - m_openSim.ModuleLoader.PostInitialise(); - m_openSim.ModuleLoader.ClearCache(); } public void Dispose() diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 2236e4388a..47252f69f4 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -757,33 +757,13 @@ namespace OpenSim switch (cmdparams[0].ToLower()) { case "list": - foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules) - { - MainConsole.Instance.Output(String.Format("Shared region module: {0}", irm.Name)); - } + //TODO: Convert to new region modules break; case "unload": - if (cmdparams.Length > 1) - { - foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules)) - { - if (rm.Name.ToLower() == cmdparams[1].ToLower()) - { - MainConsole.Instance.Output(String.Format("Unloading module: {0}", rm.Name)); - m_moduleLoader.UnloadModule(rm); - } - } - } + //TODO: Convert to new region modules break; case "load": - if (cmdparams.Length > 1) - { - foreach (Scene s in new ArrayList(SceneManager.Scenes)) - { - MainConsole.Instance.Output(String.Format("Loading module: {0}", cmdparams[1])); - m_moduleLoader.LoadRegionModules(cmdparams[1], s); - } - } + //TODO: Convert to new region modules break; } } @@ -1018,28 +998,9 @@ namespace OpenSim break; case "modules": - MainConsole.Instance.Output("The currently loaded shared modules are:"); - foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules) - { - MainConsole.Instance.Output("Shared Module: " + module.Name); - } - SceneManager.ForEachScene( delegate(Scene scene) { - m_log.Error("The currently loaded modules in " + scene.RegionInfo.RegionName + " are:"); - foreach (IRegionModule module in scene.Modules.Values) - { - if (!module.IsSharedModule) - { - m_log.Error("Region Module: " + module.Name); - } - } - } - ); - - SceneManager.ForEachScene( - delegate(Scene scene) { - MainConsole.Instance.Output("Loaded new region modules in" + scene.RegionInfo.RegionName + " are:"); + MainConsole.Instance.Output("Loaded region modules in" + scene.RegionInfo.RegionName + " are:"); foreach (IRegionModuleBase module in scene.RegionModules.Values) { Type type = module.GetType().GetInterface("ISharedRegionModule"); diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 7b591a88be..a3d6820d57 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -127,14 +127,6 @@ namespace OpenSim get { return m_httpServerPort; } } - public ModuleLoader ModuleLoader - { - get { return m_moduleLoader; } - set { m_moduleLoader = value; } - } - - protected ModuleLoader m_moduleLoader; - protected IRegistryCore m_applicationRegistry = new RegistryCore(); public IRegistryCore ApplicationRegistry @@ -223,9 +215,6 @@ namespace OpenSim base.StartupSpecific(); - // Create a ModuleLoader instance - m_moduleLoader = new ModuleLoader(m_config.Source); - LoadPlugins(); foreach (IApplicationPlugin plugin in m_plugins) { @@ -370,12 +359,6 @@ namespace OpenSim m_log.Info("[MODULES]: Loading Region's modules (old style)"); - List modules = m_moduleLoader.PickupModules(scene, "."); - - // This needs to be ahead of the script engine load, so the - // script module can pick up events exposed by a module - m_moduleLoader.InitialiseSharedModules(scene); - // Use this in the future, the line above will be deprecated soon m_log.Info("[REGIONMODULES]: Loading Region's modules (new style)"); IRegionModulesController controller; @@ -426,13 +409,6 @@ namespace OpenSim clientServer.Start(); } - if (do_post_init) - { - foreach (IRegionModule module in modules) - { - module.PostInitialise(); - } - } scene.EventManager.OnShutdown += delegate() { ShutdownRegion(scene); }; mscene = scene; @@ -722,7 +698,7 @@ namespace OpenSim return new Scene( regionInfo, circuitManager, sceneGridService, - simDataService, estateDataService, m_moduleLoader, false, + simDataService, estateDataService, false, m_config.Source, m_version); } diff --git a/OpenSim/Region/Framework/ModuleLoader.cs b/OpenSim/Region/Framework/ModuleLoader.cs deleted file mode 100644 index 14ecd4430a..0000000000 --- a/OpenSim/Region/Framework/ModuleLoader.cs +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using log4net; -using Nini.Config; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.Framework -{ - public class ModuleLoader - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - public Dictionary LoadedAssemblys = new Dictionary(); - - private readonly List m_loadedModules = new List(); - private readonly Dictionary m_loadedSharedModules = new Dictionary(); - private readonly IConfigSource m_config; - - public ModuleLoader(IConfigSource config) - { - m_config = config; - } - - public IRegionModule[] GetLoadedSharedModules - { - get - { - IRegionModule[] regionModules = new IRegionModule[m_loadedSharedModules.Count]; - m_loadedSharedModules.Values.CopyTo(regionModules, 0); - return regionModules; - } - } - - public List PickupModules(Scene scene, string moduleDir) - { - DirectoryInfo dir = new DirectoryInfo(moduleDir); - List modules = new List(); - - foreach (FileInfo fileInfo in dir.GetFiles("*.dll")) - { - modules.AddRange(LoadRegionModules(fileInfo.FullName, scene)); - } - return modules; - } - - public void LoadDefaultSharedModule(IRegionModule module) - { - if (m_loadedSharedModules.ContainsKey(module.Name)) - { - m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module not added!", module.Name); - } - else - { - m_loadedSharedModules.Add(module.Name, module); - } - } - - - public void InitialiseSharedModules(Scene scene) - { - foreach (IRegionModule module in m_loadedSharedModules.Values) - { - module.Initialise(scene, m_config); - scene.AddModule(module.Name, module); //should be doing this? - } - } - - public void InitializeModule(IRegionModule module, Scene scene) - { - module.Initialise(scene, m_config); - scene.AddModule(module.Name, module); - m_loadedModules.Add(module); - } - - /// - /// Loads/initialises a Module instance that can be used by multiple Regions - /// - /// - /// - public void LoadSharedModule(string dllName, string moduleName) - { - IRegionModule module = LoadModule(dllName, moduleName); - - if (module != null) - LoadSharedModule(module); - } - - /// - /// Loads/initialises a Module instance that can be used by multiple Regions - /// - /// - public void LoadSharedModule(IRegionModule module) - { - if (!m_loadedSharedModules.ContainsKey(module.Name)) - { - m_loadedSharedModules.Add(module.Name, module); - } - } - - public List LoadRegionModules(string dllName, Scene scene) - { - IRegionModule[] modules = LoadModules(dllName); - List initializedModules = new List(); - - if (modules.Length > 0) - { - m_log.InfoFormat("[MODULES]: Found Module Library [{0}]", dllName); - foreach (IRegionModule module in modules) - { - if (!module.IsSharedModule) - { - m_log.InfoFormat("[MODULES]: [{0}]: Initializing.", module.Name); - InitializeModule(module, scene); - initializedModules.Add(module); - } - else - { - m_log.InfoFormat("[MODULES]: [{0}]: Loading Shared Module.", module.Name); - LoadSharedModule(module); - } - } - } - return initializedModules; - } - - public void LoadRegionModule(string dllName, string moduleName, Scene scene) - { - IRegionModule module = LoadModule(dllName, moduleName); - if (module != null) - { - InitializeModule(module, scene); - } - } - - /// - /// Loads a external Module (if not already loaded) and creates a new instance of it. - /// - /// - /// - public IRegionModule LoadModule(string dllName, string moduleName) - { - IRegionModule[] modules = LoadModules(dllName); - - foreach (IRegionModule module in modules) - { - if ((module != null) && (module.Name == moduleName)) - { - return module; - } - } - - return null; - } - - public IRegionModule[] LoadModules(string dllName) - { - //m_log.DebugFormat("[MODULES]: Looking for modules in {0}", dllName); - - List modules = new List(); - - Assembly pluginAssembly; - if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly)) - { - try - { - pluginAssembly = Assembly.LoadFrom(dllName); - LoadedAssemblys.Add(dllName, pluginAssembly); - } - catch (BadImageFormatException) - { - //m_log.InfoFormat("[MODULES]: The file [{0}] is not a module assembly.", e.FileName); - } - } - - if (pluginAssembly != null) - { - try - { - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (pluginType.IsPublic) - { - if (!pluginType.IsAbstract) - { - if (pluginType.GetInterface("IRegionModule") != null) - { - modules.Add((IRegionModule)Activator.CreateInstance(pluginType)); - } - } - } - } - } - catch (Exception e) - { - m_log.ErrorFormat( - "[MODULES]: Could not load types for plugin DLL {0}. Exception {1} {2}", - pluginAssembly.FullName, e.Message, e.StackTrace); - - // justincc: Right now this is fatal to really get the user's attention - throw e; - } - } - - return modules.ToArray(); - } - - public void PostInitialise() - { - foreach (IRegionModule module in m_loadedSharedModules.Values) - { - module.PostInitialise(); - } - - foreach (IRegionModule module in m_loadedModules) - { - module.PostInitialise(); - } - } - - public void ClearCache() - { - LoadedAssemblys.Clear(); - } - - public void UnloadModule(IRegionModule rm) - { - rm.Close(); - - m_loadedModules.Remove(rm); - } - } -} diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 69c10273c0..db45d6b4f3 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -176,7 +176,6 @@ namespace OpenSim.Region.Framework.Scenes protected List m_regionRestartNotifyList = new List(); protected List m_neighbours = new List(); protected string m_simulatorVersion = "OpenSimulator Server"; - protected ModuleLoader m_moduleLoader; protected AgentCircuitManager m_authenticateHandler; protected SceneCommunicationService m_sceneGridService; @@ -659,7 +658,7 @@ namespace OpenSim.Region.Framework.Scenes public Scene(RegionInfo regInfo, AgentCircuitManager authen, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, - ModuleLoader moduleLoader, bool dumpAssetsToFile, + bool dumpAssetsToFile, IConfigSource config, string simulatorVersion) : this(regInfo) { @@ -670,7 +669,6 @@ namespace OpenSim.Region.Framework.Scenes Random random = new Random(); m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue / 2)) + (uint)(uint.MaxValue / 4); - m_moduleLoader = moduleLoader; m_authenticateHandler = authen; m_sceneGridService = sceneGridService; m_SimulationDataService = simDataService; diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index b87a38a335..d3e968e531 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -67,12 +67,6 @@ namespace OpenSim.Region.Framework.Scenes /// /// All the region modules attached to this scene. /// - public Dictionary Modules - { - get { return m_modules; } - } - protected Dictionary m_modules = new Dictionary(); - public Dictionary RegionModules { get { return m_regionModules; } @@ -272,16 +266,6 @@ namespace OpenSim.Region.Framework.Scenes /// public virtual void Close() { - // Shut down all non shared modules. - foreach (IRegionModule module in Modules.Values) - { - if (!module.IsSharedModule) - { - module.Close(); - } - } - Modules.Clear(); - try { EventManager.TriggerShutdown(); @@ -311,19 +295,6 @@ namespace OpenSim.Region.Framework.Scenes #region Module Methods - /// - /// Add a module to this scene. - /// - /// - /// - public void AddModule(string name, IRegionModule module) - { - if (!Modules.ContainsKey(name)) - { - Modules.Add(name, module); - } - } - /// /// Add a region-module to this scene. TODO: This will replace AddModule in the future. /// @@ -508,9 +479,9 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - public void AddCommand(object mod, string command, string shorthelp, string longhelp, CommandDelegate callback) + public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback) { - AddCommand(mod, command, shorthelp, longhelp, string.Empty, callback); + AddCommand(module, command, shorthelp, longhelp, string.Empty, callback); } /// @@ -528,9 +499,9 @@ namespace OpenSim.Region.Framework.Scenes /// /// public void AddCommand( - string category, object mod, string command, string shorthelp, string longhelp, CommandDelegate callback) + string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback) { - AddCommand(category, mod, command, shorthelp, longhelp, string.Empty, callback); + AddCommand(category, module, command, shorthelp, longhelp, string.Empty, callback); } /// @@ -542,29 +513,14 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - public void AddCommand(object mod, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback) + public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback) { string moduleName = ""; - if (mod != null) - { - if (mod is IRegionModule) - { - IRegionModule module = (IRegionModule)mod; - moduleName = module.Name; - } - else if (mod is IRegionModuleBase) - { - IRegionModuleBase module = (IRegionModuleBase)mod; - moduleName = module.Name; - } - else - { - throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase"); - } - } + if (module != null) + moduleName = module.Name; - AddCommand(moduleName, mod, command, shorthelp, longhelp, descriptivehelp, callback); + AddCommand(moduleName, module, command, shorthelp, longhelp, descriptivehelp, callback); } /// @@ -580,7 +536,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// public void AddCommand( - string category, object mod, string command, + string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback) { if (MainConsole.Instance == null) @@ -588,22 +544,8 @@ namespace OpenSim.Region.Framework.Scenes bool shared = false; - if (mod != null) - { - if (mod is IRegionModule) - { - IRegionModule module = (IRegionModule)mod; - shared = module.IsSharedModule; - } - else if (mod is IRegionModuleBase) - { - shared = mod is ISharedRegionModule; - } - else - { - throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase"); - } - } + if (module != null) + shared = module is ISharedRegionModule; MainConsole.Instance.Commands.AddCommand( category, shared, command, shorthelp, longhelp, descriptivehelp, callback); diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index cb5b2ba9b2..992e71df2e 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -144,22 +144,6 @@ namespace OpenSim.Region.Framework.Scenes // collect known shared modules in sharedModules Dictionary sharedModules = new Dictionary(); - lock (m_localScenes) - { - for (int i = 0; i < m_localScenes.Count; i++) - { - // extract known shared modules from scene - foreach (string k in m_localScenes[i].Modules.Keys) - { - if (m_localScenes[i].Modules[k].IsSharedModule && - !sharedModules.ContainsKey(k)) - sharedModules[k] = m_localScenes[i].Modules[k]; - } - // close scene/region - m_localScenes[i].Close(); - } - } - // all regions/scenes are now closed, we can now safely // close all shared modules foreach (IRegionModule mod in sharedModules.Values) diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs index c424439ebc..939fc33f70 100644 --- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs @@ -139,7 +139,7 @@ namespace OpenSim.Tests.Common SceneCommunicationService scs = new SceneCommunicationService(); TestScene testScene = new TestScene( - regInfo, m_acm, scs, m_simDataService, m_estateDataService, null, false, configSource, null); + regInfo, m_acm, scs, m_simDataService, m_estateDataService, false, configSource, null); INonSharedRegionModule godsModule = new GodsModule(); godsModule.Initialise(new IniConfigSource()); diff --git a/OpenSim/Tests/Common/Mock/TestScene.cs b/OpenSim/Tests/Common/Mock/TestScene.cs index eea68c3b40..d4b564869b 100644 --- a/OpenSim/Tests/Common/Mock/TestScene.cs +++ b/OpenSim/Tests/Common/Mock/TestScene.cs @@ -41,9 +41,9 @@ namespace OpenSim.Tests.Common.Mock public TestScene( RegionInfo regInfo, AgentCircuitManager authen, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, - ModuleLoader moduleLoader, bool dumpAssetsToFile, + bool dumpAssetsToFile, IConfigSource config, string simulatorVersion) - : base(regInfo, authen, sceneGridService, simDataService, estateDataService, moduleLoader, + : base(regInfo, authen, sceneGridService, simDataService, estateDataService, dumpAssetsToFile, config, simulatorVersion) { } @@ -73,4 +73,4 @@ namespace OpenSim.Tests.Common.Mock get { return m_asyncSceneObjectDeleter; } } } -} \ No newline at end of file +}