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