Adds a couple requested functions to the JsonStore script

interface. JsonPathType returns the type of node pointed to by the
path and deprecates the functionality of both JsonTestPath
functions. JsonArrayLength returns the length of an array node.
This commit is contained in:
Mic Bowman
2013-02-13 07:14:04 -08:00
parent 708c3f8b86
commit bcb172301d
4 changed files with 162 additions and 1 deletions

View File

@@ -140,6 +140,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
ValueStore = OSDParser.DeserializeJson(value);
}
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
// -----------------------------------------------------------------
public JsonStoreNodeType PathType(string expr)
{
Stack<string> 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;
}
// -----------------------------------------------------------------
/// <summary>
///
@@ -162,6 +190,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
return false;
}
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
// -----------------------------------------------------------------
public int ArrayLength(string expr)
{
Stack<string> 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;
}
// -----------------------------------------------------------------
/// <summary>
///

View File

@@ -265,6 +265,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
return m_JsonValueStore.ContainsKey(storeID);
}
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
// -----------------------------------------------------------------
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;
}
// -----------------------------------------------------------------
/// <summary>
///
@@ -370,6 +402,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
return false;
}
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
// -----------------------------------------------------------------
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;
}
// -----------------------------------------------------------------
/// <summary>
///

View File

@@ -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, "JsonAttachObjectStore");
// m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
@@ -214,6 +215,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
// -----------------------------------------------------------------
/// <summary>
@@ -318,6 +335,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
/// </summary>
// -----------------------------------------------------------------
[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)
{
@@ -358,6 +381,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
return m_store.RemoveValue(storeID,path) ? 1 : 0;
}
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
// -----------------------------------------------------------------
[ScriptInvocation]
public int JsonArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
{
return m_store.ArrayLength(storeID,path);
}
// -----------------------------------------------------------------
/// <summary>
///