diff options
author | Sean Dague | 2007-07-16 15:40:11 +0000 |
---|---|---|
committer | Sean Dague | 2007-07-16 15:40:11 +0000 |
commit | 2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 (patch) | |
tree | e3f80ad51736cf17e856547b1bcf956010927434 /OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs | |
parent | *Trunk compiles now (diff) | |
download | opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.zip opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.gz opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.bz2 opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.xz |
changed to native line ending encoding
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs | 340 |
1 files changed, 170 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 index 8b38951..78c6f67 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs | |||
@@ -1,170 +1,170 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Text; | 30 | using System.Text; |
31 | using System.IO; | 31 | using System.IO; |
32 | using System.Threading; | 32 | using System.Threading; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Interfaces; | 34 | using OpenSim.Framework.Interfaces; |
35 | using OpenSim.Framework.Utilities; | 35 | using OpenSim.Framework.Utilities; |
36 | using OpenSim.Region.Scripting; | 36 | using OpenSim.Region.Scripting; |
37 | using OpenSim.Region.Environment.Scenes; | 37 | using OpenSim.Region.Environment.Scenes; |
38 | 38 | ||
39 | namespace OpenSim.Region.Scripting.EmbeddedJVM | 39 | namespace OpenSim.Region.Scripting.EmbeddedJVM |
40 | { | 40 | { |
41 | public class JVMScript : IScript | 41 | public class JVMScript : IScript |
42 | { | 42 | { |
43 | private List<Thread> _threads = new List<Thread>(); | 43 | private List<Thread> _threads = new List<Thread>(); |
44 | private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>(); | 44 | private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>(); |
45 | private MainMemory _mainMemory; | 45 | private MainMemory _mainMemory; |
46 | 46 | ||
47 | ScriptInfo scriptInfo; | 47 | ScriptInfo scriptInfo; |
48 | 48 | ||
49 | public void Initialise(ScriptInfo info) | 49 | public void Initialise(ScriptInfo info) |
50 | { | 50 | { |
51 | scriptInfo = info; | 51 | scriptInfo = info; |
52 | 52 | ||
53 | _mainMemory = new MainMemory(); | 53 | _mainMemory = new MainMemory(); |
54 | Thread.GlobalMemory = this._mainMemory; | 54 | Thread.GlobalMemory = this._mainMemory; |
55 | Thread.World = info.world; | 55 | Thread.World = info.world; |
56 | CompileScript(); | 56 | CompileScript(); |
57 | 57 | ||
58 | scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame); | 58 | scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame); |
59 | scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence); | 59 | scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence); |
60 | } | 60 | } |
61 | 61 | ||
62 | void events_OnNewPresence(ScenePresence presence) | 62 | void events_OnNewPresence(ScenePresence presence) |
63 | { | 63 | { |
64 | for (int i = 0; i < this._threads.Count; i++) | 64 | for (int i = 0; i < this._threads.Count; i++) |
65 | { | 65 | { |
66 | if (!this._threads[i].running) | 66 | if (!this._threads[i].running) |
67 | { | 67 | { |
68 | this._threads[i].StartMethod("OnNewPresence"); | 68 | this._threads[i].StartMethod("OnNewPresence"); |
69 | bool run = true; | 69 | bool run = true; |
70 | while (run) | 70 | while (run) |
71 | { | 71 | { |
72 | run = this._threads[i].Excute(); | 72 | run = this._threads[i].Excute(); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | void events_OnFrame() | 78 | void events_OnFrame() |
79 | { | 79 | { |
80 | for (int i = 0; i < this._threads.Count; i++) | 80 | for (int i = 0; i < this._threads.Count; i++) |
81 | { | 81 | { |
82 | if (!this._threads[i].running) | 82 | if (!this._threads[i].running) |
83 | { | 83 | { |
84 | this._threads[i].StartMethod("OnFrame"); | 84 | this._threads[i].StartMethod("OnFrame"); |
85 | bool run = true; | 85 | bool run = true; |
86 | while (run) | 86 | while (run) |
87 | { | 87 | { |
88 | run = this._threads[i].Excute(); | 88 | run = this._threads[i].Excute(); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | public string getName() | 94 | public string getName() |
95 | { | 95 | { |
96 | return "JVM Scripting Engine"; | 96 | return "JVM Scripting Engine"; |
97 | } | 97 | } |
98 | 98 | ||
99 | public void LoadScript(string script) | 99 | public void LoadScript(string script) |
100 | { | 100 | { |
101 | Console.WriteLine("OpenSimJVM - loading new script: " + script); | 101 | Console.WriteLine("OpenSimJVM - loading new script: " + script); |
102 | CompileInfo comp = new CompileInfo(); | 102 | CompileInfo comp = new CompileInfo(); |
103 | comp.script = script; | 103 | comp.script = script; |
104 | comp.scriptName = script; | 104 | comp.scriptName = script; |
105 | this.CompileScripts.Enqueue(comp); | 105 | this.CompileScripts.Enqueue(comp); |
106 | } | 106 | } |
107 | 107 | ||
108 | public void CompileScript() | 108 | public void CompileScript() |
109 | { | 109 | { |
110 | CompileInfo comp = this.CompileScripts.Dequeue(); | 110 | CompileInfo comp = this.CompileScripts.Dequeue(); |
111 | string script = comp.script; | 111 | string script = comp.script; |
112 | string scriptName = comp.scriptName; | 112 | string scriptName = comp.scriptName; |
113 | try | 113 | try |
114 | { | 114 | { |
115 | //need to compile the script into a java class file | 115 | //need to compile the script into a java class file |
116 | 116 | ||
117 | //first save it to a java source file | 117 | //first save it to a java source file |
118 | TextWriter tw = new StreamWriter(scriptName + ".java"); | 118 | TextWriter tw = new StreamWriter(scriptName + ".java"); |
119 | tw.WriteLine(script); | 119 | tw.WriteLine(script); |
120 | tw.Close(); | 120 | tw.Close(); |
121 | 121 | ||
122 | //now compile | 122 | //now compile |
123 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); | 123 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); |
124 | // psi.RedirectStandardOutput = true; | 124 | // psi.RedirectStandardOutput = true; |
125 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | 125 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; |
126 | psi.UseShellExecute = false; | 126 | psi.UseShellExecute = false; |
127 | 127 | ||
128 | System.Diagnostics.Process javacomp; | 128 | System.Diagnostics.Process javacomp; |
129 | javacomp = System.Diagnostics.Process.Start(psi); | 129 | javacomp = System.Diagnostics.Process.Start(psi); |
130 | javacomp.WaitForExit(); | 130 | javacomp.WaitForExit(); |
131 | 131 | ||
132 | 132 | ||
133 | //now load in class file | 133 | //now load in class file |
134 | ClassRecord class1 = new ClassRecord(); | 134 | ClassRecord class1 = new ClassRecord(); |
135 | class1.LoadClassFromFile(scriptName + ".class"); | 135 | class1.LoadClassFromFile(scriptName + ".class"); |
136 | class1.PrintToConsole(); | 136 | class1.PrintToConsole(); |
137 | //Console.WriteLine(); | 137 | //Console.WriteLine(); |
138 | this._mainMemory.MethodArea.Classes.Add(class1); | 138 | this._mainMemory.MethodArea.Classes.Add(class1); |
139 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); | 139 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); |
140 | 140 | ||
141 | Thread newThread = new Thread(); | 141 | Thread newThread = new Thread(); |
142 | this._threads.Add(newThread); | 142 | this._threads.Add(newThread); |
143 | newThread.currentClass = class1; | 143 | newThread.currentClass = class1; |
144 | newThread.scriptInfo = scriptInfo; | 144 | newThread.scriptInfo = scriptInfo; |
145 | 145 | ||
146 | //now delete the created files | 146 | //now delete the created files |
147 | System.IO.File.Delete(scriptName + ".java"); | 147 | System.IO.File.Delete(scriptName + ".java"); |
148 | System.IO.File.Delete(scriptName + ".class"); | 148 | System.IO.File.Delete(scriptName + ".class"); |
149 | //this.OnFrame(); | 149 | //this.OnFrame(); |
150 | } | 150 | } |
151 | catch (Exception e) | 151 | catch (Exception e) |
152 | { | 152 | { |
153 | Console.WriteLine("exception"); | 153 | Console.WriteLine("exception"); |
154 | Console.WriteLine(e.StackTrace); | 154 | Console.WriteLine(e.StackTrace); |
155 | Console.WriteLine(e.Message); | 155 | Console.WriteLine(e.Message); |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | private class CompileInfo | 159 | private class CompileInfo |
160 | { | 160 | { |
161 | public string script; | 161 | public string script; |
162 | public string scriptName; | 162 | public string scriptName; |
163 | 163 | ||
164 | public CompileInfo() | 164 | public CompileInfo() |
165 | { | 165 | { |
166 | 166 | ||
167 | } | 167 | } |
168 | } | 168 | } |
169 | } | 169 | } |
170 | } | 170 | } |