From 8c130bcaf5a60fa042d8df38ba1d1e1cb328d768 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 12 Nov 2012 22:50:28 +0000 Subject: Remove the old style module loader and all references to it --- OpenSim/Region/Framework/ModuleLoader.cs | 262 ------------------------ OpenSim/Region/Framework/Scenes/Scene.cs | 4 +- OpenSim/Region/Framework/Scenes/SceneBase.cs | 80 +------- OpenSim/Region/Framework/Scenes/SceneManager.cs | 16 -- 4 files changed, 12 insertions(+), 350 deletions(-) delete mode 100644 OpenSim/Region/Framework/ModuleLoader.cs (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/ModuleLoader.cs b/OpenSim/Region/Framework/ModuleLoader.cs deleted file mode 100644 index 14ecd44..0000000 --- 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 69c1027..db45d6b 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 b87a38a..d3e968e 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(); @@ -312,19 +296,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 cb5b2ba..992e71d 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) -- cgit v1.1