diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs index 0bb45673cc..20484d4156 100644 --- a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs @@ -31,19 +31,34 @@ using OpenMetaverse; namespace OpenSim.Region.Framework.Interfaces { + // these could be expanded at some point to provide more type information + // for now value accounts for all base types + public enum JsonStoreNodeType + { + Undefined = 0, + Object = 1, + Array = 2, + Value = 3 + } + public delegate void TakeValueCallback(string s); public interface IJsonStoreModule { bool CreateStore(string value, ref UUID result); bool DestroyStore(UUID storeID); + + JsonStoreNodeType PathType(UUID storeID, string path); bool TestStore(UUID storeID); bool TestPath(UUID storeID, string path, bool useJson); + bool SetValue(UUID storeID, string path, string value, bool useJson); bool RemoveValue(UUID storeID, string path); bool GetValue(UUID storeID, string path, bool useJson, out string value); void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback); void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback); + + int ArrayLength(UUID storeID, string path); } } diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index 1abdbfc416..890e1dd782 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs @@ -125,6 +125,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore ValueStore = OSDParser.DeserializeJson(value); } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public JsonStoreNodeType PathType(string expr) + { + Stack path; + if (! ParsePathExpression(expr,out path)) + return JsonStoreNodeType.Undefined; + + OSD result = ProcessPathExpression(ValueStore,path); + + if (result == null) + return JsonStoreNodeType.Undefined; + + if (result is OSDMap) + return JsonStoreNodeType.Object; + + if (result is OSDArray) + return JsonStoreNodeType.Array; + + if (OSDBaseType(result.Type)) + return JsonStoreNodeType.Value; + + return JsonStoreNodeType.Undefined; + } + // ----------------------------------------------------------------- /// /// @@ -147,6 +175,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return false; } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public int ArrayLength(string expr) + { + Stack path; + if (! ParsePathExpression(expr,out path)) + return -1; + + OSD result = ProcessPathExpression(ValueStore,path); + if (result != null && result.Type == OSDType.Array) + { + OSDArray arr = result as OSDArray; + return arr.Count; + } + + return -1; + } + // ----------------------------------------------------------------- /// /// diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index 50d3b8d8a3..fabd8840da 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs @@ -229,6 +229,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return m_JsonValueStore.ContainsKey(storeID); } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public JsonStoreNodeType PathType(UUID storeID, string path) + { + if (! m_enabled) return JsonStoreNodeType.Undefined; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); + return JsonStoreNodeType.Undefined; + } + } + + try + { + lock (map) + return map.PathType(path); + } + catch (Exception e) + { + m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); + } + + return JsonStoreNodeType.Undefined; + } + // ----------------------------------------------------------------- /// /// @@ -325,6 +357,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return false; } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public int ArrayLength(UUID storeID, string path) + { + if (! m_enabled) return -1; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + return -1; + } + + try + { + lock (map) + { + return map.ArrayLength(path); + } + } + catch (Exception e) + { + m_log.Error("[JsonStore]: unable to retrieve value", e); + } + + return -1; + } + // ----------------------------------------------------------------- /// /// diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index b1caaf4501..0746fe05eb 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -167,7 +167,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore try { m_comms.RegisterScriptInvocations(this); - + m_comms.RegisterConstants(this); + // m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore"); // m_comms.RegisterScriptInvocation(this, "JsonTestStore"); @@ -213,6 +214,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore #endregion +#region ScriptConstantInteface + + [ScriptConstant] + public static readonly int JSONTYPEUNDEF = (int)JsonStoreNodeType.Undefined; + + [ScriptConstant] + public static readonly int JSONTYPEOBJECT = (int)JsonStoreNodeType.Object; + + [ScriptConstant] + public static readonly int JSONTYPEARRAY = (int)JsonStoreNodeType.Array; + + [ScriptConstant] + public static readonly int JSONTYPEVALUE = (int)JsonStoreNodeType.Value; + +#endregion + #region ScriptInvocationInteface // ----------------------------------------------------------------- /// @@ -302,6 +319,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- + [ScriptInvocation] + public int JsonPathType(UUID hostID, UUID scriptID, UUID storeID, string path) + { + return (int)m_store.PathType(storeID,path); + } + [ScriptInvocation] public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) { @@ -342,6 +365,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return m_store.RemoveValue(storeID,path) ? 1 : 0; } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + [ScriptInvocation] + public int JsonArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path) + { + return m_store.ArrayLength(storeID,path); + } + // ----------------------------------------------------------------- /// ///