aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-12-01 23:13:24 +0000
committerUbitUmarov2018-12-01 23:13:24 +0000
commit4ced4fed33c35599502c67a060139475fadafdb6 (patch)
treebc64d0439e461af4a264132daf7001e3c9f04c29 /OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs
parentclean a bit (diff)
downloadopensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.zip
opensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.tar.gz
opensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.tar.bz2
opensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.tar.xz
replace GetMeshModule and GetTextureModule
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs (renamed from OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs)217
1 files changed, 144 insertions, 73 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs
index b866e49..51a6ecc 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs
@@ -47,20 +47,23 @@ using Caps = OpenSim.Framework.Capabilities.Caps;
47 47
48namespace OpenSim.Region.ClientStack.Linden 48namespace OpenSim.Region.ClientStack.Linden
49{ 49{
50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetMeshModule")] 50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetAssetsModule")]
51 public class GetMeshModule : INonSharedRegionModule 51 public class GetAssetsModule : INonSharedRegionModule
52 { 52 {
53// private static readonly ILog m_log = 53// private static readonly ILog m_log =
54// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 54// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 55
56 private Scene m_scene; 56 private Scene m_scene;
57 private bool m_Enabled = true; 57 private bool m_Enabled;
58 private string m_URL; 58
59 private string m_URL2; 59 private string m_GetTextureURL;
60 private string m_GetMeshURL;
61 private string m_GetMesh2URL;
62 private string m_GetAssetURL;
60 63
61 class APollRequest 64 class APollRequest
62 { 65 {
63 public PollServiceMeshEventArgs thepoll; 66 public PollServiceAssetEventArgs thepoll;
64 public UUID reqID; 67 public UUID reqID;
65 public Hashtable request; 68 public Hashtable request;
66 } 69 }
@@ -73,15 +76,17 @@ namespace OpenSim.Region.ClientStack.Linden
73 76
74 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
75 78
76 private static GetMeshHandler m_getMeshHandler; 79 private static IAssetService m_assetService = null;
77 80 private static GetAssetsHandler m_getAssetHandler;
78 private IAssetService m_assetService = null;
79
80 private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>();
81 private Dictionary<UUID, string> m_capsDict2 = new Dictionary<UUID, string>();
82 private static Thread[] m_workerThreads = null; 81 private static Thread[] m_workerThreads = null;
83 private static int m_NumberScenes = 0; 82 private static int m_NumberScenes = 0;
84 private static BlockingCollection<APollRequest> m_queue = new BlockingCollection<APollRequest>(); 83 private static BlockingCollection<APollRequest> m_queue = new BlockingCollection<APollRequest>();
84 private static object m_loadLock = new object();
85
86 private Dictionary<UUID, string> m_capsDictTexture = new Dictionary<UUID, string>();
87 private Dictionary<UUID, string> m_capsDictGetMesh = new Dictionary<UUID, string>();
88 private Dictionary<UUID, string> m_capsDictGetMesh2 = new Dictionary<UUID, string>();
89 private Dictionary<UUID, string> m_capsDictGetAsset = new Dictionary<UUID, string>();
85 90
86 #region Region Module interfaceBase Members 91 #region Region Module interfaceBase Members
87 92
@@ -96,14 +101,20 @@ namespace OpenSim.Region.ClientStack.Linden
96 if (config == null) 101 if (config == null)
97 return; 102 return;
98 103
99 m_URL = config.GetString("Cap_GetMesh", string.Empty); 104 m_GetTextureURL = config.GetString("Cap_GetTexture", string.Empty);
100 // Cap doesn't exist 105 if (m_GetTextureURL != string.Empty)
101 if (m_URL != string.Empty) 106 m_Enabled = true;
107
108 m_GetMeshURL = config.GetString("Cap_GetMesh", string.Empty);
109 if (m_GetMeshURL != string.Empty)
102 m_Enabled = true; 110 m_Enabled = true;
103 111
104 m_URL2 = config.GetString("Cap_GetMesh2", string.Empty); 112 m_GetMesh2URL = config.GetString("Cap_GetMesh2", string.Empty);
105 // Cap doesn't exist 113 if (m_GetMesh2URL != string.Empty)
106 if (m_URL2 != string.Empty) 114 m_Enabled = true;
115
116 m_GetAssetURL = config.GetString("Cap_GetAsset", string.Empty);
117 if (m_GetAssetURL != string.Empty)
107 m_Enabled = true; 118 m_Enabled = true;
108 } 119 }
109 120
@@ -131,37 +142,39 @@ namespace OpenSim.Region.ClientStack.Linden
131 if (!m_Enabled) 142 if (!m_Enabled)
132 return; 143 return;
133 144
134 if(m_assetService == null) 145 lock(m_loadLock)
135 { 146 {
136 m_assetService = m_scene.RequestModuleInterface<IAssetService>(); 147 if (m_assetService == null && m_NumberScenes == 0)
137 // We'll reuse the same handler for all requests. 148 {
138 if(m_assetService == null) 149 m_assetService = s.RequestModuleInterface<IAssetService>();
150 // We'll reuse the same handler for all requests.
151 m_getAssetHandler = new GetAssetsHandler(m_assetService);
152 }
153
154 if (m_assetService == null)
139 { 155 {
140 m_Enabled = false; 156 m_Enabled = false;
141 return; 157 return;
142 } 158 }
143 159
144 m_getMeshHandler = new GetMeshHandler(m_assetService); 160 s.EventManager.OnRegisterCaps += RegisterCaps;
145 } 161 s.EventManager.OnDeregisterCaps += DeregisterCaps;
146
147 s.EventManager.OnRegisterCaps += RegisterCaps;
148 s.EventManager.OnDeregisterCaps += DeregisterCaps;
149
150 m_NumberScenes++;
151 162
152 if (m_workerThreads == null) 163 m_NumberScenes++;
153 {
154 m_workerThreads = new Thread[2];
155 164
156 for (uint i = 0; i < 2; i++) 165 if (m_workerThreads == null)
157 { 166 {
158 m_workerThreads[i] = WorkManager.StartThread(DoMeshRequests, 167 m_workerThreads = new Thread[3];
159 String.Format("GetMeshWorker{0}", i), 168 for (uint i = 0; i < 3; i++)
160 ThreadPriority.Normal, 169 {
161 true, 170 m_workerThreads[i] = WorkManager.StartThread(DoAssetRequests,
162 false, 171 String.Format("GetAssetWorker{0}", i),
163 null, 172 ThreadPriority.Normal,
164 int.MaxValue); 173 true,
174 false,
175 null,
176 int.MaxValue);
177 }
165 } 178 }
166 } 179 }
167 } 180 }
@@ -170,7 +183,7 @@ namespace OpenSim.Region.ClientStack.Linden
170 { 183 {
171 if(m_NumberScenes <= 0 && m_workerThreads != null) 184 if(m_NumberScenes <= 0 && m_workerThreads != null)
172 { 185 {
173 m_log.DebugFormat("[GetMeshModule] Closing"); 186 m_log.DebugFormat("[GetAssetsModule] Closing");
174 foreach (Thread t in m_workerThreads) 187 foreach (Thread t in m_workerThreads)
175 Watchdog.AbortThread(t.ManagedThreadId); 188 Watchdog.AbortThread(t.ManagedThreadId);
176 // This will fail on region shutdown. Its harmless. 189 // This will fail on region shutdown. Its harmless.
@@ -183,38 +196,36 @@ namespace OpenSim.Region.ClientStack.Linden
183 } 196 }
184 } 197 }
185 198
186 public string Name { get { return "GetMeshModule"; } } 199 public string Name { get { return "GetAssetsModule"; } }
187 200
188 #endregion 201 #endregion
189 202
190 private static void DoMeshRequests() 203 private static void DoAssetRequests()
191 { 204 {
192 while (m_NumberScenes > 0) 205 while (m_NumberScenes > 0)
193 { 206 {
194 APollRequest poolreq; 207 APollRequest poolreq;
195 if(m_queue.TryTake(out poolreq, 4500)) 208 if(m_queue.TryTake(out poolreq, 4500))
196 { 209 {
197 if(m_NumberScenes <= 0) 210 if (m_NumberScenes <= 0)
198 break; 211 break;
199 212 Watchdog.UpdateThread();
200 if(poolreq.reqID != UUID.Zero) 213 if (poolreq.reqID != UUID.Zero)
201 poolreq.thepoll.Process(poolreq); 214 poolreq.thepoll.Process(poolreq);
202 } 215 }
203 Watchdog.UpdateThread(); 216 Watchdog.UpdateThread();
204 } 217 }
205 } 218 }
206 219
207 private class PollServiceMeshEventArgs : PollServiceEventArgs 220 private class PollServiceAssetEventArgs : PollServiceEventArgs
208 { 221 {
209 private List<Hashtable> requests = 222 private List<Hashtable> requests = new List<Hashtable>();
210 new List<Hashtable>(); 223 private Dictionary<UUID, APollResponse> responses =new Dictionary<UUID, APollResponse>();
211 private Dictionary<UUID, APollResponse> responses =
212 new Dictionary<UUID, APollResponse>();
213 private HashSet<UUID> dropedResponses = new HashSet<UUID>(); 224 private HashSet<UUID> dropedResponses = new HashSet<UUID>();
214 225
215 private Scene m_scene; 226 private Scene m_scene;
216 private ScenePresence m_presence; 227 private ScenePresence m_presence;
217 public PollServiceMeshEventArgs(string uri, UUID pId, Scene scene) : 228 public PollServiceAssetEventArgs(string uri, UUID pId, Scene scene) :
218 base(null, uri, null, null, null, null, pId, int.MaxValue) 229 base(null, uri, null, null, null, null, pId, int.MaxValue)
219 { 230 {
220 m_scene = scene; 231 m_scene = scene;
@@ -326,7 +337,7 @@ namespace OpenSim.Region.ClientStack.Linden
326 } 337 }
327 } 338 }
328 339
329 curresponse = m_getMeshHandler.Handle(requestinfo.request); 340 curresponse = m_getAssetHandler.Handle(requestinfo.request);
330 341
331 lock(responses) 342 lock(responses)
332 { 343 {
@@ -360,48 +371,108 @@ namespace OpenSim.Region.ClientStack.Linden
360 protocol = "https"; 371 protocol = "https";
361 } 372 }
362 373
363 if (m_URL == "localhost") 374 string baseURL = String.Format("{0}://{1}:{2}", protocol, hostName, port);
375
376 if (m_GetTextureURL == "localhost")
364 { 377 {
365 string capUrl = "/CAPS/" + UUID.Random() + "/"; 378 string capUrl = "/CAPS/" + UUID.Random() + "/";
366 379
367 // Register this as a poll service 380 // Register this as a poll service
368 PollServiceMeshEventArgs args = new PollServiceMeshEventArgs(capUrl, agentID, m_scene); 381 PollServiceAssetEventArgs args = new PollServiceAssetEventArgs(capUrl, agentID, m_scene);
369 args.Type = PollServiceEventArgs.EventType.Mesh; 382
383 args.Type = PollServiceEventArgs.EventType.Texture;
370 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); 384 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args);
371 385
372 caps.RegisterHandler("GetMesh", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); 386 IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>();
373 m_capsDict[agentID] = capUrl; 387 if (handler != null)
388 handler.RegisterExternalUserCapsHandler(agentID, caps, "GetTexture", capUrl);
389 else
390 caps.RegisterHandler("GetTexture", baseURL + capUrl);
391 m_capsDictTexture[agentID] = capUrl;
392 }
393 else
394 {
395 caps.RegisterHandler("GetTexture", m_GetTextureURL);
374 } 396 }
375 else if (m_URL != string.Empty)
376 caps.RegisterHandler("GetMesh", m_URL);
377 397
378 if (m_URL2 == "localhost") 398 //GetMesh
399 if (m_GetMeshURL == "localhost")
379 { 400 {
380 string capUrl = "/CAPS/" + UUID.Random() + "/"; 401 string capUrl = "/CAPS/" + UUID.Random() + "/";
381 402
382 // Register this as a poll service 403 PollServiceAssetEventArgs args = new PollServiceAssetEventArgs(capUrl, agentID, m_scene);
383 PollServiceMeshEventArgs args = new PollServiceMeshEventArgs(capUrl, agentID, m_scene);
384 args.Type = PollServiceEventArgs.EventType.Mesh; 404 args.Type = PollServiceEventArgs.EventType.Mesh;
385 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); 405 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args);
386 caps.RegisterHandler("GetMesh2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); 406
387 m_capsDict2[agentID] = capUrl; 407 IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>();
408 if (handler != null)
409 handler.RegisterExternalUserCapsHandler(agentID, caps, "GetMesh", capUrl);
410 else
411 caps.RegisterHandler("GetMesh", baseURL + capUrl);
412 m_capsDictGetMesh[agentID] = capUrl;
388 } 413 }
389 else if(m_URL2 != string.Empty) 414 else if (m_GetMeshURL != string.Empty)
390 caps.RegisterHandler("GetMesh2", m_URL2); 415 caps.RegisterHandler("GetMesh", m_GetMeshURL);
416
417 //GetMesh2
418 if (m_GetMesh2URL == "localhost")
419 {
420 string capUrl = "/CAPS/" + UUID.Random() + "/";
421
422 PollServiceAssetEventArgs args = new PollServiceAssetEventArgs(capUrl, agentID, m_scene);
423 args.Type = PollServiceEventArgs.EventType.Mesh2;
424 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args);
425 IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>();
426 if (handler != null)
427 handler.RegisterExternalUserCapsHandler(agentID, caps, "GetMesh2", capUrl);
428 else
429 caps.RegisterHandler("GetMesh2", baseURL + capUrl);
430 m_capsDictGetMesh2[agentID] = capUrl;
431 }
432 else if (m_GetMesh2URL != string.Empty)
433 caps.RegisterHandler("GetMesh2", m_GetMesh2URL);
434
435 //ViewerAsset
436 if (m_GetAssetURL == "localhost")
437 {
438 string capUrl = "/CAPS/" + UUID.Random() + "/";
439
440 PollServiceAssetEventArgs args = new PollServiceAssetEventArgs(capUrl, agentID, m_scene);
441 args.Type = PollServiceEventArgs.EventType.Asset;
442 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args);
443 IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>();
444 if (handler != null)
445 handler.RegisterExternalUserCapsHandler(agentID, caps, "ViewerAsset", capUrl);
446 else
447 caps.RegisterHandler("ViewerAsset", baseURL + capUrl);
448 m_capsDictGetAsset[agentID] = capUrl;
449 }
450 else if (m_GetAssetURL != string.Empty)
451 caps.RegisterHandler("ViewerAsset", m_GetMesh2URL);
391 } 452 }
392 453
393 private void DeregisterCaps(UUID agentID, Caps caps) 454 private void DeregisterCaps(UUID agentID, Caps caps)
394 { 455 {
395 string capUrl; 456 string capUrl;
396 if (m_capsDict.TryGetValue(agentID, out capUrl)) 457 if (m_capsDictTexture.TryGetValue(agentID, out capUrl))
458 {
459 MainServer.Instance.RemovePollServiceHTTPHandler("", capUrl);
460 m_capsDictTexture.Remove(agentID);
461 }
462 if (m_capsDictGetMesh.TryGetValue(agentID, out capUrl))
397 { 463 {
398 MainServer.Instance.RemovePollServiceHTTPHandler("", capUrl); 464 MainServer.Instance.RemovePollServiceHTTPHandler("", capUrl);
399 m_capsDict.Remove(agentID); 465 m_capsDictGetMesh.Remove(agentID);
466 }
467 if (m_capsDictGetMesh2.TryGetValue(agentID, out capUrl))
468 {
469 MainServer.Instance.RemovePollServiceHTTPHandler("", capUrl);
470 m_capsDictGetMesh2.Remove(agentID);
400 } 471 }
401 if (m_capsDict2.TryGetValue(agentID, out capUrl)) 472 if (m_capsDictGetAsset.TryGetValue(agentID, out capUrl))
402 { 473 {
403 MainServer.Instance.RemovePollServiceHTTPHandler("", capUrl); 474 MainServer.Instance.RemovePollServiceHTTPHandler("", capUrl);
404 m_capsDict2.Remove(agentID); 475 m_capsDictGetAsset.Remove(agentID);
405 } 476 }
406 } 477 }
407 } 478 }