aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules
diff options
context:
space:
mode:
authorteravus2013-02-07 10:28:26 -0500
committerteravus2013-02-07 10:50:17 -0500
commit94a5232d3a07c3ff5f9b720dfc975848d750f423 (patch)
treef2329adf59b6525528db1e7e099e8beddaf39a6d /OpenSim/Region/OptionalModules
parentThis is the final commit that enables the Websocket handler (diff)
parentRename "Bounciness" to "Restitution" (diff)
downloadopensim-SC_OLD-94a5232d3a07c3ff5f9b720dfc975848d750f423.zip
opensim-SC_OLD-94a5232d3a07c3ff5f9b720dfc975848d750f423.tar.gz
opensim-SC_OLD-94a5232d3a07c3ff5f9b720dfc975848d750f423.tar.bz2
opensim-SC_OLD-94a5232d3a07c3ff5f9b720dfc975848d750f423.tar.xz
* Adds Websocket support to baseHttpServer and IHttpServer.cs . This allows modules to set up a websocket server that websocket clients can connect to. An example module is in OptionalModules/Example/WebSocketEchoTest/WebSocketEchoModule.cs
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rw-r--r--OpenSim/Region/OptionalModules/Properties/AssemblyInfo.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs64
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs28
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs42
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs61
5 files changed, 174 insertions, 23 deletions
diff --git a/OpenSim/Region/OptionalModules/Properties/AssemblyInfo.cs b/OpenSim/Region/OptionalModules/Properties/AssemblyInfo.cs
index 217b2d5..0065531 100644
--- a/OpenSim/Region/OptionalModules/Properties/AssemblyInfo.cs
+++ b/OpenSim/Region/OptionalModules/Properties/AssemblyInfo.cs
@@ -30,7 +30,7 @@ using Mono.Addins;
30// Build Number 30// Build Number
31// Revision 31// Revision
32// 32//
33[assembly: AssemblyVersion("0.7.5.*")] 33[assembly: AssemblyVersion("0.7.6.*")]
34[assembly: AssemblyFileVersion("1.0.0.0")] 34[assembly: AssemblyFileVersion("1.0.0.0")]
35 35
36[assembly: Addin("OpenSim.Region.OptionalModules", "0.1")] 36[assembly: Addin("OpenSim.Region.OptionalModules", "0.1")]
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 0b7b31b..751e463 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -49,7 +49,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
49 private static readonly ILog m_log = 49 private static readonly ILog m_log =
50 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 51
52 private OSD m_ValueStore; 52 protected virtual OSD ValueStore { get; set; }
53 53
54 protected class TakeValueCallbackClass 54 protected class TakeValueCallbackClass
55 { 55 {
@@ -108,17 +108,18 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
108 /// 108 ///
109 /// </summary> 109 /// </summary>
110 // ----------------------------------------------------------------- 110 // -----------------------------------------------------------------
111 public JsonStore() : this("") {} 111 public JsonStore()
112
113 public JsonStore(string value)
114 { 112 {
115 m_TakeStore = new List<TakeValueCallbackClass>(); 113 m_TakeStore = new List<TakeValueCallbackClass>();
116 m_ReadStore = new List<TakeValueCallbackClass>(); 114 m_ReadStore = new List<TakeValueCallbackClass>();
117 115 }
116
117 public JsonStore(string value)
118 {
118 if (String.IsNullOrEmpty(value)) 119 if (String.IsNullOrEmpty(value))
119 m_ValueStore = new OSDMap(); 120 ValueStore = new OSDMap();
120 else 121 else
121 m_ValueStore = OSDParser.DeserializeJson(value); 122 ValueStore = OSDParser.DeserializeJson(value);
122 } 123 }
123 124
124 // ----------------------------------------------------------------- 125 // -----------------------------------------------------------------
@@ -129,7 +130,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
129 public bool TestPath(string expr, bool useJson) 130 public bool TestPath(string expr, bool useJson)
130 { 131 {
131 Stack<string> path = ParsePathExpression(expr); 132 Stack<string> path = ParsePathExpression(expr);
132 OSD result = ProcessPathExpression(m_ValueStore,path); 133 OSD result = ProcessPathExpression(ValueStore,path);
133 134
134 if (result == null) 135 if (result == null)
135 return false; 136 return false;
@@ -148,7 +149,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
148 public bool GetValue(string expr, out string value, bool useJson) 149 public bool GetValue(string expr, out string value, bool useJson)
149 { 150 {
150 Stack<string> path = ParsePathExpression(expr); 151 Stack<string> path = ParsePathExpression(expr);
151 OSD result = ProcessPathExpression(m_ValueStore,path); 152 OSD result = ProcessPathExpression(ValueStore,path);
152 return ConvertOutputValue(result,out value,useJson); 153 return ConvertOutputValue(result,out value,useJson);
153 } 154 }
154 155
@@ -184,7 +185,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
184 Stack<string> path = ParsePathExpression(expr); 185 Stack<string> path = ParsePathExpression(expr);
185 string pexpr = PathExpressionToKey(path); 186 string pexpr = PathExpressionToKey(path);
186 187
187 OSD result = ProcessPathExpression(m_ValueStore,path); 188 OSD result = ProcessPathExpression(ValueStore,path);
188 if (result == null) 189 if (result == null)
189 { 190 {
190 m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); 191 m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
@@ -215,7 +216,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
215 Stack<string> path = ParsePathExpression(expr); 216 Stack<string> path = ParsePathExpression(expr);
216 string pexpr = PathExpressionToKey(path); 217 string pexpr = PathExpressionToKey(path);
217 218
218 OSD result = ProcessPathExpression(m_ValueStore,path); 219 OSD result = ProcessPathExpression(ValueStore,path);
219 if (result == null) 220 if (result == null)
220 { 221 {
221 m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); 222 m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
@@ -245,7 +246,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
245 Stack<string> path = ParsePathExpression(expr); 246 Stack<string> path = ParsePathExpression(expr);
246 if (path.Count == 0) 247 if (path.Count == 0)
247 { 248 {
248 m_ValueStore = ovalue; 249 ValueStore = ovalue;
249 return true; 250 return true;
250 } 251 }
251 252
@@ -254,7 +255,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
254 if (pexpr != "") 255 if (pexpr != "")
255 pexpr += "."; 256 pexpr += ".";
256 257
257 OSD result = ProcessPathExpression(m_ValueStore,path); 258 OSD result = ProcessPathExpression(ValueStore,path);
258 if (result == null) 259 if (result == null)
259 return false; 260 return false;
260 261
@@ -522,4 +523,41 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
522 return pkey; 523 return pkey;
523 } 524 }
524 } 525 }
526
527 public class JsonObjectStore : JsonStore
528 {
529 private static readonly ILog m_log =
530 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
531
532 private Scene m_scene;
533 private UUID m_objectID;
534
535 protected override OSD ValueStore
536 {
537 get
538 {
539 SceneObjectPart sop = m_scene.GetSceneObjectPart(m_objectID);
540 if (sop == null)
541 {
542 // This is bad
543 return null;
544 }
545
546 return sop.DynAttrs.TopLevelMap;
547 }
548
549 // cannot set the top level
550 set
551 {
552 m_log.InfoFormat("[JsonStore] cannot set top level value in object store");
553 }
554 }
555
556 public JsonObjectStore(Scene scene, UUID oid) : base()
557 {
558 m_scene = scene;
559 m_objectID = oid;
560 }
561 }
562
525} 563}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
index b9b3ebc..a36ef42 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -175,6 +175,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
175 /// 175 ///
176 /// </summary> 176 /// </summary>
177 // ----------------------------------------------------------------- 177 // -----------------------------------------------------------------
178 public bool AttachObjectStore(UUID objectID)
179 {
180 if (! m_enabled) return false;
181
182 SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID);
183 if (sop == null)
184 {
185 m_log.InfoFormat("[JsonStore] unable to attach to unknown object; {0}",objectID);
186 return false;
187 }
188
189 lock (m_JsonValueStore)
190 {
191 if (m_JsonValueStore.ContainsKey(objectID))
192 return true;
193
194 JsonStore map = new JsonObjectStore(m_scene,objectID);
195 m_JsonValueStore.Add(objectID,map);
196 }
197
198 return true;
199 }
200
201 // -----------------------------------------------------------------
202 /// <summary>
203 ///
204 /// </summary>
205 // -----------------------------------------------------------------
178 public bool CreateStore(string value, ref UUID result) 206 public bool CreateStore(string value, ref UUID result)
179 { 207 {
180 if (result == UUID.Zero) 208 if (result == UUID.Zero)
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index 5b7a79d..48b4a9f 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -39,6 +39,7 @@ using OpenMetaverse.StructuredData;
39using OpenSim.Framework; 39using OpenSim.Framework;
40using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Scenes.Scripting;
42using System.Collections.Generic; 43using System.Collections.Generic;
43using System.Text.RegularExpressions; 44using System.Text.RegularExpressions;
44 45
@@ -168,6 +169,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
168 m_comms.RegisterScriptInvocations(this); 169 m_comms.RegisterScriptInvocations(this);
169 170
170 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); 171 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore");
172 // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore");
171 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore"); 173 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
172 // m_comms.RegisterScriptInvocation(this, "JsonTestStore"); 174 // m_comms.RegisterScriptInvocation(this, "JsonTestStore");
173 175
@@ -219,6 +221,21 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
219 /// </summary> 221 /// </summary>
220 // ----------------------------------------------------------------- 222 // -----------------------------------------------------------------
221 [ScriptInvocation] 223 [ScriptInvocation]
224 public UUID JsonAttachObjectStore(UUID hostID, UUID scriptID)
225 {
226 UUID uuid = UUID.Zero;
227 if (! m_store.AttachObjectStore(hostID))
228 GenerateRuntimeError("Failed to create Json store");
229
230 return hostID;
231 }
232
233 // -----------------------------------------------------------------
234 /// <summary>
235 ///
236 /// </summary>
237 // -----------------------------------------------------------------
238 [ScriptInvocation]
222 public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value) 239 public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
223 { 240 {
224 UUID uuid = UUID.Zero; 241 UUID uuid = UUID.Zero;
@@ -256,10 +273,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
256 /// </summary> 273 /// </summary>
257 // ----------------------------------------------------------------- 274 // -----------------------------------------------------------------
258 [ScriptInvocation] 275 [ScriptInvocation]
259 public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 276 public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
260 { 277 {
261 UUID reqID = UUID.Random(); 278 UUID reqID = UUID.Random();
262 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); 279 Util.FireAndForget(o => DoJsonReadNotecard(reqID, hostID, scriptID, storeID, path, notecardIdentifier));
263 return reqID; 280 return reqID;
264 } 281 }
265 282
@@ -463,14 +480,23 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
463 /// 480 ///
464 /// </summary> 481 /// </summary>
465 // ----------------------------------------------------------------- 482 // -----------------------------------------------------------------
466 private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 483 private void DoJsonReadNotecard(
484 UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
467 { 485 {
486 UUID assetID;
487
488 if (!UUID.TryParse(notecardIdentifier, out assetID))
489 {
490 SceneObjectPart part = m_scene.GetSceneObjectPart(hostID);
491 assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard);
492 }
493
468 AssetBase a = m_scene.AssetService.Get(assetID.ToString()); 494 AssetBase a = m_scene.AssetService.Get(assetID.ToString());
469 if (a == null) 495 if (a == null)
470 GenerateRuntimeError(String.Format("Unable to find notecard asset {0}",assetID)); 496 GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID));
471 497
472 if (a.Type != (sbyte)AssetType.Notecard) 498 if (a.Type != (sbyte)AssetType.Notecard)
473 GenerateRuntimeError(String.Format("Invalid notecard asset {0}",assetID)); 499 GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID));
474 500
475 m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID); 501 m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID);
476 502
@@ -483,11 +509,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
483 } 509 }
484 catch (Exception e) 510 catch (Exception e)
485 { 511 {
486 m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}",e.Message); 512 m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message);
487 } 513 }
488 514
489 GenerateRuntimeError(String.Format("Json parsing failed for {0}",assetID.ToString())); 515 GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID));
490 m_comms.DispatchReply(scriptID,0,"",reqID.ToString()); 516 m_comms.DispatchReply(scriptID, 0, "", reqID.ToString());
491 } 517 }
492 518
493 // ----------------------------------------------------------------- 519 // -----------------------------------------------------------------
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
index 8042a93..98b5624 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
@@ -54,6 +54,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
54 private MockScriptEngine m_engine; 54 private MockScriptEngine m_engine;
55 private ScriptModuleCommsModule m_smcm; 55 private ScriptModuleCommsModule m_smcm;
56 56
57 [TestFixtureSetUp]
58 public void FixtureInit()
59 {
60 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
61 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
62 }
63
64 [TestFixtureTearDown]
65 public void TearDown()
66 {
67 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
68 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
69 // tests really shouldn't).
70 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
71 }
72
57 [SetUp] 73 [SetUp]
58 public override void SetUp() 74 public override void SetUp()
59 { 75 {
@@ -85,7 +101,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
85 101
86 private object InvokeOp(string name, params object[] args) 102 private object InvokeOp(string name, params object[] args)
87 { 103 {
88 return m_smcm.InvokeOperation(UUID.Zero, UUID.Zero, name, args); 104 return InvokeOpOnHost(name, UUID.Zero, args);
105 }
106
107 private object InvokeOpOnHost(string name, UUID hostId, params object[] args)
108 {
109 return m_smcm.InvokeOperation(hostId, UUID.Zero, name, args);
89 } 110 }
90 111
91 [Test] 112 [Test]
@@ -193,6 +214,44 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
193 Assert.That(value, Is.EqualTo("World")); 214 Assert.That(value, Is.EqualTo("World"));
194 } 215 }
195 216
217 /// <summary>
218 /// Test for reading and writing json to a notecard
219 /// </summary>
220 /// <remarks>
221 /// TODO: Really needs to test correct receipt of the link_message event. Could do this by directly fetching
222 /// it via the MockScriptEngine or perhaps by a dummy script instance.
223 /// </remarks>
224 [Test]
225 public void TestJsonWriteReadNotecard()
226 {
227 TestHelpers.InMethod();
228 TestHelpers.EnableLogging();
229
230 string notecardName = "nc1";
231
232 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1));
233 m_scene.AddSceneObject(so);
234
235 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
236
237 // Write notecard
238 UUID writeNotecardRequestId = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, storeId, "/", notecardName);
239 Assert.That(writeNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
240
241 TaskInventoryItem nc1Item = so.RootPart.Inventory.GetInventoryItem(notecardName);
242 Assert.That(nc1Item, Is.Not.Null);
243
244 // TODO: Should probably independently check the contents.
245
246 // Read notecard
247 UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
248 UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "/", notecardName);
249 Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
250
251 string value = (string)InvokeOp("JsonGetValue", storeId, "Hello");
252 Assert.That(value, Is.EqualTo("World"));
253 }
254
196 public object DummyTestMethod(object o1, object o2, object o3, object o4, object o5) { return null; } 255 public object DummyTestMethod(object o1, object o2, object o3, object o4, object o5) { return null; }
197 } 256 }
198} \ No newline at end of file 257} \ No newline at end of file