opensim – Diff between revs 1 and 2

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 1 Rev 2
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 OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator 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 using System; 28 using System;
29 using System.Collections; 29 using System.Collections;
30 using System.Collections.Generic; 30 using System.Collections.Generic;
31 using System.Reflection; 31 using System.Reflection;
32 using System.Threading; 32 using System.Threading;
33 using log4net; 33 using log4net;
34 using OpenMetaverse; 34 using OpenMetaverse;
35 using OpenSim.Framework; 35 using OpenSim.Framework;
36 using OpenSim.Framework.Monitoring; 36 using OpenSim.Framework.Monitoring;
37 using OpenSim.Region.Framework.Interfaces; 37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.ScriptEngine.Interfaces; 38 using OpenSim.Region.ScriptEngine.Interfaces;
39 using OpenSim.Region.ScriptEngine.Shared; 39 using OpenSim.Region.ScriptEngine.Shared;
40 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 40 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
41 using Timer=OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer; 41 using Timer=OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer;
42   42  
43 namespace OpenSim.Region.ScriptEngine.Shared.Api 43 namespace OpenSim.Region.ScriptEngine.Shared.Api
44 { 44 {
45 /// <summary> 45 /// <summary>
46 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc. 46 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
47 /// </summary> 47 /// </summary>
48 public class AsyncCommandManager 48 public class AsyncCommandManager
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51   51  
52 private static Thread cmdHandlerThread; 52 private static Thread cmdHandlerThread;
53 private static int cmdHandlerThreadCycleSleepms; 53 private static int cmdHandlerThreadCycleSleepms;
54 private static readonly AutoResetEvent cmdHandlerResetEvent = new AutoResetEvent(false); 54 private static readonly AutoResetEvent cmdHandlerResetEvent = new AutoResetEvent(false);
55   55  
56 /// <summary> 56 /// <summary>
57 /// Lock for reading/writing static components of AsyncCommandManager. 57 /// Lock for reading/writing static components of AsyncCommandManager.
58 /// </summary> 58 /// </summary>
59 /// <remarks> 59 /// <remarks>
60 /// This lock exists so that multiple threads from different engines and/or different copies of the same engine 60 /// This lock exists so that multiple threads from different engines and/or different copies of the same engine
61 /// are prevented from running non-thread safe code (e.g. read/write of lists) concurrently. 61 /// are prevented from running non-thread safe code (e.g. read/write of lists) concurrently.
62 /// </remarks> 62 /// </remarks>
63 private static object staticLock = new object(); 63 private static object staticLock = new object();
64   64  
65 private static List<IScriptEngine> m_ScriptEngines = 65 private static List<IScriptEngine> m_ScriptEngines =
66 new List<IScriptEngine>(); 66 new List<IScriptEngine>();
67   67  
68 public IScriptEngine m_ScriptEngine; 68 public IScriptEngine m_ScriptEngine;
69   69  
70 private static Dictionary<IScriptEngine, Dataserver> m_Dataserver = 70 private static Dictionary<IScriptEngine, Dataserver> m_Dataserver =
71 new Dictionary<IScriptEngine, Dataserver>(); 71 new Dictionary<IScriptEngine, Dataserver>();
72 private static Dictionary<IScriptEngine, Timer> m_Timer = 72 private static Dictionary<IScriptEngine, Timer> m_Timer =
73 new Dictionary<IScriptEngine, Timer>(); 73 new Dictionary<IScriptEngine, Timer>();
74 private static Dictionary<IScriptEngine, Listener> m_Listener = 74 private static Dictionary<IScriptEngine, Listener> m_Listener =
75 new Dictionary<IScriptEngine, Listener>(); 75 new Dictionary<IScriptEngine, Listener>();
76 private static Dictionary<IScriptEngine, HttpRequest> m_HttpRequest = 76 private static Dictionary<IScriptEngine, HttpRequest> m_HttpRequest =
77 new Dictionary<IScriptEngine, HttpRequest>(); 77 new Dictionary<IScriptEngine, HttpRequest>();
78 private static Dictionary<IScriptEngine, SensorRepeat> m_SensorRepeat = 78 private static Dictionary<IScriptEngine, SensorRepeat> m_SensorRepeat =
79 new Dictionary<IScriptEngine, SensorRepeat>(); 79 new Dictionary<IScriptEngine, SensorRepeat>();
80 private static Dictionary<IScriptEngine, XmlRequest> m_XmlRequest = 80 private static Dictionary<IScriptEngine, XmlRequest> m_XmlRequest =
81 new Dictionary<IScriptEngine, XmlRequest>(); 81 new Dictionary<IScriptEngine, XmlRequest>();
82   82  
83 public Dataserver DataserverPlugin 83 public Dataserver DataserverPlugin
84 { 84 {
85 get 85 get
86 { 86 {
87 lock (staticLock) 87 lock (staticLock)
88 return m_Dataserver[m_ScriptEngine]; 88 return m_Dataserver[m_ScriptEngine];
89 } 89 }
90 } 90 }
91   91  
92 public Timer TimerPlugin 92 public Timer TimerPlugin
93 { 93 {
94 get 94 get
95 { 95 {
96 lock (staticLock) 96 lock (staticLock)
97 return m_Timer[m_ScriptEngine]; 97 return m_Timer[m_ScriptEngine];
98 } 98 }
99 } 99 }
100   100  
101 public HttpRequest HttpRequestPlugin 101 public HttpRequest HttpRequestPlugin
102 { 102 {
103 get 103 get
104 { 104 {
105 lock (staticLock) 105 lock (staticLock)
106 return m_HttpRequest[m_ScriptEngine]; 106 return m_HttpRequest[m_ScriptEngine];
107 } 107 }
108 } 108 }
109   109  
110 public Listener ListenerPlugin 110 public Listener ListenerPlugin
111 { 111 {
112 get 112 get
113 { 113 {
114 lock (staticLock) 114 lock (staticLock)
115 return m_Listener[m_ScriptEngine]; 115 return m_Listener[m_ScriptEngine];
116 } 116 }
117 } 117 }
118   118  
119 public SensorRepeat SensorRepeatPlugin 119 public SensorRepeat SensorRepeatPlugin
120 { 120 {
121 get 121 get
122 { 122 {
123 lock (staticLock) 123 lock (staticLock)
124 return m_SensorRepeat[m_ScriptEngine]; 124 return m_SensorRepeat[m_ScriptEngine];
125 } 125 }
126 } 126 }
127   127  
128 public XmlRequest XmlRequestPlugin 128 public XmlRequest XmlRequestPlugin
129 { 129 {
130 get 130 get
131 { 131 {
132 lock (staticLock) 132 lock (staticLock)
133 return m_XmlRequest[m_ScriptEngine]; 133 return m_XmlRequest[m_ScriptEngine];
134 } 134 }
135 } 135 }
136   136  
137 public IScriptEngine[] ScriptEngines 137 public IScriptEngine[] ScriptEngines
138 { 138 {
139 get 139 get
140 { 140 {
141 lock (staticLock) 141 lock (staticLock)
142 return m_ScriptEngines.ToArray(); 142 return m_ScriptEngines.ToArray();
143 } 143 }
144 } 144 }
145   145  
146 public AsyncCommandManager(IScriptEngine _ScriptEngine) 146 public AsyncCommandManager(IScriptEngine _ScriptEngine)
147 { 147 {
148 m_ScriptEngine = _ScriptEngine; 148 m_ScriptEngine = _ScriptEngine;
149   149  
150 // If there is more than one scene in the simulator or multiple script engines are used on the same region 150 // If there is more than one scene in the simulator or multiple script engines are used on the same region
151 // then more than one thread could arrive at this block of code simultaneously. However, it cannot be 151 // then more than one thread could arrive at this block of code simultaneously. However, it cannot be
152 // executed concurrently both because concurrent list operations are not thread-safe and because of other 152 // executed concurrently both because concurrent list operations are not thread-safe and because of other
153 // race conditions such as the later check of cmdHandlerThread == null. 153 // race conditions such as the later check of cmdHandlerThread == null.
154 lock (staticLock) 154 lock (staticLock)
155 { 155 {
156 if (m_ScriptEngines.Count == 0) 156 if (m_ScriptEngines.Count == 0)
157 ReadConfig(); 157 ReadConfig();
158   158  
159 if (!m_ScriptEngines.Contains(m_ScriptEngine)) 159 if (!m_ScriptEngines.Contains(m_ScriptEngine))
160 m_ScriptEngines.Add(m_ScriptEngine); 160 m_ScriptEngines.Add(m_ScriptEngine);
161   161  
162 // Create instances of all plugins 162 // Create instances of all plugins
163 if (!m_Dataserver.ContainsKey(m_ScriptEngine)) 163 if (!m_Dataserver.ContainsKey(m_ScriptEngine))
164 m_Dataserver[m_ScriptEngine] = new Dataserver(this); 164 m_Dataserver[m_ScriptEngine] = new Dataserver(this);
165 if (!m_Timer.ContainsKey(m_ScriptEngine)) 165 if (!m_Timer.ContainsKey(m_ScriptEngine))
166 m_Timer[m_ScriptEngine] = new Timer(this); 166 m_Timer[m_ScriptEngine] = new Timer(this);
167 if (!m_HttpRequest.ContainsKey(m_ScriptEngine)) 167 if (!m_HttpRequest.ContainsKey(m_ScriptEngine))
168 m_HttpRequest[m_ScriptEngine] = new HttpRequest(this); 168 m_HttpRequest[m_ScriptEngine] = new HttpRequest(this);
169 if (!m_Listener.ContainsKey(m_ScriptEngine)) 169 if (!m_Listener.ContainsKey(m_ScriptEngine))
170 m_Listener[m_ScriptEngine] = new Listener(this); 170 m_Listener[m_ScriptEngine] = new Listener(this);
171 if (!m_SensorRepeat.ContainsKey(m_ScriptEngine)) 171 if (!m_SensorRepeat.ContainsKey(m_ScriptEngine))
172 m_SensorRepeat[m_ScriptEngine] = new SensorRepeat(this); 172 m_SensorRepeat[m_ScriptEngine] = new SensorRepeat(this);
173 if (!m_XmlRequest.ContainsKey(m_ScriptEngine)) 173 if (!m_XmlRequest.ContainsKey(m_ScriptEngine))
174 m_XmlRequest[m_ScriptEngine] = new XmlRequest(this); 174 m_XmlRequest[m_ScriptEngine] = new XmlRequest(this);
175   175  
176 StartThread(); 176 StartThread();
177 } 177 }
178 } 178 }
179   179  
180 private static void StartThread() 180 private static void StartThread()
181 { 181 {
182 if (cmdHandlerThread == null) 182 if (cmdHandlerThread == null)
183 { 183 {
184 // Start the thread that will be doing the work 184 // Start the thread that will be doing the work
185 cmdHandlerThread 185 cmdHandlerThread
186 = Watchdog.StartThread( 186 = Watchdog.StartThread(
187 CmdHandlerThreadLoop, "AsyncLSLCmdHandlerThread", ThreadPriority.Normal, true, true); 187 CmdHandlerThreadLoop, "AsyncLSLCmdHandlerThread", ThreadPriority.Normal, true, true);
188 } 188 }
189 } 189 }
190   190  
191 private void ReadConfig() 191 private void ReadConfig()
192 { 192 {
193 // cmdHandlerThreadCycleSleepms = m_ScriptEngine.Config.GetInt("AsyncLLCommandLoopms", 100); 193 // cmdHandlerThreadCycleSleepms = m_ScriptEngine.Config.GetInt("AsyncLLCommandLoopms", 100);
194 // TODO: Make this sane again 194 // TODO: Make this sane again
195 cmdHandlerThreadCycleSleepms = 100; 195 cmdHandlerThreadCycleSleepms = 100;
196 } 196 }
197   197  
198 ~AsyncCommandManager() 198 ~AsyncCommandManager()
199 { 199 {
200 // Shut down thread 200 // Shut down thread
201 // try 201 // try
202 // { 202 // {
203 // if (cmdHandlerThread != null) 203 // if (cmdHandlerThread != null)
204 // { 204 // {
205 // if (cmdHandlerThread.IsAlive == true) 205 // if (cmdHandlerThread.IsAlive == true)
206 // { 206 // {
207 // cmdHandlerThread.Abort(); 207 // cmdHandlerThread.Abort();
208 // //cmdHandlerThread.Join(); 208 // //cmdHandlerThread.Join();
209 // } 209 // }
210 // } 210 // }
211 // } 211 // }
212 // catch 212 // catch
213 // { 213 // {
214 // } 214 // }
215 } 215 }
216   216  
217 /// <summary> 217 /// <summary>
218 /// Main loop for the manager thread 218 /// Main loop for the manager thread
219 /// </summary> 219 /// </summary>
220 private static void CmdHandlerThreadLoop() 220 private static void CmdHandlerThreadLoop()
221 { 221 {
222 while (true) 222 while (true)
223 { 223 {
224 try 224 try
225 { 225 {
226 //Thread.Sleep(cmdHandlerThreadCycleSleepms); 226 //Thread.Sleep(cmdHandlerThreadCycleSleepms);
227   227  
228 DoOneCmdHandlerPass(); 228 DoOneCmdHandlerPass();
229 cmdHandlerResetEvent.WaitOne(-1, false); 229 cmdHandlerResetEvent.WaitOne(10, false);
230 Watchdog.UpdateThread(); 230 Watchdog.UpdateThread();
231 } 231 }
232 catch (Exception e) 232 catch (Exception e)
233 { 233 {
234 m_log.Error("[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e); 234 m_log.Error("[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e);
235 } 235 }
236 } 236 }
237 } 237 }
238   238  
239 private static void DoOneCmdHandlerPass() 239 private static void DoOneCmdHandlerPass()
240 { 240 {
241 lock (staticLock) 241 lock (staticLock)
242 { 242 {
243 // Check HttpRequests 243 // Check HttpRequests
244 m_HttpRequest[m_ScriptEngines[0]].CheckHttpRequests(); 244 m_HttpRequest[m_ScriptEngines[0]].CheckHttpRequests();
245   245  
246 // Check XMLRPCRequests 246 // Check XMLRPCRequests
247 m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests(); 247 m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests();
248   248  
249 foreach (IScriptEngine s in m_ScriptEngines) 249 foreach (IScriptEngine s in m_ScriptEngines)
250 { 250 {
251 // Check Listeners 251 // Check Listeners
252 m_Listener[s].CheckListeners(); 252 m_Listener[s].CheckListeners();
253   253  
254 // Check timers 254 // Check timers
255 m_Timer[s].CheckTimerEvents(); 255 m_Timer[s].CheckTimerEvents();
256   256  
257 // Check Sensors 257 // Check Sensors
258 m_SensorRepeat[s].CheckSenseRepeaterEvents(); 258 m_SensorRepeat[s].CheckSenseRepeaterEvents();
259   259  
260 // Check dataserver 260 // Check dataserver
261 m_Dataserver[s].ExpireRequests(); 261 m_Dataserver[s].ExpireRequests();
262 } 262 }
263 } 263 }
264 cmdHandlerResetEvent.Set(); 264 cmdHandlerResetEvent.Set();
265 } 265 }
266   266  
267 /// <summary> 267 /// <summary>
268 /// Remove a specific script (and all its pending commands) 268 /// Remove a specific script (and all its pending commands)
269 /// </summary> 269 /// </summary>
270 /// <param name="localID"></param> 270 /// <param name="localID"></param>
271 /// <param name="itemID"></param> 271 /// <param name="itemID"></param>
272 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID) 272 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID)
273 { 273 {
274 // m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID); 274 // m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID);
275   275  
276 lock (staticLock) 276 lock (staticLock)
277 { 277 {
278 // Remove dataserver events 278 // Remove dataserver events
279 m_Dataserver[engine].RemoveEvents(localID, itemID); 279 m_Dataserver[engine].RemoveEvents(localID, itemID);
280   280  
281 // Remove from: Timers 281 // Remove from: Timers
282 m_Timer[engine].UnSetTimerEvents(localID, itemID); 282 m_Timer[engine].UnSetTimerEvents(localID, itemID);
283   283  
284 // Remove from: HttpRequest 284 // Remove from: HttpRequest
285 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>(); 285 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>();
286 if (iHttpReq != null) 286 if (iHttpReq != null)
287 iHttpReq.StopHttpRequestsForScript(itemID); 287 iHttpReq.StopHttpRequestsForScript(itemID);
288   288  
289 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); 289 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
290 if (comms != null) 290 if (comms != null)
291 comms.DeleteListener(itemID); 291 comms.DeleteListener(itemID);
292   292  
293 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>(); 293 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>();
294 if (xmlrpc != null) 294 if (xmlrpc != null)
295 { 295 {
296 xmlrpc.DeleteChannels(itemID); 296 xmlrpc.DeleteChannels(itemID);
297 xmlrpc.CancelSRDRequests(itemID); 297 xmlrpc.CancelSRDRequests(itemID);
298 } 298 }
299   299  
300 // Remove Sensors 300 // Remove Sensors
301 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID); 301 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
302 } 302 }
303 } 303 }
304   304  
305 /// <summary> 305 /// <summary>
306 /// Get the sensor repeat plugin for this script engine. 306 /// Get the sensor repeat plugin for this script engine.
307 /// </summary> 307 /// </summary>
308 /// <param name="engine"></param> 308 /// <param name="engine"></param>
309 /// <returns></returns> 309 /// <returns></returns>
310 public static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine) 310 public static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine)
311 { 311 {
312 lock (staticLock) 312 lock (staticLock)
313 { 313 {
314 if (m_SensorRepeat.ContainsKey(engine)) 314 if (m_SensorRepeat.ContainsKey(engine))
315 return m_SensorRepeat[engine]; 315 return m_SensorRepeat[engine];
316 else 316 else
317 return null; 317 return null;
318 } 318 }
319 } 319 }
320   320  
321 /// <summary> 321 /// <summary>
322 /// Get the dataserver plugin for this script engine. 322 /// Get the dataserver plugin for this script engine.
323 /// </summary> 323 /// </summary>
324 /// <param name="engine"></param> 324 /// <param name="engine"></param>
325 /// <returns></returns> 325 /// <returns></returns>
326 public static Dataserver GetDataserverPlugin(IScriptEngine engine) 326 public static Dataserver GetDataserverPlugin(IScriptEngine engine)
327 { 327 {
328 lock (staticLock) 328 lock (staticLock)
329 { 329 {
330 if (m_Dataserver.ContainsKey(engine)) 330 if (m_Dataserver.ContainsKey(engine))
331 return m_Dataserver[engine]; 331 return m_Dataserver[engine];
332 else 332 else
333 return null; 333 return null;
334 } 334 }
335 } 335 }
336   336  
337 /// <summary> 337 /// <summary>
338 /// Get the timer plugin for this script engine. 338 /// Get the timer plugin for this script engine.
339 /// </summary> 339 /// </summary>
340 /// <param name="engine"></param> 340 /// <param name="engine"></param>
341 /// <returns></returns> 341 /// <returns></returns>
342 public static Timer GetTimerPlugin(IScriptEngine engine) 342 public static Timer GetTimerPlugin(IScriptEngine engine)
343 { 343 {
344 lock (staticLock) 344 lock (staticLock)
345 { 345 {
346 if (m_Timer.ContainsKey(engine)) 346 if (m_Timer.ContainsKey(engine))
347 return m_Timer[engine]; 347 return m_Timer[engine];
348 else 348 else
349 return null; 349 return null;
350 } 350 }
351 } 351 }
352   352  
353 /// <summary> 353 /// <summary>
354 /// Get the listener plugin for this script engine. 354 /// Get the listener plugin for this script engine.
355 /// </summary> 355 /// </summary>
356 /// <param name="engine"></param> 356 /// <param name="engine"></param>
357 /// <returns></returns> 357 /// <returns></returns>
358 public static Listener GetListenerPlugin(IScriptEngine engine) 358 public static Listener GetListenerPlugin(IScriptEngine engine)
359 { 359 {
360 lock (staticLock) 360 lock (staticLock)
361 { 361 {
362 if (m_Listener.ContainsKey(engine)) 362 if (m_Listener.ContainsKey(engine))
363 return m_Listener[engine]; 363 return m_Listener[engine];
364 else 364 else
365 return null; 365 return null;
366 } 366 }
367 } 367 }
368   368  
369 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) 369 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
370 { 370 {
371 List<Object> data = new List<Object>(); 371 List<Object> data = new List<Object>();
372   372  
373 lock (staticLock) 373 lock (staticLock)
374 { 374 {
375 Object[] listeners = m_Listener[engine].GetSerializationData(itemID); 375 Object[] listeners = m_Listener[engine].GetSerializationData(itemID);
376 if (listeners.Length > 0) 376 if (listeners.Length > 0)
377 { 377 {
378 data.Add("listener"); 378 data.Add("listener");
379 data.Add(listeners.Length); 379 data.Add(listeners.Length);
380 data.AddRange(listeners); 380 data.AddRange(listeners);
381 } 381 }
382   382  
383 Object[] timers=m_Timer[engine].GetSerializationData(itemID); 383 Object[] timers=m_Timer[engine].GetSerializationData(itemID);
384 if (timers.Length > 0) 384 if (timers.Length > 0)
385 { 385 {
386 data.Add("timer"); 386 data.Add("timer");
387 data.Add(timers.Length); 387 data.Add(timers.Length);
388 data.AddRange(timers); 388 data.AddRange(timers);
389 } 389 }
390   390  
391 Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID); 391 Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID);
392 if (sensors.Length > 0) 392 if (sensors.Length > 0)
393 { 393 {
394 data.Add("sensor"); 394 data.Add("sensor");
395 data.Add(sensors.Length); 395 data.Add(sensors.Length);
396 data.AddRange(sensors); 396 data.AddRange(sensors);
397 } 397 }
398 } 398 }
399   399  
400 return data.ToArray(); 400 return data.ToArray();
401 } 401 }
402   402  
403 public static void CreateFromData(IScriptEngine engine, uint localID, 403 public static void CreateFromData(IScriptEngine engine, uint localID,
404 UUID itemID, UUID hostID, Object[] data) 404 UUID itemID, UUID hostID, Object[] data)
405 { 405 {
406 int idx = 0; 406 int idx = 0;
407 int len; 407 int len;
408   408  
409 while (idx < data.Length) 409 while (idx < data.Length)
410 { 410 {
411 string type = data[idx].ToString(); 411 string type = data[idx].ToString();
412 len = (int)data[idx+1]; 412 len = (int)data[idx+1];
413 idx+=2; 413 idx+=2;
414   414  
415 if (len > 0) 415 if (len > 0)
416 { 416 {
417 Object[] item = new Object[len]; 417 Object[] item = new Object[len];
418 Array.Copy(data, idx, item, 0, len); 418 Array.Copy(data, idx, item, 0, len);
419   419  
420 idx+=len; 420 idx+=len;
421   421  
422 lock (staticLock) 422 lock (staticLock)
423 { 423 {
424 switch (type) 424 switch (type)
425 { 425 {
426 case "listener": 426 case "listener":
427 m_Listener[engine].CreateFromData(localID, itemID, 427 m_Listener[engine].CreateFromData(localID, itemID,
428 hostID, item); 428 hostID, item);
429 break; 429 break;
430 case "timer": 430 case "timer":
431 m_Timer[engine].CreateFromData(localID, itemID, 431 m_Timer[engine].CreateFromData(localID, itemID,
432 hostID, item); 432 hostID, item);
433 break; 433 break;
434 case "sensor": 434 case "sensor":
435 m_SensorRepeat[engine].CreateFromData(localID, 435 m_SensorRepeat[engine].CreateFromData(localID,
436 itemID, hostID, item); 436 itemID, hostID, item);
437 break; 437 break;
438 } 438 }
439 } 439 }
440 } 440 }
441 } 441 }
442 } 442 }
443 } 443 }
444 } 444 }
445   445