diff options
Diffstat (limited to 'OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler')
7 files changed, 0 insertions, 1113 deletions
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs deleted file mode 100644 index afa2300..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs +++ /dev/null | |||
@@ -1,240 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Reflection.Emit; | ||
33 | using System.Text; | ||
34 | using OpenSim.ScriptEngine.Shared; | ||
35 | |||
36 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
37 | { | ||
38 | public class BaseClassFactory | ||
39 | { | ||
40 | |||
41 | |||
42 | public static void MakeBaseClass(ScriptStructure script) | ||
43 | { | ||
44 | string asmName = "ScriptAssemblies"; | ||
45 | string ModuleID = asmName; | ||
46 | string ClassID = "Script"; | ||
47 | string moveToDir = "ScriptEngines"; | ||
48 | string asmFileName = ModuleID + "_" + ClassID + ".dll"; | ||
49 | if (!Directory.Exists(moveToDir)) | ||
50 | Directory.CreateDirectory(moveToDir); | ||
51 | |||
52 | ILGenerator ilgen; | ||
53 | AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly( | ||
54 | new AssemblyName(asmName), AssemblyBuilderAccess.RunAndSave); | ||
55 | |||
56 | // The module builder | ||
57 | ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule(ModuleID, asmFileName); | ||
58 | |||
59 | // The class builder | ||
60 | TypeBuilder classBuilder = modBuilder.DefineType(ClassID, TypeAttributes.Class | TypeAttributes.Public); | ||
61 | |||
62 | // The default constructor | ||
63 | //ConstructorBuilder ctorBuilder = classBuilder.DefineDefaultConstructor(MethodAttributes.Public); | ||
64 | |||
65 | |||
66 | Type[] paramsTypeArray = new Type[] {typeof (System.ParamArrayAttribute)}; | ||
67 | Type[] executeFunctionTypeArray = new Type[] {typeof (string), typeof (System.ParamArrayAttribute)}; | ||
68 | foreach (IScriptCommandProvider cp in script.RegionInfo.CommandProviders.Values) | ||
69 | { | ||
70 | Type t = cp.GetType(); | ||
71 | foreach (MethodInfo mi in t.GetMethods()) | ||
72 | { | ||
73 | MethodBuilder methodBuilder = classBuilder.DefineMethod(mi.Name, mi.Attributes, mi.GetType(), Type.EmptyTypes); | ||
74 | methodBuilder.SetParameters(paramsTypeArray); | ||
75 | //ParameterBuilder paramBuilder = methodBuilder.DefineParameter(1, ParameterAttributes.None, "args"); | ||
76 | |||
77 | ilgen = methodBuilder.GetILGenerator(); | ||
78 | //ilgen.Emit(OpCodes.Nop); | ||
79 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
80 | //ilgen.Emit(OpCodes.Ldc_I4_0); | ||
81 | //ilgen.Emit(OpCodes.Ldelem_Ref); | ||
82 | //ilgen.MarkSequencePoint(doc, 6, 1, 6, 100); | ||
83 | |||
84 | //MethodInfo ExecuteFunction = typeof(ScriptAssemblies.IScript).GetMethod( | ||
85 | // "ExecuteFunction", | ||
86 | // executeFunctionTypeArray); | ||
87 | |||
88 | ilgen.DeclareLocal(typeof(string)); | ||
89 | ilgen.Emit(OpCodes.Nop); | ||
90 | ilgen.Emit(OpCodes.Ldstr, mi.Name); | ||
91 | ilgen.Emit(OpCodes.Stloc_0); | ||
92 | ilgen.Emit(OpCodes.Ldarg_0); | ||
93 | ilgen.Emit(OpCodes.Ldloc_0); | ||
94 | ilgen.Emit(OpCodes.Ldarg_1); | ||
95 | |||
96 | // FieldInfo testInfo = classBuilder. | ||
97 | //BindingFlags.NonPublic | BindingFlags.Instance); | ||
98 | |||
99 | //ilgen.Emit(OpCodes.Ldfld, testInfo); | ||
100 | |||
101 | //ilgen.EmitCall(OpCodes.Call, ExecuteFunction, executeFunctionTypeArray); | ||
102 | ilgen.EmitCall(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine"), executeFunctionTypeArray); | ||
103 | |||
104 | // // string.Format("Hello, {0} World!", toWhom) | ||
105 | // // | ||
106 | // ilgen.Emit(OpCodes.Ldstr, "Hello, {0} World!"); | ||
107 | // ilgen.Emit(OpCodes.Ldarg_1); | ||
108 | // ilgen.Emit(OpCodes.Call, typeof(string).GetMethod | ||
109 | //("Format", new Type[] { typeof(string), typeof(object) })); | ||
110 | |||
111 | // // m_log.Debug("Hello, World!"); | ||
112 | // // | ||
113 | // ilgen.Emit(OpCodes.Call, typeof(Console).GetMethod | ||
114 | // ("WriteLine", new Type[] { typeof(string) })); | ||
115 | ilgen.Emit(OpCodes.Ret); | ||
116 | |||
117 | |||
118 | |||
119 | //Label eom = ilgen.DefineLabel(); | ||
120 | //ilgen.Emit(OpCodes.Br_S, eom); | ||
121 | //ilgen.MarkLabel(eom); | ||
122 | //ilgen.Emit(OpCodes.Ret); | ||
123 | //Type test = methodBuilder.SetParameters(); | ||
124 | |||
125 | |||
126 | //methodBuilder.SetParameters(typeof (object[])); | ||
127 | |||
128 | |||
129 | } | ||
130 | } | ||
131 | |||
132 | |||
133 | //// Two fields: m_firstname, m_lastname | ||
134 | //FieldBuilder fBuilderFirstName = classBuilder.DefineField("m_firstname", typeof(string), FieldAttributes.Private); | ||
135 | //FieldBuilder fBuilderLastName = classBuilder.DefineField("m_lastname", typeof(string), FieldAttributes.Private); | ||
136 | |||
137 | //// Two properties for this object: FirstName, LastName | ||
138 | //PropertyBuilder pBuilderFirstName = classBuilder.DefineProperty("FirstName", System.Reflection.PropertyAttributes.HasDefault, typeof(string), null); | ||
139 | //PropertyBuilder pBuilderLastName = classBuilder.DefineProperty("LastName", System.Reflection.PropertyAttributes.HasDefault, typeof(string), null); | ||
140 | |||
141 | //// Custom attributes for get, set accessors | ||
142 | //MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName; | ||
143 | |||
144 | //// get,set accessors for FirstName | ||
145 | //MethodBuilder mGetFirstNameBuilder = classBuilder.DefineMethod("get_FirstName", getSetAttr, typeof(string), Type.EmptyTypes); | ||
146 | |||
147 | //// Code generation | ||
148 | //ilgen = mGetFirstNameBuilder.GetILGenerator(); | ||
149 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
150 | //ilgen.Emit(OpCodes.Ldfld, fBuilderFirstName); // returning the firstname field | ||
151 | //ilgen.Emit(OpCodes.Ret); | ||
152 | |||
153 | //MethodBuilder mSetFirstNameBuilder = classBuilder.DefineMethod("set_FirstName", getSetAttr, null, new Type[] { typeof(string) }); | ||
154 | |||
155 | //// Code generation | ||
156 | //ilgen = mSetFirstNameBuilder.GetILGenerator(); | ||
157 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
158 | //ilgen.Emit(OpCodes.Ldarg_1); | ||
159 | //ilgen.Emit(OpCodes.Stfld, fBuilderFirstName); // setting the firstname field from the first argument (1) | ||
160 | //ilgen.Emit(OpCodes.Ret); | ||
161 | |||
162 | //// get,set accessors for LastName | ||
163 | //MethodBuilder mGetLastNameBuilder = classBuilder.DefineMethod("get_LastName", getSetAttr, typeof(string), Type.EmptyTypes); | ||
164 | |||
165 | //// Code generation | ||
166 | //ilgen = mGetLastNameBuilder.GetILGenerator(); | ||
167 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
168 | //ilgen.Emit(OpCodes.Ldfld, fBuilderLastName); // returning the firstname field | ||
169 | //ilgen.Emit(OpCodes.Ret); | ||
170 | |||
171 | //MethodBuilder mSetLastNameBuilder = classBuilder.DefineMethod("set_LastName", getSetAttr, null, new Type[] { typeof(string) }); | ||
172 | |||
173 | //// Code generation | ||
174 | //ilgen = mSetLastNameBuilder.GetILGenerator(); | ||
175 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
176 | //ilgen.Emit(OpCodes.Ldarg_1); | ||
177 | //ilgen.Emit(OpCodes.Stfld, fBuilderLastName); // setting the firstname field from the first argument (1) | ||
178 | //ilgen.Emit(OpCodes.Ret); | ||
179 | |||
180 | //// Assigning get/set accessors | ||
181 | //pBuilderFirstName.SetGetMethod(mGetFirstNameBuilder); | ||
182 | //pBuilderFirstName.SetSetMethod(mSetFirstNameBuilder); | ||
183 | |||
184 | //pBuilderLastName.SetGetMethod(mGetLastNameBuilder); | ||
185 | //pBuilderLastName.SetSetMethod(mSetLastNameBuilder); | ||
186 | |||
187 | //// Now, a custom method named GetFullName that concatenates FirstName and LastName properties | ||
188 | //MethodBuilder mGetFullNameBuilder = classBuilder.DefineMethod("GetFullName", MethodAttributes.Public, typeof(string), Type.EmptyTypes); | ||
189 | |||
190 | //// Code generation | ||
191 | //ilgen = mGetFullNameBuilder.GetILGenerator(); | ||
192 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
193 | //ilgen.Emit(OpCodes.Call, mGetFirstNameBuilder); // getting the firstname | ||
194 | //ilgen.Emit(OpCodes.Ldstr, " "); // an space | ||
195 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
196 | //ilgen.Emit(OpCodes.Call, mGetLastNameBuilder); // getting the lastname | ||
197 | |||
198 | //// We need the 'Concat' method from string type | ||
199 | //MethodInfo concatMethod = typeof(String).GetMethod("Concat", new Type[] { typeof(string), typeof(string), typeof(string) }); | ||
200 | |||
201 | //ilgen.Emit(OpCodes.Call, concatMethod); // calling concat and returning the result | ||
202 | //ilgen.Emit(OpCodes.Ret); | ||
203 | |||
204 | //// Another constructor that initializes firstname and lastname | ||
205 | //ConstructorBuilder ctorBuilder2 = classBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(string), typeof(string) }); | ||
206 | //ctorBuilder2.DefineParameter(1, ParameterAttributes.In, "firstname"); | ||
207 | //ctorBuilder2.DefineParameter(2, ParameterAttributes.In, "lastname"); | ||
208 | |||
209 | //// Code generation | ||
210 | //ilgen = ctorBuilder2.GetILGenerator(); | ||
211 | |||
212 | //// First of all, we need to call the base constructor, | ||
213 | //// the Object's constructor in this sample | ||
214 | //Type objType = Type.GetType("System.Object"); | ||
215 | //ConstructorInfo objCtor = objType.GetConstructor(Type.EmptyTypes); | ||
216 | |||
217 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
218 | //ilgen.Emit(OpCodes.Call, objCtor); // calling the Object's constructor | ||
219 | |||
220 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
221 | //ilgen.Emit(OpCodes.Ldarg_1); | ||
222 | //ilgen.Emit(OpCodes.Call, mSetFirstNameBuilder); // setting the firstname field from the first argument (1) | ||
223 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
224 | //ilgen.Emit(OpCodes.Ldarg_2); | ||
225 | //ilgen.Emit(OpCodes.Call, mSetLastNameBuilder); // setting the lastname field from the second argument (2) | ||
226 | //ilgen.Emit(OpCodes.Ret); | ||
227 | |||
228 | // Finally, create the type and save the assembly | ||
229 | classBuilder.CreateType(); | ||
230 | |||
231 | asmBuilder.Save(asmFileName); | ||
232 | string toFile = Path.Combine(moveToDir, asmFileName); | ||
233 | if (File.Exists(toFile)) | ||
234 | File.Delete(toFile); | ||
235 | File.Move(asmFileName, toFile); | ||
236 | |||
237 | //string a = ""; | ||
238 | } | ||
239 | } | ||
240 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs deleted file mode 100644 index 9468c18..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
34 | { | ||
35 | public struct LoadUnloadStructure | ||
36 | { | ||
37 | public ScriptStructure Script; | ||
38 | public LUType Action; | ||
39 | public bool PostOnRez; | ||
40 | public int StartParam; | ||
41 | |||
42 | public enum LUType | ||
43 | { | ||
44 | Unknown = 0, | ||
45 | Load = 1, | ||
46 | Unload = 2 | ||
47 | } | ||
48 | } | ||
49 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Properties/AssemblyInfo.cs deleted file mode 100644 index 1831e50..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using System.Runtime.CompilerServices; | ||
30 | using System.Runtime.InteropServices; | ||
31 | |||
32 | // General Information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | [assembly: AssemblyTitle("OpenSim.Grid.ScriptEngine.Components.DefaultScheduler")] | ||
36 | [assembly: AssemblyDescription("")] | ||
37 | [assembly: AssemblyConfiguration("")] | ||
38 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly: AssemblyProduct("OpenSim.Grid.ScriptEngine.Components.DefaultScheduler")] | ||
40 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
41 | [assembly: AssemblyTrademark("")] | ||
42 | [assembly: AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
50 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
51 | |||
52 | // Version information for an assembly consists of the following four values: | ||
53 | // | ||
54 | // Major Version | ||
55 | // Minor Version | ||
56 | // Build Number | ||
57 | // Revision | ||
58 | // | ||
59 | // You can specify all the values or you can default the Build and Revision Numbers | ||
60 | // by using the '*' as shown below: | ||
61 | // [assembly: AssemblyVersion("0.6.5.*")] | ||
62 | [assembly: AssemblyVersion("0.6.5.*")] | ||
63 | [assembly: AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs deleted file mode 100644 index 8c36764..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
34 | { | ||
35 | public class Scheduler : IScriptScheduler | ||
36 | { | ||
37 | |||
38 | private ScriptManager m_ScriptManager = new ScriptManager(); | ||
39 | public void AddScript(ScriptStructure scriptStructure) | ||
40 | { | ||
41 | m_ScriptManager.AddScript(scriptStructure); | ||
42 | } | ||
43 | |||
44 | public void Removecript(uint id, UUID itemID) | ||
45 | { | ||
46 | m_ScriptManager.RemoveScript(id, itemID); | ||
47 | } | ||
48 | |||
49 | public void Close() | ||
50 | { | ||
51 | m_ScriptManager.Close(); | ||
52 | } | ||
53 | |||
54 | } | ||
55 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs deleted file mode 100644 index 3c20f20..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
33 | using OpenSim.ScriptEngine.Shared; | ||
34 | using IScript=OpenSim.Region.ScriptEngine.Shared.ScriptBase.IScript; | ||
35 | |||
36 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
37 | { | ||
38 | public class ScriptLoader : IScriptLoader | ||
39 | { | ||
40 | // | ||
41 | // This class does AppDomain handling and loading/unloading of | ||
42 | // scripts in it. It is instanced in "ScriptEngine" and controlled | ||
43 | // from "ScriptManager" | ||
44 | // | ||
45 | // 1. Create a new AppDomain if old one is full (or doesn't exist) | ||
46 | // 2. Load scripts into AppDomain | ||
47 | // 3. Unload scripts from AppDomain (stopping them and marking | ||
48 | // them as inactive) | ||
49 | // 4. Unload AppDomain completely when all scripts in it has stopped | ||
50 | // | ||
51 | |||
52 | public string Name { get { return "SECS.DotNetEngine.Scheduler.ScriptLoader"; } } | ||
53 | private int maxScriptsPerAppDomain = 10; | ||
54 | |||
55 | // Internal list of all AppDomains | ||
56 | private List<AppDomainStructure> appDomains = | ||
57 | new List<AppDomainStructure>(); | ||
58 | private Dictionary<string, AppDomainStructure> AppDomainFiles = new Dictionary<string, AppDomainStructure>(); | ||
59 | public readonly string[] AssembliesInAppDomain = new string[] { "OpenSim.ScriptEngine.Shared.Script.dll", "OpenSim.Region.ScriptEngine.Shared.dll" }; | ||
60 | |||
61 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
62 | |||
63 | // Structure to keep track of data around AppDomain | ||
64 | private class AppDomainStructure | ||
65 | { | ||
66 | public AppDomain CurrentAppDomain; // The AppDomain itself | ||
67 | public int ScriptsLoaded; // Number of scripts loaded into AppDomain | ||
68 | public int ScriptsWaitingUnload; // Number of dead scripts | ||
69 | } | ||
70 | |||
71 | // Current AppDomain | ||
72 | private AppDomainStructure currentAD; | ||
73 | |||
74 | private object getLock = new object(); // Mutex | ||
75 | private object freeLock = new object(); // Mutex | ||
76 | |||
77 | // Find a free AppDomain, creating one if necessary | ||
78 | private AppDomainStructure GetFreeAppDomain() | ||
79 | { | ||
80 | lock (getLock) | ||
81 | { | ||
82 | // Current full? | ||
83 | if (currentAD != null && | ||
84 | currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) | ||
85 | { | ||
86 | // Add it to AppDomains list and empty current | ||
87 | appDomains.Add(currentAD); | ||
88 | currentAD = null; | ||
89 | } | ||
90 | // No current | ||
91 | if (currentAD == null) | ||
92 | { | ||
93 | // Create a new current AppDomain | ||
94 | currentAD = new AppDomainStructure(); | ||
95 | currentAD.CurrentAppDomain = PrepareNewAppDomain(); | ||
96 | } | ||
97 | |||
98 | return currentAD; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | private int AppDomainNameCount; | ||
103 | public ScriptAssemblies.IScript LoadScript(ScriptStructure script) | ||
104 | { | ||
105 | // Find next available AppDomain to put it in | ||
106 | AppDomainStructure FreeAppDomain; | ||
107 | |||
108 | // If we already have loaded file, then reuse that AppDomains | ||
109 | if (AppDomainFiles.ContainsKey(script.AssemblyFileName)) | ||
110 | FreeAppDomain = AppDomainFiles[script.AssemblyFileName]; | ||
111 | else | ||
112 | FreeAppDomain = GetFreeAppDomain(); | ||
113 | |||
114 | // Set script object AppDomain | ||
115 | script.AppDomain = FreeAppDomain.CurrentAppDomain; | ||
116 | |||
117 | // Create instance of script | ||
118 | ScriptAssemblies.IScript mbrt = (ScriptAssemblies.IScript) | ||
119 | FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap( | ||
120 | script.AssemblyFileName, "ScriptAssemblies.Script"); | ||
121 | //, true, BindingFlags.CreateInstance, null); | ||
122 | FreeAppDomain.ScriptsLoaded++; | ||
123 | |||
124 | return mbrt; | ||
125 | } | ||
126 | |||
127 | // Create and prepare a new AppDomain for scripts | ||
128 | private AppDomain PrepareNewAppDomain() | ||
129 | { | ||
130 | // Create and prepare a new AppDomain | ||
131 | AppDomainNameCount++; | ||
132 | |||
133 | // TODO: Currently security match current appdomain | ||
134 | |||
135 | // Construct and initialize settings for a second AppDomain. | ||
136 | AppDomainSetup ads = new AppDomainSetup(); | ||
137 | ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; | ||
138 | ads.DisallowBindingRedirects = true; | ||
139 | ads.DisallowCodeDownload = true; | ||
140 | ads.LoaderOptimization = LoaderOptimization.MultiDomainHost; | ||
141 | ads.ShadowCopyFiles = "false"; // Disable shadowing | ||
142 | ads.ConfigurationFile = | ||
143 | AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; | ||
144 | |||
145 | AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + | ||
146 | AppDomainNameCount, null, ads); | ||
147 | |||
148 | foreach (string file in AssembliesInAppDomain) | ||
149 | { | ||
150 | m_log.InfoFormat("[{0}] AppDomain Loading: \"{1}\"->\"{2}\".", Name, file, | ||
151 | AssemblyName.GetAssemblyName(file).ToString()); | ||
152 | AD.Load(AssemblyName.GetAssemblyName(file)); | ||
153 | } | ||
154 | |||
155 | // Return the new AppDomain | ||
156 | return AD; | ||
157 | } | ||
158 | |||
159 | // Unload appdomains that are full and have only dead scripts | ||
160 | private void UnloadAppDomains() | ||
161 | { | ||
162 | lock (freeLock) | ||
163 | { | ||
164 | // Go through all | ||
165 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) | ||
166 | { | ||
167 | // Don't process current AppDomain | ||
168 | if (ads.CurrentAppDomain != currentAD.CurrentAppDomain) | ||
169 | { | ||
170 | // Not current AppDomain | ||
171 | // Is number of unloaded bigger or equal to number of loaded? | ||
172 | if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload) | ||
173 | { | ||
174 | // Remove from internal list | ||
175 | appDomains.Remove(ads); | ||
176 | |||
177 | // Unload | ||
178 | AppDomain.Unload(ads.CurrentAppDomain); | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | // Increase "dead script" counter for an AppDomain | ||
186 | public void StopScript(AppDomain ad) | ||
187 | { | ||
188 | lock (freeLock) | ||
189 | { | ||
190 | // Check if it is current AppDomain | ||
191 | if (currentAD.CurrentAppDomain == ad) | ||
192 | { | ||
193 | // Yes - increase | ||
194 | currentAD.ScriptsWaitingUnload++; | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | // Lopp through all AppDomains | ||
199 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) | ||
200 | { | ||
201 | if (ads.CurrentAppDomain == ad) | ||
202 | { | ||
203 | // Found it | ||
204 | ads.ScriptsWaitingUnload++; | ||
205 | break; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | UnloadAppDomains(); // Outsite lock, has its own GetLock | ||
211 | } | ||
212 | |||
213 | |||
214 | |||
215 | } | ||
216 | } \ No newline at end of file | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs deleted file mode 100644 index 3dad902..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs +++ /dev/null | |||
@@ -1,203 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Region.ScriptEngine.Shared; | ||
37 | using OpenSim.ScriptEngine.Shared; | ||
38 | using EventParams=OpenSim.ScriptEngine.Shared.EventParams; | ||
39 | |||
40 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
41 | { | ||
42 | public partial class ScriptManager: IScriptExecutor | ||
43 | { | ||
44 | private const int NoWorkSleepMs = 50; | ||
45 | private const int NoWorkSleepMsInc = 1; // How much time to increase wait with on every iteration | ||
46 | private const int NoWorkSleepMsIncMax = 300; // Max time to wait | ||
47 | |||
48 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | public string Name { get { return "SECS.DotNetEngine.ScriptManager"; } } | ||
50 | private static Thread ScriptLoadUnloadThread; | ||
51 | public Dictionary<uint, Dictionary<UUID, ScriptStructure>> Scripts = new Dictionary<uint, Dictionary<UUID, ScriptStructure>>(); | ||
52 | |||
53 | private RegionInfoStructure CurrentRegion; | ||
54 | public void Initialize(RegionInfoStructure currentRegion) | ||
55 | { | ||
56 | CurrentRegion = currentRegion; | ||
57 | } | ||
58 | |||
59 | public ScriptManager() | ||
60 | { | ||
61 | ScriptLoadUnloadThread = new Thread(LoadUnloadLoop); | ||
62 | ScriptLoadUnloadThread.Name = "ScriptLoadUnloadThread"; | ||
63 | ScriptLoadUnloadThread.IsBackground = true; | ||
64 | ScriptLoadUnloadThread.Start(); | ||
65 | } | ||
66 | public void Close() { } | ||
67 | |||
68 | private void LoadUnloadLoop () | ||
69 | { | ||
70 | int _NoWorkSleepMsInc = 0; | ||
71 | while (true) | ||
72 | { | ||
73 | if (DoScriptLoadUnload()) | ||
74 | { | ||
75 | // We found work, reset counter | ||
76 | _NoWorkSleepMsInc = NoWorkSleepMs; | ||
77 | } else | ||
78 | { | ||
79 | // We didn't find work | ||
80 | // Sleep | ||
81 | Thread.Sleep(NoWorkSleepMs + NoWorkSleepMsInc); | ||
82 | // Increase sleep delay | ||
83 | _NoWorkSleepMsInc += NoWorkSleepMsInc; | ||
84 | // Make sure we don't exceed max | ||
85 | if (_NoWorkSleepMsInc > NoWorkSleepMsIncMax) | ||
86 | _NoWorkSleepMsInc = NoWorkSleepMsIncMax; | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | #region Add/Remove/Find script functions for our Script memory structure | ||
92 | private void MemAddScript(ScriptStructure script) | ||
93 | { | ||
94 | lock (scriptLock) | ||
95 | { | ||
96 | // Create object if it doesn't exist | ||
97 | if (!Scripts.ContainsKey(script.LocalID)) | ||
98 | Scripts.Add(script.LocalID, new Dictionary<UUID, ScriptStructure>()); | ||
99 | |||
100 | // Delete script if it exists | ||
101 | Dictionary<UUID, ScriptStructure> Obj; | ||
102 | if (Scripts.TryGetValue(script.LocalID, out Obj)) | ||
103 | if (Obj.ContainsKey(script.ItemID) == true) | ||
104 | Obj.Remove(script.ItemID); | ||
105 | |||
106 | // Add to object | ||
107 | Obj.Add(script.ItemID, script); | ||
108 | } | ||
109 | } | ||
110 | private void MemRemoveScript(uint LocalID, UUID ItemID) | ||
111 | { | ||
112 | // TODO: Also clean up command queue and async commands for object | ||
113 | lock (scriptLock) | ||
114 | { | ||
115 | // Create object if it doesn't exist | ||
116 | if (!Scripts.ContainsKey(LocalID)) | ||
117 | return; | ||
118 | |||
119 | // Delete script if it exists | ||
120 | Dictionary<UUID, ScriptStructure> Obj; | ||
121 | if (Scripts.TryGetValue(LocalID, out Obj)) | ||
122 | if (Obj.ContainsKey(ItemID) == true) | ||
123 | Obj.Remove(ItemID); | ||
124 | |||
125 | // Empty? | ||
126 | if (Obj.Count == 0) | ||
127 | Scripts.Remove(LocalID); | ||
128 | |||
129 | } | ||
130 | } | ||
131 | public bool TryGetScript(uint localID, UUID itemID, ref ScriptStructure script) | ||
132 | { | ||
133 | lock (scriptLock) | ||
134 | { | ||
135 | |||
136 | if (Scripts.ContainsKey(localID) == false) | ||
137 | return false; | ||
138 | |||
139 | Dictionary<UUID, ScriptStructure> Obj; | ||
140 | if (Scripts.TryGetValue(localID, out Obj)) | ||
141 | if (Obj.ContainsKey(itemID) == false) | ||
142 | return false; | ||
143 | |||
144 | // Get script | ||
145 | return Obj.TryGetValue(itemID, out script); | ||
146 | } | ||
147 | } | ||
148 | public ScriptStructure GetScript(uint localID, UUID itemID) | ||
149 | { | ||
150 | lock (scriptLock) | ||
151 | { | ||
152 | |||
153 | if (Scripts.ContainsKey(localID) == false) | ||
154 | throw new Exception("No script with LocalID " + localID + " was found."); | ||
155 | |||
156 | Dictionary<UUID, ScriptStructure> Obj; | ||
157 | if (Scripts.TryGetValue(localID, out Obj)) | ||
158 | if (Obj.ContainsKey(itemID) == false) | ||
159 | throw new Exception("No script with ItemID " + itemID + " was found."); | ||
160 | |||
161 | // Get script | ||
162 | return Obj[itemID]; | ||
163 | } | ||
164 | } | ||
165 | public bool TryGetScripts(uint localID, ref Dictionary<UUID, ScriptStructure> returnList) | ||
166 | { | ||
167 | Dictionary<UUID, ScriptStructure> getList = GetScripts(localID); | ||
168 | if (getList != null) | ||
169 | { | ||
170 | returnList = getList; | ||
171 | return true; | ||
172 | } | ||
173 | return false; | ||
174 | } | ||
175 | public Dictionary<UUID, ScriptStructure> GetScripts(uint localID) | ||
176 | { | ||
177 | lock (scriptLock) | ||
178 | { | ||
179 | |||
180 | if (Scripts.ContainsKey(localID) == false) | ||
181 | return null; | ||
182 | return Scripts[localID]; | ||
183 | } | ||
184 | } | ||
185 | #endregion | ||
186 | |||
187 | public void ExecuteCommand(EventParams p) | ||
188 | { | ||
189 | ScriptStructure ss = new ScriptStructure(); | ||
190 | if (TryGetScript(p.LocalID, p.ItemID, ref ss)) | ||
191 | ExecuteCommand(ref ss, p); | ||
192 | } | ||
193 | |||
194 | public void ExecuteCommand(ref ScriptStructure scriptContainer, EventParams p) | ||
195 | { | ||
196 | m_log.DebugFormat("[{0}] ######################################################", Name); | ||
197 | m_log.DebugFormat("[{0}] Command execution ItemID {1}: \"{2}\".", Name, scriptContainer.ItemID, p.EventName); | ||
198 | scriptContainer.ExecuteEvent(p); | ||
199 | m_log.DebugFormat("[{0}] ######################################################", Name); | ||
200 | } | ||
201 | |||
202 | } | ||
203 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs deleted file mode 100644 index dd72dbf..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs +++ /dev/null | |||
@@ -1,287 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Globalization; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
39 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
40 | using OpenSim.ScriptEngine.Shared; | ||
41 | |||
42 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
43 | { | ||
44 | public partial class ScriptManager | ||
45 | { | ||
46 | private Queue<LoadUnloadStructure> LUQueue = new Queue<LoadUnloadStructure>(); | ||
47 | private int LoadUnloadMaxQueueSize = 500; | ||
48 | private Object scriptLock = new Object(); | ||
49 | //private Dictionary<InstanceData, DetectParams[]> detparms = new Dictionary<InstanceData, DetectParams[]>(); | ||
50 | |||
51 | // Load/Unload structure | ||
52 | |||
53 | |||
54 | public void AddScript(ScriptStructure script) | ||
55 | { | ||
56 | lock (LUQueue) | ||
57 | { | ||
58 | if ((LUQueue.Count >= LoadUnloadMaxQueueSize)) | ||
59 | { | ||
60 | m_log.ErrorFormat("[{0}] ERROR: Load queue count is at {1} of max {2}. Ignoring load request for script LocalID: {3}, ItemID: {4}.", | ||
61 | Name, LUQueue.Count, LoadUnloadMaxQueueSize, script.LocalID, script.ItemID); | ||
62 | return; | ||
63 | } | ||
64 | |||
65 | LoadUnloadStructure ls = new LoadUnloadStructure(); | ||
66 | ls.Script = script; | ||
67 | ls.Action = LoadUnloadStructure.LUType.Load; | ||
68 | LUQueue.Enqueue(ls); | ||
69 | } | ||
70 | |||
71 | } | ||
72 | public void RemoveScript(uint localID, UUID itemID) | ||
73 | { | ||
74 | LoadUnloadStructure ls = new LoadUnloadStructure(); | ||
75 | |||
76 | // See if we can find script | ||
77 | if (!TryGetScript(localID, itemID, ref ls.Script)) | ||
78 | { | ||
79 | // Set manually | ||
80 | ls.Script.LocalID = localID; | ||
81 | ls.Script.ItemID = itemID; | ||
82 | } | ||
83 | ls.Script.StartParam = 0; | ||
84 | |||
85 | ls.Action = LoadUnloadStructure.LUType.Unload; | ||
86 | ls.PostOnRez = false; | ||
87 | |||
88 | lock (LUQueue) | ||
89 | { | ||
90 | LUQueue.Enqueue(ls); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | internal bool DoScriptLoadUnload() | ||
95 | { | ||
96 | bool ret = false; | ||
97 | // if (!m_started) | ||
98 | // return; | ||
99 | |||
100 | lock (LUQueue) | ||
101 | { | ||
102 | if (LUQueue.Count > 0) | ||
103 | { | ||
104 | LoadUnloadStructure item = LUQueue.Dequeue(); | ||
105 | ret = true; | ||
106 | |||
107 | if (item.Action == LoadUnloadStructure.LUType.Unload) | ||
108 | { | ||
109 | _StopScript(item.Script.LocalID, item.Script.ItemID); | ||
110 | RemoveScript(item.Script.LocalID, item.Script.ItemID); | ||
111 | } | ||
112 | else if (item.Action == LoadUnloadStructure.LUType.Load) | ||
113 | { | ||
114 | m_log.DebugFormat("[{0}] Loading script", Name); | ||
115 | _StartScript(item); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | return ret; | ||
120 | } | ||
121 | |||
122 | //public void _StartScript(uint localID, UUID itemID, string Script, int startParam, bool postOnRez) | ||
123 | private void _StartScript(LoadUnloadStructure ScriptObject) | ||
124 | { | ||
125 | m_log.DebugFormat( | ||
126 | "[{0}]: ScriptManager StartScript: localID: {1}, itemID: {2}", | ||
127 | Name, ScriptObject.Script.LocalID, ScriptObject.Script.ItemID); | ||
128 | |||
129 | // We will initialize and start the script. | ||
130 | // It will be up to the script itself to hook up the correct events. | ||
131 | |||
132 | SceneObjectPart m_host = ScriptObject.Script.RegionInfo.Scene.GetSceneObjectPart(ScriptObject.Script.LocalID); | ||
133 | |||
134 | if (null == m_host) | ||
135 | { | ||
136 | m_log.ErrorFormat( | ||
137 | "[{0}]: Could not find scene object part corresponding " + | ||
138 | "to localID {1} to start script", | ||
139 | Name, ScriptObject.Script.LocalID); | ||
140 | |||
141 | return; | ||
142 | } | ||
143 | |||
144 | //UUID assetID = UUID.Zero; | ||
145 | TaskInventoryItem taskInventoryItem = new TaskInventoryItem(); | ||
146 | //if (m_host.TaskInventory.TryGetValue(ScriptObject.Script.ItemID, out taskInventoryItem)) | ||
147 | // assetID = taskInventoryItem.AssetID; | ||
148 | |||
149 | ScenePresence presence = | ||
150 | ScriptObject.Script.RegionInfo.Scene.GetScenePresence(taskInventoryItem.OwnerID); | ||
151 | |||
152 | CultureInfo USCulture = new CultureInfo("en-US"); | ||
153 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
154 | |||
155 | try | ||
156 | { | ||
157 | // | ||
158 | // Compile script to an assembly | ||
159 | // | ||
160 | //TODO: DEBUG | ||
161 | BaseClassFactory.MakeBaseClass(ScriptObject.Script); | ||
162 | |||
163 | m_log.DebugFormat("[{0}] Compiling script {1}", Name, ScriptObject.Script.Name); | ||
164 | |||
165 | string fileName = ""; | ||
166 | try | ||
167 | { | ||
168 | IScriptCompiler compiler = | ||
169 | ScriptObject.Script.RegionInfo.FindCompiler(ScriptObject.Script.ScriptMetaData); | ||
170 | //RegionInfoStructure currentRegionInfo = ScriptObject.Script.RegionInfo; | ||
171 | fileName = compiler.Compile(ScriptObject.Script.ScriptMetaData, | ||
172 | ref ScriptObject.Script.Source); | ||
173 | ScriptObject.Script.AssemblyFileName = fileName; | ||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | m_log.ErrorFormat("[{0}] Internal error while compiling \"{1}\": {2}", Name, ScriptObject.Script.Name, e.ToString()); | ||
178 | } | ||
179 | m_log.DebugFormat("[{0}] Compiled \"{1}\" to assembly: \"{2}\".", Name, ScriptObject.Script.Name, fileName); | ||
180 | |||
181 | // Add it to our script memstruct | ||
182 | MemAddScript(ScriptObject.Script); | ||
183 | |||
184 | ScriptAssemblies.IScript CompiledScript; | ||
185 | CompiledScript = CurrentRegion.ScriptLoader.LoadScript(ScriptObject.Script); | ||
186 | ScriptObject.Script.State = "default"; | ||
187 | ScriptObject.Script.ScriptObject = CompiledScript; | ||
188 | ScriptObject.Script.Disabled = false; | ||
189 | ScriptObject.Script.Running = true; | ||
190 | //id.LineMap = LSLCompiler.LineMap(); | ||
191 | //id.Script = CompiledScript; | ||
192 | //id.Source = item.Script.Script; | ||
193 | //item.StartParam = startParam; | ||
194 | |||
195 | |||
196 | |||
197 | // TODO: Fire the first start-event | ||
198 | //int eventFlags = | ||
199 | // m_scriptEngine.m_ScriptManager.GetStateEventFlags( | ||
200 | // localID, itemID); | ||
201 | |||
202 | //m_host.SetScriptEvents(itemID, eventFlags); | ||
203 | ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script, | ||
204 | new EventParams(ScriptObject.Script.LocalID, ScriptObject.Script.ItemID, "state_entry", new object[] { }, new Region.ScriptEngine.Shared.DetectParams[0]) | ||
205 | ); | ||
206 | |||
207 | if (ScriptObject.PostOnRez) | ||
208 | { | ||
209 | ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script, | ||
210 | new EventParams(ScriptObject.Script.LocalID, "on_rez", new object[] | ||
211 | {new Region.ScriptEngine.Shared.LSL_Types.LSLInteger(ScriptObject.StartParam) | ||
212 | }, new Region.ScriptEngine.Shared.DetectParams[0])); | ||
213 | } | ||
214 | } | ||
215 | catch (Exception e) // LEGIT: User Scripting | ||
216 | { | ||
217 | if (presence != null && (!ScriptObject.PostOnRez)) | ||
218 | presence.ControllingClient.SendAgentAlertMessage( | ||
219 | "Script saved with errors, check debug window!", | ||
220 | false); | ||
221 | try | ||
222 | { | ||
223 | // DISPLAY ERROR INWORLD | ||
224 | string text = "Error compiling script:\n" + | ||
225 | e.Message.ToString(); | ||
226 | if (text.Length > 1100) | ||
227 | text = text.Substring(0, 1099); | ||
228 | |||
229 | ScriptObject.Script.RegionInfo.Scene.SimChat(Utils.StringToBytes(text), | ||
230 | ChatTypeEnum.DebugChannel, 2147483647, | ||
231 | m_host.AbsolutePosition, m_host.Name, m_host.UUID, | ||
232 | false); | ||
233 | } | ||
234 | catch (Exception e2) // LEGIT: User Scripting | ||
235 | { | ||
236 | m_log.Error("[" + | ||
237 | Name + | ||
238 | "]: Error displaying error in-world: " + | ||
239 | e2.ToString()); | ||
240 | m_log.Error("[" + | ||
241 | Name + "]: " + | ||
242 | "Errormessage: Error compiling script:\r\n" + | ||
243 | e2.Message.ToString()); | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | |||
248 | |||
249 | |||
250 | public void _StopScript(uint localID, UUID itemID) | ||
251 | { | ||
252 | ScriptStructure ss = new ScriptStructure(); | ||
253 | if (!TryGetScript(localID, itemID, ref ss)) | ||
254 | return; | ||
255 | |||
256 | m_log.DebugFormat("[{0}] Unloading script", Name); | ||
257 | |||
258 | // Stop long command on script | ||
259 | //AsyncCommandManager.RemoveScript(ss); | ||
260 | |||
261 | try | ||
262 | { | ||
263 | // Get AppDomain | ||
264 | // Tell script not to accept new requests | ||
265 | ss.Running = false; | ||
266 | ss.Disabled = true; | ||
267 | //AppDomain ad = ss.AppDomain; | ||
268 | |||
269 | // Remove from internal structure | ||
270 | MemRemoveScript(localID, itemID); | ||
271 | |||
272 | // TODO: Tell AppDomain that we have stopped script | ||
273 | |||
274 | } | ||
275 | catch (Exception e) // LEGIT: User Scripting | ||
276 | { | ||
277 | m_log.Error("[" + | ||
278 | Name + | ||
279 | "]: Exception stopping script localID: " + | ||
280 | localID + " LLUID: " + itemID.ToString() + | ||
281 | ": " + e.ToString()); | ||
282 | } | ||
283 | } | ||
284 | |||
285 | |||
286 | } | ||
287 | } | ||