aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMic Bowman2013-02-13 07:14:04 -0800
committerMic Bowman2013-02-13 07:14:04 -0800
commitbcb172301dfc1d8dcdb837be89c3ce3248500cc0 (patch)
treec6e86bda51d3922395d629f8c62f5d359b8ccbe4
parentMake path parsing more robust in the JsonStore. (diff)
downloadopensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.zip
opensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.tar.gz
opensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.tar.bz2
opensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.tar.xz
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.
-rw-r--r--OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs15
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs49
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs63
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs36
4 files changed, 162 insertions, 1 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
index cc7885a..d7907e3 100644
--- a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
@@ -31,6 +31,16 @@ using OpenMetaverse;
31 31
32namespace OpenSim.Region.Framework.Interfaces 32namespace OpenSim.Region.Framework.Interfaces
33{ 33{
34 // these could be expanded at some point to provide more type information
35 // for now value accounts for all base types
36 public enum JsonStoreNodeType
37 {
38 Undefined = 0,
39 Object = 1,
40 Array = 2,
41 Value = 3
42 }
43
34 public delegate void TakeValueCallback(string s); 44 public delegate void TakeValueCallback(string s);
35 45
36 public interface IJsonStoreModule 46 public interface IJsonStoreModule
@@ -38,13 +48,18 @@ namespace OpenSim.Region.Framework.Interfaces
38 bool AttachObjectStore(UUID objectID); 48 bool AttachObjectStore(UUID objectID);
39 bool CreateStore(string value, ref UUID result); 49 bool CreateStore(string value, ref UUID result);
40 bool DestroyStore(UUID storeID); 50 bool DestroyStore(UUID storeID);
51
52 JsonStoreNodeType PathType(UUID storeID, string path);
41 bool TestStore(UUID storeID); 53 bool TestStore(UUID storeID);
42 bool TestPath(UUID storeID, string path, bool useJson); 54 bool TestPath(UUID storeID, string path, bool useJson);
55
43 bool SetValue(UUID storeID, string path, string value, bool useJson); 56 bool SetValue(UUID storeID, string path, string value, bool useJson);
44 bool RemoveValue(UUID storeID, string path); 57 bool RemoveValue(UUID storeID, string path);
45 bool GetValue(UUID storeID, string path, bool useJson, out string value); 58 bool GetValue(UUID storeID, string path, bool useJson, out string value);
46 59
47 void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback); 60 void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback);
48 void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback); 61 void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback);
62
63 int ArrayLength(UUID storeID, string path);
49 } 64 }
50} 65}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index f7625fb..ca3989a 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -145,6 +145,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
145 /// 145 ///
146 /// </summary> 146 /// </summary>
147 // ----------------------------------------------------------------- 147 // -----------------------------------------------------------------
148 public JsonStoreNodeType PathType(string expr)
149 {
150 Stack<string> path;
151 if (! ParsePathExpression(expr,out path))
152 return JsonStoreNodeType.Undefined;
153
154 OSD result = ProcessPathExpression(ValueStore,path);
155
156 if (result == null)
157 return JsonStoreNodeType.Undefined;
158
159 if (result is OSDMap)
160 return JsonStoreNodeType.Object;
161
162 if (result is OSDArray)
163 return JsonStoreNodeType.Array;
164
165 if (OSDBaseType(result.Type))
166 return JsonStoreNodeType.Value;
167
168 return JsonStoreNodeType.Undefined;
169 }
170
171 // -----------------------------------------------------------------
172 /// <summary>
173 ///
174 /// </summary>
175 // -----------------------------------------------------------------
148 public bool TestPath(string expr, bool useJson) 176 public bool TestPath(string expr, bool useJson)
149 { 177 {
150 Stack<string> path; 178 Stack<string> path;
@@ -167,6 +195,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
167 /// 195 ///
168 /// </summary> 196 /// </summary>
169 // ----------------------------------------------------------------- 197 // -----------------------------------------------------------------
198 public int ArrayLength(string expr)
199 {
200 Stack<string> path;
201 if (! ParsePathExpression(expr,out path))
202 return -1;
203
204 OSD result = ProcessPathExpression(ValueStore,path);
205 if (result != null && result.Type == OSDType.Array)
206 {
207 OSDArray arr = result as OSDArray;
208 return arr.Count;
209 }
210
211 return -1;
212 }
213
214 // -----------------------------------------------------------------
215 /// <summary>
216 ///
217 /// </summary>
218 // -----------------------------------------------------------------
170 public bool GetValue(string expr, out string value, bool useJson) 219 public bool GetValue(string expr, out string value, bool useJson)
171 { 220 {
172 Stack<string> path; 221 Stack<string> path;
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
index cc13661..eec86ef 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -270,6 +270,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
270 /// 270 ///
271 /// </summary> 271 /// </summary>
272 // ----------------------------------------------------------------- 272 // -----------------------------------------------------------------
273 public JsonStoreNodeType PathType(UUID storeID, string path)
274 {
275 if (! m_enabled) return JsonStoreNodeType.Undefined;
276
277 JsonStore map = null;
278 lock (m_JsonValueStore)
279 {
280 if (! m_JsonValueStore.TryGetValue(storeID,out map))
281 {
282 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
283 return JsonStoreNodeType.Undefined;
284 }
285 }
286
287 try
288 {
289 lock (map)
290 return map.PathType(path);
291 }
292 catch (Exception e)
293 {
294 m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
295 }
296
297 return JsonStoreNodeType.Undefined;
298 }
299
300 // -----------------------------------------------------------------
301 /// <summary>
302 ///
303 /// </summary>
304 // -----------------------------------------------------------------
273 public bool TestPath(UUID storeID, string path, bool useJson) 305 public bool TestPath(UUID storeID, string path, bool useJson)
274 { 306 {
275 if (! m_enabled) return false; 307 if (! m_enabled) return false;
@@ -375,6 +407,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
375 /// 407 ///
376 /// </summary> 408 /// </summary>
377 // ----------------------------------------------------------------- 409 // -----------------------------------------------------------------
410 public int ArrayLength(UUID storeID, string path)
411 {
412 if (! m_enabled) return -1;
413
414 JsonStore map = null;
415 lock (m_JsonValueStore)
416 {
417 if (! m_JsonValueStore.TryGetValue(storeID,out map))
418 return -1;
419 }
420
421 try
422 {
423 lock (map)
424 {
425 return map.ArrayLength(path);
426 }
427 }
428 catch (Exception e)
429 {
430 m_log.Error("[JsonStore]: unable to retrieve value", e);
431 }
432
433 return -1;
434 }
435
436 // -----------------------------------------------------------------
437 /// <summary>
438 ///
439 /// </summary>
440 // -----------------------------------------------------------------
378 public bool GetValue(UUID storeID, string path, bool useJson, out string value) 441 public bool GetValue(UUID storeID, string path, bool useJson, out string value)
379 { 442 {
380 value = String.Empty; 443 value = String.Empty;
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index e436304..3955bff 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
167 try 167 try
168 { 168 {
169 m_comms.RegisterScriptInvocations(this); 169 m_comms.RegisterScriptInvocations(this);
170 170 m_comms.RegisterConstants(this);
171
171 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); 172 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore");
172 // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore"); 173 // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore");
173 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore"); 174 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
@@ -214,6 +215,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
214 215
215#endregion 216#endregion
216 217
218#region ScriptConstantInteface
219
220 [ScriptConstant]
221 public static readonly int JSONTYPEUNDEF = (int)JsonStoreNodeType.Undefined;
222
223 [ScriptConstant]
224 public static readonly int JSONTYPEOBJECT = (int)JsonStoreNodeType.Object;
225
226 [ScriptConstant]
227 public static readonly int JSONTYPEARRAY = (int)JsonStoreNodeType.Array;
228
229 [ScriptConstant]
230 public static readonly int JSONTYPEVALUE = (int)JsonStoreNodeType.Value;
231
232#endregion
233
217#region ScriptInvocationInteface 234#region ScriptInvocationInteface
218 // ----------------------------------------------------------------- 235 // -----------------------------------------------------------------
219 /// <summary> 236 /// <summary>
@@ -319,6 +336,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
319 /// </summary> 336 /// </summary>
320 // ----------------------------------------------------------------- 337 // -----------------------------------------------------------------
321 [ScriptInvocation] 338 [ScriptInvocation]
339 public int JsonPathType(UUID hostID, UUID scriptID, UUID storeID, string path)
340 {
341 return (int)m_store.PathType(storeID,path);
342 }
343
344 [ScriptInvocation]
322 public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) 345 public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path)
323 { 346 {
324 return m_store.TestPath(storeID,path,false) ? 1 : 0; 347 return m_store.TestPath(storeID,path,false) ? 1 : 0;
@@ -364,6 +387,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
364 /// </summary> 387 /// </summary>
365 // ----------------------------------------------------------------- 388 // -----------------------------------------------------------------
366 [ScriptInvocation] 389 [ScriptInvocation]
390 public int JsonArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
391 {
392 return m_store.ArrayLength(storeID,path);
393 }
394
395 // -----------------------------------------------------------------
396 /// <summary>
397 ///
398 /// </summary>
399 // -----------------------------------------------------------------
400 [ScriptInvocation]
367 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) 401 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
368 { 402 {
369 string value = String.Empty; 403 string value = String.Empty;