diff options
author | Homer Horwitz | 2009-04-05 17:08:11 +0000 |
---|---|---|
committer | Homer Horwitz | 2009-04-05 17:08:11 +0000 |
commit | 648452dd91e07be4ec0e81793807e86bd48362c4 (patch) | |
tree | 4c1e7f1e48381fd9049efd5eda6440f885af86a4 /OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs | |
parent | - Move IWindModule to OpenSim.Region.Framework.Interfaces (diff) | |
download | opensim-SC-648452dd91e07be4ec0e81793807e86bd48362c4.zip opensim-SC-648452dd91e07be4ec0e81793807e86bd48362c4.tar.gz opensim-SC-648452dd91e07be4ec0e81793807e86bd48362c4.tar.bz2 opensim-SC-648452dd91e07be4ec0e81793807e86bd48362c4.tar.xz |
- Add new RegionModulesControllerPlugin to the application modules
- Change several classes to use the new plugin for handling of region-modules
(NOTE: No regionmodule is using this yet)
- Add necessary prebuild parts (don't forget to runprebuild)
Attention: Work in progress. This shouldn't break anything, but you never know...
Diffstat (limited to '')
-rw-r--r-- | OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs b/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs new file mode 100644 index 0000000..7dc4a74 --- /dev/null +++ b/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs | |||
@@ -0,0 +1,192 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using Mono.Addins; | ||
33 | using OpenSim; | ||
34 | using OpenSim.Region.Framework.Interfaces; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | |||
37 | namespace OpenSim.ApplicationPlugins.RegionModulesController | ||
38 | { | ||
39 | public class RegionModulesControllerPlugin : IRegionModulesController, IApplicationPlugin | ||
40 | { | ||
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
43 | private OpenSimBase m_openSim; // for getting the config | ||
44 | |||
45 | private string m_name; | ||
46 | |||
47 | private List<Type> m_nonSharedModules = new List<Type>(); | ||
48 | private List<Type> m_sharedModules = new List<Type>(); | ||
49 | |||
50 | private List<ISharedRegionModule> m_sharedInstances = new List<ISharedRegionModule>(); | ||
51 | |||
52 | #region IApplicationPlugin implementation | ||
53 | |||
54 | public void Initialise (OpenSimBase openSim) | ||
55 | { | ||
56 | m_log.DebugFormat("[REGIONMODULES]: Initializing..."); | ||
57 | m_openSim = openSim; | ||
58 | openSim.ApplicationRegistry.RegisterInterface<IRegionModulesController>(this); | ||
59 | |||
60 | string id = AddinManager.CurrentAddin.Id; | ||
61 | int pos = id.LastIndexOf("."); | ||
62 | if (pos == -1) m_name = id; | ||
63 | else m_name = id.Substring(pos + 1); | ||
64 | |||
65 | ExtensionNodeList list = AddinManager.GetExtensionNodes("/OpenSim/RegionModules"); | ||
66 | m_log.DebugFormat("[XXX] list: {0}", list.Count); | ||
67 | // load all the (new) region-module classes | ||
68 | foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/OpenSim/RegionModules")) | ||
69 | { | ||
70 | m_log.DebugFormat("[REGIONMODULES]: Found node {0}", node.Id); | ||
71 | // TODO why does node.Type.isSubclassOf(typeof(ISharedRegionModule)) not work? | ||
72 | if (node.Type.GetInterface(typeof(ISharedRegionModule).ToString()) != null) | ||
73 | { | ||
74 | m_log.DebugFormat("[REGIONMODULES]: Found shared region module {0}, class {1}", node.Id, node.Type); | ||
75 | m_sharedModules.Add(node.Type); | ||
76 | } | ||
77 | else if (node.Type.GetInterface(typeof(INonSharedRegionModule).ToString()) != null) | ||
78 | { | ||
79 | m_log.DebugFormat("[REGIONMODULES]: Found non-shared region module {0}, class {1}", node.Id, node.Type); | ||
80 | m_nonSharedModules.Add(node.Type); | ||
81 | } | ||
82 | else | ||
83 | m_log.DebugFormat("[REGIONMODULES]: Found unknown type of module {0}, class {1}", node.Id, node.Type); | ||
84 | } | ||
85 | |||
86 | // now we've got all the region-module classes loaded, create one instance of every ISharedRegionModule, | ||
87 | // initialize and postinitialize it. This Initialise we are in is called before LoadRegion.PostInitialise | ||
88 | // is called (which loads the regions), so we don't have any regions in the server yet. | ||
89 | foreach (Type type in m_sharedModules) | ||
90 | { | ||
91 | ISharedRegionModule module = (ISharedRegionModule)Activator.CreateInstance(type); | ||
92 | m_sharedInstances.Add(module); | ||
93 | module.Initialise(openSim.ConfigSource.Source); | ||
94 | } | ||
95 | |||
96 | foreach (ISharedRegionModule module in m_sharedInstances) | ||
97 | { | ||
98 | module.PostInitialise(); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public void PostInitialise () | ||
103 | { | ||
104 | } | ||
105 | |||
106 | #endregion | ||
107 | |||
108 | #region IPlugin implementation | ||
109 | |||
110 | public void Initialise () | ||
111 | { | ||
112 | throw new System.NotImplementedException(); | ||
113 | } | ||
114 | |||
115 | #endregion | ||
116 | |||
117 | #region IDisposable implementation | ||
118 | |||
119 | public void Dispose () | ||
120 | { | ||
121 | // we expect that all regions have been removed already | ||
122 | while (m_sharedInstances.Count > 0) | ||
123 | { | ||
124 | m_sharedInstances[0].Close(); | ||
125 | m_sharedInstances.RemoveAt(0); | ||
126 | } | ||
127 | m_sharedModules.Clear(); | ||
128 | m_nonSharedModules.Clear(); | ||
129 | } | ||
130 | |||
131 | #endregion | ||
132 | |||
133 | |||
134 | public string Version | ||
135 | { | ||
136 | get | ||
137 | { | ||
138 | return AddinManager.CurrentAddin.Version; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | public string Name | ||
143 | { | ||
144 | get | ||
145 | { | ||
146 | return m_name; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | #region IRegionModulesController implementation | ||
151 | |||
152 | public void AddRegionToModules (Scene scene) | ||
153 | { | ||
154 | foreach (ISharedRegionModule module in m_sharedInstances) | ||
155 | { | ||
156 | m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to shared module {1}", | ||
157 | scene.RegionInfo.RegionName, module.Name); | ||
158 | module.AddRegion(scene); | ||
159 | scene.AddRegionModule(module.Name, module); | ||
160 | } | ||
161 | |||
162 | foreach (Type type in m_nonSharedModules) | ||
163 | { | ||
164 | INonSharedRegionModule module = (INonSharedRegionModule)Activator.CreateInstance(type); | ||
165 | m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to non-shared module {1}", | ||
166 | scene.RegionInfo.RegionName, module.Name); | ||
167 | module.Initialise(m_openSim.ConfigSource.Source); | ||
168 | module.AddRegion(scene); | ||
169 | scene.AddRegionModule(module.Name, module); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | public void RemoveRegionFromModules (Scene scene) | ||
174 | { | ||
175 | foreach (IRegionModuleBase module in scene.RegionModules.Values) | ||
176 | { | ||
177 | m_log.DebugFormat("[REGIONMODULE]: Removing scene {0} from module {1}", | ||
178 | scene.RegionInfo.RegionName, module.Name); | ||
179 | module.RemoveRegion(scene); | ||
180 | if (module is INonSharedRegionModule) | ||
181 | { | ||
182 | // as we were the only user, this instance has to die | ||
183 | module.Close(); | ||
184 | } | ||
185 | } | ||
186 | scene.RegionModules.Clear(); | ||
187 | } | ||
188 | |||
189 | #endregion | ||
190 | |||
191 | } | ||
192 | } | ||