aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
diff options
context:
space:
mode:
authorSean Dague2007-09-17 12:52:03 +0000
committerSean Dague2007-09-17 12:52:03 +0000
commitb8d9737a47696952bedec33dface8f18df47341f (patch)
tree9279f45510f8a9285ac5b9c9165ab6c741009eac /OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
parentI think this is the last bits for a consistant pristine (diff)
downloadopensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.zip
opensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.tar.gz
opensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.tar.bz2
opensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.tar.xz
fixing me some line endings
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs524
1 files changed, 262 insertions, 262 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
index a45de1e..8ab0c30 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
@@ -1,262 +1,262 @@
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;
6using OpenSim.Region.ScriptEngine.Common; 6using OpenSim.Region.ScriptEngine.Common;
7 7
8namespace OpenSim.Region.ScriptEngine.DotNetEngine 8namespace OpenSim.Region.ScriptEngine.DotNetEngine
9{ 9{
10 /// <summary> 10 /// <summary>
11 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc. 11 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
12 /// </summary> 12 /// </summary>
13 class LSLLongCmdHandler 13 class LSLLongCmdHandler
14 { 14 {
15 private Thread cmdHandlerThread; 15 private Thread cmdHandlerThread;
16 private int cmdHandlerThreadCycleSleepms = 100; 16 private int cmdHandlerThreadCycleSleepms = 100;
17 17
18 private ScriptEngine m_ScriptEngine; 18 private ScriptEngine m_ScriptEngine;
19 public LSLLongCmdHandler(ScriptEngine _ScriptEngine) 19 public LSLLongCmdHandler(ScriptEngine _ScriptEngine)
20 { 20 {
21 m_ScriptEngine = _ScriptEngine; 21 m_ScriptEngine = _ScriptEngine;
22 22
23 // Start the thread that will be doing the work 23 // Start the thread that will be doing the work
24 cmdHandlerThread = new Thread(CmdHandlerThreadLoop); 24 cmdHandlerThread = new Thread(CmdHandlerThreadLoop);
25 cmdHandlerThread.Name = "CmdHandlerThread"; 25 cmdHandlerThread.Name = "CmdHandlerThread";
26 cmdHandlerThread.Priority = ThreadPriority.BelowNormal; 26 cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
27 cmdHandlerThread.IsBackground = true; 27 cmdHandlerThread.IsBackground = true;
28 cmdHandlerThread.Start(); 28 cmdHandlerThread.Start();
29 } 29 }
30 ~LSLLongCmdHandler() 30 ~LSLLongCmdHandler()
31 { 31 {
32 // Shut down thread 32 // Shut down thread
33 try 33 try
34 { 34 {
35 if (cmdHandlerThread != null) 35 if (cmdHandlerThread != null)
36 { 36 {
37 if (cmdHandlerThread.IsAlive == true) 37 if (cmdHandlerThread.IsAlive == true)
38 { 38 {
39 cmdHandlerThread.Abort(); 39 cmdHandlerThread.Abort();
40 cmdHandlerThread.Join(); 40 cmdHandlerThread.Join();
41 } 41 }
42 } 42 }
43 } 43 }
44 catch { } 44 catch { }
45 } 45 }
46 46
47 private void CmdHandlerThreadLoop() 47 private void CmdHandlerThreadLoop()
48 { 48 {
49 while (true) 49 while (true)
50 { 50 {
51 // Check timers 51 // Check timers
52 CheckTimerEvents(); 52 CheckTimerEvents();
53 // Check HttpRequests 53 // Check HttpRequests
54 CheckHttpRequests(); 54 CheckHttpRequests();
55 55
56 // Sleep before next cycle 56 // Sleep before next cycle
57 Thread.Sleep(cmdHandlerThreadCycleSleepms); 57 Thread.Sleep(cmdHandlerThreadCycleSleepms);
58 } 58 }
59 } 59 }
60 60
61 /// <summary> 61 /// <summary>
62 /// Remove a specific script (and all its pending commands) 62 /// Remove a specific script (and all its pending commands)
63 /// </summary> 63 /// </summary>
64 /// <param name="m_localID"></param> 64 /// <param name="m_localID"></param>
65 /// <param name="m_itemID"></param> 65 /// <param name="m_itemID"></param>
66 public void RemoveScript(uint localID, LLUUID itemID) 66 public void RemoveScript(uint localID, LLUUID itemID)
67 { 67 {
68 // Remove a specific script 68 // Remove a specific script
69 69
70 // Remove from: Timers 70 // Remove from: Timers
71 UnSetTimerEvents(localID, itemID); 71 UnSetTimerEvents(localID, itemID);
72 // Remove from: HttpRequest 72 // Remove from: HttpRequest
73 StopHttpRequest(localID, itemID); 73 StopHttpRequest(localID, itemID);
74 } 74 }
75 75
76 #region TIMER 76 #region TIMER
77 77
78 // 78 //
79 // TIMER 79 // TIMER
80 // 80 //
81 private class TimerClass 81 private class TimerClass
82 { 82 {
83 public uint localID; 83 public uint localID;
84 public LLUUID itemID; 84 public LLUUID itemID;
85 public double interval; 85 public double interval;
86 public DateTime next; 86 public DateTime next;
87 } 87 }
88 private List<TimerClass> Timers = new List<TimerClass>(); 88 private List<TimerClass> Timers = new List<TimerClass>();
89 private object TimerListLock = new object(); 89 private object TimerListLock = new object();
90 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec) 90 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec)
91 { 91 {
92 Console.WriteLine("SetTimerEvent"); 92 Console.WriteLine("SetTimerEvent");
93 93
94 // Always remove first, in case this is a re-set 94 // Always remove first, in case this is a re-set
95 UnSetTimerEvents(m_localID, m_itemID); 95 UnSetTimerEvents(m_localID, m_itemID);
96 if (sec == 0) // Disabling timer 96 if (sec == 0) // Disabling timer
97 return; 97 return;
98 98
99 // Add to timer 99 // Add to timer
100 TimerClass ts = new TimerClass(); 100 TimerClass ts = new TimerClass();
101 ts.localID = m_localID; 101 ts.localID = m_localID;
102 ts.itemID = m_itemID; 102 ts.itemID = m_itemID;
103 ts.interval = sec; 103 ts.interval = sec;
104 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); 104 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
105 lock (TimerListLock) 105 lock (TimerListLock)
106 { 106 {
107 Timers.Add(ts); 107 Timers.Add(ts);
108 } 108 }
109 } 109 }
110 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID) 110 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID)
111 { 111 {
112 // Remove from timer 112 // Remove from timer
113 lock (TimerListLock) 113 lock (TimerListLock)
114 { 114 {
115 List<TimerClass> NewTimers = new List<TimerClass>(); 115 List<TimerClass> NewTimers = new List<TimerClass>();
116 foreach (TimerClass ts in Timers) 116 foreach (TimerClass ts in Timers)
117 { 117 {
118 if (ts.localID != m_localID && ts.itemID != m_itemID) 118 if (ts.localID != m_localID && ts.itemID != m_itemID)
119 { 119 {
120 NewTimers.Add(ts); 120 NewTimers.Add(ts);
121 } 121 }
122 } 122 }
123 Timers.Clear(); 123 Timers.Clear();
124 Timers = NewTimers; 124 Timers = NewTimers;
125 } 125 }
126 } 126 }
127 public void CheckTimerEvents() 127 public void CheckTimerEvents()
128 { 128 {
129 // Nothing to do here? 129 // Nothing to do here?
130 if (Timers.Count == 0) 130 if (Timers.Count == 0)
131 return; 131 return;
132 132
133 lock (TimerListLock) 133 lock (TimerListLock)
134 { 134 {
135 135
136 // Go through all timers 136 // Go through all timers
137 foreach (TimerClass ts in Timers) 137 foreach (TimerClass ts in Timers)
138 { 138 {
139 // Time has passed? 139 // Time has passed?
140 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) 140 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
141 { 141 {
142 // Add it to queue 142 // Add it to queue
143 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", new object[] { }); 143 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", new object[] { });
144 // set next interval 144 // set next interval
145 145
146 146
147 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); 147 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
148 } 148 }
149 } 149 }
150 } // lock 150 } // lock
151 } 151 }
152 #endregion 152 #endregion
153 153
154 #region HTTP REQUEST 154 #region HTTP REQUEST
155 155
156 // 156 //
157 // HTTP REAQUEST 157 // HTTP REAQUEST
158 // 158 //
159 private class HttpClass 159 private class HttpClass
160 { 160 {
161 public uint localID; 161 public uint localID;
162 public LLUUID itemID; 162 public LLUUID itemID;
163 public string url; 163 public string url;
164 public List<string> parameters; 164 public List<string> parameters;
165 public string body; 165 public string body;
166 public DateTime next; 166 public DateTime next;
167 167
168 public string response_request_id; 168 public string response_request_id;
169 public int response_status; 169 public int response_status;
170 public List<string> response_metadata; 170 public List<string> response_metadata;
171 public string response_body; 171 public string response_body;
172 172
173 public void SendRequest() 173 public void SendRequest()
174 { 174 {
175 // TODO: SEND REQUEST!!! 175 // TODO: SEND REQUEST!!!
176 } 176 }
177 public void Stop() 177 public void Stop()
178 { 178 {
179 // TODO: Cancel any ongoing request 179 // TODO: Cancel any ongoing request
180 } 180 }
181 public bool CheckResponse() 181 public bool CheckResponse()
182 { 182 {
183 // TODO: Check if we got a response yet, return true if so -- false if not 183 // TODO: Check if we got a response yet, return true if so -- false if not
184 return true; 184 return true;
185 185
186 // TODO: If we got a response, set the following then return true 186 // TODO: If we got a response, set the following then return true
187 //response_request_id 187 //response_request_id
188 //response_status 188 //response_status
189 //response_metadata 189 //response_metadata
190 //response_body 190 //response_body
191 191
192 } 192 }
193 } 193 }
194 private List<HttpClass> HttpRequests = new List<HttpClass>(); 194 private List<HttpClass> HttpRequests = new List<HttpClass>();
195 private object HttpListLock = new object(); 195 private object HttpListLock = new object();
196 public void StartHttpRequest(uint localID, LLUUID itemID, string url, List<string> parameters, string body) 196 public void StartHttpRequest(uint localID, LLUUID itemID, string url, List<string> parameters, string body)
197 { 197 {
198 Console.WriteLine("StartHttpRequest"); 198 Console.WriteLine("StartHttpRequest");
199 199
200 HttpClass htc = new HttpClass(); 200 HttpClass htc = new HttpClass();
201 htc.localID = localID; 201 htc.localID = localID;
202 htc.itemID = itemID; 202 htc.itemID = itemID;
203 htc.url = url; 203 htc.url = url;
204 htc.parameters = parameters; 204 htc.parameters = parameters;
205 htc.body = body; 205 htc.body = body;
206 lock (HttpListLock) 206 lock (HttpListLock)
207 { 207 {
208 208
209 //ADD REQUEST 209 //ADD REQUEST
210 HttpRequests.Add(htc); 210 HttpRequests.Add(htc);
211 } 211 }
212 } 212 }
213 public void StopHttpRequest(uint m_localID, LLUUID m_itemID) 213 public void StopHttpRequest(uint m_localID, LLUUID m_itemID)
214 { 214 {
215 // Remove from list 215 // Remove from list
216 lock (HttpListLock) 216 lock (HttpListLock)
217 { 217 {
218 List<HttpClass> NewHttpList = new List<HttpClass>(); 218 List<HttpClass> NewHttpList = new List<HttpClass>();
219 foreach (HttpClass ts in HttpRequests) 219 foreach (HttpClass ts in HttpRequests)
220 { 220 {
221 if (ts.localID != m_localID && ts.itemID != m_itemID) 221 if (ts.localID != m_localID && ts.itemID != m_itemID)
222 { 222 {
223 // Keeping this one 223 // Keeping this one
224 NewHttpList.Add(ts); 224 NewHttpList.Add(ts);
225 } 225 }
226 else 226 else
227 { 227 {
228 // Shutting this one down 228 // Shutting this one down
229 ts.Stop(); 229 ts.Stop();
230 } 230 }
231 } 231 }
232 HttpRequests.Clear(); 232 HttpRequests.Clear();
233 HttpRequests = NewHttpList; 233 HttpRequests = NewHttpList;
234 } 234 }
235 } 235 }
236 public void CheckHttpRequests() 236 public void CheckHttpRequests()
237 { 237 {
238 // Nothing to do here? 238 // Nothing to do here?
239 if (HttpRequests.Count == 0) 239 if (HttpRequests.Count == 0)
240 return; 240 return;
241 241
242 lock (HttpListLock) 242 lock (HttpListLock)
243 { 243 {
244 foreach (HttpClass ts in HttpRequests) 244 foreach (HttpClass ts in HttpRequests)
245 { 245 {
246 246
247 if (ts.CheckResponse() == true) 247 if (ts.CheckResponse() == true)
248 { 248 {
249 // Add it to event queue 249 // Add it to event queue
250 //key request_id, integer status, list metadata, string body 250 //key request_id, integer status, list metadata, string body
251 object[] resobj = new object[] { ts.response_request_id, ts.response_status, ts.response_metadata, ts.response_body }; 251 object[] resobj = new object[] { ts.response_request_id, ts.response_status, ts.response_metadata, ts.response_body };
252 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "http_response", resobj); 252 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "http_response", resobj);
253 // Now stop it 253 // Now stop it
254 StopHttpRequest(ts.localID, ts.itemID); 254 StopHttpRequest(ts.localID, ts.itemID);
255 } 255 }
256 } 256 }
257 } // lock 257 } // lock
258 } 258 }
259 #endregion 259 #endregion
260 260
261 } 261 }
262} 262}