aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/ModuleLoader.cs
diff options
context:
space:
mode:
authorSean Dague2007-10-19 20:27:34 +0000
committerSean Dague2007-10-19 20:27:34 +0000
commit139994757c7dab04dd03801266525e8c53395a5e (patch)
tree003ec2557de6dd80dbe1e7bc78efe8958d02d5ae /OpenSim/Region/Environment/ModuleLoader.cs
parent* Test thy commits! (oops, sorry!) (diff)
downloadopensim-SC-139994757c7dab04dd03801266525e8c53395a5e.zip
opensim-SC-139994757c7dab04dd03801266525e8c53395a5e.tar.gz
opensim-SC-139994757c7dab04dd03801266525e8c53395a5e.tar.bz2
opensim-SC-139994757c7dab04dd03801266525e8c53395a5e.tar.xz
changes to pass nini config object to the modules that get
loaded so that they may read out any bits they are interested in
Diffstat (limited to 'OpenSim/Region/Environment/ModuleLoader.cs')
-rw-r--r--OpenSim/Region/Environment/ModuleLoader.cs407
1 files changed, 205 insertions, 202 deletions
diff --git a/OpenSim/Region/Environment/ModuleLoader.cs b/OpenSim/Region/Environment/ModuleLoader.cs
index 69cc379..f88f9ac 100644
--- a/OpenSim/Region/Environment/ModuleLoader.cs
+++ b/OpenSim/Region/Environment/ModuleLoader.cs
@@ -1,202 +1,205 @@
1/* 1/*
2* Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO; 31using System.IO;
32using System.Reflection; 32using System.Reflection;
33using OpenSim.Framework.Console; 33using OpenSim.Framework.Console;
34using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Modules; 35using OpenSim.Region.Environment.Modules;
36using OpenSim.Region.Environment.Scenes; 36using OpenSim.Region.Environment.Scenes;
37 37using Nini.Config;
38namespace OpenSim.Region.Environment 38
39{ 39namespace OpenSim.Region.Environment
40 public class ModuleLoader 40{
41 { 41 public class ModuleLoader
42 public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>(); 42 {
43 43 public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>();
44 public List<IRegionModule> LoadedModules = new List<IRegionModule>(); 44
45 public Dictionary<string, IRegionModule> LoadedSharedModules = new Dictionary<string, IRegionModule>(); 45 public List<IRegionModule> LoadedModules = new List<IRegionModule>();
46 private readonly LogBase m_log; 46 public Dictionary<string, IRegionModule> LoadedSharedModules = new Dictionary<string, IRegionModule>();
47 47 private readonly LogBase m_log;
48 public ModuleLoader(LogBase log) 48 private IConfigSource m_config;
49 { 49
50 m_log = log; 50 public ModuleLoader(LogBase log, IConfigSource config)
51 } 51 {
52 52 m_log = log;
53 public void PickupModules(Scene scene, string moduleDir) 53 m_config = config;
54 { 54 }
55 DirectoryInfo dir = new DirectoryInfo(moduleDir); 55
56 56 public void PickupModules(Scene scene, string moduleDir)
57 foreach (FileInfo fileInfo in dir.GetFiles("*.dll")) 57 {
58 { 58 DirectoryInfo dir = new DirectoryInfo(moduleDir);
59 LoadRegionModules(fileInfo.FullName, scene); 59
60 } 60 foreach (FileInfo fileInfo in dir.GetFiles("*.dll"))
61 } 61 {
62 62 LoadRegionModules(fileInfo.FullName, scene);
63 public void LoadDefaultSharedModules() 63 }
64 { 64 }
65 DynamicTextureModule dynamicModule = new DynamicTextureModule(); 65
66 LoadedSharedModules.Add(dynamicModule.Name, dynamicModule); 66 public void LoadDefaultSharedModules()
67 } 67 {
68 68 DynamicTextureModule dynamicModule = new DynamicTextureModule();
69 public void InitialiseSharedModules(Scene scene) 69 LoadedSharedModules.Add(dynamicModule.Name, dynamicModule);
70 { 70 }
71 foreach (IRegionModule module in LoadedSharedModules.Values) 71
72 { 72 public void InitialiseSharedModules(Scene scene)
73 module.Initialise(scene); 73 {
74 scene.AddModule(module.Name, module); //should be doing this? 74 foreach (IRegionModule module in LoadedSharedModules.Values)
75 } 75 {
76 } 76 module.Initialise(scene, m_config);
77 77 scene.AddModule(module.Name, module); //should be doing this?
78 public void InitializeModule(IRegionModule module, Scene scene) 78 }
79 { 79 }
80 module.Initialise(scene); 80
81 scene.AddModule(module.Name, module); 81 public void InitializeModule(IRegionModule module, Scene scene)
82 LoadedModules.Add(module); 82 {
83 } 83 module.Initialise(scene, m_config);
84 84 scene.AddModule(module.Name, module);
85 /// <summary> 85 LoadedModules.Add(module);
86 /// Loads/initialises a Module instance that can be used by mutliple Regions 86 }
87 /// </summary> 87
88 /// <param name="dllName"></param> 88 /// <summary>
89 /// <param name="moduleName"></param> 89 /// Loads/initialises a Module instance that can be used by mutliple Regions
90 /// <param name="scene"></param> 90 /// </summary>
91 public void LoadSharedModule(string dllName, string moduleName) 91 /// <param name="dllName"></param>
92 { 92 /// <param name="moduleName"></param>
93 IRegionModule module = LoadModule(dllName, moduleName); 93 /// <param name="scene"></param>
94 if (module != null) 94 public void LoadSharedModule(string dllName, string moduleName)
95 { 95 {
96 LoadedSharedModules.Add(module.Name, module); 96 IRegionModule module = LoadModule(dllName, moduleName);
97 } 97 if (module != null)
98 } 98 {
99 99 LoadedSharedModules.Add(module.Name, module);
100 public void LoadRegionModules(string dllName, Scene scene) 100 }
101 { 101 }
102 IRegionModule[] modules = LoadModules(dllName); 102
103 103 public void LoadRegionModules(string dllName, Scene scene)
104 if (modules.Length > 0) 104 {
105 { 105 IRegionModule[] modules = LoadModules(dllName);
106 m_log.Verbose("MODULES", "Found Module Library [{0}]", dllName ); 106
107 foreach (IRegionModule module in modules) 107 if (modules.Length > 0)
108 { 108 {
109 m_log.Verbose("MODULES", " [{0}]: Initializing.", module.Name); 109 m_log.Verbose("MODULES", "Found Module Library [{0}]", dllName );
110 InitializeModule(module, scene); 110 foreach (IRegionModule module in modules)
111 } 111 {
112 } 112 m_log.Verbose("MODULES", " [{0}]: Initializing.", module.Name);
113 } 113 InitializeModule(module, scene);
114 114 }
115 public void LoadRegionModule(string dllName, string moduleName, Scene scene) 115 }
116 { 116 }
117 IRegionModule module = LoadModule(dllName, moduleName); 117
118 if (module != null) 118 public void LoadRegionModule(string dllName, string moduleName, Scene scene)
119 { 119 {
120 InitializeModule(module, scene); 120 IRegionModule module = LoadModule(dllName, moduleName);
121 } 121 if (module != null)
122 } 122 {
123 123 InitializeModule(module, scene);
124 /// <summary> 124 }
125 /// Loads a external Module (if not already loaded) and creates a new instance of it. 125 }
126 /// </summary> 126
127 /// <param name="dllName"></param> 127 /// <summary>
128 /// <param name="moduleName"></param> 128 /// Loads a external Module (if not already loaded) and creates a new instance of it.
129 /// <param name="scene"></param> 129 /// </summary>
130 public IRegionModule LoadModule(string dllName, string moduleName) 130 /// <param name="dllName"></param>
131 { 131 /// <param name="moduleName"></param>
132 IRegionModule[] modules = LoadModules(dllName); 132 /// <param name="scene"></param>
133 133 public IRegionModule LoadModule(string dllName, string moduleName)
134 foreach (IRegionModule module in modules) 134 {
135 { 135 IRegionModule[] modules = LoadModules(dllName);
136 if ((module != null) && (module.Name == moduleName)) 136
137 { 137 foreach (IRegionModule module in modules)
138 return module; 138 {
139 } 139 if ((module != null) && (module.Name == moduleName))
140 } 140 {
141 141 return module;
142 return null; 142 }
143 } 143 }
144 144
145 public IRegionModule[] LoadModules(string dllName) 145 return null;
146 { 146 }
147 List<IRegionModule> modules = new List<IRegionModule>(); 147
148 148 public IRegionModule[] LoadModules(string dllName)
149 Assembly pluginAssembly; 149 {
150 if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly )) 150 List<IRegionModule> modules = new List<IRegionModule>();
151 { 151
152 try 152 Assembly pluginAssembly;
153 { 153 if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly ))
154 pluginAssembly = Assembly.LoadFrom(dllName); 154 {
155 LoadedAssemblys.Add(dllName, pluginAssembly); 155 try
156 } 156 {
157 catch( BadImageFormatException e ) 157 pluginAssembly = Assembly.LoadFrom(dllName);
158 { 158 LoadedAssemblys.Add(dllName, pluginAssembly);
159 m_log.Warn( "MODULES", "The file [{0}] is not a module assembly.", e.FileName ); 159 }
160 } 160 catch( BadImageFormatException e )
161 } 161 {
162 162 m_log.Warn( "MODULES", "The file [{0}] is not a module assembly.", e.FileName );
163 163 }
164 if (pluginAssembly != null) 164 }
165 { 165
166 foreach (Type pluginType in pluginAssembly.GetTypes()) 166
167 { 167 if (pluginAssembly != null)
168 if (pluginType.IsPublic) 168 {
169 { 169 foreach (Type pluginType in pluginAssembly.GetTypes())
170 if (!pluginType.IsAbstract) 170 {
171 { 171 if (pluginType.IsPublic)
172 if( pluginType.GetInterface("IRegionModule") != null ) 172 {
173 { 173 if (!pluginType.IsAbstract)
174 modules.Add((IRegionModule) Activator.CreateInstance(pluginType)); 174 {
175 } 175 if( pluginType.GetInterface("IRegionModule") != null )
176 } 176 {
177 } 177 modules.Add((IRegionModule) Activator.CreateInstance(pluginType));
178 } 178 }
179 } 179 }
180 180 }
181 return modules.ToArray(); 181 }
182 } 182 }
183 183
184 public void PostInitialise() 184 return modules.ToArray();
185 { 185 }
186 foreach (IRegionModule module in LoadedSharedModules.Values) 186
187 { 187 public void PostInitialise()
188 module.PostInitialise(); 188 {
189 } 189 foreach (IRegionModule module in LoadedSharedModules.Values)
190 190 {
191 foreach (IRegionModule module in LoadedModules) 191 module.PostInitialise();
192 { 192 }
193 module.PostInitialise(); 193
194 } 194 foreach (IRegionModule module in LoadedModules)
195 } 195 {
196 196 module.PostInitialise();
197 public void ClearCache() 197 }
198 { 198 }
199 LoadedAssemblys.Clear(); 199
200 } 200 public void ClearCache()
201 } 201 {
202} 202 LoadedAssemblys.Clear();
203 }
204 }
205}