aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorHomer Horwitz2008-09-28 12:44:49 +0000
committerHomer Horwitz2008-09-28 12:44:49 +0000
commit4452121227f4252c4e13f032ab9e05119c594045 (patch)
tree4fc0b769f9231ab49f0c44077cff70a2663f486b /OpenSim
parentUpdate svn properties. Minor formatting cleanup. Fix a compiler warning. F... (diff)
downloadopensim-SC_OLD-4452121227f4252c4e13f032ab9e05119c594045.zip
opensim-SC_OLD-4452121227f4252c4e13f032ab9e05119c594045.tar.gz
opensim-SC_OLD-4452121227f4252c4e13f032ab9e05119c594045.tar.bz2
opensim-SC_OLD-4452121227f4252c4e13f032ab9e05119c594045.tar.xz
Refactor to avoid some duplicate code.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs117
-rw-r--r--OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs47
2 files changed, 63 insertions, 101 deletions
diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
index ebc9871..d7b99b2 100644
--- a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
+++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
@@ -91,6 +91,8 @@ namespace OpenSim.Region.Environment.Modules.Framework
91 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; 91 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
92 scene.EventManager.OnMakeChildAgent += MakeChildAgent; 92 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
93 scene.EventManager.OnRegisterCaps += OnRegisterCaps; 93 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
94
95 m_log.DebugFormat("[EVENTQUEUE]: Enabled EventQueueGetModule for region {0}", scene.RegionInfo.RegionName);
94 } 96 }
95 else 97 else
96 { 98 {
@@ -171,7 +173,7 @@ namespace OpenSim.Region.Environment.Modules.Framework
171 173
172 private void MakeChildAgent(ScenePresence avatar) 174 private void MakeChildAgent(ScenePresence avatar)
173 { 175 {
174 m_log.DebugFormat("[EVENTQUEUE]: Make Child agent {0}.", avatar.UUID); 176 m_log.DebugFormat("[EVENTQUEUE]: Make Child agent {0} in region {1}.", avatar.UUID, m_scene.RegionInfo.RegionName);
175 lock (m_ids) 177 lock (m_ids)
176 { 178 {
177 if (m_ids.ContainsKey(avatar.UUID)) 179 if (m_ids.ContainsKey(avatar.UUID))
@@ -184,7 +186,7 @@ namespace OpenSim.Region.Environment.Modules.Framework
184 186
185 public void OnRegisterCaps(UUID agentID, Caps caps) 187 public void OnRegisterCaps(UUID agentID, Caps caps)
186 { 188 {
187 m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1} region", agentID, caps, m_scene.RegionInfo.RegionName); 189 m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1} region {2}", agentID, caps, m_scene.RegionInfo.RegionName);
188 string capsBase = "/CAPS/"; 190 string capsBase = "/CAPS/";
189 caps.RegisterHandler("EventQueueGet", 191 caps.RegisterHandler("EventQueueGet",
190 new RestHTTPHandler("POST", capsBase + UUID.Random().ToString(), 192 new RestHTTPHandler("POST", capsBase + UUID.Random().ToString(),
@@ -208,97 +210,66 @@ namespace OpenSim.Region.Environment.Modules.Framework
208 // TODO: this has to be redone to not busy-wait (and block the thread), 210 // TODO: this has to be redone to not busy-wait (and block the thread),
209 // TODO: as soon as we have a non-blocking way to handle HTTP-requests. 211 // TODO: as soon as we have a non-blocking way to handle HTTP-requests.
210 212
213 if(m_log.IsDebugEnabled) {
214 String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1} from thread {2}: [ ";
215 foreach (object key in request.Keys)
216 {
217 debug += key.ToString() + "=" + request[key].ToString() + " ";
218 }
219 m_log.DebugFormat(debug + " ]", agentID, m_scene.RegionInfo.RegionName, System.Threading.Thread.CurrentThread.Name);
220 }
221
211 BlockingLLSDQueue queue = GetQueue(agentID); 222 BlockingLLSDQueue queue = GetQueue(agentID);
212 LLSD element = queue.Dequeue(15000); // 15s timeout 223 LLSD element = queue.Dequeue(15000); // 15s timeout
213 224
225 Hashtable responsedata = new Hashtable();
226
227 int thisID = 0;
228 lock (m_ids)
229 thisID = m_ids[agentID];
214 230
215 String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1}: [ "; 231 if (thisID == -1) // close-request
216 foreach (object key in request.Keys)
217 { 232 {
218 debug += key.ToString() + "=" + request[key].ToString() + " "; 233 responsedata["int_response_code"] = 502;
234 responsedata["content_type"] = "text/plain";
235 responsedata["keepalive"] = false;
236 responsedata["str_response_string"] = "";
237 return responsedata;
219 } 238 }
220 m_log.DebugFormat(debug, agentID, m_scene.RegionInfo.RegionName);
221 239
222 Hashtable responsedata = new Hashtable(); 240 LLSDArray array = new LLSDArray();
223
224 if (element == null) // didn't have an event in 15s 241 if (element == null) // didn't have an event in 15s
225 { 242 {
226 // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say! 243 // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say!
227 element = EventQueueHelper.KeepAliveEvent(); 244 array.Add(EventQueueHelper.KeepAliveEvent());
228 245 m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
229 //ScenePresence avatar;
230 //m_scene.TryGetAvatar(agentID, out avatar);
231
232 LLSDArray array = new LLSDArray();
233 array.Add(element);
234 int thisID = 0;
235 lock (m_ids)
236 thisID = m_ids[agentID];
237
238
239
240 if (thisID == -1)
241 {
242 responsedata = new Hashtable();
243 responsedata["int_response_code"] = 502;
244 responsedata["content_type"] = "text/plain";
245 responsedata["keepalive"] = false;
246 responsedata["str_response_string"] = "";
247 return responsedata;
248 }
249
250 while (queue.Count() > 0)
251 {
252 array.Add(queue.Dequeue(1));
253 thisID++;
254 }
255 LLSDMap events = new LLSDMap();
256 events.Add("events", array);
257
258 events.Add("id", new LLSDInteger(thisID));
259 lock (m_ids)
260 {
261 m_ids[agentID] = thisID + 1;
262 }
263 responsedata = new Hashtable();
264 responsedata["int_response_code"] = 200;
265 responsedata["content_type"] = "application/llsd+xml";
266 responsedata["keepalive"] = true;
267 responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events);
268 m_log.DebugFormat("[EVENTQUEUE]: sending fake response for {0} in region{1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
269
270 return responsedata;
271 } 246 }
272 else 247 else
273 { 248 {
274 ScenePresence avatar;
275 m_scene.TryGetAvatar(agentID, out avatar);
276
277 LLSDArray array = new LLSDArray();
278 array.Add(element); 249 array.Add(element);
279 int thisID = m_ids[agentID];
280 while (queue.Count() > 0) 250 while (queue.Count() > 0)
281 { 251 {
282 array.Add(queue.Dequeue(1)); 252 array.Add(queue.Dequeue(1));
283 thisID++; 253 thisID++;
284 } 254 }
285 LLSDMap events = new LLSDMap();
286 events.Add("events", array);
287
288 events.Add("id", new LLSDInteger(thisID));
289 lock (m_ids)
290 {
291 m_ids[agentID] = thisID + 1;
292 }
293 responsedata = new Hashtable();
294 responsedata["int_response_code"] = 200;
295 responsedata["content_type"] = "application/llsd+xml";
296 responsedata["keepalive"] = true;
297 responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events);
298 m_log.DebugFormat("[EVENTQUEUE]: sending fake response for {0} in region{1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
299
300 return responsedata;
301 } 255 }
256
257 LLSDMap events = new LLSDMap();
258 events.Add("events", array);
259
260 events.Add("id", new LLSDInteger(thisID));
261 lock (m_ids)
262 {
263 m_ids[agentID] = thisID + 1;
264 }
265
266 responsedata["int_response_code"] = 200;
267 responsedata["content_type"] = "application/xml";
268 responsedata["keepalive"] = true;
269 responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events);
270 m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
271
272 return responsedata;
302 } 273 }
303 } 274 }
304} 275}
diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs
index 35a7fcc..41a03d9 100644
--- a/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs
+++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs
@@ -36,23 +36,27 @@ namespace OpenSim.Region.Environment
36 { 36 {
37 private EventQueueHelper() {} // no construction possible, it's an utility class 37 private EventQueueHelper() {} // no construction possible, it's an utility class
38 38
39 private static byte[] regionHandleToByteArray(ulong regionHandle)
40 {
41 // Reverse endianness of RegionHandle
42 return new byte[]
43 {
44 (byte)((regionHandle >> 56) % 256),
45 (byte)((regionHandle >> 48) % 256),
46 (byte)((regionHandle >> 40) % 256),
47 (byte)((regionHandle >> 32) % 256),
48 (byte)((regionHandle >> 24) % 256),
49 (byte)((regionHandle >> 16) % 256),
50 (byte)((regionHandle >> 8) % 256),
51 (byte)(regionHandle % 256)
52 };
53 }
54
39 public static LLSD EnableSimulator(ulong Handle, IPEndPoint endPoint) 55 public static LLSD EnableSimulator(ulong Handle, IPEndPoint endPoint)
40 { 56 {
41 LLSDMap llsdSimInfo = new LLSDMap(3); 57 LLSDMap llsdSimInfo = new LLSDMap(3);
42 byte[] regionhandle = new byte[8];
43 int i = 0;
44 58
45 // Reverse endianness of RegionHandle 59 llsdSimInfo.Add("Handle", new LLSDBinary(regionHandleToByteArray(Handle)));
46 regionhandle[i++] = (byte)((Handle >> 56) % 256);
47 regionhandle[i++] = (byte)((Handle >> 48) % 256);
48 regionhandle[i++] = (byte)((Handle >> 40) % 256);
49 regionhandle[i++] = (byte)((Handle >> 32) % 256);
50 regionhandle[i++] = (byte)((Handle >> 24) % 256);
51 regionhandle[i++] = (byte)((Handle >> 16) % 256);
52 regionhandle[i++] = (byte)((Handle >> 8) % 256);
53 regionhandle[i++] = (byte)(Handle % 256);
54
55 llsdSimInfo.Add("Handle", new LLSDBinary(regionhandle));
56 llsdSimInfo.Add("IP", new LLSDBinary(endPoint.Address.GetAddressBytes())); 60 llsdSimInfo.Add("IP", new LLSDBinary(endPoint.Address.GetAddressBytes()));
57 llsdSimInfo.Add("Port", new LLSDInteger(endPoint.Port)); 61 llsdSimInfo.Add("Port", new LLSDInteger(endPoint.Port));
58 62
@@ -68,6 +72,7 @@ namespace OpenSim.Region.Environment
68 72
69 return llsdMessage; 73 return llsdMessage;
70 } 74 }
75
71 public static LLSD CrossRegion(ulong Handle, Vector3 pos, Vector3 lookAt, 76 public static LLSD CrossRegion(ulong Handle, Vector3 pos, Vector3 lookAt,
72 IPEndPoint newRegionExternalEndPoint, 77 IPEndPoint newRegionExternalEndPoint,
73 string capsURL, UUID AgentID, UUID SessionID) 78 string capsURL, UUID AgentID, UUID SessionID)
@@ -97,21 +102,7 @@ namespace OpenSim.Region.Environment
97 AgentDataArr.Add(AgentDataMap); 102 AgentDataArr.Add(AgentDataMap);
98 103
99 LLSDMap RegionDataMap = new LLSDMap(4); 104 LLSDMap RegionDataMap = new LLSDMap(4);
100 byte[] regionhandle = new byte[8]; 105 RegionDataMap.Add("RegionHandle", LLSD.FromBinary(regionHandleToByteArray(Handle)));
101
102 {
103 int i = 0;
104 regionhandle[i++] = (byte)((Handle >> 56) % 256);
105 regionhandle[i++] = (byte)((Handle >> 48) % 256);
106 regionhandle[i++] = (byte)((Handle >> 40) % 256);
107 regionhandle[i++] = (byte)((Handle >> 32) % 256);
108 regionhandle[i++] = (byte)((Handle >> 24) % 256);
109 regionhandle[i++] = (byte)((Handle >> 16) % 256);
110 regionhandle[i++] = (byte)((Handle >> 8) % 256);
111 regionhandle[i++] = (byte)(Handle % 256);
112 }
113
114 RegionDataMap.Add("RegionHandle", LLSD.FromBinary(regionhandle));
115 RegionDataMap.Add("SeedCapability", LLSD.FromString(capsURL)); 106 RegionDataMap.Add("SeedCapability", LLSD.FromString(capsURL));
116 RegionDataMap.Add("SimIP", LLSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes())); 107 RegionDataMap.Add("SimIP", LLSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes()));
117 RegionDataMap.Add("SimPort", LLSD.FromInteger(newRegionExternalEndPoint.Port)); 108 RegionDataMap.Add("SimPort", LLSD.FromInteger(newRegionExternalEndPoint.Port));