Mercurial > hg > octave-nkf
comparison scripts/java/org/octave/Octave.java @ 15625:acf0addfc610
include Octave Forge java package in core Octave
* scripts/java: New directory tree.
* scripts/Makefile.am: Include java/module.mk.
(JAR_FILES): New variable.
(nobase_fcnfile_DATA): Include $(JAR_FILES) in the list.
(all-local): Depend on $(JAR_FILES).
(java/PKG_ADD, java_GEN_FCN_FILES, java/$(octave_dirstamp)):
New rules.
* libinterp/link-deps (LIBOCTINTERP_LINK_DEP): Include $(JAVA_LIBS) in
the list.
* dldfcn/__java__.h, dldfcn/__java__.cc: New files.
* dldfcn/module-files (__java__.cc): New file description.
* doc/interpreter/java.txi: New file.
* doc/interpreter/octave.texi: Include java.texi.
* doc/interpreter/java-images: New directory.
* doc/interpreter/Makefile.am (JAVA_IMAGES): New variable.
(IMAGES): Include $(JAVA_IMAGSES) in the list.
(MUNGED_TEXI_SRC): Include java.texi in the list.
* configure.ac: Check for Java libraries and tools.
Include Java info in the summary message.
* build-aux/common.mk (JAVA_CPPFLAGS, JAVA_LIBS): New variables.
* NEWS: Update.
* contributors.in: Include Martin Hepperle in the list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 23 Nov 2012 15:29:13 -0500 |
parents | |
children | f96faf028d90 |
comparison
equal
deleted
inserted
replaced
15624:550147454137 | 15625:acf0addfc610 |
---|---|
1 /* Copyright (C) 2007 Michael Goffioul | |
2 ** | |
3 ** This program is free software; you can redistribute it and/or modify | |
4 ** it under the terms of the GNU General Public License as published by | |
5 ** the Free Software Foundation; either version 2 of the License, or | |
6 ** (at your option) any later version. | |
7 ** | |
8 ** This program is distributed in the hope that it will be useful, | |
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 ** GNU General Public License for more details. | |
12 ** | |
13 ** You should have received a copy of the GNU General Public License | |
14 ** along with this program; If not, see <http://www.gnu.org/licenses/>. | |
15 */ | |
16 | |
17 package org.octave; | |
18 | |
19 import java.util.*; | |
20 | |
21 public class Octave | |
22 { | |
23 static | |
24 { | |
25 System.load (System.getProperty ("octave.java.path") + java.io.File.separator + "__java__.oct"); | |
26 } | |
27 | |
28 private static Object notifyObject = null; | |
29 private static Object[] args = null; | |
30 private static LinkedList invokeList = new LinkedList(); | |
31 private static LinkedList waitList = new LinkedList(); | |
32 | |
33 public native static boolean call (String name, Object[] argin, Object[] argout); | |
34 public native static void doInvoke(int ID, Object[] args); | |
35 public native static void doEvalString(String cmd); | |
36 public native static boolean needThreadedInvokation(); | |
37 | |
38 public static void checkPendingAction() | |
39 { | |
40 if (notifyObject != null) | |
41 { | |
42 synchronized(notifyObject) | |
43 { | |
44 if (notifyObject instanceof OctaveReference) | |
45 doInvoke(((OctaveReference)notifyObject).getID(), args); | |
46 else if (notifyObject instanceof String) | |
47 doEvalString((String)notifyObject); | |
48 notifyObject.notifyAll(); | |
49 } | |
50 notifyObject = null; | |
51 args = null; | |
52 } | |
53 | |
54 Object obj; | |
55 Object[] objArgs; | |
56 | |
57 while (true) | |
58 { | |
59 obj = null; | |
60 objArgs = null; | |
61 | |
62 synchronized (invokeList) | |
63 { | |
64 if (invokeList.size() > 0) | |
65 { | |
66 obj = invokeList.remove(); | |
67 if (obj instanceof OctaveReference) | |
68 objArgs = (Object[])invokeList.remove(); | |
69 } | |
70 } | |
71 | |
72 if (obj != null) | |
73 { | |
74 if (obj instanceof Runnable) | |
75 ((Runnable)obj).run(); | |
76 else if (obj instanceof OctaveReference) | |
77 doInvoke(((OctaveReference)obj).getID(), objArgs); | |
78 else if (obj instanceof String) | |
79 doEvalString((String)obj); | |
80 } | |
81 else | |
82 break; | |
83 } | |
84 /* | |
85 synchronized(invokeList) | |
86 { | |
87 while (invokeList.size() > 0) | |
88 { | |
89 Object obj = invokeList.remove(); | |
90 if (obj instanceof Runnable) | |
91 ((Runnable)obj).run(); | |
92 if (obj instanceof OctaveReference) | |
93 { | |
94 Object[] objArgs = (Object[])invokeList.remove(); | |
95 doInvoke(((OctaveReference)obj).getID(), objArgs); | |
96 } | |
97 else if (obj instanceof String) | |
98 doEvalString((String)obj); | |
99 } | |
100 } | |
101 */ | |
102 } | |
103 | |
104 private static void checkWaitState() | |
105 { | |
106 if (waitList.size() > 0) | |
107 { | |
108 Object wObj = waitList.getFirst(); | |
109 synchronized (wObj) | |
110 { | |
111 wObj.notifyAll(); | |
112 } | |
113 } | |
114 } | |
115 | |
116 public static void invokeAndWait(OctaveReference ref, Object[] invokeArgs) | |
117 { | |
118 if (needThreadedInvokation()) | |
119 { | |
120 synchronized(ref) | |
121 { | |
122 notifyObject = ref; | |
123 args = invokeArgs; | |
124 try { checkWaitState(); ref.wait(); } | |
125 catch (InterruptedException e) {} | |
126 } | |
127 } | |
128 else | |
129 doInvoke(ref.getID(), invokeArgs); | |
130 } | |
131 | |
132 public static void evalAndWait(String cmd) | |
133 { | |
134 if (needThreadedInvokation()) | |
135 { | |
136 synchronized(cmd) | |
137 { | |
138 notifyObject = cmd; | |
139 args = null; | |
140 try { checkWaitState(); cmd.wait(); } | |
141 catch (InterruptedException e) {} | |
142 } | |
143 } | |
144 else | |
145 doEvalString(cmd); | |
146 } | |
147 | |
148 public static void invokeLater(Runnable r) | |
149 { | |
150 if (needThreadedInvokation()) | |
151 synchronized(invokeList) | |
152 { | |
153 invokeList.add(r); | |
154 checkWaitState(); | |
155 } | |
156 else | |
157 r.run(); | |
158 } | |
159 | |
160 public static void invokeLater(OctaveReference ref, Object[] invokeArgs) | |
161 { | |
162 if (needThreadedInvokation()) | |
163 synchronized(invokeList) | |
164 { | |
165 invokeList.add(ref); | |
166 invokeList.add(invokeArgs); | |
167 checkWaitState(); | |
168 } | |
169 else | |
170 doInvoke(ref.getID(), invokeArgs); | |
171 } | |
172 | |
173 public static void evalLater(String cmd) | |
174 { | |
175 if (needThreadedInvokation()) | |
176 synchronized(invokeList) | |
177 { | |
178 invokeList.add(cmd); | |
179 checkWaitState(); | |
180 } | |
181 else | |
182 doEvalString(cmd); | |
183 } | |
184 | |
185 public static void waitFor(Object wObj) | |
186 { | |
187 waitList.add(0, wObj); | |
188 synchronized (wObj) | |
189 { | |
190 while (waitList.size() > 0 && waitList.getFirst() == wObj) | |
191 { | |
192 try { wObj.wait(); } | |
193 catch (InterruptedException e) {} | |
194 checkPendingAction(); | |
195 } | |
196 } | |
197 } | |
198 | |
199 public static void endWaitFor(Object obj) | |
200 { | |
201 boolean isCurrentWaitObject = (waitList.size() > 0 && waitList.getFirst() == obj); | |
202 | |
203 waitList.remove(obj); | |
204 if (needThreadedInvokation() && isCurrentWaitObject) | |
205 synchronized (obj) | |
206 { | |
207 obj.notifyAll(); | |
208 } | |
209 } | |
210 | |
211 public static Object do_test (String name, Object arg0) throws Exception | |
212 { | |
213 Object[] argin = new Object[] { arg0 }; | |
214 Object[] argout = new Object[1]; | |
215 if (call (name, argin, argout)) | |
216 return argout[0]; | |
217 throw new Exception ("octave call failed"); | |
218 } | |
219 } |