aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs296
1 files changed, 148 insertions, 148 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
index 7ce6556..af8a62e 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
@@ -1,148 +1,148 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using System.Threading; 4using System.Threading;
5using libsecondlife; 5using libsecondlife;
6 6
7namespace OpenSim.Region.ScriptEngine.DotNetEngine 7namespace OpenSim.Region.ScriptEngine.DotNetEngine
8{ 8{
9 /// <summary> 9 /// <summary>
10 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc. 10 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
11 /// </summary> 11 /// </summary>
12 class LSLLongCmdHandler 12 class LSLLongCmdHandler
13 { 13 {
14 private Thread cmdHandlerThread; 14 private Thread cmdHandlerThread;
15 private int cmdHandlerThreadCycleSleepms = 100; 15 private int cmdHandlerThreadCycleSleepms = 100;
16 16
17 private ScriptEngine m_ScriptEngine; 17 private ScriptEngine m_ScriptEngine;
18 public LSLLongCmdHandler(ScriptEngine _ScriptEngine) 18 public LSLLongCmdHandler(ScriptEngine _ScriptEngine)
19 { 19 {
20 m_ScriptEngine = _ScriptEngine; 20 m_ScriptEngine = _ScriptEngine;
21 21
22 // Start the thread that will be doing the work 22 // Start the thread that will be doing the work
23 cmdHandlerThread = new Thread(CmdHandlerThreadLoop); 23 cmdHandlerThread = new Thread(CmdHandlerThreadLoop);
24 cmdHandlerThread.Name = "CmdHandlerThread"; 24 cmdHandlerThread.Name = "CmdHandlerThread";
25 cmdHandlerThread.Priority = ThreadPriority.BelowNormal; 25 cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
26 cmdHandlerThread.IsBackground = true; 26 cmdHandlerThread.IsBackground = true;
27 cmdHandlerThread.Start(); 27 cmdHandlerThread.Start();
28 } 28 }
29 ~LSLLongCmdHandler() 29 ~LSLLongCmdHandler()
30 { 30 {
31 // Shut down thread 31 // Shut down thread
32 try 32 try
33 { 33 {
34 if (cmdHandlerThread != null) 34 if (cmdHandlerThread != null)
35 { 35 {
36 if (cmdHandlerThread.IsAlive == true) 36 if (cmdHandlerThread.IsAlive == true)
37 { 37 {
38 cmdHandlerThread.Abort(); 38 cmdHandlerThread.Abort();
39 cmdHandlerThread.Join(); 39 cmdHandlerThread.Join();
40 } 40 }
41 } 41 }
42 } 42 }
43 catch { } 43 catch { }
44 } 44 }
45 45
46 private void CmdHandlerThreadLoop() 46 private void CmdHandlerThreadLoop()
47 { 47 {
48 while (true) 48 while (true)
49 { 49 {
50 // Check timers 50 // Check timers
51 CheckTimerEvents(); 51 CheckTimerEvents();
52 52
53 // Sleep before next cycle 53 // Sleep before next cycle
54 Thread.Sleep(cmdHandlerThreadCycleSleepms); 54 Thread.Sleep(cmdHandlerThreadCycleSleepms);
55 } 55 }
56 } 56 }
57 57
58 /// <summary> 58 /// <summary>
59 /// Remove a specific script (and all its pending commands) 59 /// Remove a specific script (and all its pending commands)
60 /// </summary> 60 /// </summary>
61 /// <param name="m_localID"></param> 61 /// <param name="m_localID"></param>
62 /// <param name="m_itemID"></param> 62 /// <param name="m_itemID"></param>
63 public void RemoveScript(uint m_localID, LLUUID m_itemID) 63 public void RemoveScript(uint m_localID, LLUUID m_itemID)
64 { 64 {
65 // Remove a specific script 65 // Remove a specific script
66 66
67 // Remove from: Timers 67 // Remove from: Timers
68 UnSetTimerEvents(m_localID, m_itemID); 68 UnSetTimerEvents(m_localID, m_itemID);
69 } 69 }
70 70
71 71
72 // 72 //
73 // TIMER 73 // TIMER
74 // 74 //
75 private class TimerClass 75 private class TimerClass
76 { 76 {
77 public uint localID; 77 public uint localID;
78 public LLUUID itemID; 78 public LLUUID itemID;
79 public double interval; 79 public double interval;
80 public DateTime next; 80 public DateTime next;
81 } 81 }
82 private List<TimerClass> Timers = new List<TimerClass>(); 82 private List<TimerClass> Timers = new List<TimerClass>();
83 private object ListLock = new object(); 83 private object ListLock = new object();
84 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec) 84 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec)
85 { 85 {
86 Console.WriteLine("SetTimerEvent"); 86 Console.WriteLine("SetTimerEvent");
87 87
88 // Always remove first, in case this is a re-set 88 // Always remove first, in case this is a re-set
89 UnSetTimerEvents(m_localID, m_itemID); 89 UnSetTimerEvents(m_localID, m_itemID);
90 if (sec == 0) // Disabling timer 90 if (sec == 0) // Disabling timer
91 return; 91 return;
92 92
93 // Add to timer 93 // Add to timer
94 TimerClass ts = new TimerClass(); 94 TimerClass ts = new TimerClass();
95 ts.localID = m_localID; 95 ts.localID = m_localID;
96 ts.itemID = m_itemID; 96 ts.itemID = m_itemID;
97 ts.interval = sec; 97 ts.interval = sec;
98 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); 98 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
99 lock (ListLock) 99 lock (ListLock)
100 { 100 {
101 Timers.Add(ts); 101 Timers.Add(ts);
102 } 102 }
103 } 103 }
104 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID) 104 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID)
105 { 105 {
106 // Remove from timer 106 // Remove from timer
107 lock (ListLock) 107 lock (ListLock)
108 { 108 {
109 List<TimerClass> NewTimers = new List<TimerClass>(); 109 List<TimerClass> NewTimers = new List<TimerClass>();
110 foreach (TimerClass ts in Timers) 110 foreach (TimerClass ts in Timers)
111 { 111 {
112 if (ts.localID != m_localID && ts.itemID != m_itemID) 112 if (ts.localID != m_localID && ts.itemID != m_itemID)
113 { 113 {
114 NewTimers.Add(ts); 114 NewTimers.Add(ts);
115 } 115 }
116 } 116 }
117 Timers.Clear(); 117 Timers.Clear();
118 Timers = NewTimers; 118 Timers = NewTimers;
119 } 119 }
120 } 120 }
121 public void CheckTimerEvents() 121 public void CheckTimerEvents()
122 { 122 {
123 // Nothing to do here? 123 // Nothing to do here?
124 if (Timers.Count == 0) 124 if (Timers.Count == 0)
125 return; 125 return;
126 126
127 lock (ListLock) 127 lock (ListLock)
128 { 128 {
129 129
130 // Go through all timers 130 // Go through all timers
131 foreach (TimerClass ts in Timers) 131 foreach (TimerClass ts in Timers)
132 { 132 {
133 // Time has passed? 133 // Time has passed?
134 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) 134 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
135 { 135 {
136 // Add it to queue 136 // Add it to queue
137 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", new object[] { }); 137 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", new object[] { });
138 // set next interval 138 // set next interval
139 139
140 140
141 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); 141 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
142 } 142 }
143 } 143 }
144 } // lock 144 } // lock
145 } 145 }
146 146
147 } 147 }
148} 148}