Commit 1241cdd4c0ab477ba9cb2f7c2d14d3e4ba1730dd

Authored by perry.werneck@gmail.com
1 parent 038c761d

Implementando plugin java

pw3270.cbp
... ... @@ -150,6 +150,10 @@
150 150 <Option target="Debug" />
151 151 <Option target="Release" />
152 152 </Unit>
  153 + <Unit filename="src/java/sample/popup.java">
  154 + <Option target="Debug" />
  155 + <Option target="Release" />
  156 + </Unit>
153 157 <Unit filename="src/java/terminal.java">
154 158 <Option target="Debug" />
155 159 <Option target="Release" />
... ...
src/classlib/session.cc
... ... @@ -121,6 +121,7 @@
121 121  
122 122 void session::set_plugin(session * (*factory)(const char *name))
123 123 {
  124 + trace("%s(%p)",__FUNCTION__,factory);
124 125 session::factory = factory;
125 126 }
126 127  
... ...
src/java/Makefile.in
... ... @@ -120,6 +120,16 @@ $(BINDIR)/java/%.class: sample/%.java $(BINDIR)/java/$(PACKAGE_NAME)/terminal.cl
120 120 @mkdir -p `dirname $@`
121 121 $(JAVAC) -encoding utf-8 -cp $(BINDIR)/java -d $(BINDIR)/java $<
122 122  
  123 +$(BINDIR)/%.class: sample/%.java $(BINDIR)/java/$(PACKAGE_NAME)/terminal.class
  124 + @echo $< ...
  125 + @mkdir -p `dirname $@`
  126 + $(JAVAC) -encoding utf-8 -cp $(BINDIR)/java -d $(BINDIR)/java $<
  127 +
  128 +%.class: sample/%.java $(BINDIR)/java/$(PACKAGE_NAME)/terminal.class
  129 + @echo $< ...
  130 + @mkdir -p `dirname $@`
  131 + $(JAVAC) -encoding utf-8 -cp $(BINDIR)/java -d `dirname $@` $<
  132 +
123 133 $(BINDIR)/java/$(PACKAGE_NAME)/%.class: %.java
124 134 @echo $< ...
125 135 @mkdir -p `dirname $@`
... ... @@ -144,6 +154,8 @@ zip: jni3270.zip
144 154 jni3270.zip: $(BINRLS)@DLLDIR@/@DLLPREFIX@jni3270@DLLEXT@ $(BINRLS)/$(PACKAGE_NAME).jar testprogram.java doc
145 155 @rm -fr .tmp.zip
146 156 @rm -f $@
  157 + @mkdir -p .tmp.zip
  158 + @mkdir -p .tmp.zip/
