aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
diff options
context:
space:
mode:
authorMic Bowman2013-01-31 14:53:16 -0800
committerMic Bowman2013-01-31 14:53:16 -0800
commit1e0420431f754ff71a97d01fae5617c1ea26cae0 (patch)
tree4d69a960e7701aa7af097b50b9259fbcc6d28021 /OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-1e0420431f754ff71a97d01fae5617c1ea26cae0.zip
opensim-SC-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.gz
opensim-SC-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.bz2
opensim-SC-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.xz
Move the JsonStore regular expressions to static variables to avoid
recompiling on every operation. Added JsonList2Path script function to simplify array iteration.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs204
1 files changed, 141 insertions, 63 deletions
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
165 165
166 try 166 try
167 { 167 {
168 m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); 168 m_comms.RegisterScriptInvocations(this);
169 m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
170 m_comms.RegisterScriptInvocation(this, "JsonTestStore");
171 169
172 m_comms.RegisterScriptInvocation(this, "JsonReadNotecard"); 170 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore");
173 m_comms.RegisterScriptInvocation(this, "JsonWriteNotecard"); 171 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
172 // m_comms.RegisterScriptInvocation(this, "JsonTestStore");
174 173
175 m_comms.RegisterScriptInvocation(this, "JsonTestPath"); 174 // m_comms.RegisterScriptInvocation(this, "JsonReadNotecard");
176 m_comms.RegisterScriptInvocation(this, "JsonTestPathJson"); 175 // m_comms.RegisterScriptInvocation(this, "JsonWriteNotecard");
177 176
178 m_comms.RegisterScriptInvocation(this, "JsonGetValue"); 177 // m_comms.RegisterScriptInvocation(this, "JsonTestPathList");
179 m_comms.RegisterScriptInvocation(this, "JsonGetValueJson"); 178 // m_comms.RegisterScriptInvocation(this, "JsonTestPath");
179 // m_comms.RegisterScriptInvocation(this, "JsonTestPathJson");
180 180
181 m_comms.RegisterScriptInvocation(this, "JsonTakeValue"); 181 // m_comms.RegisterScriptInvocation(this, "JsonGetValue");
182 m_comms.RegisterScriptInvocation(this, "JsonTakeValueJson"); 182 // m_comms.RegisterScriptInvocation(this, "JsonGetValueJson");
183 183
184 m_comms.RegisterScriptInvocation(this, "JsonReadValue"); 184 // m_comms.RegisterScriptInvocation(this, "JsonTakeValue");
185 m_comms.RegisterScriptInvocation(this, "JsonReadValueJson"); 185 // m_comms.RegisterScriptInvocation(this, "JsonTakeValueJson");
186 186
187 m_comms.RegisterScriptInvocation(this, "JsonSetValue"); 187 // m_comms.RegisterScriptInvocation(this, "JsonReadValue");
188 m_comms.RegisterScriptInvocation(this, "JsonSetValueJson"); 188 // m_comms.RegisterScriptInvocation(this, "JsonReadValueJson");
189 189
190 m_comms.RegisterScriptInvocation(this, "JsonRemoveValue"); 190 // m_comms.RegisterScriptInvocation(this, "JsonSetValue");
191 // m_comms.RegisterScriptInvocation(this, "JsonSetValueJson");
192
193 // m_comms.RegisterScriptInvocation(this, "JsonRemoveValue");
191 } 194 }
192 catch (Exception e) 195 catch (Exception e)
193 { 196 {
@@ -215,17 +218,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
215 /// 218 ///
216 /// </summary> 219 /// </summary>
217 // ----------------------------------------------------------------- 220 // -----------------------------------------------------------------
218 protected void GenerateRuntimeError(string msg) 221 [ScriptInvocation]
219 { 222 public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
220 throw new Exception("JsonStore Runtime Error: " + msg);
221 }
222
223 // -----------------------------------------------------------------
224 /// <summary>
225 ///
226 /// </summary>
227 // -----------------------------------------------------------------
228 protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
229 { 223 {
230 UUID uuid = UUID.Zero; 224 UUID uuid = UUID.Zero;
231 if (! m_store.CreateStore(value, ref uuid)) 225 if (! m_store.CreateStore(value, ref uuid))
@@ -239,7 +233,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
239 /// 233 ///
240 /// </summary> 234 /// </summary>
241 // ----------------------------------------------------------------- 235 // -----------------------------------------------------------------
242 protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) 236 [ScriptInvocation]
237 public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
243 { 238 {
244 return m_store.DestroyStore(storeID) ? 1 : 0; 239 return m_store.DestroyStore(storeID) ? 1 : 0;
245 } 240 }
@@ -249,7 +244,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
249 /// 244 ///
250 /// </summary> 245 /// </summary>
251 // ----------------------------------------------------------------- 246 // -----------------------------------------------------------------
252 protected int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID) 247 [ScriptInvocation]
248 public int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
253 { 249 {
254 return m_store.TestStore(storeID) ? 1 : 0; 250 return m_store.TestStore(storeID) ? 1 : 0;
255 } 251 }
@@ -259,7 +255,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
259 /// 255 ///
260 /// </summary> 256 /// </summary>
261 // ----------------------------------------------------------------- 257 // -----------------------------------------------------------------
262 protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 258 [ScriptInvocation]
259 public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID)
263 { 260 {
264 UUID reqID = UUID.Random(); 261 UUID reqID = UUID.Random();
265 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); 262 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); });
@@ -271,7 +268,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
271 /// 268 ///
272 /// </summary> 269 /// </summary>
273 // ----------------------------------------------------------------- 270 // -----------------------------------------------------------------
274 protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name) 271 [ScriptInvocation]
272 public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
275 { 273 {
276 UUID reqID = UUID.Random(); 274 UUID reqID = UUID.Random();
277 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); }); 275 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); });
@@ -283,12 +281,25 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
283 /// 281 ///
284 /// </summary> 282 /// </summary>
285 // ----------------------------------------------------------------- 283 // -----------------------------------------------------------------
286 protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) 284 [ScriptInvocation]
285 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
286 {
287 return JsonStore.CanonicalPathExpression(ConvertList2Path(pathlist));
288 }
289
290 // -----------------------------------------------------------------
291 /// <summary>
292 ///
293 /// </summary>
294 // -----------------------------------------------------------------
295 [ScriptInvocation]
296 public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path)
287 { 297 {
288 return m_store.TestPath(storeID,path,false) ? 1 : 0; 298 return m_store.TestPath(storeID,path,false) ? 1 : 0;
289 } 299 }
290 300
291 protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path) 301 [ScriptInvocation]
302 public int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path)
292 { 303 {
293 return m_store.TestPath(storeID,path,true) ? 1 : 0; 304 return m_store.TestPath(storeID,path,true) ? 1 : 0;
294 } 305 }
@@ -298,12 +309,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
298 /// 309 ///
299 /// </summary> 310 /// </summary>
300 // ----------------------------------------------------------------- 311 // -----------------------------------------------------------------
301 protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 312 [ScriptInvocation]
313 public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
302 { 314 {
303 return m_store.SetValue(storeID,path,value,false) ? 1 : 0; 315 return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
304 } 316 }
305 317
306 protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 318 [ScriptInvocation]
319 public int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
307 { 320 {
308 return m_store.SetValue(storeID,path,value,true) ? 1 : 0; 321 return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
309 } 322 }
@@ -313,7 +326,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
313 /// 326 ///
314 /// </summary> 327 /// </summary>
315 // ----------------------------------------------------------------- 328 // -----------------------------------------------------------------
316 protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path) 329 [ScriptInvocation]
330 public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
317 { 331 {
318 return m_store.RemoveValue(storeID,path) ? 1 : 0; 332 return m_store.RemoveValue(storeID,path) ? 1 : 0;
319 } 333 }
@@ -323,14 +337,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
323 /// 337 ///
324 /// </summary> 338 /// </summary>
325 // ----------------------------------------------------------------- 339 // -----------------------------------------------------------------
326 protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) 340 [ScriptInvocation]
341 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
327 { 342 {
328 string value = String.Empty; 343 string value = String.Empty;
329 m_store.GetValue(storeID,path,false,out value); 344 m_store.GetValue(storeID,path,false,out value);
330 return value; 345 return value;
331 } 346 }
332 347
333 protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 348 [ScriptInvocation]
349 public string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
334 { 350 {
335 string value = String.Empty; 351 string value = String.Empty;
336 m_store.GetValue(storeID,path,true, out value); 352 m_store.GetValue(storeID,path,true, out value);
@@ -342,60 +358,75 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
342 /// 358 ///
343 /// </summary> 359 /// </summary>
344 // ----------------------------------------------------------------- 360 // -----------------------------------------------------------------
345 protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path) 361 [ScriptInvocation]
362 public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
346 { 363 {
347 UUID reqID = UUID.Random(); 364 UUID reqID = UUID.Random();
348 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); }); 365 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); });
349 return reqID; 366 return reqID;
350 } 367 }
351 368
352 protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 369 [ScriptInvocation]
370 public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
353 { 371 {
354 UUID reqID = UUID.Random(); 372 UUID reqID = UUID.Random();
355 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); }); 373 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); });
356 return reqID; 374 return reqID;
357 } 375 }
358 376
359 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
360 {
361 try
362 {
363 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
364 return;
365 }
366 catch (Exception e)
367 {
368 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
369 }
370
371 DispatchValue(scriptID,reqID,String.Empty);
372 }
373
374
375 // ----------------------------------------------------------------- 377 // -----------------------------------------------------------------
376 /// <summary> 378 /// <summary>
377 /// 379 ///
378 /// </summary> 380 /// </summary>
379 // ----------------------------------------------------------------- 381 // -----------------------------------------------------------------
380 protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path) 382 [ScriptInvocation]
383 public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
381 { 384 {
382 UUID reqID = UUID.Random(); 385 UUID reqID = UUID.Random();
383 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); }); 386 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); });
384 return reqID; 387 return reqID;
385 } 388 }
386 389
387 protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 390 [ScriptInvocation]
391 public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
388 { 392 {
389 UUID reqID = UUID.Random(); 393 UUID reqID = UUID.Random();
390 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); }); 394 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); });
391 return reqID; 395 return reqID;
392 } 396 }
393 397
394 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) 398#endregion
399
400 // -----------------------------------------------------------------
401 /// <summary>
402 ///
403 /// </summary>
404 // -----------------------------------------------------------------
405 protected void GenerateRuntimeError(string msg)
406 {
407 throw new Exception("JsonStore Runtime Error: " + msg);
408 }
409
410 // -----------------------------------------------------------------
411 /// <summary>
412 ///
413 /// </summary>
414 // -----------------------------------------------------------------
415 protected void DispatchValue(UUID scriptID, UUID reqID, string value)
416 {
417 m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
418 }
419
420 // -----------------------------------------------------------------
421 /// <summary>
422 ///
423 /// </summary>
424 // -----------------------------------------------------------------
425 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
395 { 426 {
396 try 427 try
397 { 428 {
398 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); 429 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
399 return; 430 return;
400 } 431 }
401 catch (Exception e) 432 catch (Exception e)
@@ -406,16 +437,25 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
406 DispatchValue(scriptID,reqID,String.Empty); 437 DispatchValue(scriptID,reqID,String.Empty);
407 } 438 }
408 439
409#endregion
410 440
411 // ----------------------------------------------------------------- 441 // -----------------------------------------------------------------
412 /// <summary> 442 /// <summary>
413 /// 443 ///
414 /// </summary> 444 /// </summary>
415 // ----------------------------------------------------------------- 445 // -----------------------------------------------------------------
416 protected void DispatchValue(UUID scriptID, UUID reqID, string value) 446 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
417 { 447 {
418 m_comms.DispatchReply(scriptID,1,value,reqID.ToString()); 448 try
449 {
450 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
451 return;
452 }
453 catch (Exception e)
454 {
455 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
456 }
457
458 DispatchValue(scriptID,reqID,String.Empty);
419 } 459 }
420 460
421 // ----------------------------------------------------------------- 461 // -----------------------------------------------------------------
@@ -505,5 +545,43 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
505 545
506 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString()); 546 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
507 } 547 }
548
549 // -----------------------------------------------------------------
550 /// <summary>
551 /// Convert a list of values that are path components to a single string path
552 /// </summary>
553 // -----------------------------------------------------------------
554 protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$");
555 private string ConvertList2Path(object[] pathlist)
556 {
557 string path = "";
558 for (int i = 0; i < pathlist.Length; i++)
559 {
560 string token = "";
561
562 if (pathlist[i] is string)
563 {
564 token = pathlist[i].ToString();
565
566 // Check to see if this is a bare number which would not be a valid
567 // identifier otherwise
568 if (m_ArrayPattern.IsMatch(token))
569 token = '[' + token + ']';
570 }
571 else if (pathlist[i] is int)
572 {
573 token = "[" + pathlist[i].ToString() + "]";
574 }
575 else
576 {
577 token = "." + pathlist[i].ToString() + ".";
578 }
579
580 path += token + ".";
581 }
582
583 return path;
584 }
585
508 } 586 }
509} \ No newline at end of file 587} \ No newline at end of file