diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/ModuleLoader.cs | 428 |
1 files changed, 214 insertions, 214 deletions
diff --git a/OpenSim/Region/Environment/ModuleLoader.cs b/OpenSim/Region/Environment/ModuleLoader.cs index 4c66d2e..c579c1d 100644 --- a/OpenSim/Region/Environment/ModuleLoader.cs +++ b/OpenSim/Region/Environment/ModuleLoader.cs | |||
@@ -1,214 +1,214 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.IO; | 31 | using System.IO; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Framework.Console; | 33 | using OpenSim.Framework.Console; |
34 | using OpenSim.Region.Environment.Interfaces; | 34 | using OpenSim.Region.Environment.Interfaces; |
35 | using OpenSim.Region.Environment.Modules; | 35 | using OpenSim.Region.Environment.Modules; |
36 | using OpenSim.Region.Environment.Scenes; | 36 | using OpenSim.Region.Environment.Scenes; |
37 | using Nini.Config; | 37 | using Nini.Config; |
38 | 38 | ||
39 | namespace OpenSim.Region.Environment | 39 | namespace OpenSim.Region.Environment |
40 | { | 40 | { |
41 | public class ModuleLoader | 41 | public class ModuleLoader |
42 | { | 42 | { |
43 | public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>(); | 43 | public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>(); |
44 | 44 | ||
45 | public List<IRegionModule> LoadedModules = new List<IRegionModule>(); | 45 | public List<IRegionModule> LoadedModules = new List<IRegionModule>(); |
46 | public Dictionary<string, IRegionModule> LoadedSharedModules = new Dictionary<string, IRegionModule>(); | 46 | public Dictionary<string, IRegionModule> LoadedSharedModules = new Dictionary<string, IRegionModule>(); |
47 | private readonly LogBase m_log; | 47 | private readonly LogBase m_log; |
48 | private IConfigSource m_config; | 48 | private IConfigSource m_config; |
49 | 49 | ||
50 | public ModuleLoader(LogBase log, IConfigSource config) | 50 | public ModuleLoader(LogBase log, IConfigSource config) |
51 | { | 51 | { |
52 | m_log = log; | 52 | m_log = log; |
53 | m_config = config; | 53 | m_config = config; |
54 | } | 54 | } |
55 | 55 | ||
56 | public void PickupModules(Scene scene, string moduleDir) | 56 | public void PickupModules(Scene scene, string moduleDir) |
57 | { | 57 | { |
58 | DirectoryInfo dir = new DirectoryInfo(moduleDir); | 58 | DirectoryInfo dir = new DirectoryInfo(moduleDir); |
59 | 59 | ||
60 | foreach (FileInfo fileInfo in dir.GetFiles("*.dll")) | 60 | foreach (FileInfo fileInfo in dir.GetFiles("*.dll")) |
61 | { | 61 | { |
62 | LoadRegionModules(fileInfo.FullName, scene); | 62 | LoadRegionModules(fileInfo.FullName, scene); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | public void LoadDefaultSharedModules() | 66 | public void LoadDefaultSharedModules() |
67 | { | 67 | { |
68 | DynamicTextureModule dynamicModule = new DynamicTextureModule(); | 68 | DynamicTextureModule dynamicModule = new DynamicTextureModule(); |
69 | LoadedSharedModules.Add(dynamicModule.Name, dynamicModule); | 69 | LoadedSharedModules.Add(dynamicModule.Name, dynamicModule); |
70 | ChatModule chat = new ChatModule(); | 70 | ChatModule chat = new ChatModule(); |
71 | LoadedSharedModules.Add(chat.Name, chat); | 71 | LoadedSharedModules.Add(chat.Name, chat); |
72 | InstantMessageModule imMod = new InstantMessageModule(); | 72 | InstantMessageModule imMod = new InstantMessageModule(); |
73 | LoadedSharedModules.Add(imMod.Name, imMod); | 73 | LoadedSharedModules.Add(imMod.Name, imMod); |
74 | LoadImageURLModule loadMod = new LoadImageURLModule(); | 74 | LoadImageURLModule loadMod = new LoadImageURLModule(); |
75 | LoadedSharedModules.Add(loadMod.Name, loadMod); | 75 | LoadedSharedModules.Add(loadMod.Name, loadMod); |
76 | } | 76 | } |
77 | 77 | ||
78 | public void InitialiseSharedModules(Scene scene) | 78 | public void InitialiseSharedModules(Scene scene) |
79 | { | 79 | { |
80 | foreach (IRegionModule module in LoadedSharedModules.Values) | 80 | foreach (IRegionModule module in LoadedSharedModules.Values) |
81 | { | 81 | { |
82 | module.Initialise(scene, m_config); | 82 | module.Initialise(scene, m_config); |
83 | scene.AddModule(module.Name, module); //should be doing this? | 83 | scene.AddModule(module.Name, module); //should be doing this? |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | public void InitializeModule(IRegionModule module, Scene scene) | 87 | public void InitializeModule(IRegionModule module, Scene scene) |
88 | { | 88 | { |
89 | module.Initialise(scene, m_config); | 89 | module.Initialise(scene, m_config); |
90 | scene.AddModule(module.Name, module); | 90 | scene.AddModule(module.Name, module); |
91 | LoadedModules.Add(module); | 91 | LoadedModules.Add(module); |
92 | } | 92 | } |
93 | 93 | ||
94 | /// <summary> | 94 | /// <summary> |
95 | /// Loads/initialises a Module instance that can be used by mutliple Regions | 95 | /// Loads/initialises a Module instance that can be used by mutliple Regions |
96 | /// </summary> | 96 | /// </summary> |
97 | /// <param name="dllName"></param> | 97 | /// <param name="dllName"></param> |
98 | /// <param name="moduleName"></param> | 98 | /// <param name="moduleName"></param> |
99 | /// <param name="scene"></param> | 99 | /// <param name="scene"></param> |
100 | public void LoadSharedModule(string dllName, string moduleName) | 100 | public void LoadSharedModule(string dllName, string moduleName) |
101 | { | 101 | { |
102 | IRegionModule module = LoadModule(dllName, moduleName); | 102 | IRegionModule module = LoadModule(dllName, moduleName); |
103 | if (module != null) | 103 | if (module != null) |
104 | { | 104 | { |
105 | LoadedSharedModules.Add(module.Name, module); | 105 | LoadedSharedModules.Add(module.Name, module); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | public void LoadRegionModules(string dllName, Scene scene) | 109 | public void LoadRegionModules(string dllName, Scene scene) |
110 | { | 110 | { |
111 | IRegionModule[] modules = LoadModules(dllName); | 111 | IRegionModule[] modules = LoadModules(dllName); |
112 | 112 | ||
113 | if (modules.Length > 0) | 113 | if (modules.Length > 0) |
114 | { | 114 | { |
115 | m_log.Verbose("MODULES", "Found Module Library [{0}]", dllName ); | 115 | m_log.Verbose("MODULES", "Found Module Library [{0}]", dllName ); |
116 | foreach (IRegionModule module in modules) | 116 | foreach (IRegionModule module in modules) |
117 | { | 117 | { |
118 | if (!module.IsSharedModule) | 118 | if (!module.IsSharedModule) |
119 | { | 119 | { |
120 | m_log.Verbose("MODULES", " [{0}]: Initializing.", module.Name); | 120 | m_log.Verbose("MODULES", " [{0}]: Initializing.", module.Name); |
121 | InitializeModule(module, scene); | 121 | InitializeModule(module, scene); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | } | 124 | } |
125 | } | 125 | } |
126 | 126 | ||
127 | public void LoadRegionModule(string dllName, string moduleName, Scene scene) | 127 | public void LoadRegionModule(string dllName, string moduleName, Scene scene) |
128 | { | 128 | { |
129 | IRegionModule module = LoadModule(dllName, moduleName); | 129 | IRegionModule module = LoadModule(dllName, moduleName); |
130 | if (module != null) | 130 | if (module != null) |
131 | { | 131 | { |
132 | InitializeModule(module, scene); | 132 | InitializeModule(module, scene); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | /// <summary> | 136 | /// <summary> |
137 | /// Loads a external Module (if not already loaded) and creates a new instance of it. | 137 | /// Loads a external Module (if not already loaded) and creates a new instance of it. |
138 | /// </summary> | 138 | /// </summary> |
139 | /// <param name="dllName"></param> | 139 | /// <param name="dllName"></param> |
140 | /// <param name="moduleName"></param> | 140 | /// <param name="moduleName"></param> |
141 | /// <param name="scene"></param> | 141 | /// <param name="scene"></param> |
142 | public IRegionModule LoadModule(string dllName, string moduleName) | 142 | public IRegionModule LoadModule(string dllName, string moduleName) |
143 | { | 143 | { |
144 | IRegionModule[] modules = LoadModules(dllName); | 144 | IRegionModule[] modules = LoadModules(dllName); |
145 | 145 | ||
146 | foreach (IRegionModule module in modules) | 146 | foreach (IRegionModule module in modules) |
147 | { | 147 | { |
148 | if ((module != null) && (module.Name == moduleName)) | 148 | if ((module != null) && (module.Name == moduleName)) |
149 | { | 149 | { |
150 | return module; | 150 | return module; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | return null; | 154 | return null; |
155 | } | 155 | } |
156 | 156 | ||
157 | public IRegionModule[] LoadModules(string dllName) | 157 | public IRegionModule[] LoadModules(string dllName) |
158 | { | 158 | { |
159 | List<IRegionModule> modules = new List<IRegionModule>(); | 159 | List<IRegionModule> modules = new List<IRegionModule>(); |
160 | 160 | ||
161 | Assembly pluginAssembly; | 161 | Assembly pluginAssembly; |
162 | if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly )) | 162 | if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly )) |
163 | { | 163 | { |
164 | try | 164 | try |
165 | { | 165 | { |
166 | pluginAssembly = Assembly.LoadFrom(dllName); | 166 | pluginAssembly = Assembly.LoadFrom(dllName); |
167 | LoadedAssemblys.Add(dllName, pluginAssembly); | 167 | LoadedAssemblys.Add(dllName, pluginAssembly); |
168 | } | 168 | } |
169 | catch( BadImageFormatException e ) | 169 | catch( BadImageFormatException e ) |
170 | { | 170 | { |
171 | m_log.Warn( "MODULES", "The file [{0}] is not a module assembly.", e.FileName ); | 171 | m_log.Warn( "MODULES", "The file [{0}] is not a module assembly.", e.FileName ); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | if (pluginAssembly != null) | 176 | if (pluginAssembly != null) |
177 | { | 177 | { |
178 | foreach (Type pluginType in pluginAssembly.GetTypes()) | 178 | foreach (Type pluginType in pluginAssembly.GetTypes()) |
179 | { | 179 | { |
180 | if (pluginType.IsPublic) | 180 | if (pluginType.IsPublic) |
181 | { | 181 | { |
182 | if (!pluginType.IsAbstract) | 182 | if (!pluginType.IsAbstract) |
183 | { | 183 | { |
184 | if( pluginType.GetInterface("IRegionModule") != null ) | 184 | if( pluginType.GetInterface("IRegionModule") != null ) |
185 | { | 185 | { |
186 | modules.Add((IRegionModule) Activator.CreateInstance(pluginType)); | 186 | modules.Add((IRegionModule) Activator.CreateInstance(pluginType)); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | } | 189 | } |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | return modules.ToArray(); | 193 | return modules.ToArray(); |
194 | } | 194 | } |
195 | 195 | ||
196 | public void PostInitialise() | 196 | public void PostInitialise() |
197 | { | 197 | { |
198 | foreach (IRegionModule module in LoadedSharedModules.Values) | 198 | foreach (IRegionModule module in LoadedSharedModules.Values) |
199 | { | 199 | { |
200 | module.PostInitialise(); | 200 | module.PostInitialise(); |
201 | } | 201 | } |
202 | 202 | ||
203 | foreach (IRegionModule module in LoadedModules) | 203 | foreach (IRegionModule module in LoadedModules) |
204 | { | 204 | { |
205 | module.PostInitialise(); | 205 | module.PostInitialise(); |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | public void ClearCache() | 209 | public void ClearCache() |
210 | { | 210 | { |
211 | LoadedAssemblys.Clear(); | 211 | LoadedAssemblys.Clear(); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | } | 214 | } |