opensim – Diff between revs 3 and 4

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 3 Rev 4
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 System.Timers.Timer cmdEventTimer = new System.Timers.Timer();
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 (!cmdEventTimer.Enabled.Equals(false)) return;
182 if (cmdHandlerThread == null) 183 // Start the timer event
-   184 cmdEventTimer.Elapsed += (sender, args) =>
183 { 185 {
-   186 try
-   187 {
184 // Start the thread that will be doing the work 188 DoOneCmdHandlerPass();
185 cmdHandlerThread 189 }
186 = Watchdog.StartThread( 190 catch (Exception e)
-   191 {
187 CmdHandlerThreadLoop, "AsyncLSLCmdHandlerThread", ThreadPriority.Normal, true, true); 192 m_log.Error("[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e);
-   193 }
188 } 194 };
-   195 cmdEventTimer.Interval = cmdHandlerThreadCycleSleepms;
-   196 cmdEventTimer.Enabled = true;
189 } 197 }
190   198  
191 private void ReadConfig() 199 private void ReadConfig()
192 { 200 {
193 // cmdHandlerThreadCycleSleepms = m_ScriptEngine.Config.GetInt("AsyncLLCommandLoopms", 100); 201 // cmdHandlerThreadCycleSleepms = m_ScriptEngine.Config.GetInt("AsyncLLCommandLoopms", 100);
194 // TODO: Make this sane again 202 // TODO: Make this sane again
195 cmdHandlerThreadCycleSleepms = 100; 203 cmdHandlerThreadCycleSleepms = 10;
196 } 204 }
197   205  
198 ~AsyncCommandManager() 206 ~AsyncCommandManager()
199 { 207 {
200 // Shut down thread 208 // Shut down thread
201 // try 209 // try
202 // { 210 // {
203 // if (cmdHandlerThread != null) 211 // if (cmdHandlerThread != null)
204 // { 212 // {
205 // if (cmdHandlerThread.IsAlive == true) 213 // if (cmdHandlerThread.IsAlive == true)
206 // { 214 // {
207 // cmdHandlerThread.Abort(); 215 // cmdHandlerThread.Abort();
208 // //cmdHandlerThread.Join(); 216 // //cmdHandlerThread.Join();
209 // } 217 // }
210 // } 218 // }
211 // } 219 // }
212 // catch 220 // catch
213 // { 221 // {
214 // } 222 // }
215 } 223 }
216   224  
217 /// <summary> 225 /// <summary>
218 /// Main loop for the manager thread 226 /// Main loop for the manager thread
219 /// </summary> 227 /// </summary>
220 private static void CmdHandlerThreadLoop() 228 private static void CmdHandlerThreadLoop()
221 { 229 {
222 while (true) 230 while (true)
223 { 231 {
224 try 232 try
225 { 233 {
226 //Thread.Sleep(cmdHandlerThreadCycleSleepms); 234 Thread.Sleep(cmdHandlerThreadCycleSleepms);
227   235  
228 DoOneCmdHandlerPass(); -  
-   236 DoOneCmdHandlerPass();
229 cmdHandlerResetEvent.WaitOne(cmdHandlerThreadCycleSleepms, false); 237  
230 Watchdog.UpdateThread(); 238 Watchdog.UpdateThread();
231 } 239 }
232 catch (Exception e) 240 catch (Exception e)
233 { 241 {
234 m_log.Error("[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e); 242 m_log.Error("[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e);
235 } 243 }
236 } 244 }
237 } 245 }
238   246  
239 private static void DoOneCmdHandlerPass() 247 private static void DoOneCmdHandlerPass()
240 { 248 {
241 lock (staticLock) 249 lock (staticLock)
242 { 250 {
243 // Check HttpRequests 251 // Check HttpRequests
244 m_HttpRequest[m_ScriptEngines[0]].CheckHttpRequests(); 252 m_HttpRequest[m_ScriptEngines[0]].CheckHttpRequests();
245   253  
246 // Check XMLRPCRequests 254 // Check XMLRPCRequests
247 m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests(); 255 m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests();
248   256  
249 foreach (IScriptEngine s in m_ScriptEngines) 257 foreach (IScriptEngine s in m_ScriptEngines)
250 { 258 {
251 // Check Listeners 259 // Check Listeners
252 m_Listener[s].CheckListeners(); 260 m_Listener[s].CheckListeners();
253   261  
254 // Check timers 262 // Check timers
255 m_Timer[s].CheckTimerEvents(); 263 m_Timer[s].CheckTimerEvents();
256   264  
257 // Check Sensors 265 // Check Sensors
258 m_SensorRepeat[s].CheckSenseRepeaterEvents(); 266 m_SensorRepeat[s].CheckSenseRepeaterEvents();
259   267  
260 // Check dataserver 268 // Check dataserver
261 m_Dataserver[s].ExpireRequests(); 269 m_Dataserver[s].ExpireRequests();
262 } 270 }
263 } 271 }
264 cmdHandlerResetEvent.Set(); -  
265 } 272 }
266   273  
267 /// <summary> 274 /// <summary>
268 /// Remove a specific script (and all its pending commands) 275 /// Remove a specific script (and all its pending commands)
269 /// </summary> 276 /// </summary>
270 /// <param name="localID"></param> 277 /// <param name="localID"></param>
271 /// <param name="itemID"></param> 278 /// <param name="itemID"></param>
272 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID) 279 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID)
273 { 280 {
274 // m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID); 281 // m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID);
275   282  
276 lock (staticLock) 283 lock (staticLock)
277 { 284 {
278 // Remove dataserver events 285 // Remove dataserver events
279 m_Dataserver[engine].RemoveEvents(localID, itemID); 286 m_Dataserver[engine].RemoveEvents(localID, itemID);
280   287  
281 // Remove from: Timers 288 // Remove from: Timers
282 m_Timer[engine].UnSetTimerEvents(localID, itemID); 289 m_Timer[engine].UnSetTimerEvents(localID, itemID);
283   290  
284 // Remove from: HttpRequest 291 // Remove from: HttpRequest
285 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>(); 292 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>();
286 if (iHttpReq != null) 293 if (iHttpReq != null)
287 iHttpReq.StopHttpRequestsForScript(itemID); 294 iHttpReq.StopHttpRequestsForScript(itemID);
288   295  
289 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); 296 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
290 if (comms != null) 297 if (comms != null)
291 comms.DeleteListener(itemID); 298 comms.DeleteListener(itemID);
292   299  
293 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>(); 300 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>();
294 if (xmlrpc != null) 301 if (xmlrpc != null)
295 { 302 {
296 xmlrpc.DeleteChannels(itemID); 303 xmlrpc.DeleteChannels(itemID);
297 xmlrpc.CancelSRDRequests(itemID); 304 xmlrpc.CancelSRDRequests(itemID);
298 } 305 }
299   306  
300 // Remove Sensors 307 // Remove Sensors
301 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID); 308 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
302 } 309 }
303 } 310 }
304   311  
305 /// <summary> 312 /// <summary>
306 /// Get the sensor repeat plugin for this script engine. 313 /// Get the sensor repeat plugin for this script engine.
307 /// </summary> 314 /// </summary>
308 /// <param name="engine"></param> 315 /// <param name="engine"></param>
309 /// <returns></returns> 316 /// <returns></returns>
310 public static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine) 317 public static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine)
311 { 318 {
312 lock (staticLock) 319 lock (staticLock)
313 { 320 {
314 if (m_SensorRepeat.ContainsKey(engine)) 321 if (m_SensorRepeat.ContainsKey(engine))
315 return m_SensorRepeat[engine]; 322 return m_SensorRepeat[engine];
316 else 323 else
317 return null; 324 return null;
318 } 325 }
319 } 326 }
320   327  
321 /// <summary> 328 /// <summary>
322 /// Get the dataserver plugin for this script engine. 329 /// Get the dataserver plugin for this script engine.
323 /// </summary> 330 /// </summary>
324 /// <param name="engine"></param> 331 /// <param name="engine"></param>
325 /// <returns></returns> 332 /// <returns></returns>
326 public static Dataserver GetDataserverPlugin(IScriptEngine engine) 333 public static Dataserver GetDataserverPlugin(IScriptEngine engine)
327 { 334 {
328 lock (staticLock) 335 lock (staticLock)
329 { 336 {
330 if (m_Dataserver.ContainsKey(engine)) 337 if (m_Dataserver.ContainsKey(engine))
331 return m_Dataserver[engine]; 338 return m_Dataserver[engine];
332 else 339 else
333 return null; 340 return null;
334 } 341 }
335 } 342 }
336   343  
337 /// <summary> 344 /// <summary>
338 /// Get the timer plugin for this script engine. 345 /// Get the timer plugin for this script engine.
339 /// </summary> 346 /// </summary>
340 /// <param name="engine"></param> 347 /// <param name="engine"></param>
341 /// <returns></returns> 348 /// <returns></returns>
342 public static Timer GetTimerPlugin(IScriptEngine engine) 349 public static Timer GetTimerPlugin(IScriptEngine engine)
343 { 350 {
344 lock (staticLock) 351 lock (staticLock)
345 { 352 {
346 if (m_Timer.ContainsKey(engine)) 353 if (m_Timer.ContainsKey(engine))
347 return m_Timer[engine]; 354 return m_Timer[engine];
348 else 355 else
349 return null; 356 return null;
350 } 357 }
351 } 358 }
352   359  
353 /// <summary> 360 /// <summary>
354 /// Get the listener plugin for this script engine. 361 /// Get the listener plugin for this script engine.
355 /// </summary> 362 /// </summary>
356 /// <param name="engine"></param> 363 /// <param name="engine"></param>
357 /// <returns></returns> 364 /// <returns></returns>
358 public static Listener GetListenerPlugin(IScriptEngine engine) 365 public static Listener GetListenerPlugin(IScriptEngine engine)
359 { 366 {
360 lock (staticLock) 367 lock (staticLock)
361 { 368 {
362 if (m_Listener.ContainsKey(engine)) 369 if (m_Listener.ContainsKey(engine))
363 return m_Listener[engine]; 370 return m_Listener[engine];
364 else 371 else
365 return null; 372 return null;
366 } 373 }
367 } 374 }
368   375  
369 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) 376 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
370 { 377 {
371 List<Object> data = new List<Object>(); 378 List<Object> data = new List<Object>();
372   379  
373 lock (staticLock) 380 lock (staticLock)
374 { 381 {
375 Object[] listeners = m_Listener[engine].GetSerializationData(itemID); 382 Object[] listeners = m_Listener[engine].GetSerializationData(itemID);
376 if (listeners.Length > 0) 383 if (listeners.Length > 0)
377 { 384 {
378 data.Add("listener"); 385 data.Add("listener");
379 data.Add(listeners.Length); 386 data.Add(listeners.Length);
380 data.AddRange(listeners); 387 data.AddRange(listeners);
381 } 388 }
382   389  
383 Object[] timers=m_Timer[engine].GetSerializationData(itemID); 390 Object[] timers=m_Timer[engine].GetSerializationData(itemID);
384 if (timers.Length > 0) 391 if (timers.Length > 0)
385 { 392 {
386 data.Add("timer"); 393 data.Add("timer");
387 data.Add(timers.Length); 394 data.Add(timers.Length);
388 data.AddRange(timers); 395 data.AddRange(timers);
389 } 396 }
390   397  
391 Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID); 398 Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID);
392 if (sensors.Length > 0) 399 if (sensors.Length > 0)
393 { 400 {
394 data.Add("sensor"); 401 data.Add("sensor");
395 data.Add(sensors.Length); 402 data.Add(sensors.Length);
396 data.AddRange(sensors); 403 data.AddRange(sensors);
397 } 404 }
398 } 405 }
399   406  
400 return data.ToArray(); 407 return data.ToArray();
401 } 408 }
402   409  
403 public static void CreateFromData(IScriptEngine engine, uint localID, 410 public static void CreateFromData(IScriptEngine engine, uint localID,
404 UUID itemID, UUID hostID, Object[] data) 411 UUID itemID, UUID hostID, Object[] data)
405 { 412 {
406 int idx = 0; 413 int idx = 0;
407 int len; 414 int len;
408   415  
409 while (idx < data.Length) 416 while (idx < data.Length)
410 { 417 {
411 string type = data[idx].ToString(); 418 string type = data[idx].ToString();
412 len = (int)data[idx+1]; 419 len = (int)data[idx+1];
413 idx+=2; 420 idx+=2;
414   421  
415 if (len > 0) 422 if (len > 0)
416 { 423 {
417 Object[] item = new Object[len]; 424 Object[] item = new Object[len];
418 Array.Copy(data, idx, item, 0, len); 425 Array.Copy(data, idx, item, 0, len);
419   426  
420 idx+=len; 427 idx+=len;
421   428  
422 lock (staticLock) 429 lock (staticLock)
423 { 430 {
424 switch (type) 431 switch (type)
425 { 432 {
426 case "listener": 433 case "listener":
427 m_Listener[engine].CreateFromData(localID, itemID, 434 m_Listener[engine].CreateFromData(localID, itemID,
428 hostID, item); 435 hostID, item);
429 break; 436 break;
430 case "timer": 437 case "timer":
431 m_Timer[engine].CreateFromData(localID, itemID, 438 m_Timer[engine].CreateFromData(localID, itemID,
432 hostID, item); 439 hostID, item);
433 break; 440 break;
434 case "sensor": 441 case "sensor":
435 m_SensorRepeat[engine].CreateFromData(localID, 442 m_SensorRepeat[engine].CreateFromData(localID,
436 itemID, hostID, item); 443 itemID, hostID, item);
437 break; 444 break;
438 } 445 }
439 } 446 }
440 } 447 }
441 } 448 }
442 } 449 }
443 } 450 }
444 } 451 }
445   452  
-   453
Generated by GNU Enscript 1.6.5.90.
-   454  
-   455  
-   456