Commit 958b8c4867e5a0448a5427b5afcd715c8e9ac524
1 parent
b2979209
Exists in
master
Reimplementando geração da jni num projeto separado.
Showing
4 changed files
with
517 additions
and
6 deletions
Show diff stats
.gitignore
configure.ac
... | ... | @@ -427,6 +427,7 @@ dnl Configure which files to generate. |
427 | 427 | dnl --------------------------------------------------------------------------- |
428 | 428 | |
429 | 429 | dnl AC_CONFIG_FILES(Makefile) |
430 | +AC_CONFIG_FILES(src/jni/Makefile) | |
430 | 431 | |
431 | 432 | dnl --------------------------------------------------------------------------- |
432 | 433 | dnl Output the generated config.status script. | ... | ... |
src/jni/Makefile.in
... | ... | @@ -63,8 +63,9 @@ SHELL=@SHELL@ |
63 | 63 | MKDIR=@MKDIR_P@ |
64 | 64 | |
65 | 65 | CXX=@CXX@ |
66 | -CC=@CC@ | |
67 | 66 | LD=@CXX@ |
67 | +JAVAH=@JAVAH@ | |
68 | +JAVAC=@JAVAC@ | |
68 | 69 | |
69 | 70 | LIBS=-lpw3270cpp @LIBS@ @LIBICONV@ |
70 | 71 | CXXFLAGS=@CXXFLAGS@ @JNI_CPPFLAGS@ |
... | ... | @@ -72,26 +73,55 @@ LDFLAGS=@LDFLAGS@ |
72 | 73 | |
73 | 74 | #---[ Rules ]---------------------------------------------------------------------------- |
74 | 75 | |
75 | -DEPENDS=*.h Makefile | |
76 | +DEPENDS=../include/*.h Makefile | |
76 | 77 | |
77 | 78 | $(OBJDBG)/%.o: \ |
78 | 79 | %.cc \ |
80 | + jni3270.h \ | |
79 | 81 | $(DEPENDS) |
80 | 82 | |
81 | 83 | @echo $< ... |
82 | 84 | @$(MKDIR) `dirname $@` |
83 | 85 | @$(CXX) $(CFLAGS) -fstack-check -DDEBUG=1 \ |
84 | - -DBUILD_DATE=`date +"0x%Y%m%d"`\ | |
85 | - -g -o $@ -c $< | |
86 | + -DBUILD_DATE=`date +"0x%Y%m%d"`\ | |
87 | + -g -o $@ -c $< | |
86 | 88 | |
87 | 89 | $(OBJRLS)/%.o: \ |
88 | 90 | %.cc \ |
91 | + jni3270.h \ | |
89 | 92 | $(DEPENDS) |
90 | 93 | |
91 | 94 | @echo $< ... |
92 | 95 | @$(MKDIR) `dirname $@` |
93 | 96 | @$(CXX) $(CFLAGS) -DNDEBUG=1 \ |
94 | - -DBUILD_DATE=`date +"0x%Y%m%d"` \ | |
95 | - -o $@ -c $< | |
97 | + -DBUILD_DATE=`date +"0x%Y%m%d"` \ | |
98 | + -o $@ -c $< | |
96 | 99 | |
100 | +$(BINDIR)/java/pw3270/%.class: \ | |
101 | + ../%.java | |
102 | + | |
103 | + @echo $< ... | |
104 | + @mkdir -p `dirname $@` | |
105 | + @$(JAVAC) -encoding utf-8 -d $(BINDIR)/java $^ | |
106 | + | |
107 | + | |
108 | +jni3270.h: \ | |
109 | + $(BINDIR)/java/pw3270/terminal.class | |
110 | + | |
111 | + @echo $< ... | |
112 | + @mkdir -p `dirname $@` | |
113 | + @$(JAVAH) -o $@ -classpath $(BINDIR)/java pw3270.terminal | |
114 | + | |
115 | + | |
116 | +#---[ Debug Targets ]-------------------------------------------------------------------- | |
117 | + | |
118 | +Debug: \ | |
119 | + $(BINDBG)/$(LIBNAME) | |
120 | + | |
121 | +$(BINDBG)/$(LIBNAME): \ | |
122 | + $(foreach SRC, $(basename $(SOURCES)), $(OBJDBG)/$(SRC).o) | |
123 | + | |
124 | + @echo $(basename $@) ... | |
125 | + @$(MKDIR) `dirname $@` | |
126 | + @$(LD) -shared -Wl,-soname,$(notdir $@) $(LDFLAGS) -o $@ $^ $(LIBS) | |
97 | 127 | ... | ... |
... | ... | @@ -0,0 +1,479 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | |
20 | + * | |
21 | + * Este programa está nomeado como terminal.java e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | +package pw3270; | |
31 | + | |
32 | +public class terminal | |
33 | +{ | |
34 | + // Is native library loaded? | |
35 | + private static boolean loaded = false; | |
36 | + | |
37 | + // lib3270's session handle | |
38 | + private long nativeHandle; | |
39 | + | |
40 | + // Init/Deinit | |
41 | + private native int init(); | |
42 | + private native int init(String id); | |
43 | + private native int deinit(); | |
44 | + | |
45 | + /** | |
46 | + * Wait for an specified amount of time. | |
47 | + * <p> | |
48 | + * Wait for the specified time keeping the main loop active. | |
49 | + * | |
50 | + * @param seconds Number of seconds to wait. | |
51 | + * | |
52 | + */ | |
53 | + public native int wait(int seconds); | |
54 | + | |
55 | + /** | |
56 | + * Wait for terminal negociation. | |
57 | + * <p> | |
58 | + * Wait on a loop until the terminal contents are | |
59 | + * ready for reading. | |
60 | + * | |
61 | + * @param seconds Maximum time (in seconds) to wait for. | |
62 | + * | |
63 | + * @return 0 for success, error code if not. | |
64 | + * | |
65 | + */ | |
66 | + public native int wait_for_ready(int seconds); | |
67 | + | |
68 | + /** | |
69 | + * Wait for text at defined position | |
70 | + * | |
71 | + * @param row Row for text to compare. | |
72 | + * @param col Column for text to compare. | |
73 | + * @param text String to compare. | |
74 | + * @param seconds Maximum time (in seconds) to wait for. | |
75 | + * | |
76 | + * @return 0 for success, error code if not. | |
77 | + * | |
78 | + */ | |
79 | + public native int wait_for_string_at(int row, int col, String text, int seconds); | |
80 | + | |
81 | + /** | |
82 | + * Get the current lib3270 version. | |
83 | + * | |
84 | + * @return String with the current lib3270 version. | |
85 | + * | |
86 | + */ | |
87 | + public native String get_version(); | |
88 | + | |
89 | + /** | |
90 | + * Get the current lib3270 revision. | |
91 | + * | |
92 | + * @return String with the current lib3270 revision. | |
93 | + * | |
94 | + */ | |
95 | + public native String get_revision(); | |
96 | + | |
97 | + /** | |
98 | + * Get the current lib3270 encoding. | |
99 | + * | |
100 | + * @return String with the current lib3270 encoding (ISO-8859-1). | |
101 | + * | |
102 | + */ | |
103 | + public native String get_encoding(); | |
104 | + | |
105 | + // Get/Set/Text with charset translation | |
106 | + | |
107 | + /** | |
108 | + * Get terminal contents starting at desired address. | |
109 | + * | |
110 | + * @param baddr Address of the beginning of the string. | |
111 | + * @param len Length of the string. | |
112 | + * | |
113 | + * @return Terminal contents with "len" bytes starting at "baddr" position. | |
114 | + * | |
115 | + */ | |
116 | + public native String get_string(int baddr, int len); | |
117 | + | |
118 | + /** | |
119 | + * Get terminal contents starting at row, col. | |
120 | + * | |
121 | + * @param row Row of the text. | |
122 | + * @param col Column of the text. | |
123 | + * @param sz Size to read. | |
124 | + * | |
125 | + * @return Contents of terminal at row, col with sz bytes. | |
126 | + * | |
127 | + */ | |
128 | + public native String get_string_at(int row, int col, int sz); | |
129 | + | |
130 | + /** | |
131 | + * Set terminal contents at position. | |
132 | + * | |
133 | + * @param row Row for starting of change. | |
134 | + * @param col Column for starting of change. | |
135 | + * @param str Text to set. | |
136 | + * | |
137 | + * @return 0 if ok, error code if not. | |
138 | + * | |
139 | + */ | |
140 | + public native int set_string_at(int row, int col, String str); | |
141 | + | |
142 | + /** | |
143 | + * Compare terminal contents. | |
144 | + * | |
145 | + * @param row Row for text to compare. | |
146 | + * @param col Column for text to compare. | |
147 | + * @param text String to compare. | |
148 | + * | |
149 | + * @return result of strcmp() from text and terminal contents. | |
150 | + * | |
151 | + */ | |
152 | + public native int cmp_string_at(int row, int col, String text); | |
153 | + | |
154 | + | |
155 | + public native int input_string(String str); | |
156 | + | |
157 | + // Cursor management | |
158 | + | |
159 | + /** | |
160 | + * Move cursor to selected position. | |
161 | + * | |
162 | + * @param row Row of the new cursor position. | |
163 | + * @param col Column of the new cursor position. | |
164 | + * | |
165 | + * @return Address of current cursor position. | |
166 | + * | |
167 | + */ | |
168 | + public native int set_cursor_position(int row, int col); | |
169 | + | |
170 | + /** | |
171 | + * Set cursor offset in the terminal buffer. | |
172 | + * | |
173 | + * @param addr New cursor offset. | |
174 | + * | |
175 | + * @return Original cursor offset. | |
176 | + * | |
177 | + */ | |
178 | + public native int set_cursor_addr(int addr); | |
179 | + | |
180 | + /** | |
181 | + * Get cursor offset | |
182 | + * | |
183 | + * @return Current cursor offset. | |
184 | + * | |
185 | + */ | |
186 | + public native int get_cursor_addr(); | |
187 | + | |
188 | + // Keyboard actions | |
189 | + | |
190 | + /** | |
191 | + * Send an "ENTER" action. | |
192 | + * | |
193 | + * @return reserved. | |
194 | + * | |
195 | + */ | |
196 | + public native int enter(); | |
197 | + | |
198 | + /** | |
199 | + * Send a pfkey to host. | |
200 | + * | |
201 | + * @param key PFkey number. | |
202 | + * | |
203 | + * @return reserved. | |
204 | + * | |
205 | + */ | |
206 | + public native int pfkey(int key); | |
207 | + | |
208 | + /** | |
209 | + * Send a pakey to host. | |
210 | + * | |
211 | + * @param key PFkey number. | |
212 | + * | |
213 | + * @return reserved. | |
214 | + * | |
215 | + */ | |
216 | + public native int pakey(int key); | |
217 | + | |
218 | + // Actions | |
219 | + | |
220 | + /** | |
221 | + * quit remote pw3270 window. | |
222 | + * <p> | |
223 | + * Only valid if connected to a remote window | |
224 | + * | |
225 | + * @return reserved. | |
226 | + * | |
227 | + */ | |
228 | + public native int quit(); | |
229 | + | |
230 | + public native int erase(); | |
231 | + public native int erase_eol(); | |
232 | + public native int erase_input(); | |
233 | + | |
234 | + | |
235 | + /** | |
236 | + * Erase from cursor position until the end of the field. | |
237 | + * | |
238 | + * @return reserved. | |
239 | + * | |
240 | + */ | |
241 | + public native int erase_eof(); | |
242 | + | |
243 | + | |
244 | + /** | |
245 | + * Open print dialog. | |
246 | + * <p> | |
247 | + * Only valid if connected to a remote window | |
248 | + * | |
249 | + * @return reserved | |
250 | + * | |
251 | + */ | |
252 | + public native int print(); | |
253 | + | |
254 | + // Connect/Disconnect | |
255 | + | |
256 | + /** | |
257 | + * Connect to 3270 host. | |
258 | + * <p> | |
259 | + * Connect to the 3270 host | |
260 | + * <p> | |
261 | + * URI formats: | |
262 | + * <ul> | |
263 | + * <li>tn3270://[HOSTNAME]:[HOSTPORT] for non SSL connections.</li> | |
264 | + * <li>tn3270s://[HOSTNAME]:[HOSTPORT] for ssl connection.</li> | |
265 | + * </ul> | |
266 | + * | |
267 | + * @param host Host URI. | |
268 | + * @param seconds How many seconds to wait for a connection. | |
269 | + * | |
270 | + * @return 0 if ok, error code if not. | |
271 | + * | |
272 | + */ | |
273 | + public native int connect(String host, int seconds); | |
274 | + | |
275 | + /** | |
276 | + * Disconnect from host. | |
277 | + * | |
278 | + * @return 0 if ok, error code if not. | |
279 | + * | |
280 | + */ | |
281 | + public native int disconnect(); | |
282 | + | |
283 | + /** | |
284 | + * Load native module. | |
285 | + * | |
286 | + */ | |
287 | + private synchronized void load() { | |
288 | + | |
289 | + if(!loaded) { | |
290 | + System.loadLibrary("jni3270"); | |
291 | + loaded = true; | |
292 | + } | |
293 | + | |
294 | + } | |
295 | + | |
296 | + /** | |
297 | + * Creates a tn3270 terminal without associating it | |
298 | + * with any pw3270 window. | |
299 | + * | |
300 | + */ | |
301 | + public terminal() { | |
302 | + | |
303 | + load(); | |
304 | + init(); | |
305 | + | |
306 | + } | |
307 | + | |
308 | + /** | |
309 | + * Get the field start address. | |
310 | + * | |
311 | + * @param baddr address of the field. | |
312 | + * | |
313 | + * @return Address of current field start. | |
314 | + * | |
315 | + */ | |
316 | + public native int get_field_start(int baddr); | |
317 | + | |
318 | + /** | |
319 | + * Get the current field start address. | |
320 | + * | |
321 | + * @return Current field start address. | |
322 | + * | |
323 | + */ | |
324 | + public int get_field_start() { | |
325 | + return get_field_start(-1); | |
326 | + } | |
327 | + | |
328 | + /** | |
329 | + * Get the field length. | |
330 | + * | |
331 | + * @param baddr Address of the field. | |
332 | + * | |
333 | + * @return Field length. | |
334 | + * | |
335 | + */ | |
336 | + public native int get_field_len(int baddr); | |
337 | + | |
338 | + /** | |
339 | + * Get the current field length. | |
340 | + * | |
341 | + * @return Current field length. | |
342 | + * | |
343 | + */ | |
344 | + public int get_field_len() { | |
345 | + return get_field_len(-1); | |
346 | + } | |
347 | + | |
348 | + /** | |
349 | + * Get next field address from informed position. | |
350 | + * | |
351 | + * @param baddr Field address. | |
352 | + * | |
353 | + * @return Address of the next field. | |
354 | + * | |
355 | + */ | |
356 | + public native int get_next_unprotected(int baddr); | |
357 | + | |
358 | + /** | |
359 | + * Check if the address is protected. | |
360 | + * | |
361 | + * @param baddr Field address. | |
362 | + * | |
363 | + * @return Protect state. | |
364 | + * | |
365 | + */ | |
366 | + public native int get_is_protected(int baddr); | |
367 | + | |
368 | + /** | |
369 | + * Check if the address is protected. | |
370 | + * | |
371 | + * @param row Screen row. | |
372 | + * @param col Screen col. | |
373 | + * | |
374 | + * @return Protect state. | |
375 | + * | |
376 | + */ | |
377 | + public native int get_is_protected_at(int row, int col); | |
378 | + | |
379 | + /** | |
380 | + * Get next field address. | |
381 | + * | |
382 | + * @return Address of the next field. | |
383 | + * | |
384 | + */ | |
385 | + public int get_next_unprotected() { | |
386 | + return get_next_unprotected(-1); | |
387 | + } | |
388 | + | |
389 | + /** | |
390 | + * Open popup dialog. | |
391 | + * | |
392 | + * @param id Dialog type. | |
393 | + * @param title Window title. | |
394 | + * @param message Dialog message. | |
395 | + * @param secondary Dialog secondary text. | |
396 | + * | |
397 | + * @return reserved. | |
398 | + * | |
399 | + */ | |
400 | + public native int popup_dialog(int id, String title, String message, String secondary); | |
401 | + | |
402 | + /** | |
403 | + * Launch a lib3270 action by name. | |
404 | + * | |
405 | + * @param name Name of the action to fire. | |
406 | + * | |
407 | + * @return Return code of the action call. | |
408 | + * | |
409 | + */ | |
410 | + public native int action(String name); | |
411 | + | |
412 | + /** | |
413 | + * File selection dialog. | |
414 | + * | |
415 | + * @param action Dialog action. | |
416 | + * @param title Window title. | |
417 | + * @param extension File extension. | |
418 | + * @param filename Default file name; | |
419 | + * | |
420 | + * @return Selected file name. | |
421 | + * | |
422 | + */ | |
423 | + public native String file_chooser_dialog(int action, String title, String extension, String filename); | |
424 | + | |
425 | + public native int set_copy(String text); | |
426 | + public native String get_copy(); | |
427 | + | |
428 | + public native String get_clipboard(); | |
429 | + public native int set_clipboard(String text); | |
430 | + | |
431 | + public native boolean is_connected(); | |
432 | + public native boolean is_ready(); | |
433 | + | |
434 | + /** | |
435 | + * Set unlock delay in milliseconds. | |
436 | + * | |
437 | + * Overrides the default value for the unlock delay (the delay between the host unlocking the | |
438 | + * keyboard and lib3270 actually performing the unlock). | |
439 | + * | |
440 | + * The value is in milliseconds; use 0 to turn off the delay completely. | |
441 | + * | |
442 | + * @param ms Delay in milliseconds. | |
443 | + * | |
444 | + */ | |
445 | + public native void set_unlock_delay(int ms); | |
446 | + | |
447 | + public native void log(String msg); | |
448 | + | |
449 | + /** | |
450 | + * Get Screen contents. | |
451 | + * | |
452 | + */ | |
453 | + public native String toString(); | |
454 | + | |
455 | + /** | |
456 | + * Get connection SSL state | |
457 | + * | |
458 | + * @return State of SSL connection (0 = Unsafe, 1 = Valid CA, 2 = Invalid CA or self-signed, 3 = Negotiating, 4 = Undefined) | |
459 | + * | |
460 | + */ | |
461 | + public native int get_secure(); | |
462 | + | |
463 | + /** | |
464 | + * Creates a tn3270 terminal associated with a | |
465 | + * pw3270 window. | |
466 | + * | |
467 | + * @param id String identifying the target window ("pw3270:a") or "" to run without window. | |
468 | + * | |
469 | + */ | |
470 | + public terminal(String id) { | |
471 | + load(); | |
472 | + init(id); | |
473 | + } | |
474 | + | |
475 | + protected void finalize( ) throws Throwable { | |
476 | + deinit(); | |
477 | + } | |
478 | + | |
479 | +}; | ... | ... |