aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/LSLLongCmdHandler.cs
diff options
context:
space:
mode:
authorTedd Hansen2008-01-12 14:30:22 +0000
committerTedd Hansen2008-01-12 14:30:22 +0000
commitbacbade369a5244f9bcc611488b59f3bd4c8a564 (patch)
tree2cd909eff401066a69dba96615cbf736fdd73be5 /OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/LSLLongCmdHandler.cs
parent* Trying something to see if it helps teleports and border crossings (diff)
downloadopensim-SC_OLD-bacbade369a5244f9bcc611488b59f3bd4c8a564.zip
opensim-SC_OLD-bacbade369a5244f9bcc611488b59f3bd4c8a564.tar.gz
opensim-SC_OLD-bacbade369a5244f9bcc611488b59f3bd4c8a564.tar.bz2
opensim-SC_OLD-bacbade369a5244f9bcc611488b59f3bd4c8a564.tar.xz
Major reorganizing of DotNetEngine. Moved common script engine parts to ScriptEngine.Common, only .Net-specific code in DotNetEngine. AppDomains, event handling, event execution queue and multithreading, script load/unload queue, etc has been moved to ScriptEngine.Common.
Loads of things has been put into interfaces instead of the specific class. We are now one step closer to ScriptServer, and its very easy to implement new script languages. Just a few lines required to make them a OpenSim script module with all its glory.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/LSLLongCmdHandler.cs (renamed from OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs)588
1 files changed, 294 insertions, 294 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/LSLLongCmdHandler.cs
index 1e4dc99..94241eb 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/LSLLongCmdHandler.cs
@@ -1,295 +1,295 @@
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 OpenSim Project nor the 12* * Neither the name of the OpenSim 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 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Threading; 31using System.Threading;
32using libsecondlife; 32using libsecondlife;
33using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Modules; 34using OpenSim.Region.Environment.Modules;
35 35
36namespace OpenSim.Region.ScriptEngine.DotNetEngine 36namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
37{ 37{
38 /// <summary> 38 /// <summary>
39 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc. 39 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
40 /// </summary> 40 /// </summary>
41 internal class LSLLongCmdHandler 41 public class LSLLongCmdHandler
42 { 42 {
43 private Thread cmdHandlerThread; 43 private Thread cmdHandlerThread;
44 private int cmdHandlerThreadCycleSleepms = 100; 44 private int cmdHandlerThreadCycleSleepms = 100;
45 45
46 private ScriptEngine m_ScriptEngine; 46 private ScriptEngine m_ScriptEngine;
47 47
48 public LSLLongCmdHandler(ScriptEngine _ScriptEngine) 48 public LSLLongCmdHandler(ScriptEngine _ScriptEngine)
49 { 49 {
50 m_ScriptEngine = _ScriptEngine; 50 m_ScriptEngine = _ScriptEngine;
51 51
52 // Start the thread that will be doing the work 52 // Start the thread that will be doing the work
53 cmdHandlerThread = new Thread(CmdHandlerThreadLoop); 53 cmdHandlerThread = new Thread(CmdHandlerThreadLoop);
54 cmdHandlerThread.Name = "CmdHandlerThread"; 54 cmdHandlerThread.Name = "CmdHandlerThread";
55 cmdHandlerThread.Priority = ThreadPriority.BelowNormal; 55 cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
56 cmdHandlerThread.IsBackground = true; 56 cmdHandlerThread.IsBackground = true;
57 cmdHandlerThread.Start(); 57 cmdHandlerThread.Start();
58 } 58 }
59 59
60 ~LSLLongCmdHandler() 60 ~LSLLongCmdHandler()
61 { 61 {
62 // Shut down thread 62 // Shut down thread
63 try 63 try
64 { 64 {
65 if (cmdHandlerThread != null) 65 if (cmdHandlerThread != null)
66 { 66 {
67 if (cmdHandlerThread.IsAlive == true) 67 if (cmdHandlerThread.IsAlive == true)
68 { 68 {
69 cmdHandlerThread.Abort(); 69 cmdHandlerThread.Abort();
70 cmdHandlerThread.Join(); 70 cmdHandlerThread.Join();
71 } 71 }
72 } 72 }
73 } 73 }
74 catch 74 catch
75 { 75 {
76 } 76 }
77 } 77 }
78 78
79 private void CmdHandlerThreadLoop() 79 private void CmdHandlerThreadLoop()
80 { 80 {
81 while (true) 81 while (true)
82 { 82 {
83 // Check timers 83 // Check timers
84 CheckTimerEvents(); 84 CheckTimerEvents();
85 Thread.Sleep(25); 85 Thread.Sleep(25);
86 // Check HttpRequests 86 // Check HttpRequests
87 CheckHttpRequests(); 87 CheckHttpRequests();
88 Thread.Sleep(25); 88 Thread.Sleep(25);
89 // Check XMLRPCRequests 89 // Check XMLRPCRequests
90 CheckXMLRPCRequests(); 90 CheckXMLRPCRequests();
91 Thread.Sleep(25); 91 Thread.Sleep(25);
92 // Check Listeners 92 // Check Listeners
93 CheckListeners(); 93 CheckListeners();
94 Thread.Sleep(25); 94 Thread.Sleep(25);
95 95
96 // Sleep before next cycle 96 // Sleep before next cycle
97 //Thread.Sleep(cmdHandlerThreadCycleSleepms); 97 //Thread.Sleep(cmdHandlerThreadCycleSleepms);
98 } 98 }
99 } 99 }
100 100
101 /// <summary> 101 /// <summary>
102 /// Remove a specific script (and all its pending commands) 102 /// Remove a specific script (and all its pending commands)
103 /// </summary> 103 /// </summary>
104 /// <param name="m_localID"></param> 104 /// <param name="m_localID"></param>
105 /// <param name="m_itemID"></param> 105 /// <param name="m_itemID"></param>
106 public void RemoveScript(uint localID, LLUUID itemID) 106 public void RemoveScript(uint localID, LLUUID itemID)
107 { 107 {
108 // Remove a specific script 108 // Remove a specific script
109 109
110 // Remove from: Timers 110 // Remove from: Timers
111 UnSetTimerEvents(localID, itemID); 111 UnSetTimerEvents(localID, itemID);
112 // Remove from: HttpRequest 112 // Remove from: HttpRequest
113 IHttpRequests iHttpReq = 113 IHttpRequests iHttpReq =
114 m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>(); 114 m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
115 iHttpReq.StopHttpRequest(localID, itemID); 115 iHttpReq.StopHttpRequest(localID, itemID);
116 } 116 }
117 117
118 #region TIMER 118 #region TIMER
119 119
120 // 120 //
121 // TIMER 121 // TIMER
122 // 122 //
123 private class TimerClass 123 private class TimerClass
124 { 124 {
125 public uint localID; 125 public uint localID;
126 public LLUUID itemID; 126 public LLUUID itemID;
127 public double interval; 127 public double interval;
128 public DateTime next; 128 public DateTime next;
129 } 129 }
130 130
131 private List<TimerClass> Timers = new List<TimerClass>(); 131 private List<TimerClass> Timers = new List<TimerClass>();
132 private object TimerListLock = new object(); 132 private object TimerListLock = new object();
133 133
134 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec) 134 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec)
135 { 135 {
136 Console.WriteLine("SetTimerEvent"); 136 Console.WriteLine("SetTimerEvent");
137 137
138 // Always remove first, in case this is a re-set 138 // Always remove first, in case this is a re-set
139 UnSetTimerEvents(m_localID, m_itemID); 139 UnSetTimerEvents(m_localID, m_itemID);
140 if (sec == 0) // Disabling timer 140 if (sec == 0) // Disabling timer
141 return; 141 return;
142 142
143 // Add to timer 143 // Add to timer
144 TimerClass ts = new TimerClass(); 144 TimerClass ts = new TimerClass();
145 ts.localID = m_localID; 145 ts.localID = m_localID;
146 ts.itemID = m_itemID; 146 ts.itemID = m_itemID;
147 ts.interval = sec; 147 ts.interval = sec;
148 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); 148 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
149 lock (TimerListLock) 149 lock (TimerListLock)
150 { 150 {
151 Timers.Add(ts); 151 Timers.Add(ts);
152 } 152 }
153 } 153 }
154 154
155 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID) 155 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID)
156 { 156 {
157 // Remove from timer 157 // Remove from timer
158 lock (TimerListLock) 158 lock (TimerListLock)
159 { 159 {
160 List<TimerClass> NewTimers = new List<TimerClass>(); 160 List<TimerClass> NewTimers = new List<TimerClass>();
161 foreach (TimerClass ts in Timers) 161 foreach (TimerClass ts in Timers)
162 { 162 {
163 if (ts.localID != m_localID && ts.itemID != m_itemID) 163 if (ts.localID != m_localID && ts.itemID != m_itemID)
164 { 164 {
165 NewTimers.Add(ts); 165 NewTimers.Add(ts);
166 } 166 }
167 } 167 }
168 Timers.Clear(); 168 Timers.Clear();
169 Timers = NewTimers; 169 Timers = NewTimers;
170 } 170 }
171 } 171 }
172 172
173 public void CheckTimerEvents() 173 public void CheckTimerEvents()
174 { 174 {
175 // Nothing to do here? 175 // Nothing to do here?
176 if (Timers.Count == 0) 176 if (Timers.Count == 0)
177 return; 177 return;
178 178
179 lock (TimerListLock) 179 lock (TimerListLock)
180 { 180 {
181 // Go through all timers 181 // Go through all timers
182 foreach (TimerClass ts in Timers) 182 foreach (TimerClass ts in Timers)
183 { 183 {
184 // Time has passed? 184 // Time has passed?
185 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) 185 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
186 { 186 {
187 // Add it to queue 187 // Add it to queue
188 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", 188 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer",
189 new object[] {}); 189 new object[] {});
190 // set next interval 190 // set next interval
191 191
192 192
193 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); 193 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
194 } 194 }
195 } 195 }
196 } // lock 196 } // lock
197 } 197 }
198 198
199 #endregion 199 #endregion
200 200
201 #region HTTP REQUEST 201 #region HTTP REQUEST
202 202
203 public void CheckHttpRequests() 203 public void CheckHttpRequests()
204 { 204 {
205 if (m_ScriptEngine.World == null) 205 if (m_ScriptEngine.World == null)
206 return; 206 return;
207 207
208 IHttpRequests iHttpReq = 208 IHttpRequests iHttpReq =
209 m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>(); 209 m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
210 210
211 HttpRequestClass httpInfo = null; 211 HttpRequestClass httpInfo = null;
212 212
213 if (iHttpReq != null) 213 if (iHttpReq != null)
214 httpInfo = iHttpReq.GetNextCompletedRequest(); 214 httpInfo = iHttpReq.GetNextCompletedRequest();
215 215
216 while (httpInfo != null) 216 while (httpInfo != null)
217 { 217 {
218 //Console.WriteLine("PICKED HTTP REQ:" + httpInfo.response_body + httpInfo.status); 218 //Console.WriteLine("PICKED HTTP REQ:" + httpInfo.response_body + httpInfo.status);
219 219
220 // Deliver data to prim's remote_data handler 220 // Deliver data to prim's remote_data handler
221 // 221 //
222 // TODO: Returning null for metadata, since the lsl function 222 // TODO: Returning null for metadata, since the lsl function
223 // only returns the byte for HTTP_BODY_TRUNCATED, which is not 223 // only returns the byte for HTTP_BODY_TRUNCATED, which is not
224 // implemented here yet anyway. Should be fixed if/when maxsize 224 // implemented here yet anyway. Should be fixed if/when maxsize
225 // is supported 225 // is supported
226 226
227 object[] resobj = new object[] 227 object[] resobj = new object[]
228 { 228 {
229 httpInfo.reqID.ToString(), httpInfo.status, null, httpInfo.response_body 229 httpInfo.reqID.ToString(), httpInfo.status, null, httpInfo.response_body
230 }; 230 };
231 231
232 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( 232 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
233 httpInfo.localID, httpInfo.itemID, "http_response", resobj 233 httpInfo.localID, httpInfo.itemID, "http_response", resobj
234 ); 234 );
235 235
236 httpInfo.Stop(); 236 httpInfo.Stop();
237 httpInfo = null; 237 httpInfo = null;
238 238
239 httpInfo = iHttpReq.GetNextCompletedRequest(); 239 httpInfo = iHttpReq.GetNextCompletedRequest();
240 } 240 }
241 } 241 }
242 242
243 #endregion 243 #endregion
244 244
245 public void CheckXMLRPCRequests() 245 public void CheckXMLRPCRequests()
246 { 246 {
247 if (m_ScriptEngine.World == null) 247 if (m_ScriptEngine.World == null)
248 return; 248 return;
249 249
250 IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 250 IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
251 251
252 if (xmlrpc != null) 252 if (xmlrpc != null)
253 { 253 {
254 while (xmlrpc.hasRequests()) 254 while (xmlrpc.hasRequests())
255 { 255 {
256 RPCRequestInfo rInfo = xmlrpc.GetNextRequest(); 256 RPCRequestInfo rInfo = xmlrpc.GetNextRequest();
257 //Console.WriteLine("PICKED REQUEST"); 257 //Console.WriteLine("PICKED REQUEST");
258 258
259 //Deliver data to prim's remote_data handler 259 //Deliver data to prim's remote_data handler
260 object[] resobj = new object[] 260 object[] resobj = new object[]
261 { 261 {
262 2, rInfo.GetChannelKey().ToString(), rInfo.GetMessageID().ToString(), "", 262 2, rInfo.GetChannelKey().ToString(), rInfo.GetMessageID().ToString(), "",
263 rInfo.GetIntValue(), 263 rInfo.GetIntValue(),
264 rInfo.GetStrVal() 264 rInfo.GetStrVal()
265 }; 265 };
266 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( 266 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
267 rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", resobj 267 rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", resobj
268 ); 268 );
269 } 269 }
270 } 270 }
271 } 271 }
272 272
273 public void CheckListeners() 273 public void CheckListeners()
274 { 274 {
275 if (m_ScriptEngine.World == null) 275 if (m_ScriptEngine.World == null)
276 return; 276 return;
277 IWorldComm comms = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 277 IWorldComm comms = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
278 278
279 while (comms.HasMessages()) 279 while (comms.HasMessages())
280 { 280 {
281 ListenerInfo lInfo = comms.GetNextMessage(); 281 ListenerInfo lInfo = comms.GetNextMessage();
282 282
283 //Deliver data to prim's listen handler 283 //Deliver data to prim's listen handler
284 object[] resobj = new object[] 284 object[] resobj = new object[]
285 { 285 {
286 lInfo.GetChannel(), lInfo.GetName(), lInfo.GetID().ToString(), lInfo.GetMessage() 286 lInfo.GetChannel(), lInfo.GetName(), lInfo.GetID().ToString(), lInfo.GetMessage()
287 }; 287 };
288 288
289 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( 289 m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
290 lInfo.GetLocalID(), lInfo.GetItemID(), "listen", resobj 290 lInfo.GetLocalID(), lInfo.GetItemID(), "listen", resobj
291 ); 291 );
292 } 292 }
293 } 293 }
294 } 294 }
295} \ No newline at end of file 295} \ No newline at end of file