From 30e06b0742512caf08d1ab67505f9ab381dae9f5 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 5 Mar 2013 20:32:06 -0800 Subject: Convert doubles passed back through the MOD interface into LSL_Floats --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index d0922aa..21bae27 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -266,6 +266,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { llist[i] = new LSL_Float((float)result[i]); } + else if (result[i] is double) + { + llist[i] = new LSL_Float((double)result[i]); + } else if (result[i] is UUID) { llist[i] = new LSL_Key(result[i].ToString()); -- cgit v1.1 From 9875e840f7e71f0b253c0b2aa90d47edc9c77b64 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 5 Mar 2013 20:33:17 -0800 Subject: 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. --- .../Framework/Interfaces/IJsonStoreModule.cs | 14 +++++- .../Scripting/JsonStore/JsonStore.cs | 39 ++++++++++++++++- .../Scripting/JsonStore/JsonStoreModule.cs | 36 +++++++++++++++- .../Scripting/JsonStore/JsonStoreScriptModule.cs | 39 ++++++++++++++--- .../JsonStore/Tests/JsonStoreScriptModuleTests.cs | 50 +++++++++++----------- 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 Value = 3 } + public enum JsonStoreValueType + { + Undefined = 0, + Boolean = 1, + Integer = 2, + Float = 3, + String = 4, + UUID = 5 + } + public delegate void TakeValueCallback(string s); public interface IJsonStoreModule @@ -49,7 +59,9 @@ namespace OpenSim.Region.Framework.Interfaces bool CreateStore(string value, ref UUID result); bool DestroyStore(UUID storeID); - JsonStoreNodeType GetPathType(UUID storeID, string path); + JsonStoreNodeType GetNodeType(UUID storeID, string path); + JsonStoreValueType GetValueType(UUID storeID, string path); + bool TestStore(UUID storeID); 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 /// /// // ----------------------------------------------------------------- - public JsonStoreNodeType PathType(string expr) + public JsonStoreNodeType GetNodeType(string expr) { Stack path; if (! ParsePathExpression(expr,out path)) @@ -173,6 +173,43 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- + public JsonStoreValueType GetValueType(string expr) + { + Stack path; + if (! ParsePathExpression(expr,out path)) + return JsonStoreValueType.Undefined; + + OSD result = ProcessPathExpression(ValueStore,path); + + if (result == null) + return JsonStoreValueType.Undefined; + + if (result is OSDMap) + return JsonStoreValueType.Undefined; + + if (result is OSDArray) + return JsonStoreValueType.Undefined; + + if (result is OSDBoolean) + return JsonStoreValueType.Boolean; + + if (result is OSDInteger) + return JsonStoreValueType.Integer; + + if (result is OSDReal) + return JsonStoreValueType.Float; + + if (result is OSDString) + return JsonStoreValueType.String; + + return JsonStoreValueType.Undefined; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- public int ArrayLength(string expr) { Stack 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 /// /// // ----------------------------------------------------------------- - public JsonStoreNodeType GetPathType(UUID storeID, string path) + public JsonStoreNodeType GetNodeType(UUID storeID, string path) { if (! m_enabled) return JsonStoreNodeType.Undefined; @@ -287,7 +287,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore try { lock (map) - return map.PathType(path); + return map.GetNodeType(path); } catch (Exception e) { @@ -302,6 +302,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- + public JsonStoreValueType GetValueType(UUID storeID, string path) + { + if (! m_enabled) return JsonStoreValueType.Undefined; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); + return JsonStoreValueType.Undefined; + } + } + + try + { + lock (map) + return map.GetValueType(path); + } + catch (Exception e) + { + m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); + } + + return JsonStoreValueType.Undefined; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- public bool SetValue(UUID storeID, string path, string value, bool useJson) { 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 #region ScriptConstantsInterface [ScriptConstant] - public static readonly int JSON_TYPE_UNDEF = (int)JsonStoreNodeType.Undefined; + public static readonly int JSON_NODETYPE_UNDEF = (int)JsonStoreNodeType.Undefined; [ScriptConstant] - public static readonly int JSON_TYPE_OBJECT = (int)JsonStoreNodeType.Object; + public static readonly int JSON_NODETYPE_OBJECT = (int)JsonStoreNodeType.Object; [ScriptConstant] - public static readonly int JSON_TYPE_ARRAY = (int)JsonStoreNodeType.Array; + public static readonly int JSON_NODETYPE_ARRAY = (int)JsonStoreNodeType.Array; [ScriptConstant] - public static readonly int JSON_TYPE_VALUE = (int)JsonStoreNodeType.Value; + public static readonly int JSON_NODETYPE_VALUE = (int)JsonStoreNodeType.Value; + + [ScriptConstant] + public static readonly int JSON_VALUETYPE_UNDEF = (int)JsonStoreValueType.Undefined; + + [ScriptConstant] + public static readonly int JSON_VALUETYPE_BOOLEAN = (int)JsonStoreValueType.Boolean; + + [ScriptConstant] + public static readonly int JSON_VALUETYPE_INTEGER = (int)JsonStoreValueType.Integer; + + [ScriptConstant] + public static readonly int JSON_VALUETYPE_FLOAT = (int)JsonStoreValueType.Float; + + [ScriptConstant] + public static readonly int JSON_VALUETYPE_STRING = (int)JsonStoreValueType.String; + #endregion @@ -310,9 +326,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// // ----------------------------------------------------------------- [ScriptInvocation] - public int JsonGetPathType(UUID hostID, UUID scriptID, UUID storeID, string path) + public int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path) + { + return (int)m_store.GetNodeType(storeID,path); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + [ScriptInvocation] + public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path) { - return (int)m_store.GetPathType(storeID,path); + return (int)m_store.GetValueType(storeID,path); } // ----------------------------------------------------------------- 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 Assert.That(dsrv, Is.EqualTo(1)); - int tprv = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); - Assert.That(tprv, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); + int tprv = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); + Assert.That(tprv, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); } [Test] @@ -277,8 +277,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); Assert.That(returnValue, Is.EqualTo(1)); - int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello"); Assert.That(returnValue2, Is.EqualTo("")); @@ -291,8 +291,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); Assert.That(returnValue, Is.EqualTo(1)); - int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); string returnValue2 = (string)InvokeOp("JsonGetJson", storeId, "Hello"); Assert.That(returnValue2, Is.EqualTo("")); @@ -306,11 +306,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello[0]"); Assert.That(returnValue, Is.EqualTo(1)); - int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello[0]"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[0]"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); - result = (int)InvokeOp("JsonGetPathType", storeId, "Hello[1]"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); + result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[1]"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); string stringReturnValue = (string)InvokeOp("JsonGetValue", storeId, "Hello[0]"); Assert.That(stringReturnValue, Is.EqualTo("value2")); @@ -433,7 +433,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests } [Test] - public void TestJsonGetPathType() + public void TestJsonGetNodeType() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); @@ -441,41 +441,41 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }"); { - int result = (int)InvokeOp("JsonGetPathType", storeId, "."); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_OBJECT)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "."); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT)); } { - int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_OBJECT)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT)); } { - int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_ARRAY)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_ARRAY)); } { - int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World[0]"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[0]"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); } { - int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World[1]"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[1]"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); } // Test for non-existant path { - int result = (int)InvokeOp("JsonGetPathType", storeId, "foo"); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); + int result = (int)InvokeOp("JsonGetNodeType", storeId, "foo"); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); } // Test for non-existant store { UUID fakeStoreId = TestHelpers.ParseTail(0x500); - int result = (int)InvokeOp("JsonGetPathType", fakeStoreId, "."); - Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF)); + int result = (int)InvokeOp("JsonGetNodeType", fakeStoreId, "."); + Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); } } -- cgit v1.1