diff options
author | Mic Bowman | 2013-03-05 20:33:17 -0800 |
---|---|---|
committer | Mic Bowman | 2013-03-05 20:33:17 -0800 |
commit | 9875e840f7e71f0b253c0b2aa90d47edc9c77b64 (patch) | |
tree | c2d71dc50c1f9eb48879d65038c6efd2ccca5686 /OpenSim | |
parent | Convert doubles passed back through the MOD interface into LSL_Floats (diff) | |
download | opensim-SC_OLD-9875e840f7e71f0b253c0b2aa90d47edc9c77b64.zip opensim-SC_OLD-9875e840f7e71f0b253c0b2aa90d47edc9c77b64.tar.gz opensim-SC_OLD-9875e840f7e71f0b253c0b2aa90d47edc9c77b64.tar.bz2 opensim-SC_OLD-9875e840f7e71f0b253c0b2aa90d47edc9c77b64.tar.xz |
Per discussions with justincc... split the JsonStore type
functions into one for node type and one for value type.
Define and export constants for both nodes and values.
Diffstat (limited to 'OpenSim')
5 files changed, 143 insertions, 35 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs index 345f01b..b67312e 100644 --- a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs | |||
@@ -41,6 +41,16 @@ namespace OpenSim.Region.Framework.Interfaces | |||
41 | Value = 3 | 41 | Value = 3 |
42 | } | 42 | } |
43 | 43 | ||
44 | public enum JsonStoreValueType | ||
45 | { | ||
46 | Undefined = 0, | ||
47 | Boolean = 1, | ||
48 | Integer = 2, | ||
49 | Float = 3, | ||
50 | String = 4, | ||
51 | UUID = 5 | ||
52 | } | ||
53 | |||
44 | public delegate void TakeValueCallback(string s); | 54 | public delegate void TakeValueCallback(string s); |
45 | 55 | ||
46 | public interface IJsonStoreModule | 56 | public interface IJsonStoreModule |
@@ -49,7 +59,9 @@ namespace OpenSim.Region.Framework.Interfaces | |||
49 | bool CreateStore(string value, ref UUID result); | 59 | bool CreateStore(string value, ref UUID result); |
50 | bool DestroyStore(UUID storeID); | 60 | bool DestroyStore(UUID storeID); |
51 | 61 | ||
52 | JsonStoreNodeType GetPathType(UUID storeID, string path); | 62 | JsonStoreNodeType GetNodeType(UUID storeID, string path); |
63 | JsonStoreValueType GetValueType(UUID storeID, string path); | ||
64 | |||
53 | bool TestStore(UUID storeID); | 65 | bool TestStore(UUID storeID); |
54 | 66 | ||
55 | bool SetValue(UUID storeID, string path, string value, bool useJson); | 67 | bool SetValue(UUID storeID, string path, string value, bool useJson); |
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index 40adba1..e498c6a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |||
@@ -145,7 +145,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
145 | /// | 145 | /// |
146 | /// </summary> | 146 | /// </summary> |
147 | // ----------------------------------------------------------------- | 147 | // ----------------------------------------------------------------- |
148 | public JsonStoreNodeType PathType(string expr) | 148 | public JsonStoreNodeType GetNodeType(string expr) |
149 | { | 149 | { |
150 | Stack<string> path; | 150 | Stack<string> path; |
151 | if (! ParsePathExpression(expr,out path)) | 151 | if (! ParsePathExpression(expr,out path)) |
@@ -173,6 +173,43 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
173 | /// | 173 | /// |
174 | /// </summary> | 174 | /// </summary> |
175 | // ----------------------------------------------------------------- | 175 | // ----------------------------------------------------------------- |
176 | public JsonStoreValueType GetValueType(string expr) | ||
177 | { | ||
178 | Stack<string> path; | ||
179 | if (! ParsePathExpression(expr,out path)) | ||
180 | return JsonStoreValueType.Undefined; | ||
181 | |||
182 | OSD result = ProcessPathExpression(ValueStore,path); | ||
183 | |||
184 | if (result == null) | ||
185 | return JsonStoreValueType.Undefined; | ||
186 | |||
187 | if (result is OSDMap) | ||
188 | return JsonStoreValueType.Undefined; | ||
189 | |||
190 | if (result is OSDArray) | ||
191 | return JsonStoreValueType.Undefined; | ||
192 | |||
193 | if (result is OSDBoolean) | ||
194 | return JsonStoreValueType.Boolean; | ||
195 | |||
196 | if (result is OSDInteger) | ||
197 | return JsonStoreValueType.Integer; | ||
198 | |||
199 | if (result is OSDReal) | ||
200 | return JsonStoreValueType.Float; | ||
201 | |||
202 | if (result is OSDString) | ||
203 | return JsonStoreValueType.String; | ||
204 | |||
205 | return JsonStoreValueType.Undefined; | ||
206 | } | ||
207 | |||
208 | // ----------------------------------------------------------------- | ||
209 | /// <summary> | ||
210 | /// | ||
211 | /// </summary> | ||
212 | // ----------------------------------------------------------------- | ||
176 | public int ArrayLength(string expr) | 213 | public int ArrayLength(string expr) |
177 | { | 214 | { |
178 | Stack<string> path; | 215 | Stack<string> path; |
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index e78a2f4..5fbfcc5 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs | |||
@@ -270,7 +270,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
270 | /// | 270 | /// |
271 | /// </summary> | 271 | /// </summary> |
272 | // ----------------------------------------------------------------- | 272 | // ----------------------------------------------------------------- |
273 | public JsonStoreNodeType GetPathType(UUID storeID, string path) | 273 | public JsonStoreNodeType GetNodeType(UUID storeID, string path) |
274 | { | 274 | { |
275 | if (! m_enabled) return JsonStoreNodeType.Undefined; | 275 | if (! m_enabled) return JsonStoreNodeType.Undefined; |
276 | 276 | ||
@@ -287,7 +287,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
287 | try | 287 | try |
288 | { | 288 | { |
289 | lock (map) | 289 | lock (map) |
290 | return map.PathType(path); | 290 | return map.GetNodeType(path); |
291 | } | 291 | } |
292 | catch (Exception e) | 292 | catch (Exception e) |
293 | { | 293 | { |
@@ -302,6 +302,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
302 | /// | 302 | /// |
303 | /// </summary> | 303 | /// </summary> |
304 | // ----------------------------------------------------------------- | 304 | // ----------------------------------------------------------------- |
305 | public JsonStoreValueType GetValueType(UUID storeID, string path) | ||
306 | { | ||
307 | if (! m_enabled) return JsonStoreValueType.Undefined; | ||
308 | |||
309 | JsonStore map = null; | ||
310 | lock (m_JsonValueStore) | ||
311 | { | ||
312 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
313 | { | ||
314 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); | ||
315 | return JsonStoreValueType.Undefined; | ||
316 | } | ||
317 | } | ||
318 | |||
319 | try | ||
320 | { | ||
321 | lock (map) | ||
322 | return map.GetValueType(path); | ||
323 | } | ||
324 | catch (Exception e) | ||
325 | { | ||
326 | m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); | ||
327 | } | ||
328 | |||
329 | return JsonStoreValueType.Undefined; | ||
330 | } | ||
331 | |||
332 | // ----------------------------------------------------------------- | ||
333 | /// <summary> | ||
334 | /// | ||
335 | /// </summary> | ||
336 | // ----------------------------------------------------------------- | ||
305 | public bool SetValue(UUID storeID, string path, string value, bool useJson) | 337 | public bool SetValue(UUID storeID, string path, string value, bool useJson) |
306 | { | 338 | { |
307 | if (! m_enabled) return false; | 339 | if (! m_enabled) return false; |
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index e13eb56..4a754a9 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs | |||
@@ -192,16 +192,32 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
192 | #region ScriptConstantsInterface | 192 | #region ScriptConstantsInterface |
193 | 193 | ||
194 | [ScriptConstant] | 194 | [ScriptConstant] |
195 | public static readonly int JSON_TYPE_UNDEF = (int)JsonStoreNodeType.Undefined; | 195 | public static readonly int JSON_NODETYPE_UNDEF = (int)JsonStoreNodeType.Undefined; |
196 | 196 | ||
197 | [ScriptConstant] | 197 | [ScriptConstant] |
198 | public static readonly int JSON_TYPE_OBJECT = (int)JsonStoreNodeType.Object; | 198 | public static readonly int JSON_NODETYPE_OBJECT = (int)JsonStoreNodeType.Object; |
199 | 199 | ||
200 | [ScriptConstant] | 200 | [ScriptConstant] |
201 | public static readonly int JSON_TYPE_ARRAY = (int)JsonStoreNodeType.Array; | 201 | public static readonly int JSON_NODETYPE_ARRAY = (int)JsonStoreNodeType.Array; |
202 | 202 | ||
203 | [ScriptConstant] | 203 | [ScriptConstant] |
204 | public static readonly int JSON_TYPE_VALUE = (int)JsonStoreNodeType.Value; | 204 | public static readonly int JSON_NODETYPE_VALUE = (int)JsonStoreNodeType.Value; |
205 | |||
206 | [ScriptConstant] | ||
207 | public static readonly int JSON_VALUETYPE_UNDEF = (int)JsonStoreValueType.Undefined; | ||
208 | |||
209 | [ScriptConstant] | ||
210 | public static readonly int JSON_VALUETYPE_BOOLEAN = (int)JsonStoreValueType.Boolean; | ||
211 | |||
212 | [ScriptConstant] | ||
213 | public static readonly int JSON_VALUETYPE_INTEGER = (int)JsonStoreValueType.Integer; | ||
214 | |||
215 | [ScriptConstant] | ||
216 | public static readonly int JSON_VALUETYPE_FLOAT = (int)JsonStoreValueType.Float; | ||
217 | |||
218 | [ScriptConstant] | ||
219 | public static readonly int JSON_VALUETYPE_STRING = (int)JsonStoreValueType.String; | ||
220 | |||
205 | 221 | ||
206 | #endregion | 222 | #endregion |
207 | 223 | ||
@@ -310,9 +326,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
310 | /// </summary> | 326 | /// </summary> |
311 | // ----------------------------------------------------------------- | 327 | // ----------------------------------------------------------------- |
312 | [ScriptInvocation] | 328 | [ScriptInvocation] |
313 | public int JsonGetPathType(UUID hostID, UUID scriptID, UUID storeID, string path) | 329 | public int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path) |
330 | { | ||
331 | return (int)m_store.GetNodeType(storeID,path); | ||
332 | } | ||
333 | |||
334 | // ----------------------------------------------------------------- | ||
335 | /// <summary> | ||
336 | /// | ||
337 | /// </summary> | ||
338 | // ----------------------------------------------------------------- | ||
339 | [ScriptInvocation] | ||
340 | public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
314 | { | 341 | { |
315 | return (int)m_store.GetPathType(storeID,path); | 342 | return (int)m_store.GetValueType(storeID,path); |
316 | } | 343 | } |
317 | 344 | ||
318 | // ----------------------------------------------------------------- | 345 | // ----------------------------------------------------------------- |
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs index b64dbd4..bfa9937 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs | |||
@@ -158,8 +158,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests | |||
158 | 158 | ||
159 | Assert.That(dsrv, Is.EqualTo(1)); | 159 | Assert.That(dsrv, Is.EqualTo(1)); |
160 | 160 | ||
161 | int tprv = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); | 161 | int tprv = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); |
162 | Assert.That(tprv, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); | 162 | Assert.That(tprv, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
163 | } | 163 | } |
164 | 164 | ||
165 | [Test] | 165 | [Test] |
@@ -277,8 +277,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests | |||
277 | int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); | 277 | int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); |
278 | Assert.That(returnValue, Is.EqualTo(1)); | 278 | Assert.That(returnValue, Is.EqualTo(1)); |
279 | 279 | ||
280 | int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); | 280 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); |
281 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); | 281 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
282 | 282 | ||
283 | string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello"); | 283 | string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello"); |
284 | Assert.That(returnValue2, Is.EqualTo("")); | 284 | Assert.That(returnValue2, Is.EqualTo("")); |
@@ -291,8 +291,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests | |||
291 | int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); | 291 | int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); |
292 | Assert.That(returnValue, Is.EqualTo(1)); | 292 | Assert.That(returnValue, Is.EqualTo(1)); |
293 | 293 | ||
294 | int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); | 294 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); |
295 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); | 295 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
296 | 296 | ||
297 | string returnValue2 = (string)InvokeOp("JsonGetJson", storeId, "Hello"); | 297 | string returnValue2 = (string)InvokeOp("JsonGetJson", storeId, "Hello"); |
298 | Assert.That(returnValue2, Is.EqualTo("")); | 298 | Assert.That(returnValue2, Is.EqualTo("")); |
@@ -306,11 +306,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests | |||
306 | int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello[0]"); | 306 | int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello[0]"); |
307 | Assert.That(returnValue, Is.EqualTo(1)); | 307 | Assert.That(returnValue, Is.EqualTo(1)); |
308 | 308 | ||
309 | int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello[0]"); | 309 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[0]"); |
310 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE)); | 310 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); |
311 | 311 | ||
312 | result = (int)InvokeOp("JsonGetPathType", storeId, "Hello[1]"); | 312 | result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[1]"); |
313 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); | 313 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
314 | 314 | ||
315 | string stringReturnValue = (string)InvokeOp("JsonGetValue", storeId, "Hello[0]"); | 315 | string stringReturnValue = (string)InvokeOp("JsonGetValue", storeId, "Hello[0]"); |
316 | Assert.That(stringReturnValue, Is.EqualTo("value2")); | 316 | Assert.That(stringReturnValue, Is.EqualTo("value2")); |
@@ -433,7 +433,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests | |||
433 | } | 433 | } |
434 | 434 | ||
435 | [Test] | 435 | [Test] |
436 | public void TestJsonGetPathType() | 436 | public void TestJsonGetNodeType() |
437 | { | 437 | { |
438 | TestHelpers.InMethod(); | 438 | TestHelpers.InMethod(); |
439 | // TestHelpers.EnableLogging(); | 439 | // TestHelpers.EnableLogging(); |
@@ -441,41 +441,41 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests | |||
441 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }"); | 441 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }"); |
442 | 442 | ||
443 | { | 443 | { |
444 | int result = (int)InvokeOp("JsonGetPathType", storeId, "."); | 444 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "."); |
445 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_OBJECT)); | 445 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT)); |
446 | } | 446 | } |
447 | 447 | ||
448 | { | 448 | { |
449 | int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); | 449 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); |
450 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_OBJECT)); | 450 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT)); |
451 | } | 451 | } |
452 | 452 | ||
453 | { | 453 | { |
454 | int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World"); | 454 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World"); |
455 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_ARRAY)); | 455 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_ARRAY)); |
456 | } | 456 | } |
457 | 457 | ||
458 | { | 458 | { |
459 | int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World[0]"); | 459 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[0]"); |
460 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE)); | 460 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); |
461 | } | 461 | } |
462 | 462 | ||
463 | { | 463 | { |
464 | int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World[1]"); | 464 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[1]"); |
465 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE)); | 465 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); |
466 | } | 466 | } |
467 | 467 | ||
468 | // Test for non-existant path | 468 | // Test for non-existant path |
469 | { | 469 | { |
470 | int result = (int)InvokeOp("JsonGetPathType", storeId, "foo"); | 470 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "foo"); |
471 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); | 471 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
472 | } | 472 | } |
473 | 473 | ||
474 | // Test for non-existant store | 474 | // Test for non-existant store |
475 | { | 475 | { |
476 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); | 476 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
477 | int result = (int)InvokeOp("JsonGetPathType", fakeStoreId, "."); | 477 | int result = (int)InvokeOp("JsonGetNodeType", fakeStoreId, "."); |
478 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); | 478 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||