From 1e0420431f754ff71a97d01fae5617c1ea26cae0 Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Thu, 31 Jan 2013 14:53:16 -0800
Subject: Move the JsonStore regular expressions to static variables to avoid
recompiling on every operation. Added JsonList2Path script function to
simplify array iteration.
---
.../Scripting/JsonStore/JsonStoreScriptModule.cs | 204 ++++++++++++++-------
1 file changed, 141 insertions(+), 63 deletions(-)
(limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs')
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index 29955af..5b7a79d 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -165,29 +165,32 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
try
{
- m_comms.RegisterScriptInvocation(this, "JsonCreateStore");
- m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
- m_comms.RegisterScriptInvocation(this, "JsonTestStore");
+ m_comms.RegisterScriptInvocations(this);
- m_comms.RegisterScriptInvocation(this, "JsonReadNotecard");
- m_comms.RegisterScriptInvocation(this, "JsonWriteNotecard");
+ // m_comms.RegisterScriptInvocation(this, "JsonCreateStore");
+ // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
+ // m_comms.RegisterScriptInvocation(this, "JsonTestStore");
- m_comms.RegisterScriptInvocation(this, "JsonTestPath");
- m_comms.RegisterScriptInvocation(this, "JsonTestPathJson");
+ // m_comms.RegisterScriptInvocation(this, "JsonReadNotecard");
+ // m_comms.RegisterScriptInvocation(this, "JsonWriteNotecard");
- m_comms.RegisterScriptInvocation(this, "JsonGetValue");
- m_comms.RegisterScriptInvocation(this, "JsonGetValueJson");
+ // m_comms.RegisterScriptInvocation(this, "JsonTestPathList");
+ // m_comms.RegisterScriptInvocation(this, "JsonTestPath");
+ // m_comms.RegisterScriptInvocation(this, "JsonTestPathJson");
- m_comms.RegisterScriptInvocation(this, "JsonTakeValue");
- m_comms.RegisterScriptInvocation(this, "JsonTakeValueJson");
+ // m_comms.RegisterScriptInvocation(this, "JsonGetValue");
+ // m_comms.RegisterScriptInvocation(this, "JsonGetValueJson");
- m_comms.RegisterScriptInvocation(this, "JsonReadValue");
- m_comms.RegisterScriptInvocation(this, "JsonReadValueJson");
+ // m_comms.RegisterScriptInvocation(this, "JsonTakeValue");
+ // m_comms.RegisterScriptInvocation(this, "JsonTakeValueJson");
- m_comms.RegisterScriptInvocation(this, "JsonSetValue");
- m_comms.RegisterScriptInvocation(this, "JsonSetValueJson");
+ // m_comms.RegisterScriptInvocation(this, "JsonReadValue");
+ // m_comms.RegisterScriptInvocation(this, "JsonReadValueJson");
- m_comms.RegisterScriptInvocation(this, "JsonRemoveValue");
+ // m_comms.RegisterScriptInvocation(this, "JsonSetValue");
+ // m_comms.RegisterScriptInvocation(this, "JsonSetValueJson");
+
+ // m_comms.RegisterScriptInvocation(this, "JsonRemoveValue");
}
catch (Exception e)
{
@@ -215,17 +218,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected void GenerateRuntimeError(string msg)
- {
- throw new Exception("JsonStore Runtime Error: " + msg);
- }
-
- // -----------------------------------------------------------------
- ///
- ///
- ///
- // -----------------------------------------------------------------
- protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
+ [ScriptInvocation]
+ public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
{
UUID uuid = UUID.Zero;
if (! m_store.CreateStore(value, ref uuid))
@@ -239,7 +233,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
+ [ScriptInvocation]
+ public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
{
return m_store.DestroyStore(storeID) ? 1 : 0;
}
@@ -249,7 +244,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
+ [ScriptInvocation]
+ public int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
{
return m_store.TestStore(storeID) ? 1 : 0;
}
@@ -259,7 +255,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID)
+ [ScriptInvocation]
+ public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID)
{
UUID reqID = UUID.Random();
Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); });
@@ -271,7 +268,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
+ [ScriptInvocation]
+ public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
{
UUID reqID = UUID.Random();
Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); });
@@ -283,12 +281,25 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
+ {
+ return JsonStore.CanonicalPathExpression(ConvertList2Path(pathlist));
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ ///
+ ///
+ // -----------------------------------------------------------------
+ [ScriptInvocation]
+ public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path)
{
return m_store.TestPath(storeID,path,false) ? 1 : 0;
}
- protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path)
{
return m_store.TestPath(storeID,path,true) ? 1 : 0;
}
@@ -298,12 +309,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
+ [ScriptInvocation]
+ public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
{
return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
}
- protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
+ [ScriptInvocation]
+ public int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
{
return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
}
@@ -313,7 +326,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
{
return m_store.RemoveValue(storeID,path) ? 1 : 0;
}
@@ -323,14 +337,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
{
string value = String.Empty;
m_store.GetValue(storeID,path,false,out value);
return value;
}
- protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
{
string value = String.Empty;
m_store.GetValue(storeID,path,true, out value);
@@ -342,60 +358,75 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
///
///
// -----------------------------------------------------------------
- protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
{
UUID reqID = UUID.Random();
Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); });
return reqID;
}
- protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
{
UUID reqID = UUID.Random();
Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); });
return reqID;
}
- private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
- {
- try
- {
- m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
- return;
- }
- catch (Exception e)
- {
- m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
- }
-
- DispatchValue(scriptID,reqID,String.Empty);
- }
-
-
// -----------------------------------------------------------------
///
///
///
// -----------------------------------------------------------------
- protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
{
UUID reqID = UUID.Random();
Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); });
return reqID;
}
- protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
+ [ScriptInvocation]
+ public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
{
UUID reqID = UUID.Random();
Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); });
return reqID;
}
- private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
+#endregion
+
+ // -----------------------------------------------------------------
+ ///
+ ///
+ ///
+ // -----------------------------------------------------------------
+ protected void GenerateRuntimeError(string msg)
+ {
+ throw new Exception("JsonStore Runtime Error: " + msg);
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ ///
+ ///
+ // -----------------------------------------------------------------
+ protected void DispatchValue(UUID scriptID, UUID reqID, string value)
+ {
+ m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ ///
+ ///
+ // -----------------------------------------------------------------
+ private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
{
try
{
- m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
+ m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
return;
}
catch (Exception e)
@@ -406,16 +437,25 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
DispatchValue(scriptID,reqID,String.Empty);
}
-#endregion
// -----------------------------------------------------------------
///
///
///
// -----------------------------------------------------------------
- protected void DispatchValue(UUID scriptID, UUID reqID, string value)
+ private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
{
- m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
+ try
+ {
+ m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
+ return;
+ }
+ catch (Exception e)
+ {
+ m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
+ }
+
+ DispatchValue(scriptID,reqID,String.Empty);
}
// -----------------------------------------------------------------
@@ -505,5 +545,43 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
}
+
+ // -----------------------------------------------------------------
+ ///
+ /// Convert a list of values that are path components to a single string path
+ ///
+ // -----------------------------------------------------------------
+ protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$");
+ private string ConvertList2Path(object[] pathlist)
+ {
+ string path = "";
+ for (int i = 0; i < pathlist.Length; i++)
+ {
+ string token = "";
+
+ if (pathlist[i] is string)
+ {
+ token = pathlist[i].ToString();
+
+ // Check to see if this is a bare number which would not be a valid
+ // identifier otherwise
+ if (m_ArrayPattern.IsMatch(token))
+ token = '[' + token + ']';
+ }
+ else if (pathlist[i] is int)
+ {
+ token = "[" + pathlist[i].ToString() + "]";
+ }
+ else
+ {
+ token = "." + pathlist[i].ToString() + ".";
+ }
+
+ path += token + ".";
+ }
+
+ return path;
+ }
+
}
}
\ No newline at end of file
--
cgit v1.1