29 using System.Collections.Generic;
30 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
39 namespace OpenSim.ApplicationPlugins.RegionModulesController
41 [Extension(Path =
"/OpenSim/Startup", Id =
"LoadRegions", NodeName =
"Plugin")]
46 private static readonly ILog m_log =
48 MethodBase.GetCurrentMethod().DeclaringType);
54 public bool LoadModulesFromAddins {
get; set; }
60 private string m_name;
63 private List<TypeExtensionNode> m_nonSharedModules =
64 new List<TypeExtensionNode>();
65 private List<TypeExtensionNode> m_sharedModules =
66 new List<TypeExtensionNode>();
69 private List<ISharedRegionModule> m_sharedInstances =
70 new List<ISharedRegionModule>();
74 LoadModulesFromAddins =
true;
77 #region IApplicationPlugin implementation
83 m_log.DebugFormat(
"[REGIONMODULES]: Initializing...");
85 if (!LoadModulesFromAddins)
89 string id = AddinManager.CurrentAddin.Id;
92 int pos = id.LastIndexOf(
".");
96 m_name = id.Substring(pos + 1);
99 IConfig modulesConfig =
100 m_openSim.ConfigSource.Source.Configs[
"Modules"];
101 if (modulesConfig == null)
102 modulesConfig = m_openSim.ConfigSource.Source.AddConfig(
"Modules");
104 Dictionary<RuntimeAddin, IList<int>> loadedModules =
new Dictionary<RuntimeAddin, IList<int>>();
107 foreach (TypeExtensionNode node
in AddinManager.GetExtensionNodes(
"/OpenSim/RegionModules"))
108 AddNode(node, modulesConfig, loadedModules);
110 foreach (KeyValuePair<RuntimeAddin, IList<int>> loadedModuleData
in loadedModules)
113 "[REGIONMODULES]: From plugin {0}, (version {1}), loaded {2} modules, {3} shared, {4} non-shared {5} unknown",
114 loadedModuleData.Key.Id,
115 loadedModuleData.Key.Version,
116 loadedModuleData.Value[0] + loadedModuleData.Value[1] + loadedModuleData.Value[2],
117 loadedModuleData.Value[0], loadedModuleData.Value[1], loadedModuleData.Value[2]);
127 foreach (TypeExtensionNode node
in m_sharedModules)
132 string moduleString =
133 modulesConfig.GetString(
"Setup_" + node.Id, String.Empty);
135 if (moduleString ==
"disabled")
139 if (moduleString !=
String.Empty)
142 string[] moduleParts = moduleString.Split(
new char[] {
'/' },
144 if (moduleParts.Length > 1)
145 ctorArgs[0] = Convert.ToUInt32(moduleParts[0]);
155 node.Type, ctorArgs);
164 m_sharedInstances.Add(module);
165 module.Initialise(m_openSim.ConfigSource.Source);
171 m_log.DebugFormat(
"[REGIONMODULES]: PostInitializing...");
176 module.PostInitialise();
182 #region IPlugin implementation
184 private void AddNode(
185 TypeExtensionNode node, IConfig modulesConfig, Dictionary<RuntimeAddin, IList<int>> loadedModules)
187 IList<int> loadedModuleData;
189 if (!loadedModules.ContainsKey(node.Addin))
190 loadedModules.Add(node.Addin,
new List<int> { 0, 0, 0 });
192 loadedModuleData = loadedModules[node.Addin];
196 if (CheckModuleEnabled(node, modulesConfig))
198 m_log.DebugFormat(
"[REGIONMODULES]: Found shared region module {0}, class {1}", node.Id, node.Type);
199 m_sharedModules.Add(node);
200 loadedModuleData[0]++;
205 if (CheckModuleEnabled(node, modulesConfig))
207 m_log.DebugFormat(
"[REGIONMODULES]: Found non-shared region module {0}, class {1}", node.Id, node.Type);
208 m_nonSharedModules.Add(node);
209 loadedModuleData[1]++;
214 m_log.WarnFormat(
"[REGIONMODULES]: Found unknown type of module {0}, class {1}", node.Id, node.Type);
215 loadedModuleData[2]++;
223 throw new System.NotImplementedException();
228 #region IDisposable implementation
235 while (m_sharedInstances.Count > 0)
237 m_sharedInstances[0].Close();
238 m_sharedInstances.RemoveAt(0);
241 m_sharedModules.Clear();
242 m_nonSharedModules.Clear();
247 public string Version
251 return AddinManager.CurrentAddin.Version;
263 #region Region Module interfacesController implementation
274 string moduleString =
275 modulesConfig.GetString(
"Setup_" + node.Id, String.Empty);
278 if (moduleString !=
String.Empty)
282 if (moduleString ==
"disabled")
286 string[] moduleParts = moduleString.Split(
new char[] {
'/' }, 2);
288 string className = moduleParts[0];
289 if (moduleParts.Length > 1)
290 className = moduleParts[1];
293 if (className !=
String.Empty &&
294 node.Type.ToString() != className)
308 Dictionary<Type, ISharedRegionModule> deferredSharedModules =
309 new Dictionary<Type, ISharedRegionModule>();
310 Dictionary<Type, INonSharedRegionModule> deferredNonSharedModules =
311 new Dictionary<Type, INonSharedRegionModule>();
316 Type s = scene.GetType();
317 MethodInfo mi = s.GetMethod(
"RequestModuleInterface");
320 List<ISharedRegionModule> sharedlist =
321 new List<ISharedRegionModule>();
333 Type replaceableInterface = module.ReplaceableInterface;
334 if (replaceableInterface != null)
336 MethodInfo mii = mi.MakeGenericMethod(replaceableInterface);
338 if (mii.Invoke(scene,
new object[0]) != null)
340 m_log.DebugFormat(
"[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString());
344 deferredSharedModules[replaceableInterface] = module;
345 m_log.DebugFormat(
"[REGIONMODULE]: Deferred load of {0}", module.Name);
349 m_log.DebugFormat(
"[REGIONMODULE]: Adding scene {0} to shared module {1}",
350 scene.RegionInfo.RegionName, module.Name);
352 module.AddRegion(scene);
353 scene.AddRegionModule(module.Name, module);
355 sharedlist.Add(module);
358 IConfig modulesConfig =
359 m_openSim.ConfigSource.Source.Configs[
"Modules"];
362 List<INonSharedRegionModule> list =
new List<INonSharedRegionModule>();
363 foreach (TypeExtensionNode node
in m_nonSharedModules)
368 string moduleString =
369 modulesConfig.GetString(
"Setup_" + node.Id, String.Empty);
372 if (moduleString ==
"disabled")
376 if (moduleString !=
String.Empty)
379 string[] moduleParts = moduleString.Split(
new char[] {
'/'},
381 if (moduleParts.Length > 1)
382 ctorArgs[0] = Convert.ToUInt32(moduleParts[0]);
388 Type[] ctorParamTypes =
new Type[ctorArgs.Length];
389 for (
int i = 0; i < ctorParamTypes.Length; i++)
390 ctorParamTypes[i] = ctorArgs[i].GetType();
392 if (node.Type.GetConstructor(ctorParamTypes) != null)
398 Type replaceableInterface = module.ReplaceableInterface;
399 if (replaceableInterface != null)
401 MethodInfo mii = mi.MakeGenericMethod(replaceableInterface);
403 if (mii.Invoke(scene,
new object[0]) != null)
405 m_log.DebugFormat(
"[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString());
409 deferredNonSharedModules[replaceableInterface] = module;
410 m_log.DebugFormat(
"[REGIONMODULE]: Deferred load of {0}", module.Name);
414 m_log.DebugFormat(
"[REGIONMODULE]: Adding scene {0} to non-shared module {1}",
415 scene.RegionInfo.RegionName, module.Name);
418 module.Initialise(m_openSim.ConfigSource.Source);
429 module.AddRegion(scene);
430 scene.AddRegionModule(module.Name, module);
439 Type replaceableInterface = module.ReplaceableInterface;
440 MethodInfo mii = mi.MakeGenericMethod(replaceableInterface);
442 if (mii.Invoke(scene,
new object[0]) != null)
444 m_log.DebugFormat(
"[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString());
448 m_log.DebugFormat(
"[REGIONMODULE]: Adding scene {0} to shared module {1} (deferred)",
449 scene.RegionInfo.RegionName, module.Name);
452 module.AddRegion(scene);
453 scene.AddRegionModule(module.Name, module);
455 sharedlist.Add(module);
459 List<INonSharedRegionModule> deferredlist =
460 new List<INonSharedRegionModule>();
465 Type replaceableInterface = module.ReplaceableInterface;
466 if (replaceableInterface != null)
468 MethodInfo mii = mi.MakeGenericMethod(replaceableInterface);
470 if (mii.Invoke(scene,
new object[0]) != null)
472 m_log.DebugFormat(
"[REGIONMODULE]: Not loading {0} because another module has registered {1}", module.Name, replaceableInterface.ToString());
477 m_log.DebugFormat(
"[REGIONMODULE]: Adding scene {0} to non-shared module {1} (deferred)",
478 scene.RegionInfo.RegionName, module.Name);
480 module.Initialise(m_openSim.ConfigSource.Source);
483 deferredlist.Add(module);
489 module.AddRegion(scene);
490 scene.AddRegionModule(module.Name, module);
505 module.RegionLoaded(scene);
510 module.RegionLoaded(scene);
513 scene.AllModulesLoaded();
520 m_log.DebugFormat(
"[REGIONMODULE]: Removing scene {0} from module {1}",
521 scene.RegionInfo.RegionName, module.Name);
522 module.RemoveRegion(scene);
529 scene.RegionModules.Clear();
void Initialise(OpenSimBase openSim)
Initialize the Plugin
OpenSimulator Application Plugin framework interface
void RemoveRegionFromModules(Scene scene)
bool CheckModuleEnabled(TypeExtensionNode node, IConfig modulesConfig)
Check that the given module is no disabled in the [Modules] section of the config files...
void Initialise()
Default-initialises the plugin
RegionModulesControllerPlugin()
Interactive OpenSim region server
Common OpenSimulator simulator code
void AddRegionToModules(Scene scene)
void PostInitialise()
Called when the application loading is completed