aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/ModuleLoader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/ModuleLoader.cs')
-rw-r--r--OpenSim/Region/Environment/ModuleLoader.cs327
1 files changed, 0 insertions, 327 deletions
diff --git a/OpenSim/Region/Environment/ModuleLoader.cs b/OpenSim/Region/Environment/ModuleLoader.cs
deleted file mode 100644
index f06fa0f..0000000
--- a/OpenSim/Region/Environment/ModuleLoader.cs
+++ /dev/null
@@ -1,327 +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 OpenSim 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.Environment.Interfaces;
35using OpenSim.Region.Environment.Modules.Agent.AssetTransaction;
36using OpenSim.Region.Environment.Modules.Avatar.Chat;
37using OpenSim.Region.Environment.Modules.Avatar.InstantMessage;
38using OpenSim.Region.Environment.Modules.Scripting.DynamicTexture;
39using OpenSim.Region.Environment.Modules.Scripting.LoadImageURL;
40using OpenSim.Region.Environment.Modules.Scripting.XMLRPC;
41using OpenSim.Region.Environment.Scenes;
42
43//TODO: Why do we reference InstantMessageModule here?
44
45namespace OpenSim.Region.Environment
46{
47 public class ModuleLoader
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>();
52
53 private readonly List<IRegionModule> m_loadedModules = new List<IRegionModule>();
54 private readonly Dictionary<string, IRegionModule> m_loadedSharedModules = new Dictionary<string, IRegionModule>();
55 private readonly IConfigSource m_config;
56
57 public ModuleLoader(IConfigSource config)
58 {
59 m_config = config;
60 }
61
62 public IRegionModule[] GetLoadedSharedModules
63 {
64 get
65 {
66 IRegionModule[] regionModules = new IRegionModule[m_loadedSharedModules.Count];
67 m_loadedSharedModules.Values.CopyTo(regionModules, 0);
68 return regionModules;
69 }
70 }
71
72 public List<IRegionModule> PickupModules(Scene scene, string moduleDir)
73 {
74 DirectoryInfo dir = new DirectoryInfo(moduleDir);
75 List<IRegionModule> modules = new List<IRegionModule>();
76
77 foreach (FileInfo fileInfo in dir.GetFiles("*.dll"))
78 {
79 modules.AddRange(LoadRegionModules(fileInfo.FullName, scene));
80 }
81 return modules;
82 }
83
84 public void LoadDefaultSharedModules()
85 {
86 DynamicTextureModule dynamicModule = new DynamicTextureModule();
87 if (m_loadedSharedModules.ContainsKey(dynamicModule.Name))
88 {
89 m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", dynamicModule.Name, "DynamicTextureModule");
90 }
91 else
92 {
93 m_loadedSharedModules.Add(dynamicModule.Name, dynamicModule);
94 }
95
96 // ChatModule chat = new ChatModule();
97 // if (m_loadedSharedModules.ContainsKey(chat.Name))
98 // {
99 // m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", chat.Name, "ChatModule");
100 // }
101 // else
102 // {
103 // m_loadedSharedModules.Add(chat.Name, chat);
104 // }
105
106 InstantMessageModule imMod = new InstantMessageModule();
107 if (m_loadedSharedModules.ContainsKey(imMod.Name))
108 {
109 m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", imMod.Name, "InstantMessageModule");
110 }
111 else
112 {
113 m_loadedSharedModules.Add(imMod.Name, imMod);
114 }
115
116 LoadImageURLModule loadMod = new LoadImageURLModule();
117 if (m_loadedSharedModules.ContainsKey(loadMod.Name))
118 {
119 m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", loadMod.Name, "LoadImageURLModule");
120 }
121 else
122 {
123 m_loadedSharedModules.Add(loadMod.Name, loadMod);
124 }
125
126 // AvatarFactoryModule avatarFactory = new AvatarFactoryModule();
127 // if (m_loadedSharedModules.ContainsKey(avatarFactory.Name))
128 // {
129 // m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", avatarFactory.Name, "AvarFactoryModule");
130 // }
131 // else
132 // {
133 // m_loadedSharedModules.Add(avatarFactory.Name, avatarFactory);
134 // }
135
136 XMLRPCModule xmlRpcMod = new XMLRPCModule();
137 if (m_loadedSharedModules.ContainsKey(xmlRpcMod.Name))
138 {
139 m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", xmlRpcMod.Name, "XMLRPCModule");
140 }
141 else
142 {
143 m_loadedSharedModules.Add(xmlRpcMod.Name, xmlRpcMod);
144 }
145 //TextureDownloadModule textureModule = new TextureDownloadModule();
146
147 //LoadedSharedModules.Add(textureModule.Name, textureModule);
148
149 AssetTransactionModule transactionsModule = new AssetTransactionModule();
150 if (m_loadedSharedModules.ContainsKey(transactionsModule.Name))
151 {
152 m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", transactionsModule.Name, "TransactionModule");
153 }
154 else
155 {
156 m_loadedSharedModules.Add(transactionsModule.Name, transactionsModule);
157 }
158
159 }
160
161 public void InitialiseSharedModules(Scene scene)
162 {
163 foreach (IRegionModule module in m_loadedSharedModules.Values)
164 {
165 module.Initialise(scene, m_config);
166 scene.AddModule(module.Name, module); //should be doing this?
167 }
168 }
169
170 public void InitializeModule(IRegionModule module, Scene scene)
171 {
172 module.Initialise(scene, m_config);
173 scene.AddModule(module.Name, module);
174 m_loadedModules.Add(module);
175 }
176
177 /// <summary>
178 /// Loads/initialises a Module instance that can be used by multiple Regions
179 /// </summary>
180 /// <param name="dllName"></param>
181 /// <param name="moduleName"></param>
182 public void LoadSharedModule(string dllName, string moduleName)
183 {
184 IRegionModule module = LoadModule(dllName, moduleName);
185
186 if (module != null)
187 LoadSharedModule(module);
188 }
189
190 /// <summary>
191 /// Loads/initialises a Module instance that can be used by multiple Regions
192 /// </summary>
193 /// <param name="module"></param>
194 public void LoadSharedModule(IRegionModule module)
195 {
196 if (!m_loadedSharedModules.ContainsKey(module.Name))
197 {
198 m_loadedSharedModules.Add(module.Name, module);
199 }
200 }
201
202 public List<IRegionModule> LoadRegionModules(string dllName, Scene scene)
203 {
204 IRegionModule[] modules = LoadModules(dllName);
205 List<IRegionModule> initializedModules = new List<IRegionModule>();
206
207 if (modules.Length > 0)
208 {
209 m_log.InfoFormat("[MODULES]: Found Module Library [{0}]", dllName);
210 foreach (IRegionModule module in modules)
211 {
212 if (!module.IsSharedModule)
213 {
214 m_log.InfoFormat("[MODULES]: [{0}]: Initializing.", module.Name);
215 InitializeModule(module, scene);
216 initializedModules.Add(module);
217 }
218 else
219 {
220 m_log.InfoFormat("[MODULES]: [{0}]: Loading Shared Module.", module.Name);
221 LoadSharedModule(module);
222 }
223 }
224 }
225 return initializedModules;
226 }
227
228 public void LoadRegionModule(string dllName, string moduleName, Scene scene)
229 {
230 IRegionModule module = LoadModule(dllName, moduleName);
231 if (module != null)
232 {
233 InitializeModule(module, scene);
234 }
235 }
236
237 /// <summary>
238 /// Loads a external Module (if not already loaded) and creates a new instance of it.
239 /// </summary>
240 /// <param name="dllName"></param>
241 /// <param name="moduleName"></param>
242 public IRegionModule LoadModule(string dllName, string moduleName)
243 {
244 IRegionModule[] modules = LoadModules(dllName);
245
246 foreach (IRegionModule module in modules)
247 {
248 if ((module != null) && (module.Name == moduleName))
249 {
250 return module;
251 }
252 }
253
254 return null;
255 }
256
257 public IRegionModule[] LoadModules(string dllName)
258 {
259 List<IRegionModule> modules = new List<IRegionModule>();
260
261 Assembly pluginAssembly;
262 if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly))
263 {
264 try
265 {
266 pluginAssembly = Assembly.LoadFrom(dllName);
267 LoadedAssemblys.Add(dllName, pluginAssembly);
268 }
269 catch (BadImageFormatException)
270 {
271 //m_log.InfoFormat("[MODULES]: The file [{0}] is not a module assembly.", e.FileName);
272 }
273 }
274
275 if (pluginAssembly != null)
276 {
277 try
278 {
279 foreach (Type pluginType in pluginAssembly.GetTypes())
280 {
281 if (pluginType.IsPublic)
282 {
283 if (!pluginType.IsAbstract)
284 {
285 if (pluginType.GetInterface("IRegionModule") != null)
286 {
287 modules.Add((IRegionModule)Activator.CreateInstance(pluginType));
288 }
289 }
290 }
291 }
292 }
293 catch (ReflectionTypeLoadException)
294 {
295 m_log.InfoFormat("[MODULES]: Could not load types for [{0}].", pluginAssembly.FullName);
296 }
297 }
298
299 return modules.ToArray();
300 }
301
302 public void PostInitialise()
303 {
304 foreach (IRegionModule module in m_loadedSharedModules.Values)
305 {
306 module.PostInitialise();
307 }
308
309 foreach (IRegionModule module in m_loadedModules)
310 {
311 module.PostInitialise();
312 }
313 }
314
315 public void ClearCache()
316 {
317 LoadedAssemblys.Clear();
318 }
319
320 public void UnloadModule(IRegionModule rm)
321 {
322 rm.Close();
323
324 m_loadedModules.Remove(rm);
325 }
326 }
327}