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