aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs')
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs182
1 files changed, 0 insertions, 182 deletions
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs
deleted file mode 100644
index 89a90ae..0000000
--- a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs
+++ /dev/null
@@ -1,182 +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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using System.Text;
31using log4net;
32using Nini.Config;
33using OpenSim.ApplicationPlugins.ScriptEngine.Components;
34using OpenSim.Region.Environment.Scenes;
35
36namespace 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 lock (Components)
76 {
77 lock (ComponentRegistry.providers)
78 {
79 try
80 {
81 if (ComponentRegistry.providers.ContainsKey(c))
82 Components.Add(Activator.CreateInstance(ComponentRegistry.providers[c]) as ComponentBase);
83 else
84 m_log.Error("[" + Name + "]: Component \"" + c + "\" not found, can not load");
85 }
86 catch (Exception ex)
87 {
88 m_log.Error("[" + Name + "]: Exception loading \"" + c + "\": " + ex.ToString());
89 }
90 }
91 }
92 }
93
94
95 // Run Initialize on all our providers, hand over a reference of ourself.
96 foreach (ComponentBase p in Components.ToArray())
97 {
98 try
99 {
100 p.Initialize(this);
101 }
102 catch (Exception ex)
103 {
104 lock (Components)
105 {
106 m_log.Error("[" + Name + "]: Error initializing \"" + p.GetType().FullName + "\": " +
107 ex.ToString());
108 if (Components.Contains(p))
109 Components.Remove(p);
110 }
111 }
112 }
113 // All modules has been initialized, call Start() on them.
114 foreach (ComponentBase p in Components.ToArray())
115 {
116 try
117 {
118 p.Start();
119 }
120 catch (Exception ex)
121 {
122 lock (Components)
123 {
124 m_log.Error("[" + Name + "]: Error starting \"" + p.GetType().FullName + "\": " + ex.ToString());
125 if (Components.Contains(p))
126 Components.Remove(p);
127 }
128 }
129 }
130
131 }
132
133 #region Functions to return lists based on type
134 // Predicate for searching List for a certain type
135 private static bool FindType<T>(ComponentBase pb)
136 {
137 if (pb.GetType() is T)
138 return true;
139 return false;
140 }
141 public List<ComponentBase> GetCommandComponentList()
142 {
143 return Components.FindAll(FindType<CommandBase>);
144 }
145 public List<ComponentBase> GetCompilerComponentList()
146 {
147 return Components.FindAll(FindType<CompilerBase>);
148 }
149 public List<ComponentBase> GetEventComponentList()
150 {
151 return Components.FindAll(FindType<EventBase>);
152 }
153 public List<ComponentBase> GetScheduleComponentList()
154 {
155 return Components.FindAll(FindType<SchedulerBase>);
156 }
157
158 #endregion
159
160 public void Close()
161 {
162 // We need to shut down
163
164 // First call abstracted PreClose()
165 PreClose();
166
167 // Then Call Close() on all components
168 foreach (ComponentBase p in Components.ToArray())
169 {
170 try
171 {
172 p.Close();
173 }
174 catch (Exception)
175 {
176 // TODO: Print error to console
177 }
178 }
179 }
180 }
181}
182