From 85198a45cb944a3de7402d7fccc75ec499002f01 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 6 Mar 2012 02:01:47 +0000 Subject: Fix off by one error in script error reporting. --- OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 8b88588..65d3b9b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs @@ -118,7 +118,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools emessage = emessage.Substring(slinfo.Length+2); message = String.Format("({0},{1}) {2}", - e.slInfo.lineNumber - 2, + e.slInfo.lineNumber - 1, e.slInfo.charPosition - 1, emessage); throw new Exception(message); -- cgit v1.1 From a92153ed88859af9d68b206ec320fc993fe5cdc7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 6 Mar 2012 02:21:19 +0000 Subject: Get all test methods in OpenSim.Region.ScriptEngine.Tests.dll to report that they're running --- .../Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | 95 ++++++++++++++++++++++ .../Shared/CodeTools/Tests/CompilerTest.cs | 7 +- .../ScriptEngine/Shared/Tests/LSL_ApiTest.cs | 11 ++- .../Shared/Tests/LSL_TypesTestLSLFloat.cs | 74 ++++++++++++++--- .../Shared/Tests/LSL_TypesTestLSLInteger.cs | 8 ++ .../Shared/Tests/LSL_TypesTestLSLString.cs | 8 ++ .../ScriptEngine/Shared/Tests/LSL_TypesTestList.cs | 42 ++++++++-- .../Shared/Tests/LSL_TypesTestVector3.cs | 9 +- 8 files changed, 228 insertions(+), 26 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index 63afb0b..2add011 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs @@ -29,6 +29,7 @@ using System.Collections.Generic; using System.Text.RegularExpressions; using NUnit.Framework; using OpenSim.Region.ScriptEngine.Shared.CodeTools; +using OpenSim.Tests.Common; namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests { @@ -43,6 +44,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests [Test] public void TestDefaultState() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -63,6 +66,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests [Test] public void TestCustomState() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -93,6 +98,8 @@ state another_state [Test] public void TestEventWithArguments() { + TestHelpers.InMethod(); + string input = @"default { at_rot_target(integer tnum, rotation targetrot, rotation ourrot) @@ -113,6 +120,8 @@ state another_state [Test] public void TestIntegerDeclaration() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -135,6 +144,8 @@ state another_state [Test] public void TestLoneIdent() { + TestHelpers.InMethod(); + // A lone ident should be removed completely as it's an error in C# // (MONO at least). string input = @"default @@ -161,6 +172,8 @@ state another_state [Test] public void TestAssignments() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -187,6 +200,8 @@ state another_state [Test] public void TestAdditionSubtractionOperator() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -215,6 +230,8 @@ state another_state [Test] public void TestStrings() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -242,6 +259,8 @@ state another_state [Test] public void TestBinaryExpression() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -284,6 +303,8 @@ state another_state [Test] public void TestFloatConstants() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -336,6 +357,8 @@ state another_state [Test] public void TestComments() { + TestHelpers.InMethod(); + string input = @"// this test tests comments default { @@ -358,6 +381,8 @@ default [Test] public void TestStringsWithEscapedQuotesAndComments() { + TestHelpers.InMethod(); + string input = @"// this test tests strings, with escaped quotes and comments in strings default { @@ -397,6 +422,8 @@ default [Test] public void TestCStyleComments() { + TestHelpers.InMethod(); + string input = @"/* this test tests comments of the C variety */ @@ -426,6 +453,8 @@ default [Test] public void TestGlobalDefinedFunctions() { + TestHelpers.InMethod(); + string input = @"// this test tests custom defined functions string onefunc() @@ -470,6 +499,8 @@ default [Test] public void TestGlobalDeclaredVariables() { + TestHelpers.InMethod(); + string input = @"// this test tests custom defined functions and global variables string globalString; @@ -525,6 +556,8 @@ default [Test] public void TestMoreAssignments() { + TestHelpers.InMethod(); + string input = @"// this test tests +=, -=, *=, /=, %= string globalString; @@ -579,6 +612,8 @@ default [Test] public void TestVectorConstantNotation() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -606,6 +641,8 @@ default [Test] public void TestVectorMemberAccess() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -632,6 +669,8 @@ default [Test] public void TestExpressionInParentheses() { + TestHelpers.InMethod(); + string input = @"default { touch_start(integer num_detected) @@ -660,6 +699,8 @@ default [Test] public void TestIncrementDecrementOperator() { + TestHelpers.InMethod(); + string input = @"// here we'll test the ++ and -- operators default @@ -690,6 +731,8 @@ default [Test] public void TestLists() { + TestHelpers.InMethod(); + string input = @"// testing lists default @@ -718,6 +761,8 @@ default [Test] public void TestIfStatement() { + TestHelpers.InMethod(); + string input = @"// let's test if statements default @@ -822,6 +867,8 @@ default [Test] public void TestIfElseStatement() { + TestHelpers.InMethod(); + string input = @"// let's test complex logical expressions default @@ -928,6 +975,8 @@ default [Test] public void TestWhileLoop() { + TestHelpers.InMethod(); + string input = @"// let's test while loops default @@ -968,6 +1017,8 @@ default [Test] public void TestDoWhileLoop() { + TestHelpers.InMethod(); + string input = @"// let's test do-while loops default @@ -1012,6 +1063,8 @@ default [Test] public void TestForLoop() { + TestHelpers.InMethod(); + string input = @"// let's test for loops default @@ -1056,6 +1109,8 @@ default [Test] public void TestFloatsWithTrailingDecimal() { + TestHelpers.InMethod(); + string input = @"// a curious feature of LSL that allows floats to be defined with a trailing dot default @@ -1108,6 +1163,8 @@ default [Test] public void TestUnaryAndBinaryOperators() { + TestHelpers.InMethod(); + string input = @"// let's test a few more operators default @@ -1144,6 +1201,8 @@ default [Test] public void TestTypecasts() { + TestHelpers.InMethod(); + string input = @"// let's test typecasts default @@ -1189,6 +1248,8 @@ default [Test] public void TestStates() { + TestHelpers.InMethod(); + string input = @"// let's test states default @@ -1229,6 +1290,8 @@ state statetwo [Test] public void TestHexIntegerConstants() { + TestHelpers.InMethod(); + string input = @"// let's test hex integers default @@ -1261,6 +1324,8 @@ default [Test] public void TestJumps() { + TestHelpers.InMethod(); + string input = @"// let's test jumps default @@ -1291,6 +1356,8 @@ default [Test] public void TestImplicitVariableInitialization() { + TestHelpers.InMethod(); + string input = @"// let's test implicitly initializing variables default @@ -1334,6 +1401,8 @@ default [Test] public void TestMultipleEqualsExpression() { + TestHelpers.InMethod(); + string input = @"// let's test x = y = 5 type expressions default @@ -1366,6 +1435,8 @@ default [Test] public void TestUnaryExpressionLastInVectorConstant() { + TestHelpers.InMethod(); + string input = @"// let's test unary expressions some more default @@ -1390,6 +1461,8 @@ default [Test] public void TestVectorMemberPlusEquals() { + TestHelpers.InMethod(); + string input = @"// let's test unary expressions some more default @@ -1424,6 +1497,8 @@ default [Test] public void TestWhileLoopWithNoBody() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1447,6 +1522,8 @@ default [Test] public void TestDoWhileLoopWithNoBody() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1472,6 +1549,8 @@ default [Test] public void TestIfWithNoBody() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1495,6 +1574,8 @@ default [Test] public void TestIfElseWithNoBody() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1521,6 +1602,8 @@ default [Test] public void TestForLoopWithNoBody() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1544,6 +1627,8 @@ default [Test] public void TestForLoopWithNoAssignment() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1569,6 +1654,8 @@ default [Test] public void TestForLoopWithOnlyIdentInAssignment() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1594,6 +1681,8 @@ default [Test] public void TestAssignmentInIfWhileDoWhile() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1631,6 +1720,8 @@ default [Test] public void TestLSLListHack() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1656,6 +1747,8 @@ default [ExpectedException(typeof(System.Exception))] public void TestSyntaxError() { + TestHelpers.InMethod(); + string input = @"default { state_entry() @@ -1682,6 +1775,8 @@ default [ExpectedException(typeof(System.Exception))] public void TestSyntaxErrorDeclaringVariableInForLoop() { + TestHelpers.InMethod(); + string input = @"default { state_entry() diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs index c5483c8..1fa6954 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs @@ -31,6 +31,7 @@ using System.Collections.Generic; using Microsoft.CSharp; using NUnit.Framework; using OpenSim.Region.ScriptEngine.Shared.CodeTools; +using OpenSim.Tests.Common; namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests { @@ -92,6 +93,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests //[Test] public void TestUseUndeclaredVariable() { + TestHelpers.InMethod(); + m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); string input = @"default @@ -124,6 +127,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests //[Test] public void TestCastAndConcatString() { + TestHelpers.InMethod(); + m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); string input = @"string s = "" a string""; @@ -150,4 +155,4 @@ default Assert.AreEqual(0, m_compilerResults.Errors.Count); } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs index 3baa723..9cf9258 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs @@ -46,7 +46,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [TestFixture, LongRunning] public class LSL_ApiTest { - private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6; private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d; private const float FLOAT_ACCURACY = 0.00005f; @@ -55,7 +54,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [SetUp] public void SetUp() { - IConfigSource initConfigSource = new IniConfigSource(); IConfig config = initConfigSource.AddConfig("XEngine"); config.Set("Enabled", "true"); @@ -75,6 +73,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestllAngleBetween() { + TestHelpers.InMethod(); + CheckllAngleBetween(new Vector3(1, 0, 0), 0, 1, 1); CheckllAngleBetween(new Vector3(1, 0, 0), 90, 1, 1); CheckllAngleBetween(new Vector3(1, 0, 0), 180, 1, 1); @@ -158,6 +158,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests // llRot2Euler test. public void TestllRot2Euler() { + TestHelpers.InMethod(); + // 180, 90 and zero degree rotations. CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f)); CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.707107f, 0.707107f)); @@ -256,6 +258,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests // llSetPrimitiveParams and llGetPrimitiveParams test. public void TestllSetPrimitiveParams() { + TestHelpers.InMethod(); + // Create Prim1. Scene scene = SceneHelpers.SetupScene(); string obj1Name = "Prim1"; @@ -486,9 +490,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests } [Test] - // llVecNorm test. public void TestllVecNorm() { + TestHelpers.InMethod(); + // Check special case for normalizing zero vector. CheckllVecNorm(new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), new LSL_Types.Vector3(0.0d, 0.0d, 0.0d)); // Check various vectors. diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs index 10b52cf..3ed2562 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs @@ -213,6 +213,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConstructFromInt() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (KeyValuePair number in m_intDoubleSet) @@ -228,6 +230,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConstructFromDouble() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (KeyValuePair number in m_doubleDoubleSet) @@ -243,6 +247,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLFloatToInt() { + TestHelpers.InMethod(); + int testNumber; foreach (KeyValuePair number in m_doubleIntSet) @@ -258,6 +264,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLFloatToUint() { + TestHelpers.InMethod(); + uint testNumber; foreach (KeyValuePair number in m_doubleUintSet) @@ -273,6 +281,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastLSLFloatToBooleanTrue() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; bool testBool; @@ -291,6 +301,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastLSLFloatToBooleanFalse() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0); bool testBool = testFloat; @@ -303,6 +315,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastIntToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (int number in m_intList) @@ -318,6 +332,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastLSLIntegerToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (int number in m_intList) @@ -333,6 +349,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLIntegerToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (int number in m_intList) @@ -348,6 +366,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastStringToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (KeyValuePair number in m_stringDoubleSet) @@ -363,6 +383,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLStringToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (KeyValuePair number in m_stringDoubleSet) @@ -378,6 +400,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastDoubleToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (double number in m_doubleList) @@ -393,6 +417,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastLSLFloatToDouble() { + TestHelpers.InMethod(); + double testNumber; LSL_Types.LSLFloat testFloat; @@ -411,19 +437,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLFloatToFloat() { - float testFloat; - float numberAsFloat; - LSL_Types.LSLFloat testLSLFloat; - foreach (double number in m_doubleList) - { - testLSLFloat = new LSL_Types.LSLFloat(number); - numberAsFloat = (float)number; - testFloat = (float)testLSLFloat; - - Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance)); - } - } + TestHelpers.InMethod(); + + float testFloat; + float numberAsFloat; + LSL_Types.LSLFloat testLSLFloat; + foreach (double number in m_doubleList) + { + testLSLFloat = new LSL_Types.LSLFloat(number); + numberAsFloat = (float)number; + testFloat = (float)testLSLFloat; + + Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance)); + } + } /// /// Tests the equality (==) operator. @@ -431,6 +459,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestEqualsOperator() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloatA, testFloatB; foreach (double number in m_doubleList) @@ -450,6 +480,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestNotEqualOperator() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloatA, testFloatB; foreach (double number in m_doubleList) @@ -469,6 +501,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestIncrementOperator() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; double testNumber; @@ -493,6 +527,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestDecrementOperator() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; double testNumber; @@ -517,6 +553,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestToString() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; foreach (KeyValuePair number in m_doubleStringSet) @@ -532,6 +570,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestAddTwoLSLFloats() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testResult; foreach (KeyValuePair number in m_doubleDoubleSet) @@ -547,6 +587,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestSubtractTwoLSLFloats() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testResult; foreach (KeyValuePair number in m_doubleDoubleSet) @@ -562,6 +604,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestMultiplyTwoLSLFloats() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testResult; foreach (KeyValuePair number in m_doubleDoubleSet) @@ -577,6 +621,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestDivideTwoLSLFloats() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testResult; foreach (KeyValuePair number in m_doubleDoubleSet) @@ -595,6 +641,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastBooleanToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testFloat; testFloat = (1 == 0); @@ -610,4 +658,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs index 3ad673b..8d1169a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs @@ -79,6 +79,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLFloatToLSLInteger() { + TestHelpers.InMethod(); + LSL_Types.LSLInteger testInteger; foreach (KeyValuePair number in m_doubleIntSet) @@ -94,6 +96,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastStringToLSLInteger() { + TestHelpers.InMethod(); + LSL_Types.LSLInteger testInteger; foreach (KeyValuePair number in m_stringIntSet) @@ -109,6 +113,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLStringToLSLInteger() { + TestHelpers.InMethod(); + LSL_Types.LSLInteger testInteger; foreach (KeyValuePair number in m_stringIntSet) @@ -124,6 +130,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastBooleanToLSLInteger() { + TestHelpers.InMethod(); + LSL_Types.LSLInteger testInteger; testInteger = (1 == 0); diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs index fa976ed..c4ca1a8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs @@ -71,6 +71,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConstructFromLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLString testString; foreach (KeyValuePair number in m_doubleStringSet) @@ -86,6 +88,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLFloatToLSLString() { + TestHelpers.InMethod(); + LSL_Types.LSLString testString; foreach (KeyValuePair number in m_doubleStringSet) @@ -101,6 +105,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestExplicitCastLSLStringToQuaternion() { + TestHelpers.InMethod(); + string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>"; LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString); @@ -118,6 +124,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestImplicitCastBooleanToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLString testString; testString = (LSL_Types.LSLString) (1 == 0); diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs index 66a7329..b81225f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs @@ -44,6 +44,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConcatenateString() { + TestHelpers.InMethod(); + LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); testList += new LSL_Types.LSLString("addition"); @@ -64,6 +66,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConcatenateInteger() { + TestHelpers.InMethod(); + LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); testList += new LSL_Types.LSLInteger(20); @@ -84,6 +88,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConcatenateDouble() { + TestHelpers.InMethod(); + LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); testList += new LSL_Types.LSLFloat(2.0f); @@ -104,6 +110,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestCastLSLIntegerItemToLSLInteger() { + TestHelpers.InMethod(); + LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(123); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -116,6 +124,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestCastLSLFloatItemToLSLFloat() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(123.45678987); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -128,6 +138,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestCastLSLStringItemToLSLString() { + TestHelpers.InMethod(); + LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello there"); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -140,6 +152,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestCastVector3ItemToVector3() { + TestHelpers.InMethod(); + LSL_Types.Vector3 testValue = new LSL_Types.Vector3(12.34, 56.987654, 0.00987); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -151,6 +165,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestCastQuaternionItemToQuaternion() { + TestHelpers.InMethod(); + LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.34, 56.44323, 765.983421, 0.00987); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -165,6 +181,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetLSLIntegerItemForLSLIntegerItem() { + TestHelpers.InMethod(); + LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(999911); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -177,6 +195,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetLSLFloatItemForLSLFloatItem() { + TestHelpers.InMethod(); + LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(321.45687876); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -189,11 +209,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetLSLFloatItemForLSLIntegerItem() { - LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(3060987); - LSL_Types.LSLFloat testFloatValue = new LSL_Types.LSLFloat(testValue); - LSL_Types.list testList = new LSL_Types.list(testValue); + TestHelpers.InMethod(); + + LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(3060987); + LSL_Types.LSLFloat testFloatValue = new LSL_Types.LSLFloat(testValue); + LSL_Types.list testList = new LSL_Types.list(testValue); - Assert.AreEqual(testFloatValue, testList.GetLSLFloatItem(0)); + Assert.AreEqual(testFloatValue, testList.GetLSLFloatItem(0)); } /// @@ -202,6 +224,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetLSLStringItemForLSLStringItem() { + TestHelpers.InMethod(); + LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello all"); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -214,6 +238,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetLSLStringItemForKeyItem() { + TestHelpers.InMethod(); + LSL_Types.key testValue = new LSL_Types.key("98000000-0000-2222-3333-100000001000"); LSL_Types.LSLString testStringValue = new LSL_Types.LSLString(testValue); @@ -228,6 +254,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetVector3ItemForVector3Item() { + TestHelpers.InMethod(); + LSL_Types.Vector3 testValue = new LSL_Types.Vector3(92.34, 58.98754, -0.10987); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -239,6 +267,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetQuaternionItemForQuaternionItem() { + TestHelpers.InMethod(); + LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.64, 59.43723, 765.3421, 4.00987); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -251,6 +281,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestGetKeyItemForKeyItem() { + TestHelpers.InMethod(); + LSL_Types.key testValue = new LSL_Types.key("00000000-0000-2222-3333-100000001012"); LSL_Types.list testList = new LSL_Types.list(testValue); @@ -258,4 +290,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests Assert.AreEqual(testValue, testList.GetKeyItem(0)); } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs index 195af7f..ebf8001 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs @@ -32,16 +32,17 @@ using OpenSim.Region.ScriptEngine.Shared; namespace OpenSim.Region.ScriptEngine.Shared.Tests { + /// + /// Tests for Vector3 + /// [TestFixture] public class LSL_TypesTestVector3 { - /// - /// Tests for Vector3 - /// [Test] - public void TestDotProduct() { + TestHelpers.InMethod(); + // The numbers we test for. Dictionary expectsSet = new Dictionary(); expectsSet.Add("<1, 2, 3> * <2, 3, 4>", 20.0); -- cgit v1.1 From b3449e998ab7fc9a952559821caea6484fc57e6e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 6 Mar 2012 02:30:22 +0000 Subject: Fix TestSyntaxError() and TestSyntaxErrorDeclaringVariableInForLoop() They were all failing assertions but the exceptions these threw were caught as expected Exceptions. I don't think we can easily distinguish these from the Exceptions that we're expecting. So for now we'll do some messy manually checking with boolean setting instead. This patch also corrects the assertions themselves. --- .../Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index 2add011..7763619 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs @@ -1744,11 +1744,12 @@ default } [Test] - [ExpectedException(typeof(System.Exception))] public void TestSyntaxError() { TestHelpers.InMethod(); + bool gotException = false; + string input = @"default { state_entry() @@ -1764,19 +1765,22 @@ default } catch (System.Exception e) { - // The syntax error is on line 6, char 5 (expected ';', found + // The syntax error is on line 5, char 4 (expected ';', found // '}'). - Assert.AreEqual("(4,4) syntax error", e.Message); - throw; + Assert.AreEqual("(5,4) syntax error", e.Message); + gotException = true; } + + Assert.That(gotException, Is.True); } [Test] - [ExpectedException(typeof(System.Exception))] public void TestSyntaxErrorDeclaringVariableInForLoop() { TestHelpers.InMethod(); + bool gotException = false; + string input = @"default { state_entry() @@ -1792,11 +1796,13 @@ default } catch (System.Exception e) { - // The syntax error is on line 5, char 14 (Syntax error) - Assert.AreEqual("(3,13) syntax error", e.Message); + // The syntax error is on line 4, char 13 (Syntax error) + Assert.AreEqual("(4,13) syntax error", e.Message); - throw; + gotException = true; } + + Assert.That(gotException, Is.True); } } } -- cgit v1.1 From 98251cdab364baf20537a1b5a6260c68e6630ccf Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 6 Mar 2012 23:21:17 +0000 Subject: Add sensor, dataserver requests, timer and listener counts to "xengine status" command. This is for diagnostic purposes. --- .../Api/Implementation/AsyncCommandManager.cs | 53 +++++++++++++++++++++- .../Api/Implementation/Plugins/Dataserver.cs | 9 ++++ .../Shared/Api/Implementation/Plugins/Listener.cs | 25 +++++----- .../Api/Implementation/Plugins/SensorRepeat.cs | 12 +++++ .../Shared/Api/Implementation/Plugins/Timer.cs | 9 ++++ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 15 ++++++ 6 files changed, 111 insertions(+), 12 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs index 14edde4..993d10f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs @@ -247,7 +247,58 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // Remove Sensors m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID); + } + + /// + /// Get the sensor repeat plugin for this script engine. + /// + /// + /// + public static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine) + { + if (m_SensorRepeat.ContainsKey(engine)) + return m_SensorRepeat[engine]; + else + return null; + } + /// + /// Get the dataserver plugin for this script engine. + /// + /// + /// + public static Dataserver GetDataserverPlugin(IScriptEngine engine) + { + if (m_Dataserver.ContainsKey(engine)) + return m_Dataserver[engine]; + else + return null; + } + + /// + /// Get the timer plugin for this script engine. + /// + /// + /// + public static Timer GetTimerPlugin(IScriptEngine engine) + { + if (m_Timer.ContainsKey(engine)) + return m_Timer[engine]; + else + return null; + } + + /// + /// Get the listener plugin for this script engine. + /// + /// + /// + public static Listener GetListenerPlugin(IScriptEngine engine) + { + if (m_Listener.ContainsKey(engine)) + return m_Listener[engine]; + else + return null; } public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) @@ -270,7 +321,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api data.AddRange(timers); } - Object[] sensors=m_SensorRepeat[engine].GetSerializationData(itemID); + Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID); if (sensors.Length > 0) { data.Add("sensor"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs index 7fa19b1..9f78a49 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs @@ -38,6 +38,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins { public AsyncCommandManager m_CmdManager; + public int DataserverRequestsCount + { + get + { + lock (DataserverRequests) + return DataserverRequests.Count; + } + } + private Dictionary DataserverRequests = new Dictionary(); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs index 740816f..93e0261 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs @@ -42,22 +42,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins public AsyncCommandManager m_CmdManager; + private IWorldComm m_commsPlugin; + + public int ListenerCount + { + get { return m_commsPlugin.ListenerCount; } + } + public Listener(AsyncCommandManager CmdManager) { m_CmdManager = CmdManager; + m_commsPlugin = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface(); } public void CheckListeners() { if (m_CmdManager.m_ScriptEngine.World == null) return; - IWorldComm comms = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface(); - if (comms != null) + if (m_commsPlugin != null) { - while (comms.HasMessages()) + while (m_commsPlugin.HasMessages()) { - ListenerInfo lInfo = (ListenerInfo)comms.GetNextMessage(); + ListenerInfo lInfo = (ListenerInfo)m_commsPlugin.GetNextMessage(); //Deliver data to prim's listen handler object[] resobj = new object[] @@ -81,17 +88,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins public Object[] GetSerializationData(UUID itemID) { - IWorldComm comms = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface(); - - return comms.GetSerializationData(itemID); + return m_commsPlugin.GetSerializationData(itemID); } public void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data) { - IWorldComm comms = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface(); - - comms.CreateFromData(localID, itemID, hostID, data); + m_commsPlugin.CreateFromData(localID, itemID, hostID, data); } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index fbb7c39..1c272f8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -44,6 +44,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins public AsyncCommandManager m_CmdManager; + /// + /// Number of sensors active. + /// + public int SensorsCount + { + get + { + lock (SenseRepeatListLock) + return SenseRepeaters.Count; + } + } + public SensorRepeat(AsyncCommandManager CmdManager) { m_CmdManager = CmdManager; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs index eeb59d9..bc63030 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs @@ -37,6 +37,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins { public AsyncCommandManager m_CmdManager; + public int TimersCount + { + get + { + lock (TimerListLock) + return Timers.Count; + } + } + public Timer(AsyncCommandManager CmdManager) { m_CmdManager = CmdManager; diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index c68f03f..d1cac9c 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -49,7 +49,10 @@ using OpenSim.Region.ScriptEngine.Shared; using OpenSim.Region.ScriptEngine.Shared.ScriptBase; using OpenSim.Region.ScriptEngine.Shared.CodeTools; using OpenSim.Region.ScriptEngine.Shared.Instance; +using OpenSim.Region.ScriptEngine.Shared.Api; +using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; using OpenSim.Region.ScriptEngine.Interfaces; +using Timer = OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer; using ScriptCompileQueue = OpenSim.Framework.LocklessQueue; @@ -386,6 +389,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine sb.AppendFormat("Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks); // sb.AppendFormat("Assemblies loaded : {0}\n", m_Assemblies.Count); + SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(this); + sb.AppendFormat("Sensors : {0}\n", sr.SensorsCount); + + Dataserver ds = AsyncCommandManager.GetDataserverPlugin(this); + sb.AppendFormat("Dataserver requests : {0}\n", ds.DataserverRequestsCount); + + Timer t = AsyncCommandManager.GetTimerPlugin(this); + sb.AppendFormat("Timers : {0}\n", t.TimersCount); + + Listener l = AsyncCommandManager.GetListenerPlugin(this); + sb.AppendFormat("Listeners : {0}\n", l.ListenerCount); + MainConsole.Instance.OutputFormat(sb.ToString()); } -- cgit v1.1 From 749c3fef8ad2d3af97fcd9ab9c72740675e46715 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 8 Mar 2012 01:51:37 +0000 Subject: Change "help" to display categories/module list then "help " to display commands in a category. This is to deal with the hundred lines of command splurge when one previously typed "help" Modelled somewhat on the mysql console One can still type help to get per command help at any point. Categories capitalized to avoid conflict with the all-lowercase commands (except for commander system, as of yet). Does not affect command parsing or any other aspects of the console apart from the help system. Backwards compatible with existing modules. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index d1cac9c..b433430 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -277,22 +277,22 @@ namespace OpenSim.Region.ScriptEngine.XEngine } MainConsole.Instance.Commands.AddCommand( - "scripts", false, "xengine status", "xengine status", "Show status information", + "Scripts", false, "xengine status", "xengine status", "Show status information", "Show status information on the script engine.", HandleShowStatus); MainConsole.Instance.Commands.AddCommand( - "scripts", false, "scripts show", "scripts show []", "Show script information", + "Scripts", false, "scripts show", "scripts show []", "Show script information", "Show information on all scripts known to the script engine." + "If a is given then only information on that script will be shown.", HandleShowScripts); MainConsole.Instance.Commands.AddCommand( - "scripts", false, "show scripts", "show scripts []", "Show script information", + "Scripts", false, "show scripts", "show scripts []", "Show script information", "Synonym for scripts show command", HandleShowScripts); MainConsole.Instance.Commands.AddCommand( - "scripts", false, "scripts suspend", "scripts suspend []", "Suspends all running scripts", + "Scripts", false, "scripts suspend", "scripts suspend []", "Suspends all running scripts", "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a" + " script that is currently processing an event.\n" + "Suspended scripts will continue to accumulate events but won't process them.\n" @@ -300,20 +300,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript)); MainConsole.Instance.Commands.AddCommand( - "scripts", false, "scripts resume", "scripts resume []", "Resumes all suspended scripts", + "Scripts", false, "scripts resume", "scripts resume []", "Resumes all suspended scripts", "Resumes all currently suspended scripts.\n" + "Resumed scripts will process all events accumulated whilst suspended." + "If a is given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); MainConsole.Instance.Commands.AddCommand( - "scripts", false, "scripts stop", "scripts stop []", "Stops all running scripts", + "Scripts", false, "scripts stop", "scripts stop []", "Stops all running scripts", "Stops all running scripts." + "If a is given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); MainConsole.Instance.Commands.AddCommand( - "scripts", false, "scripts start", "scripts start []", "Starts all stopped scripts", + "Scripts", false, "scripts start", "scripts start []", "Starts all stopped scripts", "Starts all stopped scripts." + "If a is given then only that script will be started. Otherwise, all suitable scripts are started.", (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); -- cgit v1.1 From 42a7a8506262f69155ee6393c601f3a427f1ef77 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 9 Mar 2012 00:57:49 +0000 Subject: FireAndForget scripted rez - port from Avination --- .../Shared/Api/Implementation/LSL_Api.cs | 87 ++++++++++++---------- 1 file changed, 46 insertions(+), 41 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 0003515..786ae6e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2771,64 +2771,69 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s)) - return; - float dist = (float)llVecDist(llGetPos(), pos); + Util.FireAndForget(delegate (object x) + { + if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s)) + return; + float dist = (float)llVecDist(llGetPos(), pos); - if (dist > m_ScriptDistanceFactor * 10.0f) - return; + if (dist > m_ScriptDistanceFactor * 10.0f) + return; - TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); + //Clone is thread-safe + TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); - foreach (KeyValuePair inv in partInventory) - { - if (inv.Value.Name == inventory) + foreach (KeyValuePair inv in partInventory) { - // make sure we're an object. - if (inv.Value.InvType != (int)InventoryType.Object) + if (inv.Value.Name == inventory) { - llSay(0, "Unable to create requested object. Object is missing from database."); - return; - } + // make sure we're an object. + if (inv.Value.InvType != (int)InventoryType.Object) + { + llSay(0, "Unable to create requested object. Object is missing from database."); + return; + } - Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); - Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z); + Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); + Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z); - // need the magnitude later - float velmag = (float)Util.GetMagnitude(llvel); + // need the magnitude later + // float velmag = (float)Util.GetMagnitude(llvel); - SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); + SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); - // If either of these are null, then there was an unknown error. - if (new_group == null) - continue; + // If either of these are null, then there was an unknown error. + if (new_group == null) + continue; - // objects rezzed with this method are die_at_edge by default. - new_group.RootPart.SetDieAtEdge(true); + // objects rezzed with this method are die_at_edge by default. + new_group.RootPart.SetDieAtEdge(true); - new_group.ResumeScripts(); + new_group.ResumeScripts(); - m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( - "object_rez", new Object[] { - new LSL_String( - new_group.RootPart.UUID.ToString()) }, - new DetectParams[0])); + m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( + "object_rez", new Object[] { + new LSL_String( + new_group.RootPart.UUID.ToString()) }, + new DetectParams[0])); - float groupmass = new_group.GetMass(); + float groupmass = new_group.GetMass(); - if (new_group.RootPart.PhysActor != null && new_group.RootPart.PhysActor.IsPhysical && llvel != Vector3.Zero) - { - //Recoil. - llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0); + if (new_group.RootPart.PhysActor != null && new_group.RootPart.PhysActor.IsPhysical && llvel != Vector3.Zero) + { + //Recoil. + llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0); + } + // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) + return; } - // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) - ScriptSleep((int)((groupmass * velmag) / 10)); - ScriptSleep(100); - return; } - } - llSay(0, "Could not find object " + inventory); + llSay(0, "Could not find object " + inventory); + }); + + //ScriptSleep((int)((groupmass * velmag) / 10)); + ScriptSleep(100); } public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) -- cgit v1.1 From 94e58ff6b9368975925cea4697077a8e59162bc0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 9 Mar 2012 02:38:11 +0000 Subject: Use SP.ParentPart instead of ParentID in places where it's more efficient (saving extra null checks, etc.) However, it looks like we should retain SP.ParentID since it's much easier to use that in places where another thread could change ParentPart to null. Otherwise one has to clumsily put ParentPart in a reference, etc. to avoid a race. --- .../Shared/Api/Implementation/LSL_Api.cs | 24 +++++++--------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 786ae6e..bb374ed 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3825,7 +3825,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api List nametable = new List(); World.ForEachRootScenePresence(delegate(ScenePresence presence) { - if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) + SceneObjectPart sitPart = presence.ParentPart; + if (sitPart != null && m_host.ParentGroup.HasChildPrim(sitPart.LocalId)) nametable.Add(presence.ControllingClient.Name); }); @@ -4393,22 +4394,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // Find pushee position // Pushee Linked? - if (pusheeav.ParentID != 0) - { - SceneObjectPart parentobj = World.GetSceneObjectPart(pusheeav.ParentID); - if (parentobj != null) - { - PusheePos = parentobj.AbsolutePosition; - } - else - { - PusheePos = pusheeav.AbsolutePosition; - } - } + SceneObjectPart sitPart = pusheeav.ParentPart; + if (sitPart != null) + PusheePos = sitPart.AbsolutePosition; else - { PusheePos = pusheeav.AbsolutePosition; - } } if (!pusheeIsAvatar) @@ -5603,7 +5593,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api flags |= ScriptBaseClass.AGENT_IN_AIR; } - if (agent.ParentID != 0) + if (agent.ParentPart != null) { flags |= ScriptBaseClass.AGENT_ON_OBJECT; flags |= ScriptBaseClass.AGENT_SITTING; @@ -7692,7 +7682,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api World.ForEachRootScenePresence(delegate(ScenePresence presence) { if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) - avatarCount++; + avatarCount++; }); return m_host.ParentGroup.PrimCount + avatarCount; -- cgit v1.1 From 824eb7ed20a006a7abf0b1cd4d7f46d9c154647e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 10 Mar 2012 19:51:28 -0800 Subject: Added osGetGridGatekeeperURI() --- .../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 14 ++++++++++++++ .../Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 1 + .../Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++ 3 files changed, 20 insertions(+) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 8edd146..3dbc31a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2093,6 +2093,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return HomeURI; } + public string osGetGridGatekeeperURI() + { + CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI"); + m_host.AddScriptLPS(1); + + string gatekeeperURI = String.Empty; + IConfigSource config = m_ScriptEngine.ConfigSource; + + if (config.Configs["GridService"] != null) + gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI); + + return gatekeeperURI; + } + public string osGetGridCustom(string key) { CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 82a6caf..a5b906f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -161,6 +161,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces string osGetGridName(); string osGetGridLoginURI(); string osGetGridHomeURI(); + string osGetGridGatekeeperURI(); string osGetGridCustom(string key); LSL_String osFormatString(string str, LSL_List strings); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 4341246..e048da2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -457,6 +457,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osGetGridHomeURI(); } + public string osGetGridGatekeeperURI() + { + return m_OSSL_Functions.osGetGridGatekeeperURI(); + } + public string osGetGridCustom(string key) { return m_OSSL_Functions.osGetGridCustom(key); -- cgit v1.1 From 25592bbd852e9350bca25f240d6d54c7a54e28a0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 12 Mar 2012 21:16:05 +0000 Subject: Add max thread and min thread information to "xengine status" region console command --- OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 3 +++ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 2 ++ 2 files changed, 5 insertions(+) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index bc1902b..4010167 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -578,7 +578,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance return true; if (!m_InSelfDelete) + { +// m_log.ErrorFormat("[SCRIPT INSTANCE]: Aborting script {0} {1}", ScriptName, ItemID); result.Abort(); + } lock (m_EventQueue) { diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index b433430..66349e3 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -384,6 +384,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine sb.AppendFormat("Unique scripts : {0}\n", m_uniqueScripts.Count); sb.AppendFormat("Scripts waiting for load : {0}\n", m_CompileQueue.Count); + sb.AppendFormat("Max threads : {0}\n", m_ThreadPool.MaxThreads); + sb.AppendFormat("Min threads : {0}\n", m_ThreadPool.MinThreads); sb.AppendFormat("Allocated threads : {0}\n", m_ThreadPool.ActiveThreads); sb.AppendFormat("In use threads : {0}\n", m_ThreadPool.InUseThreads); sb.AppendFormat("Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks); -- cgit v1.1 From 95ec96bf86ebebbc6c2f2c3f3a2bd8ce3f9990f4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 14 Mar 2012 00:29:36 +0000 Subject: refactor: rename ScriptInstance.m_CurrentResult to m_CurrentWorkItem to make it more understandable as to what it is and what it does (hold a thread pool work item for a waiting of in-progress event) Also add other various illustrative comments --- .../ScriptEngine/Interfaces/IScriptInstance.cs | 8 ++- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 66 ++++++++++++++-------- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 1 - 3 files changed, 50 insertions(+), 25 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index d3200d5..f00e41f 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -89,7 +89,7 @@ namespace OpenSim.Region.ScriptEngine.Interfaces void Start(); /// - /// Stop the script. + /// Stop the script instance. /// /// /// true if the script was successfully stopped, false otherwise @@ -97,13 +97,17 @@ namespace OpenSim.Region.ScriptEngine.Interfaces void SetState(string state); + /// + /// Post an event to this script instance. + /// + /// void PostEvent(EventParams data); void Suspend(); void Resume(); /// - /// Process the next event queued for this script + /// Process the next event queued for this script instance. /// /// object EventProcessor(); diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 4010167..b840730 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -58,7 +58,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IScriptEngine m_Engine; - private IScriptWorkItem m_CurrentResult = null; + + /// + /// The current work item if an event for this script is running or waiting to run, + /// + /// + /// Null if there is no running or waiting to run event. Must be changed only under an m_EventQueue lock. + /// + private IScriptWorkItem m_CurrentWorkItem; + private Queue m_EventQueue = new Queue(32); private bool m_RunEvents = false; private UUID m_ItemID; @@ -157,7 +165,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { // Need to place ourselves back in a work item if there are events to process if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) - m_CurrentResult = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = m_Engine.QueueEventHandler(this); } } } @@ -527,8 +535,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (m_EventQueue.Count > 0) { - if (m_CurrentResult == null) - m_CurrentResult = m_Engine.QueueEventHandler(this); + if (m_CurrentWorkItem == null) + m_CurrentWorkItem = m_Engine.QueueEventHandler(this); // else // m_log.Error("[Script] Tried to start a script that was already queued"); } @@ -540,52 +548,58 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // m_log.DebugFormat( // "[SCRIPT INSTANCE]: Stopping script {0} {1} with timeout {2}", ScriptName, ItemID, timeout); - IScriptWorkItem result; + IScriptWorkItem workItem; lock (m_EventQueue) { if (!Running) return true; - if (m_CurrentResult == null) + // If we're not running or waiting to run an event then we can safely stop. + if (m_CurrentWorkItem == null) { m_RunEvents = false; return true; } - if (m_CurrentResult.Cancel()) + // If we are waiting to run an event then we can try to cancel it. + if (m_CurrentWorkItem.Cancel()) { - m_CurrentResult = null; + m_CurrentWorkItem = null; m_RunEvents = false; return true; } - result = m_CurrentResult; + workItem = m_CurrentWorkItem; m_RunEvents = false; } - if (result.Wait(new TimeSpan((long)timeout * 100000))) + // Wait for the current event to complete. + if (workItem.Wait(new TimeSpan((long)timeout * 100000))) { return true; } lock (m_EventQueue) { - result = m_CurrentResult; + workItem = m_CurrentWorkItem; } - if (result == null) + if (workItem == null) return true; + // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then + // forcibly abort the work item (this aborts the underlying thread). if (!m_InSelfDelete) { // m_log.ErrorFormat("[SCRIPT INSTANCE]: Aborting script {0} {1}", ScriptName, ItemID); - result.Abort(); + + workItem.Abort(); } lock (m_EventQueue) { - m_CurrentResult = null; + m_CurrentWorkItem = null; } return true; @@ -606,6 +620,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance throw new EventAbortException(); } + /// + /// Post an event to this script instance. + /// + /// + /// The request to run the event is sent + /// + /// public void PostEvent(EventParams data) { // m_log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}", @@ -672,9 +693,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_EventQueue.Enqueue(data); - if (m_CurrentResult == null) + if (m_CurrentWorkItem == null) { - m_CurrentResult = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = m_Engine.QueueEventHandler(this); } } } @@ -701,11 +722,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) { - m_CurrentResult = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = m_Engine.QueueEventHandler(this); } else { - m_CurrentResult = null; + m_CurrentWorkItem = null; } return 0; } @@ -825,15 +846,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } } + + // If there are more events and we are currently running and not shutting down, then ask the + // script engine to run the next event. lock (m_EventQueue) { if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) { - m_CurrentResult = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = m_Engine.QueueEventHandler(this); } else { - m_CurrentResult = null; + m_CurrentWorkItem = null; } } @@ -943,8 +967,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public void SaveState(string assembly) { - - // If we're currently in an event, just tell it to save upon return // if (m_InEvent) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 66349e3..ab41873 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -990,7 +990,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine lock (m_Scripts) { // Create the object record - if ((!m_Scripts.ContainsKey(itemID)) || (m_Scripts[itemID].AssetID != assetID)) { -- cgit v1.1 From 12cebb12d5b095fc8d1a2936b9537ad0e0e7dbe7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Mar 2012 00:06:52 +0000 Subject: Alleviate an issue where calling Thread.Abort() on script WorkItems can fail to release locks, resulting in a crippled simulator. This seems to be a particular problem with ReaderWriterLockSlim, though other locks can be affected as well. It has been seen to happen when llDie() is called in a linkset running more than one script. Alleviation here means supplying a ScriptInstance.Stop() timeout of 1000ms rather than 0ms, to give events a chance to complete. Also, we check the IsRunning status at the top of the ScriptInstance.EventProcessor() so that another event doesn't start in the mean time. Ultimately, a better solution may have to be found since a long-running event would still exceed the timeout and be aborted. --- .../Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 13 ++++++++++--- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index b840730..6a9cd72 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -546,7 +546,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public bool Stop(int timeout) { // m_log.DebugFormat( -// "[SCRIPT INSTANCE]: Stopping script {0} {1} with timeout {2}", ScriptName, ItemID, timeout); +// "[SCRIPT INSTANCE]: Stopping script {0} {1} in {2} {3} with timeout {4} {5} {6}", +// ScriptName, ItemID, PrimName, ObjectID, timeout, m_InSelfDelete, DateTime.Now.Ticks); IScriptWorkItem workItem; @@ -575,7 +576,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } // Wait for the current event to complete. - if (workItem.Wait(new TimeSpan((long)timeout * 100000))) + if (!m_InSelfDelete && workItem.Wait(new TimeSpan((long)timeout * 100000))) { return true; } @@ -592,7 +593,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // forcibly abort the work item (this aborts the underlying thread). if (!m_InSelfDelete) { -// m_log.ErrorFormat("[SCRIPT INSTANCE]: Aborting script {0} {1}", ScriptName, ItemID); +// m_log.ErrorFormat( +// "[SCRIPT INSTANCE]: Aborting script {0} {1} in prim {2} {3} {4} {5}", +// ScriptName, ItemID, PrimName, ObjectID, m_InSelfDelete, DateTime.Now.Ticks); workItem.Abort(); } @@ -706,6 +709,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance /// public object EventProcessor() { + // We check here as the thread stopping this instance from running may itself hold the m_Script lock. + if (!Running) + return 0; + lock (m_Script) { // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index ab41873..44397b7 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1118,7 +1118,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine } instance.ClearQueue(); - instance.Stop(0); + + // Give the script some time to finish processing its last event. Simply aborting the script thread can + // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort. + instance.Stop(1000); + // bool objectRemoved = false; lock (m_PrimObjects) -- cgit v1.1 From 2f81e53f63012f0ed1623dc6159da01a3807fbf6 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Mar 2012 00:20:47 +0000 Subject: Fix a problem where multiple near simultaneous calls to llDie() from multiple scripts in the same linkset can cause unnecessary thread aborts. The first llDie() could lock Scene.m_deleting_scene_object. The second llDie() would then wait at this lock. The first llDie() would go on to remove the second script but always abort it since the second script's WorkItem would not go away. Easiest solution here is to remove the m_deleting_scene_object since it's no longer justified - we no longer lock m_parts but take a copy instead. This also requires an adjustment in XEngine.OnRemoveScript not to use instance.ObjectID instead when firing the OnObjectRemoved event. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 44397b7..105d97d 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -176,12 +176,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine get { return m_ConfigSource; } } + /// + /// Event fired after the script engine has finished removing a script. + /// public event ScriptRemoved OnScriptRemoved; + + /// + /// Event fired after the script engine has finished removing a script from an object. + /// public event ObjectRemoved OnObjectRemoved; - // - // IRegionModule functions - // public void Initialise(IConfigSource configSource) { if (configSource.Configs["XEngine"] == null) @@ -1122,7 +1126,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine // Give the script some time to finish processing its last event. Simply aborting the script thread can // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort. instance.Stop(1000); - + // bool objectRemoved = false; lock (m_PrimObjects) @@ -1153,14 +1157,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine UnloadAppDomain(instance.AppDomain); } - instance = null; - ObjectRemoved handlerObjectRemoved = OnObjectRemoved; if (handlerObjectRemoved != null) - { - SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); - handlerObjectRemoved(part.UUID); - } + handlerObjectRemoved(instance.ObjectID); ScriptRemoved handlerScriptRemoved = OnScriptRemoved; if (handlerScriptRemoved != null) -- cgit v1.1 From 5ddda892388fe22912d8992f1c9d24b3667926f0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Mar 2012 00:48:19 +0000 Subject: Remove duplication of m_RunEvents and Running --- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 6a9cd72..cc4be73 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -68,7 +68,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private IScriptWorkItem m_CurrentWorkItem; private Queue m_EventQueue = new Queue(32); - private bool m_RunEvents = false; private UUID m_ItemID; private uint m_LocalID; private UUID m_ObjectID; @@ -141,11 +140,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } } - public bool Running - { - get { return m_RunEvents; } - set { m_RunEvents = value; } - } + public bool Running { get; set; } public bool Suspended { @@ -164,7 +159,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance lock (m_EventQueue) { // Need to place ourselves back in a work item if there are events to process - if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) + if ((m_EventQueue.Count > 0) && Running && (!m_ShuttingDown)) m_CurrentWorkItem = m_Engine.QueueEventHandler(this); } } @@ -369,13 +364,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance part.SetScriptEvents(m_ItemID, (int)m_Script.GetStateEventFlags(State)); - if (m_RunEvents && (!m_ShuttingDown)) + if (Running && (!m_ShuttingDown)) { - m_RunEvents = false; + Running = false; } else { - m_RunEvents = false; + Running = false; m_startOnInit = false; } @@ -531,7 +526,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (Running) return; - m_RunEvents = true; + Running = true; if (m_EventQueue.Count > 0) { @@ -559,7 +554,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // If we're not running or waiting to run an event then we can safely stop. if (m_CurrentWorkItem == null) { - m_RunEvents = false; + Running = false; return true; } @@ -567,12 +562,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (m_CurrentWorkItem.Cancel()) { m_CurrentWorkItem = null; - m_RunEvents = false; + Running = false; return true; } workItem = m_CurrentWorkItem; - m_RunEvents = false; + Running = false; } // Wait for the current event to complete. @@ -727,7 +722,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance data = (EventParams) m_EventQueue.Dequeue(); if (data == null) // Shouldn't happen { - if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) + if (m_EventQueue.Count > 0 && Running && !m_ShuttingDown) { m_CurrentWorkItem = m_Engine.QueueEventHandler(this); } @@ -853,12 +848,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } } - // If there are more events and we are currently running and not shutting down, then ask the // script engine to run the next event. lock (m_EventQueue) { - if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) + if (m_EventQueue.Count > 0 && Running && (!m_ShuttingDown)) { m_CurrentWorkItem = m_Engine.QueueEventHandler(this); } -- cgit v1.1 From f0c1746063dff537d83babcf617b7cf88ed612dc Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Mar 2012 01:26:38 +0000 Subject: minor: correct indentation levels --- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index cc4be73..afa9191 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -282,19 +282,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { m_Apis[api] = am.CreateApi(api); m_Apis[api].Initialize(engine, part, m_LocalID, itemID); - } - - try - { - if (dom != System.AppDomain.CurrentDomain) - m_Script = (IScript)dom.CreateInstanceAndUnwrap( - Path.GetFileNameWithoutExtension(assembly), - "SecondLife.Script"); - else - m_Script = (IScript)Assembly.Load( - Path.GetFileNameWithoutExtension(assembly)).CreateInstance( - "SecondLife.Script"); - + } + + try + { + if (dom != System.AppDomain.CurrentDomain) + m_Script = (IScript)dom.CreateInstanceAndUnwrap( + Path.GetFileNameWithoutExtension(assembly), + "SecondLife.Script"); + else + m_Script = (IScript)Assembly.Load( + Path.GetFileNameWithoutExtension(assembly)).CreateInstance( + "SecondLife.Script"); //ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); //RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); -- cgit v1.1 From 2d32401e23f216565f64163fb3220d035e45b0a8 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Mar 2012 01:32:16 +0000 Subject: Simplify some logic in the ScriptInstance constructor - running is set to false in both if/else branches --- .../Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index afa9191..8b0dbaa 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -363,15 +363,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance part.SetScriptEvents(m_ItemID, (int)m_Script.GetStateEventFlags(State)); - if (Running && (!m_ShuttingDown)) - { - Running = false; - } - else - { - Running = false; + Running = false; + + if (m_ShuttingDown) m_startOnInit = false; - } // we get new rez events on sim restart, too // but if there is state, then we fire the change @@ -380,7 +375,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // We loaded state, don't force a re-save m_SaveState = false; m_startedFromSavedState = true; - } } else -- cgit v1.1 From acb1355ff203b55ae2581b5606e251b8fa91b252 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Mar 2012 02:02:31 +0000 Subject: Remove property/field duplication in ScriptInstance where it's unnecessary. --- .../ScriptEngine/Interfaces/IScriptInstance.cs | 8 + .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 277 ++++++++------------- 2 files changed, 115 insertions(+), 170 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index f00e41f..8762642 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -68,8 +68,16 @@ namespace OpenSim.Region.ScriptEngine.Interfaces /// bool Suspended { get; set; } + /// + /// Is the script shutting down? + /// bool ShuttingDown { get; set; } + + /// + /// Script state + /// string State { get; set; } + IScriptEngine Engine { get; } UUID AppDomain { get; set; } string PrimName { get; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 8b0dbaa..968351b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -56,43 +56,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public class ScriptInstance : MarshalByRefObject, IScriptInstance { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private IScriptEngine m_Engine; /// /// The current work item if an event for this script is running or waiting to run, /// /// - /// Null if there is no running or waiting to run event. Must be changed only under an m_EventQueue lock. + /// Null if there is no running or waiting to run event. Must be changed only under an EventQueue lock. /// private IScriptWorkItem m_CurrentWorkItem; - private Queue m_EventQueue = new Queue(32); - private UUID m_ItemID; - private uint m_LocalID; - private UUID m_ObjectID; - private UUID m_AssetID; private IScript m_Script; - private UUID m_AppDomain; private DetectParams[] m_DetectParams; private bool m_TimerQueued; private DateTime m_EventStart; private bool m_InEvent; - private string m_PrimName; - private string m_ScriptName; private string m_Assembly; - private int m_StartParam; private string m_CurrentEvent = String.Empty; private bool m_InSelfDelete; private int m_MaxScriptQueue; private bool m_SaveState = true; - private bool m_ShuttingDown; private int m_ControlEventsInQueue; private int m_LastControlLevel; private bool m_CollisionInQueue; - private TaskInventoryItem m_thisScriptTask; + // The following is for setting a minimum delay between events private double m_minEventDelay; + private long m_eventDelayTicks; private long m_nextEventTimeTicks; private bool m_startOnInit = true; @@ -103,21 +92,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private UUID m_CurrentStateHash; private UUID m_RegionID; - private Dictionary, KeyValuePair> - m_LineMap; - - public Dictionary, KeyValuePair> - LineMap - { - get { return m_LineMap; } - set { m_LineMap = value; } - } + public Dictionary, KeyValuePair> LineMap { get; set; } private Dictionary m_Apis = new Dictionary(); - // Script state - private string m_State = "default"; - public Object[] PluginData = new Object[0]; /// @@ -156,11 +134,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (wasSuspended && !m_Suspended) { - lock (m_EventQueue) + lock (EventQueue) { // Need to place ourselves back in a work item if there are events to process - if ((m_EventQueue.Count > 0) && Running && (!m_ShuttingDown)) - m_CurrentWorkItem = m_Engine.QueueEventHandler(this); + if (EventQueue.Count > 0 && Running && !ShuttingDown) + m_CurrentWorkItem = Engine.QueueEventHandler(this); } } } @@ -168,79 +146,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } private bool m_Suspended; - public bool ShuttingDown - { - get { return m_ShuttingDown; } - set { m_ShuttingDown = value; } - } + public bool ShuttingDown { get; set; } - public string State - { - get { return m_State; } - set { m_State = value; } - } + public string State { get; set; } - public IScriptEngine Engine - { - get { return m_Engine; } - } + public IScriptEngine Engine { get; private set; } - public UUID AppDomain - { - get { return m_AppDomain; } - set { m_AppDomain = value; } - } + public UUID AppDomain { get; set; } - public string PrimName - { - get { return m_PrimName; } - } + public string PrimName { get; private set; } - public string ScriptName - { - get { return m_ScriptName; } - } + public string ScriptName { get; private set; } - public UUID ItemID - { - get { return m_ItemID; } - } + public UUID ItemID { get; private set; } - public UUID ObjectID - { - get { return m_ObjectID; } - } + public UUID ObjectID { get; private set; } - public uint LocalID - { - get { return m_LocalID; } - } + public uint LocalID { get; private set; } - public UUID AssetID - { - get { return m_AssetID; } - } + public UUID AssetID { get; private set; } - public Queue EventQueue - { - get { return m_EventQueue; } - } + public Queue EventQueue { get; private set; } - public void ClearQueue() - { - m_TimerQueued = false; - m_EventQueue.Clear(); - } + public int StartParam { get; set; } - public int StartParam - { - get { return m_StartParam; } - set { m_StartParam = value; } - } + public TaskInventoryItem ScriptTask { get; private set; } - public TaskInventoryItem ScriptTask + public void ClearQueue() { - get { return m_thisScriptTask; } + m_TimerQueued = false; + EventQueue.Clear(); } public ScriptInstance(IScriptEngine engine, SceneObjectPart part, @@ -249,16 +184,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance int startParam, bool postOnRez, StateSource stateSource, int maxScriptQueue) { - m_Engine = engine; - - m_LocalID = part.LocalId; - m_ObjectID = part.UUID; - m_ItemID = itemID; - m_AssetID = assetID; - m_PrimName = primName; - m_ScriptName = scriptName; + State = "default"; + EventQueue = new Queue(32); + + Engine = engine; + LocalID = part.LocalId; + ObjectID = part.UUID; + ItemID = itemID; + AssetID = assetID; + PrimName = primName; + ScriptName = scriptName; m_Assembly = assembly; - m_StartParam = startParam; + StartParam = startParam; m_MaxScriptQueue = maxScriptQueue; m_stateSource = stateSource; m_postOnRez = postOnRez; @@ -269,9 +206,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { lock (part.TaskInventory) { - if (part.TaskInventory.ContainsKey(m_ItemID)) + if (part.TaskInventory.ContainsKey(ItemID)) { - m_thisScriptTask = part.TaskInventory[m_ItemID]; + ScriptTask = part.TaskInventory[ItemID]; } } } @@ -281,7 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance foreach (string api in am.GetApis()) { m_Apis[api] = am.CreateApi(api); - m_Apis[api].Initialize(engine, part, m_LocalID, itemID); + m_Apis[api].Initialize(engine, part, LocalID, itemID); } try @@ -315,7 +252,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // // m_log.Debug("[Script] Script instance created"); - part.SetScriptEvents(m_ItemID, + part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); } catch (Exception e) @@ -330,7 +267,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_SaveState = true; string savedState = Path.Combine(Path.GetDirectoryName(assembly), - m_ItemID.ToString() + ".state"); + ItemID.ToString() + ".state"); if (File.Exists(savedState)) { string xml = String.Empty; @@ -354,18 +291,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance ScriptSerializer.Deserialize(xml, this); - AsyncCommandManager.CreateFromData(m_Engine, - m_LocalID, m_ItemID, m_ObjectID, + AsyncCommandManager.CreateFromData(Engine, + LocalID, ItemID, ObjectID, PluginData); -// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", m_PrimName, m_ScriptName); +// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName); - part.SetScriptEvents(m_ItemID, + part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); Running = false; - if (m_ShuttingDown) + if (ShuttingDown) m_startOnInit = false; // we get new rez events on sim restart, too @@ -393,7 +330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } // else // { -// ScenePresence presence = m_Engine.World.GetScenePresence(part.OwnerID); +// ScenePresence presence = Engine.World.GetScenePresence(part.OwnerID); // if (presence != null && (!postOnRez)) // presence.ControllingClient.SendAgentAlertMessage("Compile successful", false); @@ -411,7 +348,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (m_postOnRez) { PostEvent(new EventParams("on_rez", - new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0])); + new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0])); } if (m_stateSource == StateSource.AttachedRez) @@ -445,7 +382,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (m_postOnRez) { PostEvent(new EventParams("on_rez", - new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0])); + new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0])); } if (m_stateSource == StateSource.AttachedRez) @@ -459,7 +396,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private void ReleaseControls() { - SceneObjectPart part = m_Engine.World.GetSceneObjectPart(m_LocalID); + SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); if (part != null) { @@ -467,18 +404,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance UUID permsGranter; lock (part.TaskInventory) { - if (!part.TaskInventory.ContainsKey(m_ItemID)) + if (!part.TaskInventory.ContainsKey(ItemID)) return; - permsGranter = part.TaskInventory[m_ItemID].PermsGranter; - permsMask = part.TaskInventory[m_ItemID].PermsMask; + permsGranter = part.TaskInventory[ItemID].PermsGranter; + permsMask = part.TaskInventory[ItemID].PermsMask; } if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) { - ScenePresence presence = m_Engine.World.GetScenePresence(permsGranter); + ScenePresence presence = Engine.World.GetScenePresence(permsGranter); if (presence != null) - presence.UnRegisterControlEventsToScript(m_LocalID, m_ItemID); + presence.UnRegisterControlEventsToScript(LocalID, ItemID); } } } @@ -486,13 +423,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public void DestroyScriptInstance() { ReleaseControls(); - AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); + AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); } public void RemoveState() { string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly), - m_ItemID.ToString() + ".state"); + ItemID.ToString() + ".state"); try { @@ -505,7 +442,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public void VarDump(Dictionary vars) { - // m_log.Info("Variable dump for script "+ m_ItemID.ToString()); + // m_log.Info("Variable dump for script "+ ItemID.ToString()); // foreach (KeyValuePair v in vars) // { // m_log.Info("Variable: "+v.Key+" = "+v.Value.ToString()); @@ -514,17 +451,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public void Start() { - lock (m_EventQueue) + lock (EventQueue) { if (Running) return; Running = true; - if (m_EventQueue.Count > 0) + if (EventQueue.Count > 0) { if (m_CurrentWorkItem == null) - m_CurrentWorkItem = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = Engine.QueueEventHandler(this); // else // m_log.Error("[Script] Tried to start a script that was already queued"); } @@ -539,7 +476,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance IScriptWorkItem workItem; - lock (m_EventQueue) + lock (EventQueue) { if (!Running) return true; @@ -569,7 +506,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance return true; } - lock (m_EventQueue) + lock (EventQueue) { workItem = m_CurrentWorkItem; } @@ -588,7 +525,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance workItem.Abort(); } - lock (m_EventQueue) + lock (EventQueue) { m_CurrentWorkItem = null; } @@ -621,7 +558,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public void PostEvent(EventParams data) { // m_log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}", -// m_PrimName, m_ScriptName, data.EventName, m_State); +// PrimName, ScriptName, data.EventName, State); if (!Running) return; @@ -636,9 +573,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_nextEventTimeTicks = DateTime.Now.Ticks + m_eventDelayTicks; } - lock (m_EventQueue) + lock (EventQueue) { - if (m_EventQueue.Count >= m_MaxScriptQueue) + if (EventQueue.Count >= m_MaxScriptQueue) return; if (data.EventName == "timer") @@ -682,11 +619,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_CollisionInQueue = true; } - m_EventQueue.Enqueue(data); + EventQueue.Enqueue(data); if (m_CurrentWorkItem == null) { - m_CurrentWorkItem = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = Engine.QueueEventHandler(this); } } } @@ -710,14 +647,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance EventParams data = null; - lock (m_EventQueue) + lock (EventQueue) { - data = (EventParams) m_EventQueue.Dequeue(); + data = (EventParams)EventQueue.Dequeue(); if (data == null) // Shouldn't happen { - if (m_EventQueue.Count > 0 && Running && !m_ShuttingDown) + if (EventQueue.Count > 0 && Running && !ShuttingDown) { - m_CurrentWorkItem = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = Engine.QueueEventHandler(this); } else { @@ -744,28 +681,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (data.EventName == "state") // Hardcoded state change { // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", - // m_PrimName, m_ScriptName, data.Params[0].ToString()); - m_State = data.Params[0].ToString(); - AsyncCommandManager.RemoveScript(m_Engine, - m_LocalID, m_ItemID); + // PrimName, ScriptName, data.Params[0].ToString()); + State = data.Params[0].ToString(); + AsyncCommandManager.RemoveScript(Engine, + LocalID, ItemID); - SceneObjectPart part = m_Engine.World.GetSceneObjectPart( - m_LocalID); + SceneObjectPart part = Engine.World.GetSceneObjectPart( + LocalID); if (part != null) { - part.SetScriptEvents(m_ItemID, + part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); } } else { - if (m_Engine.World.PipeEventsForScript(m_LocalID) || + if (Engine.World.PipeEventsForScript(LocalID) || data.EventName == "control") // Don't freeze avies! { - SceneObjectPart part = m_Engine.World.GetSceneObjectPart( - m_LocalID); + SceneObjectPart part = Engine.World.GetSceneObjectPart( + LocalID); // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", - // m_PrimName, m_ScriptName, data.EventName, m_State); + // PrimName, ScriptName, data.EventName, State); try { @@ -807,7 +744,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (text.Length > 1000) text = text.Substring(0, 1000); - m_Engine.World.SimChat(Utils.StringToBytes(text), + Engine.World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, 2147483647, part.AbsolutePosition, part.Name, part.UUID, false); @@ -829,13 +766,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { m_InSelfDelete = true; if (part != null) - m_Engine.World.DeleteSceneObject(part.ParentGroup, false); + Engine.World.DeleteSceneObject(part.ParentGroup, false); } else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) { m_InSelfDelete = true; if (part != null) - part.Inventory.RemoveInventoryItem(m_ItemID); + part.Inventory.RemoveInventoryItem(ItemID); } } } @@ -843,11 +780,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // If there are more events and we are currently running and not shutting down, then ask the // script engine to run the next event. - lock (m_EventQueue) + lock (EventQueue) { - if (m_EventQueue.Count > 0 && Running && (!m_ShuttingDown)) + if (EventQueue.Count > 0 && Running && !ShuttingDown) { - m_CurrentWorkItem = m_Engine.QueueEventHandler(this); + m_CurrentWorkItem = Engine.QueueEventHandler(this); } else { @@ -880,15 +817,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance ReleaseControls(); Stop(0); - SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID); - part.Inventory.GetInventoryItem(m_ItemID).PermsMask = 0; - part.Inventory.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero; - AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); - m_EventQueue.Clear(); + SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); + part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; + part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; + AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); + EventQueue.Clear(); m_Script.ResetVars(); - m_State = "default"; + State = "default"; - part.SetScriptEvents(m_ItemID, + part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); if (running) Start(); @@ -905,16 +842,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance ReleaseControls(); m_Script.ResetVars(); - SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID); - part.Inventory.GetInventoryItem(m_ItemID).PermsMask = 0; - part.Inventory.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero; - AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); + SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); + part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; + part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; + AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); - m_EventQueue.Clear(); + EventQueue.Clear(); m_Script.ResetVars(); - m_State = "default"; + State = "default"; - part.SetScriptEvents(m_ItemID, + part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); if (m_CurrentEvent != "state_entry") @@ -969,7 +906,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance return; } - PluginData = AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID); + PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID); string xml = ScriptSerializer.Serialize(this); @@ -981,7 +918,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { try { - FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state")); + FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state")); System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); Byte[] buf = enc.GetBytes(xml); fs.Write(buf, 0, buf.Length); @@ -991,7 +928,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { // m_log.Error("Unable to save xml\n"+e.ToString()); } - //if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state"))) + //if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state"))) //{ // throw new Exception("Completed persistence save, but no file was created"); //} @@ -1008,7 +945,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public override string ToString() { - return String.Format("{0} {1} on {2}", m_ScriptName, m_ItemID, m_PrimName); + return String.Format("{0} {1} on {2}", ScriptName, ItemID, PrimName); } string FormatException(Exception e) @@ -1076,7 +1013,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // Force an update of the in-memory plugin data // - PluginData = AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID); + PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID); return ScriptSerializer.Serialize(this); } -- cgit v1.1 From 402ff75d781d6f4e38eee8884d7b4411bb756c9b Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Thu, 15 Mar 2012 13:16:02 -0700 Subject: Adds a new script command 'modInvoke' to invoke registered functions from region modules. The LSL translator is extended to generate the modInvoke format of commands for directly inlined function calls. A region module can register a function Test() with the name "Test". LSL code can call that function as "Test()". The compiler will translate that invocation into modInvoke("Test", ...) --- .../Shared/Api/Implementation/MOD_Api.cs | 109 +++++++++++++++++++++ .../ScriptEngine/Shared/Api/Interface/IMOD_Api.cs | 9 ++ .../ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs | 15 +++ .../Shared/CodeTools/CSCodeGenerator.cs | 28 +++++- .../ScriptEngine/Shared/CodeTools/Compiler.cs | 5 +- 5 files changed, 163 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index d4facdd..2942104 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -116,6 +116,115 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); } + /// + /// + /// + /// The name of the function to invoke + /// List of parameters + /// string result of the invocation + public string modInvokeS(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(string)) + MODError(String.Format("return type mismatch for {0}",fname)); + + return (string)modInvoke(fname,parms); + } + + public int modInvokeI(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(int)) + MODError(String.Format("return type mismatch for {0}",fname)); + + return (int)modInvoke(fname,parms); + } + + public float modInvokeF(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(float)) + MODError(String.Format("return type mismatch for {0}",fname)); + + return (float)modInvoke(fname,parms); + } + + /// + /// Invokes a preregistered function through the ScriptModuleComms class + /// + /// The name of the function to invoke + /// List of parameters + /// string result of the invocation + protected object modInvoke(string fname, params object[] parms) + { + if (!m_MODFunctionsEnabled) + { + MODShoutError("Module command functions not enabled"); + return ""; + } + + Type[] signature = m_comms.LookupTypeSignature(fname); + if (signature.Length != parms.Length) + MODError(String.Format("wrong number of parameters to function {0}",fname)); + + object[] convertedParms = new object[parms.Length]; + + for (int i = 0; i < parms.Length; i++) + { + if (parms[i] is LSL_String) + { + if (signature[i] != typeof(string)) + MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + + convertedParms[i] = (string)(LSL_String)parms[i]; + } + else if (parms[i] is LSL_Integer) + { + if (signature[i] != typeof(int)) + MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + + convertedParms[i] = (int)(LSL_Integer)parms[i]; + } + else if (parms[i] is LSL_Float) + { + if (signature[i] != typeof(float)) + MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + + convertedParms[i] = (float)(LSL_Float)parms[i]; + } + else if (parms[i] is LSL_Key) + { + if (signature[i] != typeof(string)) + MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + + convertedParms[i] = (string)(LSL_Key)parms[i]; + } + else if (parms[i] is LSL_Rotation) + { + if (signature[i] != typeof(string)) + MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + + convertedParms[i] = (string)(LSL_Rotation)parms[i]; + } + else if (parms[i] is LSL_Vector) + { + if (signature[i] != typeof(string)) + MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + + convertedParms[i] = (string)(LSL_Vector)parms[i]; + } + else + { + if (signature[i] != parms[i].GetType()) + MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + + convertedParms[i] = parms[i]; + } + } + + return m_comms.InvokeOperation(m_itemID,fname,convertedParms); + } + public string modSendCommand(string module, string command, string k) { if (!m_MODFunctionsEnabled) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs index e08eca5..756a59f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs @@ -40,6 +40,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces { public interface IMOD_Api { + // Invocation functions + string modInvokeS(string fname, params object[] parms); + int modInvokeI(string fname, params object[] parms); + float modInvokeF(string fname, params object[] parms); + // vector modInvokeV(string fname, params object[] parms); + // rotation modInvokeV(string fname, params object[] parms); + // key modInvokeK(string fname, params object[] parms); + // list modInvokeL(string fname, params object[] parms); + //Module functions string modSendCommand(string modules, string command, string k); } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs index 6525c76..04b7f14 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs @@ -58,6 +58,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase m_MOD_Functions = (IMOD_Api)api; } + public string modInvokeS(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeS(fname, parms); + } + + public int modInvokeI(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeI(fname, parms); + } + + public float modInvokeF(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeF(fname, parms); + } + public string modSendCommand(string module, string command, string k) { return m_MOD_Functions.modSendCommand(module, command, k); diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 65d3b9b..28c031f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs @@ -32,6 +32,8 @@ using System.Reflection; using log4net; using Tools; +using OpenSim.Region.Framework.Interfaces; + namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { public class CSCodeGenerator : ICodeConverter @@ -45,12 +47,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools private int m_CSharpLine; // the current line of generated C# code private int m_CSharpCol; // the current column of generated C# code private List m_warnings = new List(); + private IScriptModuleComms m_comms = null; /// /// Creates an 'empty' CSCodeGenerator instance. /// public CSCodeGenerator() { + m_comms = null; + ResetCounters(); + } + + public CSCodeGenerator(IScriptModuleComms comms) + { + m_comms = comms; ResetCounters(); } @@ -866,8 +876,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { string retstr = String.Empty; - retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc); - + string modinvoke = m_comms.LookupModInvocation(fc.Id); + if (modinvoke != null) + { + if (fc.kids[0] is ArgumentList) + { + if ((fc.kids[0] as ArgumentList).kids.Count == 0) + retstr += Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc); + else + retstr += Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc); + } + } + else + { + retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc); + } + foreach (SYMBOL kid in fc.kids) retstr += GenerateNode(kid); diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index c10143b..8f2ec49 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs @@ -35,6 +35,7 @@ using Microsoft.CSharp; //using Microsoft.JScript; using Microsoft.VisualBasic; using log4net; + using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.ScriptEngine.Interfaces; using OpenMetaverse; @@ -293,6 +294,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { // m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script); + IScriptModuleComms comms = m_scriptEngine.World.RequestModuleInterface(); + linemap = null; m_warnings.Clear(); @@ -382,7 +385,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools if (language == enumCompileType.lsl) { // Its LSL, convert it to C# - LSL_Converter = (ICodeConverter)new CSCodeGenerator(); + LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms); compileScript = LSL_Converter.Convert(Script); // copy converter warnings into our warnings. -- cgit v1.1 From 8b5298a62eb6910ac228b3fe0ab328b6aea79794 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Thu, 15 Mar 2012 13:37:43 -0700 Subject: Protect the scriptmodulecomms interface. --- OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 28c031f..b24f016 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs @@ -876,7 +876,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { string retstr = String.Empty; - string modinvoke = m_comms.LookupModInvocation(fc.Id); + string modinvoke = null; + if (m_comms != null) + modinvoke = m_comms.LookupModInvocation(fc.Id); + if (modinvoke != null) { if (fc.kids[0] is ArgumentList) -- cgit v1.1 From a4b01ef38a735ffe70b402061871a9c99f2757ed Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 16 Mar 2012 00:34:30 +0000 Subject: Replace script-lines-per-second with the script execution time scaled by its measurement period and an idealised frame time. The previous lines-per-second measurement used for top scripts report was inaccurate, since lines executed does not reflect time taken to execute. Also, every fetch of the report would reset all the numbers limiting its usefulness and we weren't even guaranteed to see the top 100. The actual measurement value should be script execution time per frame but XEngine does not work this way. Therefore, we use actual script execution time scaled by the measurement period and an idealised frame time. This is still not ideal but gives reasonable results and allows scripts to be compared. This commit moves script execution time calculations from SceneGraph into IScriptModule implementations. --- .../ScriptEngine/Interfaces/IScriptInstance.cs | 15 ++++++ .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 21 ++++++++- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 53 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index 8762642..11f54a2 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -78,6 +78,21 @@ namespace OpenSim.Region.ScriptEngine.Interfaces /// string State { get; set; } + /// + /// Time the script was last started + /// + DateTime TimeStarted { get; } + + /// + /// Tick the last measurement period was started. + /// + long MeasurementPeriodTickStart { get; } + + /// + /// Ticks spent executing in the last measurement period. + /// + long MeasurementPeriodExecutionTime { get; } + IScriptEngine Engine { get; } UUID AppDomain { get; set; } string PrimName { get; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 968351b..b177287 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -172,6 +172,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public TaskInventoryItem ScriptTask { get; private set; } + public DateTime TimeStarted { get; private set; } + + public long MeasurementPeriodTickStart { get; private set; } + + public long MeasurementPeriodExecutionTime { get; private set; } + + public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute; + public void ClearQueue() { m_TimerQueued = false; @@ -458,6 +466,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance Running = true; + TimeStarted = DateTime.Now; + MeasurementPeriodTickStart = Util.EnvironmentTickCount(); + MeasurementPeriodExecutionTime = 0; + if (EventQueue.Count > 0) { if (m_CurrentWorkItem == null) @@ -710,8 +722,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_EventStart = DateTime.Now; m_InEvent = true; + int start = Util.EnvironmentTickCount(); + + // Reset the measurement period when we reach the end of the current one. + if (start - MeasurementPeriodTickStart > MaxMeasurementPeriod) + MeasurementPeriodTickStart = start; + m_Script.ExecuteEvent(State, data.EventName, data.Params); + MeasurementPeriodExecutionTime += Util.EnvironmentTickCount() - start; + m_InEvent = false; m_CurrentEvent = String.Empty; @@ -720,7 +740,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // This will be the very first event we deliver // (state_entry) in default state // - SaveState(m_Assembly); m_SaveState = false; diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 105d97d..bddb1b9 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1891,6 +1891,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine } } + public Dictionary GetObjectScriptsExecutionTimes() + { + long tickNow = Util.EnvironmentTickCount(); + Dictionary topScripts = new Dictionary(); + + lock (m_Scripts) + { + foreach (IScriptInstance si in m_Scripts.Values) + { + if (!topScripts.ContainsKey(si.LocalID)) + topScripts[si.LocalID] = 0; + +// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; +// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); + + // Execution time of the script adjusted by it's measurement period to make scripts started at + // different times comparable. +// float adjustedExecutionTime +// = (float)si.MeasurementPeriodExecutionTime +// / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod) +// / TimeSpan.TicksPerMillisecond; + + long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; + + // Avoid divide by zerp + if (ticksElapsed == 0) + ticksElapsed = 1; + + // Scale execution time to the ideal 55 fps frame time for these reasons. + // + // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no + // 'script execution time per frame', which is the original purpose of this value. + // + // 2) Giving the raw execution times is misleading since scripts start at different times, making + // it impossible to compare scripts. + // + // 3) Scaling the raw execution time to the time that the script has been running is better but + // is still misleading since a script that has just been rezzed may appear to have been running + // for much longer. + // + // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect + // since the figure does not represent actual execution time and very hard running scripts will + // never exceed 18ms (though this is a very high number for script execution so is a warning sign). + float adjustedExecutionTime + = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f; + + topScripts[si.LocalID] += adjustedExecutionTime; + } + } + + return topScripts; + } + public void SuspendScript(UUID itemID) { // m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID); -- cgit v1.1 From c386b68373d0f4c46811423a2ba9ffbb486a1d9f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 16 Mar 2012 01:31:53 +0000 Subject: Aggregate script execution times by linksets rather than individual prims. This is for the top scripts report. --- OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs | 11 +++++++++++ OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 6 ++++++ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 5 ++--- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index 11f54a2..b04f6b6 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -99,6 +99,17 @@ namespace OpenSim.Region.ScriptEngine.Interfaces string ScriptName { get; } UUID ItemID { get; } UUID ObjectID { get; } + + /// + /// UUID of the root object for the linkset that the script is in. + /// + UUID RootObjectID { get; } + + /// + /// Local id of the root object for the linkset that the script is in. + /// + uint RootLocalID { get; } + uint LocalID { get; } UUID AssetID { get; } Queue EventQueue { get; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index b177287..6e36742 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -164,6 +164,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public uint LocalID { get; private set; } + public UUID RootObjectID { get; private set; } + + public uint RootLocalID { get; private set; } + public UUID AssetID { get; private set; } public Queue EventQueue { get; private set; } @@ -198,6 +202,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance Engine = engine; LocalID = part.LocalId; ObjectID = part.UUID; + RootLocalID = part.ParentGroup.LocalId; + RootObjectID = part.ParentGroup.UUID; ItemID = itemID; AssetID = assetID; PrimName = primName; diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index bddb1b9..3697f78 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1083,7 +1083,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (!m_PrimObjects[localID].Contains(itemID)) m_PrimObjects[localID].Add(itemID); - } if (!m_Assemblies.ContainsKey(assetID)) @@ -1901,7 +1900,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine foreach (IScriptInstance si in m_Scripts.Values) { if (!topScripts.ContainsKey(si.LocalID)) - topScripts[si.LocalID] = 0; + topScripts[si.RootLocalID] = 0; // long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; // float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); @@ -1937,7 +1936,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine float adjustedExecutionTime = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f; - topScripts[si.LocalID] += adjustedExecutionTime; + topScripts[si.RootLocalID] += adjustedExecutionTime; } } -- cgit v1.1 From 9497a7c7bd901686999da7bc1cba0b587186570b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 16 Mar 2012 03:32:14 +0000 Subject: refactor: separate out console and status report generation parts of XEngine --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 3697f78..d4108d7 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -380,6 +380,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) return; + MainConsole.Instance.OutputFormat(GetStatusReport()); + } + + public string GetStatusReport() + { StringBuilder sb = new StringBuilder(); sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName); @@ -407,7 +412,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine Listener l = AsyncCommandManager.GetListenerPlugin(this); sb.AppendFormat("Listeners : {0}\n", l.ListenerCount); - MainConsole.Instance.OutputFormat(sb.ToString()); + return sb.ToString(); } public void HandleShowScripts(string module, string[] cmdparams) -- cgit v1.1 From 4a57112f19c0e4eb3545fdc0cbbbd68ce46c6eaa Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 17 Mar 2012 04:02:23 +0000 Subject: Add osGetInventoryDesc() as per http://opensimulator.org/mantis/view.php?id=5927 This allows one to get description data for a given prim inventory item. Thanks MarcelEdward and GuduleLapointe! --- .../Shared/Api/Implementation/OSSL_Api.cs | 23 ++++++++++++++++++++++ .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 2 ++ .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++ 3 files changed, 30 insertions(+) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 3dbc31a..2ecd890 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2957,5 +2957,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); } + + /// + /// Get the description from an inventory item + /// + /// + /// Item description + public LSL_String osGetInventoryDesc(string item) + { + m_host.AddScriptLPS(1); + + lock (m_host.TaskInventory) + { + foreach (KeyValuePair inv in m_host.TaskInventory) + { + if (inv.Value.Name == item) + { + return inv.Value.Description.ToString(); + } + } + } + + return String.Empty; + } } } \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index a5b906f..8f9efc0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -229,5 +229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_List osGetAvatarList(); LSL_String osUnixTimeToTimestamp(long time); + + LSL_String osGetInventoryDesc(string item); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index e048da2..09e5992 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -863,5 +863,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { return m_OSSL_Functions.osUnixTimeToTimestamp(time); } + + public LSL_String osGetInventoryDesc(string item) + { + return m_OSSL_Functions.osGetInventoryDesc(item); + } } } -- cgit v1.1 From 437f18bc4149517d169bf1abd8295b9be28abbb1 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 19 Mar 2012 21:43:23 +0000 Subject: Stop console command "xengine status" throwing an exception if there are no scripts in a region. Addresses http://opensimulator.org/mantis/view.php?id=5940 --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index d4108d7..7712076 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -401,16 +401,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine // sb.AppendFormat("Assemblies loaded : {0}\n", m_Assemblies.Count); SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(this); - sb.AppendFormat("Sensors : {0}\n", sr.SensorsCount); + sb.AppendFormat("Sensors : {0}\n", sr != null ? sr.SensorsCount : 0); Dataserver ds = AsyncCommandManager.GetDataserverPlugin(this); - sb.AppendFormat("Dataserver requests : {0}\n", ds.DataserverRequestsCount); + sb.AppendFormat("Dataserver requests : {0}\n", ds != null ? ds.DataserverRequestsCount : 0); Timer t = AsyncCommandManager.GetTimerPlugin(this); - sb.AppendFormat("Timers : {0}\n", t.TimersCount); + sb.AppendFormat("Timers : {0}\n", t != null ? t.TimersCount : 0); Listener l = AsyncCommandManager.GetListenerPlugin(this); - sb.AppendFormat("Listeners : {0}\n", l.ListenerCount); + sb.AppendFormat("Listeners : {0}\n", l != null ? l.ListenerCount : 0); return sb.ToString(); } -- cgit v1.1 From 1a8769e6eff0eab750a528f27d127637edbd292b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 21 Mar 2012 23:57:39 +0000 Subject: Instead of loading default avatar animations in both SLUtil and AvatarAnimations, load just in AvatarAnimations instead. This lets us remove the dependency of OpenSim.Framework.dll on data/avataranimations.xml, which is not necessary for ROBUST. This commit also takes care of the odd situation where animations are stored and used internally with uppercase names (e.g. "STAND") but scripts refer to them with lowercase names (e.g. "sit"). --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index bb374ed..27f7c03 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -4314,7 +4314,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_host.RegionHandle == presence.RegionHandle) { - Dictionary animationstateNames = AnimationSet.Animations.AnimStateNames; + Dictionary animationstateNames = AvatarAnimations.AnimStateNames; if (presence != null) { @@ -5600,7 +5600,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } if (agent.Animator.Animations.DefaultAnimation.AnimID - == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) + == AvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) { flags |= ScriptBaseClass.AGENT_SITTING; } @@ -7714,7 +7714,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_Vector lower; LSL_Vector upper; if (presence.Animator.Animations.DefaultAnimation.AnimID - == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) + == AvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) { // This is for ground sitting avatars float height = presence.Appearance.AvatarHeight / 2.66666667f; -- cgit v1.1 From 9949ac2f9f448faaa873b98451c6025d687358a2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 22 Mar 2012 00:10:41 +0000 Subject: refactor: Rename AvatarAnimations -> DefaultAvatarAnimations for code clarity since non-default animations are handled completely separately from this class --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 27f7c03..d7a629b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -4314,7 +4314,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_host.RegionHandle == presence.RegionHandle) { - Dictionary animationstateNames = AvatarAnimations.AnimStateNames; + Dictionary animationstateNames = DefaultAvatarAnimations.AnimStateNames; if (presence != null) { @@ -5600,7 +5600,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } if (agent.Animator.Animations.DefaultAnimation.AnimID - == AvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) + == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) { flags |= ScriptBaseClass.AGENT_SITTING; } @@ -7714,7 +7714,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_Vector lower; LSL_Vector upper; if (presence.Animator.Animations.DefaultAnimation.AnimID - == AvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) + == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) { // This is for ground sitting avatars float height = presence.Appearance.AvatarHeight / 2.66666667f; -- cgit v1.1 From c4b2d24f337eeaf8c7d8e643c3491d491d584cde Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 22 Mar 2012 22:17:07 +0000 Subject: Add llGiveInventory() test from object to object where both objects are owned by the same user. --- .../Shared/Tests/LSL_ApiInventoryTests.cs | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs new file mode 100644 index 0000000..ca27b27 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs @@ -0,0 +1,111 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using log4net; +using Nini.Config; +using NUnit.Framework; +using OpenMetaverse; +using OpenMetaverse.Assets; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Region.CoreModules.Avatar.AvatarFactory; +using OpenSim.Region.OptionalModules.World.NPC; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.ScriptEngine.Shared; +using OpenSim.Region.ScriptEngine.Shared.Api; +using OpenSim.Services.Interfaces; +using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Mock; + +namespace OpenSim.Region.ScriptEngine.Shared.Tests +{ + /// + /// Tests for inventory functions in LSL + /// + [TestFixture] + public class LSL_ApiInventoryTests + { + protected Scene m_scene; + protected XEngine.XEngine m_engine; + + [SetUp] + public void SetUp() + { + IConfigSource initConfigSource = new IniConfigSource(); + IConfig config = initConfigSource.AddConfig("XEngine"); + config.Set("Enabled", "true"); + + m_scene = SceneHelpers.SetupScene(); + SceneHelpers.SetupSceneModules(m_scene, initConfigSource); + + m_engine = new XEngine.XEngine(); + m_engine.Initialise(initConfigSource); + m_engine.AddRegion(m_scene); + } + + /// + /// Test giving inventory from an object to an object where both are owned by the same user. + /// + [Test] + public void TestLlGiveInventorySameOwner() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + UUID userId = TestHelpers.ParseTail(0x1); + string inventoryItemName = "item1"; + + SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, userId, "so1", 0x10); + m_scene.AddSceneObject(so1); + + // Create an object embedded inside the first + UUID itemId = TestHelpers.ParseTail(0x20); + TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); + + LSL_Api api = new LSL_Api(); + api.Initialize(m_engine, so1.RootPart, so1.RootPart.LocalId, so1.RootPart.UUID); + + // Create a second object + SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100); + m_scene.AddSceneObject(so2); + + api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); + + // Item has copy permissions so original should stay intact. + List originalItems = so1.RootPart.Inventory.GetInventoryItems(); + Assert.That(originalItems.Count, Is.EqualTo(1)); + + List copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName); + Assert.That(copiedItems.Count, Is.EqualTo(1)); + Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); + } + } +} \ No newline at end of file -- cgit v1.1 From 760010d6fb6aac313d79ce0a4d0016d3809246a0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 22 Mar 2012 22:33:37 +0000 Subject: Fix llGiveInventory() so that it checks the destination part for AllowInventoryDrop, not the source. This allows llAllowInventoryDrop() to work. Regression test added for this case. --- .../Shared/Tests/LSL_ApiInventoryTests.cs | 59 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs index ca27b27..e2d0db2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs @@ -75,7 +75,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests /// Test giving inventory from an object to an object where both are owned by the same user. /// [Test] - public void TestLlGiveInventorySameOwner() + public void TestLlGiveInventoryO2OSameOwner() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); @@ -107,5 +107,62 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests Assert.That(copiedItems.Count, Is.EqualTo(1)); Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); } + + /// + /// Test giving inventory from an object to an object where they have different owners + /// + [Test] + public void TestLlGiveInventoryO2ODifferentOwners() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + UUID user1Id = TestHelpers.ParseTail(0x1); + UUID user2Id = TestHelpers.ParseTail(0x2); + string inventoryItemName = "item1"; + + SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); + m_scene.AddSceneObject(so1); + LSL_Api api = new LSL_Api(); + api.Initialize(m_engine, so1.RootPart, so1.RootPart.LocalId, so1.RootPart.UUID); + + // Create an object embedded inside the first + UUID itemId = TestHelpers.ParseTail(0x20); + TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, user1Id); + + // Create a second object + SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); + m_scene.AddSceneObject(so2); + LSL_Api api2 = new LSL_Api(); + api2.Initialize(m_engine, so2.RootPart, so2.RootPart.LocalId, so2.RootPart.UUID); + + // *** Firstly, we test where llAllowInventoryDrop() has not been called. *** + api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); + + { + // Item has copy permissions so original should stay intact. + List originalItems = so1.RootPart.Inventory.GetInventoryItems(); + Assert.That(originalItems.Count, Is.EqualTo(1)); + + // Should have not copied + List copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName); + Assert.That(copiedItems.Count, Is.EqualTo(0)); + } + + // *** Secondly, we turn on allow inventory drop in the target and retest. *** + api2.llAllowInventoryDrop(1); + api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); + + { + // Item has copy permissions so original should stay intact. + List originalItems = so1.RootPart.Inventory.GetInventoryItems(); + Assert.That(originalItems.Count, Is.EqualTo(1)); + + // Should now have copied. + List copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName); + Assert.That(copiedItems.Count, Is.EqualTo(1)); + Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); + } + } } } \ No newline at end of file -- cgit v1.1 From 6b87a29c86f9e8612ffb348767c6544af989fc13 Mon Sep 17 00:00:00 2001 From: nebadon Date: Fri, 23 Mar 2012 02:22:57 -0700 Subject: fix yield prolog so it compiles with mono 2.11 there has been a bugzilla report files with mono project in regards to this change, this simply lets us move forward with using mono 2.11 for now : https://bugzilla.xamarin.com/show_bug.cgi?id=4052 --- .../ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs | 6 +++--- OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs index 04357a9..09a9a08 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs @@ -226,7 +226,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog break; } } - + int z = 0; try { if (gotMatch) @@ -235,8 +235,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog finally { // Manually finalize all the iterators. - for (int i = 0; i < nIterators; ++i) - iterators[i].Dispose(); + for (z = 0; z < nIterators; ++z) + iterators[z].Dispose(); } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs index d8f44c1..f2171dd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs @@ -576,7 +576,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog break; } } - + int z = 0; try { if (gotMatch) @@ -585,8 +585,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog finally { // Manually finalize all the iterators. - for (int i = 0; i < nIterators; ++i) - iterators[i].Dispose(); + for (z = 0; z < nIterators; ++z) + iterators[z].Dispose(); } } -- cgit v1.1 From a14437ad5abf4d4dc95897216224548515a599e7 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Sat, 24 Mar 2012 22:43:42 -0700 Subject: Add support for key, vector, rotation and list types for both arguments and return values to the modInvoke family of functions. See http://opensimulator.org/wiki/OSSL_Script_Library/ModInvoke --- .../Shared/Api/Implementation/MOD_Api.cs | 245 ++++++++++++++++----- .../ScriptEngine/Shared/Api/Interface/IMOD_Api.cs | 24 +- .../ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs | 34 ++- 3 files changed, 229 insertions(+), 74 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 2942104..1bcbcd3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -120,33 +120,101 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// /// /// The name of the function to invoke - /// List of parameters + /// List of parameters /// string result of the invocation - public string modInvokeS(string fname, params object[] parms) + public LSL_String modInvokeS(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(string)) MODError(String.Format("return type mismatch for {0}",fname)); - return (string)modInvoke(fname,parms); + string result = (string)modInvoke(fname,parms); + return new LSL_String(result); } - public int modInvokeI(string fname, params object[] parms) + public LSL_Integer modInvokeI(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(int)) MODError(String.Format("return type mismatch for {0}",fname)); - return (int)modInvoke(fname,parms); + int result = (int)modInvoke(fname,parms); + return new LSL_Integer(result); } - public float modInvokeF(string fname, params object[] parms) + public LSL_Float modInvokeF(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(float)) MODError(String.Format("return type mismatch for {0}",fname)); - return (float)modInvoke(fname,parms); + float result = (float)modInvoke(fname,parms); + return new LSL_Float(result); + } + + public LSL_Key modInvokeK(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(UUID)) + MODError(String.Format("return type mismatch for {0}",fname)); + + UUID result = (UUID)modInvoke(fname,parms); + return new LSL_Key(result.ToString()); + } + + public LSL_Vector modInvokeV(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(OpenMetaverse.Vector3)) + MODError(String.Format("return type mismatch for {0}",fname)); + + OpenMetaverse.Vector3 result = (OpenMetaverse.Vector3)modInvoke(fname,parms); + return new LSL_Vector(result.X,result.Y,result.Z); + } + + public LSL_Rotation modInvokeR(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(OpenMetaverse.Quaternion)) + MODError(String.Format("return type mismatch for {0}",fname)); + + OpenMetaverse.Quaternion result = (OpenMetaverse.Quaternion)modInvoke(fname,parms); + return new LSL_Rotation(result.X,result.Y,result.Z,result.W); + } + + public LSL_List modInvokeL(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(object[])) + MODError(String.Format("return type mismatch for {0}",fname)); + + object[] result = (object[])modInvoke(fname,parms); + object[] llist = new object[result.Length]; + for (int i = 0; i < result.Length; i++) + { + if (result[i] is string) + llist[i] = new LSL_String((string)result[i]); + else if (result[i] is int) + llist[i] = new LSL_Integer((int)result[i]); + else if (result[i] is float) + llist[i] = new LSL_Float((float)result[i]); + else if (result[i] is OpenMetaverse.Vector3) + { + OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i]; + llist[i] = new LSL_Vector(vresult.X,vresult.Y,vresult.Z); + } + else if (result[i] is OpenMetaverse.Quaternion) + { + OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i]; + llist[i] = new LSL_Rotation(qresult.X,qresult.Y,qresult.Z,qresult.W); + } + else + { + MODError(String.Format("unknown list element returned by {0}",fname)); + } + } + + return new LSL_List(llist); } /// @@ -168,63 +236,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api MODError(String.Format("wrong number of parameters to function {0}",fname)); object[] convertedParms = new object[parms.Length]; - for (int i = 0; i < parms.Length; i++) - { - if (parms[i] is LSL_String) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (string)(LSL_String)parms[i]; - } - else if (parms[i] is LSL_Integer) - { - if (signature[i] != typeof(int)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (int)(LSL_Integer)parms[i]; - } - else if (parms[i] is LSL_Float) - { - if (signature[i] != typeof(float)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (float)(LSL_Float)parms[i]; - } - else if (parms[i] is LSL_Key) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (string)(LSL_Key)parms[i]; - } - else if (parms[i] is LSL_Rotation) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); - - convertedParms[i] = (string)(LSL_Rotation)parms[i]; - } - else if (parms[i] is LSL_Vector) - { - if (signature[i] != typeof(string)) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + convertedParms[i] = ConvertFromLSL(parms[i],signature[i]); - convertedParms[i] = (string)(LSL_Vector)parms[i]; - } - else - { - if (signature[i] != parms[i].GetType()) - MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name)); + // now call the function, the contract with the function is that it will always return + // non-null but don't trust it completely + try + { + object result = m_comms.InvokeOperation(m_itemID,fname,convertedParms); + if (result != null) + return result; - convertedParms[i] = parms[i]; - } + MODError(String.Format("Invocation of {0} failed; null return value",fname)); + } + catch (Exception e) + { + MODError(String.Format("Invocation of {0} failed; {1}",fname,e.Message)); } - return m_comms.InvokeOperation(m_itemID,fname,convertedParms); + return null; } + /// + /// Send a command to functions registered on an event + /// public string modSendCommand(string module, string command, string k) { if (!m_MODFunctionsEnabled) @@ -239,5 +274,101 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return req.ToString(); } + + /// + /// + protected object ConvertFromLSL(object lslparm, Type type) + { + // ---------- String ---------- + if (lslparm is LSL_String) + { + if (type == typeof(string)) + return (string)(LSL_String)lslparm; + + // Need to check for UUID since keys are often treated as strings + if (type == typeof(UUID)) + return new UUID((string)(LSL_String)lslparm); + } + + // ---------- Integer ---------- + else if (lslparm is LSL_Integer) + { + if (type == typeof(int)) + return (int)(LSL_Integer)lslparm; + } + + // ---------- Float ---------- + else if (lslparm is LSL_Float) + { + if (type == typeof(float)) + return (float)(LSL_Float)lslparm; + } + + // ---------- Key ---------- + else if (lslparm is LSL_Key) + { + if (type == typeof(UUID)) + return new UUID((LSL_Key)lslparm); + } + + // ---------- Rotation ---------- + else if (lslparm is LSL_Rotation) + { + if (type == typeof(OpenMetaverse.Quaternion)) + { + LSL_Rotation rot = (LSL_Rotation)lslparm; + return new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s); + } + } + + // ---------- Vector ---------- + else if (lslparm is LSL_Vector) + { + if (type == typeof(OpenMetaverse.Vector3)) + { + LSL_Vector vect = (LSL_Vector)lslparm; + return new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z); + } + } + + // ---------- List ---------- + else if (lslparm is LSL_List) + { + if (type == typeof(object[])) + { + object[] plist = (lslparm as LSL_List).Data; + object[] result = new object[plist.Length]; + for (int i = 0; i < plist.Length; i++) + { + if (plist[i] is LSL_String) + result[i] = (string)(LSL_String)plist[i]; + else if (plist[i] is LSL_Integer) + result[i] = (int)(LSL_Integer)plist[i]; + else if (plist[i] is LSL_Float) + result[i] = (float)(LSL_Float)plist[i]; + else if (plist[i] is LSL_Key) + result[i] = new UUID((LSL_Key)plist[i]); + else if (plist[i] is LSL_Rotation) + { + LSL_Rotation rot = (LSL_Rotation)plist[i]; + result[i] = new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s); + } + else if (plist[i] is LSL_Vector) + { + LSL_Vector vect = (LSL_Vector)plist[i]; + result[i] = new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z); + } + else + MODError("unknown LSL list element type"); + } + + return result; + } + } + + MODError(String.Format("parameter type mismatch; expecting {0}",type.Name)); + return null; + } + } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs index 756a59f..d258f76 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs @@ -28,26 +28,26 @@ using System.Collections; using OpenSim.Region.ScriptEngine.Interfaces; -using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; -using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; -using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; +using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; +using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; +using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; +using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; -using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; -using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; +using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces { public interface IMOD_Api { // Invocation functions - string modInvokeS(string fname, params object[] parms); - int modInvokeI(string fname, params object[] parms); - float modInvokeF(string fname, params object[] parms); - // vector modInvokeV(string fname, params object[] parms); - // rotation modInvokeV(string fname, params object[] parms); - // key modInvokeK(string fname, params object[] parms); - // list modInvokeL(string fname, params object[] parms); + LSL_String modInvokeS(string fname, params object[] parms); + LSL_Integer modInvokeI(string fname, params object[] parms); + LSL_Float modInvokeF(string fname, params object[] parms); + LSL_Key modInvokeK(string fname, params object[] parms); + LSL_Vector modInvokeV(string fname, params object[] parms); + LSL_Rotation modInvokeR(string fname, params object[] parms); + LSL_List modInvokeL(string fname, params object[] parms); //Module functions string modSendCommand(string modules, string command, string k); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs index 04b7f14..e7a4b2b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs @@ -39,10 +39,14 @@ using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; -using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; -using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; + using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; +using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; +using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; +using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; +using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; +using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { @@ -58,21 +62,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase m_MOD_Functions = (IMOD_Api)api; } - public string modInvokeS(string fname, params object[] parms) + public LSL_String modInvokeS(string fname, params object[] parms) { return m_MOD_Functions.modInvokeS(fname, parms); } - public int modInvokeI(string fname, params object[] parms) + public LSL_Integer modInvokeI(string fname, params object[] parms) { return m_MOD_Functions.modInvokeI(fname, parms); } - public float modInvokeF(string fname, params object[] parms) + public LSL_Float modInvokeF(string fname, params object[] parms) { return m_MOD_Functions.modInvokeF(fname, parms); } + public LSL_Key modInvokeK(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeK(fname, parms); + } + + public LSL_Vector modInvokeV(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeV(fname, parms); + } + + public LSL_Rotation modInvokeR(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeR(fname, parms); + } + + public LSL_List modInvokeL(string fname, params object[] parms) + { + return m_MOD_Functions.modInvokeL(fname, parms); + } + public string modSendCommand(string module, string command, string k) { return m_MOD_Functions.modSendCommand(module, command, k); -- cgit v1.1 From 7e0936e4b6ec0596390266a8435dea9c3f19f09c Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 26 Mar 2012 14:19:55 +0100 Subject: Add a hust UUID to the script invocations --- .../Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 11 ++++++++++- OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs | 1 + OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 1bcbcd3..7c07e15 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -122,6 +122,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// The name of the function to invoke /// List of parameters /// string result of the invocation + public void modInvokeN(string fname, params object[] parms) + { + Type returntype = m_comms.LookupReturnType(fname); + if (returntype != typeof(string)) + MODError(String.Format("return type mismatch for {0}",fname)); + + modInvoke(fname,parms); + } + public LSL_String modInvokeS(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); @@ -243,7 +252,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // non-null but don't trust it completely try { - object result = m_comms.InvokeOperation(m_itemID,fname,convertedParms); + object result = m_comms.InvokeOperation(m_host.UUID, m_itemID, fname, convertedParms); if (result != null) return result; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs index d258f76..aa78aaa 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs @@ -41,6 +41,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces public interface IMOD_Api { // Invocation functions + void modInvokeN(string fname, params object[] parms); LSL_String modInvokeS(string fname, params object[] parms); LSL_Integer modInvokeI(string fname, params object[] parms); LSL_Float modInvokeF(string fname, params object[] parms); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs index e7a4b2b..1c47138 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs @@ -62,6 +62,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase m_MOD_Functions = (IMOD_Api)api; } + public void modInvokeN(string fname, params object[] parms) + { + m_MOD_Functions.modInvokeN(fname, parms); + } + public LSL_String modInvokeS(string fname, params object[] parms) { return m_MOD_Functions.modInvokeS(fname, parms); -- cgit v1.1