diff options
author | Tedd Hansen | 2008-09-21 00:03:13 +0000 |
---|---|---|
committer | Tedd Hansen | 2008-09-21 00:03:13 +0000 |
commit | 752d3f3879f13dc77f35b5e8ada2cdf5ba625ee4 (patch) | |
tree | 3aa418cb4f46747c6d789fa6c97a3f7997eabe0a /OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs | |
parent | And re-reverse the names from last commit (diff) | |
download | opensim-SC-752d3f3879f13dc77f35b5e8ada2cdf5ba625ee4.zip opensim-SC-752d3f3879f13dc77f35b5e8ada2cdf5ba625ee4.tar.gz opensim-SC-752d3f3879f13dc77f35b5e8ada2cdf5ba625ee4.tar.bz2 opensim-SC-752d3f3879f13dc77f35b5e8ada2cdf5ba625ee4.tar.xz |
EXPERIMENTAL: Early commit of new Script Engine Component System
Diffstat (limited to 'OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs')
-rw-r--r-- | OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs new file mode 100644 index 0000000..c0a37a0 --- /dev/null +++ b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs | |||
@@ -0,0 +1,166 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using System.Text; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.ApplicationPlugins.ScriptEngine.Components; | ||
34 | using OpenSim.Region.Environment.Scenes; | ||
35 | |||
36 | namespace OpenSim.ApplicationPlugins.ScriptEngine | ||
37 | { | ||
38 | public abstract class RegionScriptEngineBase | ||
39 | { | ||
40 | |||
41 | /// <summary> | ||
42 | /// Called on region initialize | ||
43 | /// </summary> | ||
44 | public abstract void Initialize(); | ||
45 | public abstract string Name { get; } | ||
46 | /// <summary> | ||
47 | /// Called before components receive Close() | ||
48 | /// </summary> | ||
49 | public abstract void PreClose(); | ||
50 | // Hold list of all the different components we have working for us | ||
51 | public List<ComponentBase> Components = new List<ComponentBase>(); | ||
52 | |||
53 | public Scene m_Scene; | ||
54 | public IConfigSource m_ConfigSource; | ||
55 | public readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | public void Initialize(Scene scene, IConfigSource source) | ||
58 | { | ||
59 | // Region started | ||
60 | m_Scene = scene; | ||
61 | m_ConfigSource = source; | ||
62 | Initialize(); | ||
63 | } | ||
64 | |||
65 | /// <summary> | ||
66 | /// Creates instances of script engine components inside "components" List | ||
67 | /// </summary> | ||
68 | /// <param name="ComponentList">Array of comonent names to initialize</param> | ||
69 | public void InitializeComponents(string[] ComponentList) | ||
70 | { | ||
71 | // Take list of providers to initialize and make instances of them | ||
72 | foreach (string c in ComponentList) | ||
73 | { | ||
74 | m_log.Info("[" + Name + "]: Loading: " + c); | ||
75 | try | ||
76 | { | ||
77 | if (ComponentRegistry.providers.ContainsKey(c)) | ||
78 | Components.Add(Activator.CreateInstance(ComponentRegistry.providers[c]) as ComponentBase); | ||
79 | else | ||
80 | m_log.Error("[" + Name + "]: Component \"" + c + "\" not found, can not load"); | ||
81 | } catch (Exception ex) | ||
82 | { | ||
83 | m_log.Error("[" + Name + "]: Exception loading \"" + c + "\": " + ex.ToString()); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
88 | // Run Initialize on all our providers, hand over a reference of ourself. | ||
89 | foreach (ComponentBase p in Components) | ||
90 | { | ||
91 | try | ||
92 | { | ||
93 | p.Initialize(this); | ||
94 | } | ||
95 | catch (Exception ex) | ||
96 | { | ||
97 | m_log.Error("[" + Name + "]: Error initializing \"" + p.GetType().FullName + "\": " + ex.ToString()); | ||
98 | Components.Remove(p); | ||
99 | } | ||
100 | } | ||
101 | // All modules has been initialized, call Start() on them. | ||
102 | foreach (ComponentBase p in Components) | ||
103 | { | ||
104 | try | ||
105 | { | ||
106 | p.Start(); | ||
107 | } | ||
108 | catch (Exception ex) | ||
109 | { | ||
110 | m_log.Error("[" + Name + "]: Error starting \"" + p.GetType().FullName + "\": " + ex.ToString()); | ||
111 | Components.Remove(p); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | } | ||
116 | |||
117 | #region Functions to return lists based on type | ||
118 | // Predicate for searching List for a certain type | ||
119 | private static bool FindType<T>(ComponentBase pb) | ||
120 | { | ||
121 | if (pb.GetType() is T) | ||
122 | return true; | ||
123 | return false; | ||
124 | } | ||
125 | public List<ComponentBase> GetCommandComponentList() | ||
126 | { | ||
127 | return Components.FindAll(FindType<CommandBase>); | ||
128 | } | ||
129 | public List<ComponentBase> GetCompilerComponentList() | ||
130 | { | ||
131 | return Components.FindAll(FindType<CompilerBase>); | ||
132 | } | ||
133 | public List<ComponentBase> GetEventComponentList() | ||
134 | { | ||
135 | return Components.FindAll(FindType<EventBase>); | ||
136 | } | ||
137 | public List<ComponentBase> GetScheduleComponentList() | ||
138 | { | ||
139 | return Components.FindAll(FindType<SchedulerBase>); | ||
140 | } | ||
141 | |||
142 | #endregion | ||
143 | |||
144 | public void Close() | ||
145 | { | ||
146 | // We need to shut down | ||
147 | |||
148 | // First call abstracted PreClose() | ||
149 | PreClose(); | ||
150 | |||
151 | // Then Call Close() on all components | ||
152 | foreach (ComponentBase p in Components) | ||
153 | { | ||
154 | try | ||
155 | { | ||
156 | p.Close(); | ||
157 | } | ||
158 | catch (Exception ex) | ||
159 | { | ||
160 | // TODO: Print error to console | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | |||