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