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