From c73ee1d06eb94c5c08691de2f353f7ef2964a67c Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 6 Aug 2009 01:10:45 +0100 Subject: Complete the work on the Replaceable interface logic. From this commit onwards the mere presence of a full version of a replaceable module will cause the replaceable module in core to be deactivated. --- .../RegionModulesControllerPlugin.cs | 103 ++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) (limited to 'OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs') diff --git a/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs b/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs index 9f7abd0..6331519 100644 --- a/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs +++ b/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs @@ -149,21 +149,68 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController public void AddRegionToModules (Scene scene) { + Dictionary deferredSharedModules = + new Dictionary(); + Dictionary deferredNonSharedModules = + new Dictionary(); + + Type s = scene.GetType(); + MethodInfo mi = s.GetMethod("RequestModuleInterface"); + + List sharedlist = new List(); foreach (ISharedRegionModule module in m_sharedInstances) { + Type replaceableInterface = module.ReplacableInterface; + if (replaceableInterface != null) + { + MethodInfo mii = mi.MakeGenericMethod(replaceableInterface); + + if (mii.Invoke(scene, new object[0]) != null) + { + m_log.DebugFormat("[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString()); + continue; + } + + deferredSharedModules[replaceableInterface] = module; + m_log.DebugFormat("[REGIONMODULE]: Deferred load of {0}", module.Name); + continue; + } + m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to shared module {1}", scene.RegionInfo.RegionName, module.Name); + module.AddRegion(scene); scene.AddRegionModule(module.Name, module); + + sharedlist.Add(module); } List list = new List(); foreach (Type type in m_nonSharedModules) { INonSharedRegionModule module = (INonSharedRegionModule)Activator.CreateInstance(type); + + Type replaceableInterface = module.ReplacableInterface; + if (replaceableInterface != null) + { + MethodInfo mii = mi.MakeGenericMethod(replaceableInterface); + + if (mii.Invoke(scene, new object[0]) != null) + { + m_log.DebugFormat("[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString()); + continue; + } + + deferredNonSharedModules[replaceableInterface] = module; + m_log.DebugFormat("[REGIONMODULE]: Deferred load of {0}", module.Name); + continue; + } + m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to non-shared module {1}", scene.RegionInfo.RegionName, module.Name); + module.Initialise(m_openSim.ConfigSource.Source); + list.Add(module); } @@ -173,6 +220,60 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController scene.AddRegionModule(module.Name, module); } + // Now all modules without a replaceable base interface are loaded + // Replaceable modules have either been skipped, or omitted. + // Now scan the deferred modules here + + foreach (ISharedRegionModule module in deferredSharedModules.Values) + { + Type replaceableInterface = module.ReplacableInterface; + MethodInfo mii = mi.MakeGenericMethod(replaceableInterface); + + if (mii.Invoke(scene, new object[0]) != null) + { + m_log.DebugFormat("[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString()); + continue; + } + + m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to shared module {1} (deferred)", + scene.RegionInfo.RegionName, module.Name); + + module.AddRegion(scene); + scene.AddRegionModule(module.Name, module); + + sharedlist.Add(module); + } + + List deferredlist = new List(); + foreach (INonSharedRegionModule module in deferredNonSharedModules.Values) + { + Type replaceableInterface = module.ReplacableInterface; + if (replaceableInterface != null) + { + MethodInfo mii = mi.MakeGenericMethod(replaceableInterface); + + if (mii.Invoke(scene, new object[0]) != null) + { + m_log.DebugFormat("[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString()); + continue; + } + } + + m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to non-shared module {1} (deferred)", + scene.RegionInfo.RegionName, module.Name); + + module.Initialise(m_openSim.ConfigSource.Source); + + list.Add(module); + deferredlist.Add(module); + } + + foreach (INonSharedRegionModule module in deferredlist) + { + module.AddRegion(scene); + scene.AddRegionModule(module.Name, module); + } + // This is needed for all module types. Modules will register // Interfaces with scene in AddScene, and will also need a means // to access interfaces registered by other modules. Without @@ -183,7 +284,7 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController // and unneccessary caching logic repeated in all modules. // The extra function stub is just that much cleaner // - foreach (ISharedRegionModule module in m_sharedInstances) + foreach (ISharedRegionModule module in sharedlist) { module.RegionLoaded(scene); } -- cgit v1.1