opensim – Diff between revs 5 and 6

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