aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs
diff options
context:
space:
mode:
authorMW2007-04-11 13:32:50 +0000
committerMW2007-04-11 13:32:50 +0000
commit00b7058e000d7871df2ae40075ead1042e8e81ac (patch)
tree2a7e4d5c51b4567b97a7fc06c1c970e6a4ac9d44 /OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs
parentsmall improvement to the jvm and test script (diff)
downloadopensim-SC_OLD-00b7058e000d7871df2ae40075ead1042e8e81ac.zip
opensim-SC_OLD-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.gz
opensim-SC_OLD-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.bz2
opensim-SC_OLD-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.xz
Attempt to rearrange some of the directories
Diffstat (limited to 'OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs')
-rw-r--r--OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs134
1 files changed, 134 insertions, 0 deletions
diff --git a/OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs b/OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs
new file mode 100644
index 0000000..b47bb50
--- /dev/null
+++ b/OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs
@@ -0,0 +1,134 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using System.Threading;
6using OpenSim.Framework;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Framework.Utilities;
9
10namespace OpenSim.Scripting.EmbeddedJVM
11{
12 public class OpenSimJVM : IScriptEngine
13 {
14 private List<Thread> _threads = new List<Thread>();
15 private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>();
16 private MainMemory _mainMemory;
17 private System.Threading.Thread compileThread;
18
19 public OpenSimJVM()
20 {
21
22 }
23
24 public bool Init(IScriptAPI api)
25 {
26 Console.WriteLine("Creating OpenSim JVM scripting engine");
27 _mainMemory = new MainMemory();
28 Thread.GlobalMemory = this._mainMemory;
29 Thread.OpenSimScriptAPI = api;
30 compileThread = new System.Threading.Thread(new ThreadStart(CompileScript));
31 compileThread.IsBackground = true;
32 compileThread.Start();
33 return true;
34 }
35
36 public string GetName()
37 {
38 return "OpenSimJVM";
39 }
40
41 public void LoadScript(string script, string scriptName, uint entityID)
42 {
43 Console.WriteLine("OpenSimJVM - loading new script: " + scriptName);
44 CompileInfo comp = new CompileInfo();
45 comp.entityId = entityID;
46 comp.script = script;
47 comp.scriptName = scriptName;
48 this.CompileScripts.Enqueue(comp);
49 }
50
51 public void CompileScript()
52 {
53 while (true)
54 {
55 CompileInfo comp = this.CompileScripts.Dequeue();
56 string script = comp.script;
57 string scriptName = comp.scriptName;
58 uint entityID = comp.entityId;
59 try
60 {
61 //need to compile the script into a java class file
62
63 //first save it to a java source file
64 TextWriter tw = new StreamWriter(scriptName + ".java");
65 tw.WriteLine(script);
66 tw.Close();
67
68 //now compile
69 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java");
70 // psi.RedirectStandardOutput = true;
71 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
72 psi.UseShellExecute = false;
73
74 System.Diagnostics.Process javacomp;
75 javacomp = System.Diagnostics.Process.Start(psi);
76 javacomp.WaitForExit();
77
78
79 //now load in class file
80 ClassRecord class1 = new ClassRecord();
81 class1.LoadClassFromFile(scriptName + ".class");
82 class1.PrintToConsole();
83 //Console.WriteLine();
84 this._mainMemory.MethodArea.Classes.Add(class1);
85 class1.AddMethodsToMemory(this._mainMemory.MethodArea);
86
87 Thread newThread = new Thread();
88 this._threads.Add(newThread);
89 newThread.EntityId = entityID;
90 newThread.currentClass = class1;
91
92 //now delete the created files
93 System.IO.File.Delete(scriptName + ".java");
94 System.IO.File.Delete(scriptName + ".class");
95 //this.OnFrame();
96 }
97 catch (Exception e)
98 {
99 Console.WriteLine("exception");
100 Console.WriteLine(e.StackTrace);
101 Console.WriteLine(e.Message);
102 }
103 }
104 }
105
106 public void OnFrame()
107 {
108 for (int i = 0; i < this._threads.Count; i++)
109 {
110 if (!this._threads[i].running)
111 {
112 this._threads[i].StartMethod("OnFrame");
113 bool run = true;
114 while (run)
115 {
116 run = this._threads[i].Excute();
117 }
118 }
119 }
120 }
121
122 private class CompileInfo
123 {
124 public string script;
125 public string scriptName;
126 public uint entityId;
127
128 public CompileInfo()
129 {
130
131 }
132 }
133 }
134}