diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs index 57232b5bb7..d3c2941a5b 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 @@ -48,7 +58,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 aee70828ef..44b36b01fc 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs @@ -130,7 +130,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- - public JsonStoreNodeType PathType(string expr) + public JsonStoreNodeType GetNodeType(string expr) { Stack path; if (! ParsePathExpression(expr,out path)) @@ -153,6 +153,43 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return JsonStoreNodeType.Undefined; } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + 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; + } + // ----------------------------------------------------------------- /// /// diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index 35407f6497..dee2cc767d 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs @@ -234,7 +234,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; @@ -251,7 +251,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore try { lock (map) - return map.PathType(path); + return map.GetNodeType(path); } catch (Exception e) { @@ -261,6 +261,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return JsonStoreNodeType.Undefined; } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + 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; + } + // ----------------------------------------------------------------- /// /// diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index db4ad980c4..44201b3870 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 @@ -295,9 +311,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.GetPathType(storeID,path); + return (int)m_store.GetNodeType(storeID,path); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + [ScriptInvocation] + public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string 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 b64dbd40e9..bfa9937873 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)); } }