diff options
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs deleted file mode 100644 index 78c6f67..0000000 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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 System.IO; | ||
32 | using System.Threading; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Utilities; | ||
36 | using OpenSim.Region.Scripting; | ||
37 | using OpenSim.Region.Environment.Scenes; | ||
38 | |||
39 | namespace OpenSim.Region.Scripting.EmbeddedJVM | ||
40 | { | ||
41 | public class JVMScript : IScript | ||
42 | { | ||
43 | private List<Thread> _threads = new List<Thread>(); | ||
44 | private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>(); | ||
45 | private MainMemory _mainMemory; | ||
46 | |||
47 | ScriptInfo scriptInfo; | ||
48 | |||
49 | public void Initialise(ScriptInfo info) | ||
50 | { | ||
51 | scriptInfo = info; | ||
52 | |||
53 | _mainMemory = new MainMemory(); | ||
54 | Thread.GlobalMemory = this._mainMemory; | ||
55 | Thread.World = info.world; | ||
56 | CompileScript(); | ||
57 | |||
58 | scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame); | ||
59 | scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence); | ||
60 | } | ||
61 | |||
62 | void events_OnNewPresence(ScenePresence presence) | ||
63 | { | ||
64 | for (int i = 0; i < this._threads.Count; i++) | ||
65 | { | ||
66 | if (!this._threads[i].running) | ||
67 | { | ||
68 | this._threads[i].StartMethod("OnNewPresence"); | ||
69 | bool run = true; | ||
70 | while (run) | ||
71 | { | ||
72 | run = this._threads[i].Excute(); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | void events_OnFrame() | ||
79 | { | ||
80 | for (int i = 0; i < this._threads.Count; i++) | ||
81 | { | ||
82 | if (!this._threads[i].running) | ||
83 | { | ||
84 | this._threads[i].StartMethod("OnFrame"); | ||
85 | bool run = true; | ||
86 | while (run) | ||
87 | { | ||
88 | run = this._threads[i].Excute(); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | |||
94 | public string getName() | ||
95 | { | ||
96 | return "JVM Scripting Engine"; | ||
97 | } | ||
98 | |||
99 | public void LoadScript(string script) | ||
100 | { | ||
101 | Console.WriteLine("OpenSimJVM - loading new script: " + script); | ||
102 | CompileInfo comp = new CompileInfo(); | ||
103 | comp.script = script; | ||
104 | comp.scriptName = script; | ||
105 | this.CompileScripts.Enqueue(comp); | ||
106 | } | ||
107 | |||
108 | public void CompileScript() | ||
109 | { | ||
110 | CompileInfo comp = this.CompileScripts.Dequeue(); | ||
111 | string script = comp.script; | ||
112 | string scriptName = comp.scriptName; | ||
113 | try | ||
114 | { | ||
115 | //need to compile the script into a java class file | ||
116 | |||
117 | //first save it to a java source file | ||
118 | TextWriter tw = new StreamWriter(scriptName + ".java"); | ||
119 | tw.WriteLine(script); | ||
120 | tw.Close(); | ||
121 | |||
122 | //now compile | ||
123 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); | ||
124 | // psi.RedirectStandardOutput = true; | ||
125 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | ||
126 | psi.UseShellExecute = false; | ||
127 | |||
128 | System.Diagnostics.Process javacomp; | ||
129 | javacomp = System.Diagnostics.Process.Start(psi); | ||
130 | javacomp.WaitForExit(); | ||
131 | |||
132 | |||
133 | //now load in class file | ||
134 | ClassRecord class1 = new ClassRecord(); | ||
135 | class1.LoadClassFromFile(scriptName + ".class"); | ||
136 | class1.PrintToConsole(); | ||
137 | //Console.WriteLine(); | ||
138 | this._mainMemory.MethodArea.Classes.Add(class1); | ||
139 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); | ||
140 | |||
141 | Thread newThread = new Thread(); | ||
142 | this._threads.Add(newThread); | ||
143 | newThread.currentClass = class1; | ||
144 | newThread.scriptInfo = scriptInfo; | ||
145 | |||
146 | //now delete the created files | ||
147 | System.IO.File.Delete(scriptName + ".java"); | ||
148 | System.IO.File.Delete(scriptName + ".class"); | ||
149 | //this.OnFrame(); | ||
150 | } | ||
151 | catch (Exception e) | ||
152 | { | ||
153 | Console.WriteLine("exception"); | ||
154 | Console.WriteLine(e.StackTrace); | ||
155 | Console.WriteLine(e.Message); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | private class CompileInfo | ||
160 | { | ||
161 | public string script; | ||
162 | public string scriptName; | ||
163 | |||
164 | public CompileInfo() | ||
165 | { | ||
166 | |||
167 | } | ||
168 | } | ||
169 | } | ||
170 | } | ||