147 159 @zip -9 -j $@ $(BINRLS)@DLLDIR@/@DLLPREFIX@jni3270@DLLEXT@ $(BINRLS)/$(PACKAGE_NAME).jar testprogram.java
148 160 @zip -9 -r $@ doc
149 161  
... ...
src/java/main.cc
... ... @@ -33,6 +33,7 @@
33 33 /*---[ Implement ]----------------------------------------------------------------------------------*/
34 34  
35 35 void set_java_session_factory(PW3270_NAMESPACE::session * (*factory)(const char *name)) {
  36 + trace("%s(%p)",__FUNCTION__,factory);
36 37 session::set_plugin(factory);
37 38 }
38 39  
... ... @@ -49,6 +50,8 @@ session * getHandle(JNIEnv *env, jobject obj) {
49 50  
50 51 JNIEXPORT jint JNICALL Java_pw3270_terminal_init__(JNIEnv *env, jobject obj) {
51 52  
  53 + trace("%s",__FUNCTION__);
  54 +
52 55 try {
53 56  
54 57 jlong handle = reinterpret_cast<jlong>(session::create());
... ... @@ -56,6 +59,7 @@ JNIEXPORT jint JNICALL Java_pw3270_terminal_init__(JNIEnv *env, jobject obj) {
56 59  
57 60 } catch(std::exception &e) {
58 61  
  62 + trace("%s: %s",__FUNCTION__,e.what());
59 63 env->ThrowNew(env->FindClass("java/lang/Exception"), e.what());
60 64  
61 65 }
... ...
src/java/plugin.cc
... ... @@ -306,10 +306,22 @@
306 306  
307 307 /*---[ Implement ]----------------------------------------------------------------------------------*/
308 308  
309   - static session * factory(const char *name)
310   - {
311   - return new plugin(lib3270_get_default_session_handle());
312   - }
  309 +extern "C" {
  310 +
  311 + static session * factory(const char *name)
  312 + {
  313 + debug("---> %s",__FUNCTION__);
  314 + return new plugin(lib3270_get_default_session_handle());
  315 + }
  316 +
  317 + static jint JNICALL jni_vfprintf(FILE *fp, const char *format, va_list args)
  318 + {
  319 + lib3270_write_va_log(lib3270_get_default_session_handle(),"java",format,args);
  320 + return 0;
  321 + }
  322 +
  323 +}
  324 +
313 325  
314 326 LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window)
315 327 {
... ... @@ -367,20 +379,32 @@
367 379 memset(&vm_args,0,sizeof(vm_args));
368 380 memset(options,0,sizeof(options));
369 381  
370   - vm_args.version = JNI_VERSION_1_2;
371   - vm_args.nOptions = 0;
372   - vm_args.options = options;
  382 + vm_args.version = JNI_VERSION_1_4;
  383 + vm_args.nOptions = 0;
  384 + vm_args.options = options;
  385 + vm_args.ignoreUnrecognized = JNI_FALSE;
  386 +
  387 + options[vm_args.nOptions].optionString = g_strdup("vfprintf");
  388 + options[vm_args.nOptions].extraInfo = (void *) jni_vfprintf;
  389 + vm_args.nOptions++;
373 390  
374   -#ifdef DEBUG
375   - options[vm_args.nOptions++].optionString = g_strdup("-verbose");
376   -#endif
  391 +//#ifdef DEBUG
  392 +// options[vm_args.nOptions++].optionString = g_strdup("-verbose");
  393 +//#endif
377 394  
378 395 gchar * dirname = g_path_get_dirname(filename);
379 396  
380 397 #if defined( WIN32 )
381 398  
  399 + g_mkdir_with_parents("./jvm-exports",0777);
  400 +
382 401 options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=%s",".");
383   - options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=.;%s",dirname);
  402 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=./jvm-exports;%s",dirname);
  403 +
  404 +#elif defined(DEBUG)
  405 +
  406 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=%s:.bin/Debug:.bin/Debug/lib",JNIDIR);
  407 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=%s:%s:./src/java/.bin/java",JARDIR,dirname);
384 408  
385 409 #else
386 410  
... ... @@ -458,7 +482,15 @@
458 482  
459 483 jobjectArray args = env->NewObjectArray(0, env->FindClass("java/lang/String"), env->NewStringUTF(""));
460 484  
461   - env->CallStaticVoidMethod(cls, mid, args);
  485 + try {
  486 +
  487 + env->CallStaticVoidMethod(cls, mid, args);
  488 +
  489 + } catch(std::exception &e) {
  490 +
  491 + trace("%s",e.what());
  492 + }
  493 +
462 494  
463 495 }
464 496  
... ...
src/java/run.sh
... ... @@ -3,5 +3,5 @@ make -C ../.. Debug
3 3 make Debug
4 4 make .bin/java/${1}.class
5 5  
6   -LD_LIBRARY_PATH=../../.bin/Debug/lib/ java -Djava.library.path=.bin/Debug -cp .bin/java/ ${1}
  6 +LD_LIBRARY_PATH=../../.bin/Debug/lib/ java -Djava.library.path=/usr/local/lib64/java:.bin/Debug/lib -cp .bin/java/ ${1}
7 7  
... ...
src/java/sample/popup.java 0 → 100755
... ... @@ -0,0 +1,23 @@
  1 +
  2 +import pw3270.*;
  3 +
  4 +public class popup
  5 +{
  6 + public static void main (String[] args)
  7 + {
  8 + System.out.println("Begin");
  9 +
  10 + try {
  11 +
  12 + terminal host = new terminal();
  13 + System.out.println("Output: " + host.popup_dialog(0,"Title","This is a popup message", "And this is a secondary and more detailed text"));
  14 +
  15 + } catch( Exception e ) {
  16 +
  17 + System.out.println("Error: " + e);
  18 +
  19 + }
  20 +
  21 + System.out.println("End");
  22 + }
  23 +};
... ...