aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/ModuleLoader.cs262
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneBase.cs80
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs16
4 files changed, 12 insertions, 350 deletions
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 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using log4net;
33using Nini.Config;
34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes;
36
37namespace OpenSim.Region.Framework
38{
39 public class ModuleLoader
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>();
44
45 private readonly List<IRegionModule> m_loadedModules = new List<IRegionModule>();
46 private readonly Dictionary<string, IRegionModule> m_loadedSharedModules = new Dictionary<string, IRegionModule>();
47 private readonly IConfigSource m_config;
48
49 public ModuleLoader(IConfigSource config)
50 {
51 m_config = config;
52 }
53
54 public IRegionModule[] GetLoadedSharedModules
55 {
56 get
57 {
58 IRegionModule[] regionModules = new IRegionModule[m_loadedSharedModules.Count];
59 m_loadedSharedModules.Values.CopyTo(regionModules, 0);
60 return regionModules;
61 }
62 }
63
64 public List<IRegionModule> PickupModules(Scene scene, string moduleDir)
65 {
66 DirectoryInfo dir = new DirectoryInfo(moduleDir);
67 List<IRegionModule> modules = new List<IRegionModule>();
68
69 foreach (FileInfo fileInfo in dir.GetFiles("*.dll"))
70 {
71 modules.AddRange(LoadRegionModules(fileInfo.FullName, scene));
72 }
73 return modules;
74 }
75
76 public void LoadDefaultSharedModule(IRegionModule module)
77 {
78 if (m_loadedSharedModules.ContainsKey(module.Name))
79 {
80 m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module not added!", module.Name);
81 }
82 else
83 {
84 m_loadedSharedModules.Add(module.Name, module);
85 }
86 }
87
88
89 public void InitialiseSharedModules(Scene scene)
90 {
91 foreach (IRegionModule module in m_loadedSharedModules.Values)
92 {
93 module.Initialise(scene, m_config);
94 scene.AddModule(module.Name, module); //should be doing this?
95 }
96 }
97
98 public void InitializeModule(IRegionModule module, Scene scene)
99 {
100 module.Initialise(scene, m_config);
101 scene.AddModule(module.Name, module);
102 m_loadedModules.Add(module);
103 }
104
105 /// <summary>
106 /// Loads/initialises a Module instance that can be used by multiple Regions
107 /// </summary>
108 /// <param name="dllName"></param>
109 /// <param name="moduleName"></param>
110 public void LoadSharedModule(string dllName, string moduleName)
111 {
112 IRegionModule module = LoadModule(dllName, moduleName);
113
114 if (module != null)
115 LoadSharedModule(module);
116 }
117
118 /// <summary>
119 /// Loads/initialises a Module instance that can be used by multiple Regions
120 /// </summary>
121 /// <param name="module"></param>
122 public void LoadSharedModule(IRegionModule module)
123 {
124 if (!m_loadedSharedModules.ContainsKey(module.Name))
125 {
126 m_loadedSharedModules.Add(module.Name, module);
127 }
128 }
129
130 public List<IRegionModule> LoadRegionModules(string dllName, Scene scene)
131 {
132 IRegionModule[] modules = LoadModules(dllName);
133 List<IRegionModule> initializedModules = new List<IRegionModule>();
134
135 if (modules.Length > 0)
136 {
137 m_log.InfoFormat("[MODULES]: Found Module Library [{0}]", dllName);
138 foreach (IRegionModule module in modules)
139 {
140 if (!module.IsSharedModule)
141 {
142 m_log.InfoFormat("[MODULES]: [{0}]: Initializing.", module.Name);
143 InitializeModule(module, scene);
144 initializedModules.Add(module);
145 }
146 else
147 {
148 m_log.InfoFormat("[MODULES]: [{0}]: Loading Shared Module.", module.Name);
149 LoadSharedModule(module);
150 }
151 }
152 }
153 return initializedModules;
154 }
155
156 public void LoadRegionModule(string dllName, string moduleName, Scene scene)
157 {
158 IRegionModule module = LoadModule(dllName, moduleName);
159 if (module != null)
160 {
161 InitializeModule(module, scene);
162 }
163 }
164
165 /// <summary>
166 /// Loads a external Module (if not already loaded) and creates a new instance of it.
167 /// </summary>
168 /// <param name="dllName"></param>
169 /// <param name="moduleName"></param>
170 public IRegionModule LoadModule(string dllName, string moduleName)
171 {
172 IRegionModule[] modules = LoadModules(dllName);
173
174 foreach (IRegionModule module in modules)
175 {
176 if ((module != null) && (module.Name == moduleName))
177 {
178 return module;
179 }
180 }
181
182 return null;
183 }
184
185 public IRegionModule[] LoadModules(string dllName)
186 {
187 //m_log.DebugFormat("[MODULES]: Looking for modules in {0}", dllName);
188
189 List<IRegionModule> modules = new List<IRegionModule>();
190
191 Assembly pluginAssembly;
192 if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly))
193 {
194 try
195 {
196 pluginAssembly = Assembly.LoadFrom(dllName);
197 LoadedAssemblys.Add(dllName, pluginAssembly);
198 }
199 catch (BadImageFormatException)
200 {
201 //m_log.InfoFormat("[MODULES]: The file [{0}] is not a module assembly.", e.FileName);
202 }
203 }
204
205 if (pluginAssembly != null)
206 {
207 try
208 {
209 foreach (Type pluginType in pluginAssembly.GetTypes())
210 {
211 if (pluginType.IsPublic)
212 {
213 if (!pluginType.IsAbstract)
214 {
215 if (pluginType.GetInterface("IRegionModule") != null)
216 {
217 modules.Add((IRegionModule)Activator.CreateInstance(pluginType));
218 }
219 }
220 }
221 }
222 }
223 catch (Exception e)
224 {
225 m_log.ErrorFormat(
226 "[MODULES]: Could not load types for plugin DLL {0}. Exception {1} {2}",
227 pluginAssembly.FullName, e.Message, e.StackTrace);
228
229 // justincc: Right now this is fatal to really get the user's attention
230 throw e;
231 }
232 }
233
234 return modules.ToArray();
235 }
236
237 public void PostInitialise()
238 {
239 foreach (IRegionModule module in m_loadedSharedModules.Values)
240 {
241 module.PostInitialise();
242 }
243
244 foreach (IRegionModule module in m_loadedModules)
245 {
246 module.PostInitialise();
247 }
248 }
249
250 public void ClearCache()
251 {
252 LoadedAssemblys.Clear();
253 }
254
255 public void UnloadModule(IRegionModule rm)
256 {
257 rm.Close();
258
259 m_loadedModules.Remove(rm);
260 }
261 }
262}
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
176 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 176 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
177 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 177 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
178 protected string m_simulatorVersion = "OpenSimulator Server"; 178 protected string m_simulatorVersion = "OpenSimulator Server";
179 protected ModuleLoader m_moduleLoader;
180 protected AgentCircuitManager m_authenticateHandler; 179 protected AgentCircuitManager m_authenticateHandler;
181 protected SceneCommunicationService m_sceneGridService; 180 protected SceneCommunicationService m_sceneGridService;
182 181
@@ -659,7 +658,7 @@ namespace OpenSim.Region.Framework.Scenes
659 public Scene(RegionInfo regInfo, AgentCircuitManager authen, 658 public Scene(RegionInfo regInfo, AgentCircuitManager authen,
660 SceneCommunicationService sceneGridService, 659 SceneCommunicationService sceneGridService,
661 ISimulationDataService simDataService, IEstateDataService estateDataService, 660 ISimulationDataService simDataService, IEstateDataService estateDataService,
662 ModuleLoader moduleLoader, bool dumpAssetsToFile, 661 bool dumpAssetsToFile,
663 IConfigSource config, string simulatorVersion) 662 IConfigSource config, string simulatorVersion)
664 : this(regInfo) 663 : this(regInfo)
665 { 664 {
@@ -670,7 +669,6 @@ namespace OpenSim.Region.Framework.Scenes
670 Random random = new Random(); 669 Random random = new Random();
671 670
672 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue / 2)) + (uint)(uint.MaxValue / 4); 671 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue / 2)) + (uint)(uint.MaxValue / 4);
673 m_moduleLoader = moduleLoader;
674 m_authenticateHandler = authen; 672 m_authenticateHandler = authen;
675 m_sceneGridService = sceneGridService; 673 m_sceneGridService = sceneGridService;
676 m_SimulationDataService = simDataService; 674 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
67 /// <value> 67 /// <value>
68 /// All the region modules attached to this scene. 68 /// All the region modules attached to this scene.
69 /// </value> 69 /// </value>
70 public Dictionary<string, IRegionModule> Modules
71 {
72 get { return m_modules; }
73 }
74 protected Dictionary<string, IRegionModule> m_modules = new Dictionary<string, IRegionModule>();
75
76 public Dictionary<string, IRegionModuleBase> RegionModules 70 public Dictionary<string, IRegionModuleBase> RegionModules
77 { 71 {
78 get { return m_regionModules; } 72 get { return m_regionModules; }
@@ -272,16 +266,6 @@ namespace OpenSim.Region.Framework.Scenes
272 /// </summary> 266 /// </summary>
273 public virtual void Close() 267 public virtual void Close()
274 { 268 {
275 // Shut down all non shared modules.
276 foreach (IRegionModule module in Modules.Values)
277 {
278 if (!module.IsSharedModule)
279 {
280 module.Close();
281 }
282 }
283 Modules.Clear();
284
285 try 269 try
286 { 270 {
287 EventManager.TriggerShutdown(); 271 EventManager.TriggerShutdown();
@@ -312,19 +296,6 @@ namespace OpenSim.Region.Framework.Scenes
312 #region Module Methods 296 #region Module Methods
313 297
314 /// <summary> 298 /// <summary>
315 /// Add a module to this scene.
316 /// </summary>
317 /// <param name="name"></param>
318 /// <param name="module"></param>
319 public void AddModule(string name, IRegionModule module)
320 {
321 if (!Modules.ContainsKey(name))
322 {
323 Modules.Add(name, module);
324 }
325 }
326
327 /// <summary>
328 /// Add a region-module to this scene. TODO: This will replace AddModule in the future. 299 /// Add a region-module to this scene. TODO: This will replace AddModule in the future.
329 /// </summary> 300 /// </summary>
330 /// <param name="name"></param> 301 /// <param name="name"></param>
@@ -508,9 +479,9 @@ namespace OpenSim.Region.Framework.Scenes
508 /// <param name="shorthelp"></param> 479 /// <param name="shorthelp"></param>
509 /// <param name="longhelp"></param> 480 /// <param name="longhelp"></param>
510 /// <param name="callback"></param> 481 /// <param name="callback"></param>
511 public void AddCommand(object mod, string command, string shorthelp, string longhelp, CommandDelegate callback) 482 public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
512 { 483 {
513 AddCommand(mod, command, shorthelp, longhelp, string.Empty, callback); 484 AddCommand(module, command, shorthelp, longhelp, string.Empty, callback);
514 } 485 }
515 486
516 /// <summary> 487 /// <summary>
@@ -528,9 +499,9 @@ namespace OpenSim.Region.Framework.Scenes
528 /// <param name="longhelp"></param> 499 /// <param name="longhelp"></param>
529 /// <param name="callback"></param> 500 /// <param name="callback"></param>
530 public void AddCommand( 501 public void AddCommand(
531 string category, object mod, string command, string shorthelp, string longhelp, CommandDelegate callback) 502 string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
532 { 503 {
533 AddCommand(category, mod, command, shorthelp, longhelp, string.Empty, callback); 504 AddCommand(category, module, command, shorthelp, longhelp, string.Empty, callback);
534 } 505 }
535 506
536 /// <summary> 507 /// <summary>
@@ -542,29 +513,14 @@ namespace OpenSim.Region.Framework.Scenes
542 /// <param name="longhelp"></param> 513 /// <param name="longhelp"></param>
543 /// <param name="descriptivehelp"></param> 514 /// <param name="descriptivehelp"></param>
544 /// <param name="callback"></param> 515 /// <param name="callback"></param>
545 public void AddCommand(object mod, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback) 516 public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
546 { 517 {
547 string moduleName = ""; 518 string moduleName = "";
548 519
549 if (mod != null) 520 if (module != null)
550 { 521 moduleName = module.Name;
551 if (mod is IRegionModule)
552 {
553 IRegionModule module = (IRegionModule)mod;
554 moduleName = module.Name;
555 }
556 else if (mod is IRegionModuleBase)
557 {
558 IRegionModuleBase module = (IRegionModuleBase)mod;
559 moduleName = module.Name;
560 }
561 else
562 {
563 throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase");
564 }
565 }
566 522
567 AddCommand(moduleName, mod, command, shorthelp, longhelp, descriptivehelp, callback); 523 AddCommand(moduleName, module, command, shorthelp, longhelp, descriptivehelp, callback);
568 } 524 }
569 525
570 /// <summary> 526 /// <summary>
@@ -580,7 +536,7 @@ namespace OpenSim.Region.Framework.Scenes
580 /// <param name="descriptivehelp"></param> 536 /// <param name="descriptivehelp"></param>
581 /// <param name="callback"></param> 537 /// <param name="callback"></param>
582 public void AddCommand( 538 public void AddCommand(
583 string category, object mod, string command, 539 string category, IRegionModuleBase module, string command,
584 string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback) 540 string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
585 { 541 {
586 if (MainConsole.Instance == null) 542 if (MainConsole.Instance == null)
@@ -588,22 +544,8 @@ namespace OpenSim.Region.Framework.Scenes
588 544
589 bool shared = false; 545 bool shared = false;
590 546
591 if (mod != null) 547 if (module != null)
592 { 548 shared = module is ISharedRegionModule;
593 if (mod is IRegionModule)
594 {
595 IRegionModule module = (IRegionModule)mod;
596 shared = module.IsSharedModule;
597 }
598 else if (mod is IRegionModuleBase)
599 {
600 shared = mod is ISharedRegionModule;
601 }
602 else
603 {
604 throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase");
605 }
606 }
607 549
608 MainConsole.Instance.Commands.AddCommand( 550 MainConsole.Instance.Commands.AddCommand(
609 category, shared, command, shorthelp, longhelp, descriptivehelp, callback); 551 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
144 // collect known shared modules in sharedModules 144 // collect known shared modules in sharedModules
145 Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>(); 145 Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>();
146 146
147 lock (m_localScenes)
148 {
149 for (int i = 0; i < m_localScenes.Count; i++)
150 {
151 // extract known shared modules from scene
152 foreach (string k in m_localScenes[i].Modules.Keys)
153 {
154 if (m_localScenes[i].Modules[k].IsSharedModule &&
155 !sharedModules.ContainsKey(k))
156 sharedModules[k] = m_localScenes[i].Modules[k];
157 }
158 // close scene/region
159 m_localScenes[i].Close();
160 }
161 }
162
163 // all regions/scenes are now closed, we can now safely 147 // all regions/scenes are now closed, we can now safely
164 // close all shared modules 148 // close all shared modules
165 foreach (IRegionModule mod in sharedModules.Values) 149 foreach (IRegionModule mod in sharedModules.Values)