Commit ef6656b07a92ef580b2a68f5750fb34b7089fb3f

Authored by Perry Werneck
1 parent b23f768e
Exists in master

Movendo plugin java para projeto separado.

Makefile.in
... ... @@ -211,7 +211,8 @@ $(BINRLS)/$(PLUGIN): \
211 211 @make -C src/plugin $@
212 212  
213 213 Debug: \
214   - $(BINDBG)/$(LIBNAME)
  214 + $(BINDBG)/$(LIBNAME) \
  215 + $(BINDBG)/$(PLUGIN)
215 216  
216 217 run: \
217 218 $(BINDBG)/$(LIBNAME) \
... ... @@ -233,6 +234,9 @@ $(BINDBG)/$(PLUGIN): \
233 234  
234 235 @make -C src/plugin $@
235 236  
  237 +cleanDebug: \
  238 + clean
  239 +
236 240 clean:
237 241 @rm -fr $(BINDIR)
238 242 @rm -fr $(OBJDIR)
... ...
pw3270-java.cbp
... ... @@ -3,6 +3,7 @@
3 3 <FileVersion major="1" minor="6" />
4 4 <Project>
5 5 <Option title="JNI module for pw3270/lib3270" />
  6 + <Option makefile_is_custom="1" />
6 7 <Option pch_mode="2" />
7 8 <Option compiler="gcc" />
8 9 <Build>
... ... @@ -47,7 +48,10 @@
47 48 <Unit filename="src/jni/main.cc" />
48 49 <Unit filename="src/jni/private.h" />
49 50 <Unit filename="src/jni/startstop.cc" />
  51 + <Unit filename="src/plugin/call.cc" />
50 52 <Unit filename="src/plugin/plugin.cc" />
  53 + <Unit filename="src/plugin/private.h" />
  54 + <Unit filename="src/plugin/startstop.cc" />
51 55 <Unit filename="src/terminal.java" />
52 56 <Extensions>
53 57 <code_completion />
... ...
src/plugin/Makefile.in
... ... @@ -67,8 +67,8 @@ CXX=@CXX@
67 67 CC=@CC@
68 68 LD=@CXX@
69 69  
70   -LIBS=-lpw3270cpp @LIBS@ @GTK_LIBS@ @REXX_LIBS@
71   -CFLAGS=-I$(BASEDIR)/src/include @CFLAGS@ @GTK_CFLAGS@
  70 +LIBS=-lpw3270cpp @LIBS@ @GTK_LIBS@
  71 +CXXFLAGS=@CXXFLAGS@ @GTK_CFLAGS@
72 72 LDFLAGS=@LDFLAGS@
73 73  
74 74 #---[ Rules ]----------------------------------------------------------------------------
... ... @@ -80,7 +80,7 @@ $(OBJDBG)/%.o: \
80 80  
81 81 @echo $< ...
82 82 @$(MKDIR) `dirname $@`
83   - @$(CXX) $(CFLAGS) -fstack-check -DDEBUG=1 \
  83 + @$(CXX) $(CXXFLAGS) -fstack-check -DDEBUG=1 \
84 84 -DBUILD_DATE=`date +"0x%Y%m%d"`\
85 85 -g -o $@ -c $<
86 86  
... ... @@ -91,7 +91,7 @@ $(OBJRLS)/%.o: \
91 91  
92 92 @echo $< ...
93 93 @$(MKDIR) `dirname $@`
94   - @$(CXX) $(CFLAGS) -DNDEBUG=1 \
  94 + @$(CXX) $(CXXFLAGS) -DNDEBUG=1 \
95 95 -DBUILD_DATE=`date +"0x%Y%m%d"` \
96 96 -o $@ -c $<
97 97  
... ...
src/plugin/call.cc
... ... @@ -29,137 +29,99 @@
29 29  
30 30  
31 31 #include "private.h"
32   - #include <v3270.h>
  32 + #include <lib3270.h>
33 33 #include <lib3270/trace.h>
34 34 #include <lib3270/log.h>
  35 + #include <pw3270/v3270.h>
35 36  
36 37  
37 38 /*---[ Implement ]----------------------------------------------------------------------------------*/
38 39  
39   -namespace PW3270_NAMESPACE {
  40 +void call(GtkWidget *widget, const char *classname) {
40 41  
  42 + debug("%s(%s)",__FUNCTION__,classname);
41 43  
42   - void java::call(GtkWidget *widget, const char *classname) {
  44 + if(!trylock()) {
43 45  
44   - debug("%s(%s)",__FUNCTION__,classname);
  46 + failed(widget, _( "Can't access java virtual machine" ), "%s", strerror(EBUSY));
  47 + return;
45 48  
46   - if(!trylock()) {
47   -
48   - failed(widget, _( "Can't access java virtual machine" ), "%s", strerror(EBUSY));
49   - return;
50   -
51   - }
52   -
53   - if(jvm || load_jvm(widget)) {
54   -
55   - v3270_set_script(widget,'J',TRUE);
56   -
57   - try {
58   -
59   - jclass cls;
60   - jmethodID mid;
61   -
62   - /*
63   -
64   - DONT WORK!!
65   - http://stackoverflow.com/questions/271506/why-cant-system-setproperty-change-the-classpath-at-runtime
66   -
67   - // Atualizar o classpath
68   - cls = env->FindClass("java/lang/System");
69   - if(!cls) {
70   - throw exception( _( "Can't find class %s" ), "java/lang/System");
71   - }
72   -
73   - mid = env->GetStaticMethodID(cls, "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
74   - if(!mid) {
75   - throw exception( _( "Can't find method %s/%s" ), "java/lang/System","setProperty");
76   - }
77   -
78   - lib3270_trace_event(v3270_get_session(widget),"java.class.path=%s\n",classpath);
79   -
80   - jstring name = env->NewStringUTF("java.class.path");
81   - jstring path = env->NewStringUTF(classpath);
  49 + }
82 50  
83   - jstring rc = (jstring) env->CallObjectMethod(cls,mid,name,path);
  51 + if(jvm || load_jvm(widget)) {
84 52  
85   - env->DeleteLocalRef(name);
86   - env->DeleteLocalRef(path);
87   - env->DeleteLocalRef(rc);
88   - */
  53 + v3270_set_script(widget,'J',TRUE);
89 54  
90   - // Get application entry point.
91   - cls = env->FindClass(classname);
92   - if(!cls) {
93   - throw exception( _( "Can't find class %s" ), classname);
94   - }
  55 + try {
95 56  
96   - mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
97   - if(!mid) {
98   - throw exception( _( "Can't find method %s/%s" ), classname, "main");
99   - }
  57 + jclass cls;
  58 + jmethodID mid;
100 59  
101   - // Build arguments
102   - jobjectArray args = env->NewObjectArray(0, env->FindClass("java/lang/String"), env->NewStringUTF(""));
103   -
104   - // Call main()
105   - env->CallStaticVoidMethod(cls, mid, args);
  60 + // Get application entry point.
  61 + cls = env->FindClass(classname);
  62 + if(!cls) {
  63 + throw exception( _( "Can't find class %s" ), classname);
  64 + }
106 65  
107   - // Check for exception
108   - jthrowable exc = env->ExceptionOccurred();
109   - env->ExceptionClear();
  66 + mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
  67 + if(!mid) {
  68 + throw exception( _( "Can't find method %s/%s" ), classname, "main");
  69 + }
110 70  
111   - if (exc) {
112   - jclass throwable_class = env->FindClass("java/lang/Throwable");
  71 + // Build arguments
  72 + jobjectArray args = env->NewObjectArray(0, env->FindClass("java/lang/String"), env->NewStringUTF(""));
113 73  
114   - jmethodID jni_getMessage = env->GetMethodID(throwable_class,"getMessage","()Ljava/lang/String;");
115   - jstring j_msg = (jstring) env->CallObjectMethod(exc,jni_getMessage);
  74 + // Call main()
  75 + env->CallStaticVoidMethod(cls, mid, args);
116 76  
117   - GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
118   - GTK_DIALOG_DESTROY_WITH_PARENT,
119   - GTK_MESSAGE_ERROR,
120   - GTK_BUTTONS_OK_CANCEL,
121   - _( "Java application \"%s\" has failed." ), classname );
  77 + // Check for exception
  78 + jthrowable exc = env->ExceptionOccurred();
  79 + env->ExceptionClear();
122 80  
123   - gtk_window_set_title(GTK_WINDOW(dialog), _( "Java error" ));
  81 + if (exc) {
  82 + jclass throwable_class = env->FindClass("java/lang/Throwable");
124 83  
125   - if(!env->IsSameObject(j_msg,NULL)) {
  84 + jmethodID jni_getMessage = env->GetMethodID(throwable_class,"getMessage","()Ljava/lang/String;");
  85 + jstring j_msg = (jstring) env->CallObjectMethod(exc,jni_getMessage);
126 86  
127   - const char * msg = env->GetStringUTFChars(j_msg, 0);
  87 + GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  88 + GTK_DIALOG_DESTROY_WITH_PARENT,
  89 + GTK_MESSAGE_ERROR,
  90 + GTK_BUTTONS_OK_CANCEL,
  91 + _( "Java application \"%s\" has failed." ), classname );
128 92  
129   - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",msg);
  93 + gtk_window_set_title(GTK_WINDOW(dialog), _( "Java error" ));
130 94  
131   - env->ReleaseStringUTFChars( j_msg, msg);
132   - }
  95 + if(!env->IsSameObject(j_msg,NULL)) {
133 96  
134   - if(gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_CANCEL)
135   - gtk_main_quit();
136   - gtk_widget_destroy(dialog);
  97 + const char * msg = env->GetStringUTFChars(j_msg, 0);
137 98  
  99 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",msg);
138 100  
  101 + env->ReleaseStringUTFChars( j_msg, msg);
139 102 }
140 103  
141   - // And finish
142   - env->DeleteLocalRef(args);
  104 + if(gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_CANCEL)
  105 + gtk_main_quit();
  106 + gtk_widget_destroy(dialog);
143 107  
144   - } catch(std::exception &e) {
145   -
146   - failed(widget,_("Can't start java application"),"%s", e.what());
147 108  
148 109 }
149 110  
150   -/*
151   - g_free(dirname);
152   - g_free(classname);
153   - g_free(classpath);
154   -*/
  111 + // And finish
  112 + env->DeleteLocalRef(args);
155 113  
156   - v3270_set_script(widget,'J',FALSE);
  114 + } catch(std::exception &e) {
157 115  
158   - }
  116 + failed(widget,_("Can't start java application"),"%s", e.what());
159 117  
160   - unlock();
  118 + }
161 119  
  120 + v3270_set_script(widget,'J',FALSE);
162 121  
163 122 }
164 123  
  124 + unlock();
  125 +
  126 +
165 127 }
... ...
src/plugin/plugin.cc
... ... @@ -51,12 +51,11 @@
51 51  
52 52 #include <pw3270.h>
53 53 #include <pw3270/plugin.h>
54   - #include <v3270.h>
  54 + #include <pw3270/v3270.h>
55 55 #include <lib3270/actions.h>
56 56 #include <lib3270/log.h>
57 57 #include <lib3270/trace.h>
58 58 #include <lib3270/charset.h>
59   - #include <pw3270/class.h>
60 59 #include <pw3270/trace.h>
61 60  
62 61  
... ... @@ -75,7 +74,7 @@
75 74  
76 75 namespace PW3270_NAMESPACE {
77 76  
78   - void java::lock() {
  77 + void lock() {
79 78 #if GTK_CHECK_VERSION(2,32,0)
80 79 g_mutex_lock(&mutex);
81 80 #else
... ... @@ -83,7 +82,7 @@ namespace PW3270_NAMESPACE {
83 82 #endif // GTK_CHECK_VERSION
84 83 }
85 84  
86   - void java::unlock() {
  85 + void unlock() {
87 86 #if GTK_CHECK_VERSION(2,32,0)
88 87 g_mutex_unlock(&mutex);
89 88 #else
... ... @@ -91,7 +90,7 @@ namespace PW3270_NAMESPACE {
91 90 #endif // GTK_CHECK_VERSION
92 91 }
93 92  
94   - bool java::trylock() {
  93 + bool trylock() {
95 94 #if GTK_CHECK_VERSION(2,32,0)
96 95 return g_mutex_trylock(&mutex);
97 96 #else
... ...
src/plugin/private.h 0 → 100644
... ... @@ -0,0 +1,59 @@
  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 private.h 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 + * Referências:
  29 + *
  30 + * http://thebreakfastpost.com/2012/01/26/wrapping-a-c-library-with-jni-part-2/
  31 + *
  32 + */
  33 +#ifndef PRIVATE_H_INCLUDED
  34 +
  35 + #define PRIVATE_H_INCLUDED
  36 +
  37 + #include <jni.h>
  38 +
  39 + #include <exception>
  40 +
  41 + #include <malloc.h>
  42 + #include <libintl.h>
  43 +
  44 + #include <glib/gi18n.h>
  45 + #include <gtk/gtk.h>
  46 +
  47 + G_GNUC_INTERNAL JavaVM * jvm;
  48 + G_GNUC_INTERNAL JNIEnv * env;
  49 +
  50 + G_GNUC_INTERNAL bool load_jvm(GtkWidget *widget);
  51 + G_GNUC_INTERNAL void call(GtkWidget *widget, const char *classname);
  52 + G_GNUC_INTERNAL void lock();
  53 + G_GNUC_INTERNAL void unlock();
  54 + G_GNUC_INTERNAL bool trylock();
  55 + G_GNUC_INTERNAL void failed(GtkWidget *widget, const char *msg, const char *format, ...);
  56 +
  57 + using namespace std;
  58 +
  59 +#endif // PRIVATE_H_INCLUDED
... ...
src/plugin/startstop.cc
... ... @@ -131,289 +131,283 @@ extern &quot;C&quot; {
131 131 }
132 132  
133 133  
134   - namespace PW3270_NAMESPACE {
  134 +JavaVM * jvm = NULL;
  135 +JNIEnv * env = NULL;
135 136  
136   - JavaVM * java::jvm = NULL;
137   - JNIEnv * java::env = NULL;
138   -#ifdef _WIN32
139   - HMODULE java::hModule = NULL;
140   -#endif // _WIN32
  137 +void failed(GtkWidget *widget, const char *msg, const char *format, ...) {
141 138  
142   - void java::failed(GtkWidget *widget, const char *msg, const char *format, ...) {
  139 + GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  140 + GTK_DIALOG_DESTROY_WITH_PARENT,
  141 + GTK_MESSAGE_ERROR,
  142 + GTK_BUTTONS_OK_CANCEL,
  143 + "%s", msg );
143 144  
144   - GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
145   - GTK_DIALOG_DESTROY_WITH_PARENT,
146   - GTK_MESSAGE_ERROR,
147   - GTK_BUTTONS_OK_CANCEL,
148   - "%s", msg );
  145 + gtk_window_set_title(GTK_WINDOW(dialog), _( "Java error" ));
149 146  
150   - gtk_window_set_title(GTK_WINDOW(dialog), _( "Java error" ));
  147 + if(format) {
151 148  
152   - if(format) {
  149 + va_list arg_ptr;
  150 + va_start(arg_ptr, format);
  151 + gchar *msg = g_strdup_vprintf(format,arg_ptr);
  152 + va_end(arg_ptr);
  153 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",msg);
  154 + g_free(msg);
153 155  
154   - va_list arg_ptr;
155   - va_start(arg_ptr, format);
156   - gchar *msg = g_strdup_vprintf(format,arg_ptr);
157   - va_end(arg_ptr);
158   - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",msg);
159   - g_free(msg);
160   -
161   - }
  156 + }
162 157  
163   - if(gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_CANCEL)
164   - gtk_main_quit();
165   - gtk_widget_destroy(dialog);
  158 + if(gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_CANCEL)
  159 + gtk_main_quit();
  160 + gtk_widget_destroy(dialog);
166 161  
167   - }
  162 +}
168 163  
169 164  
170 165 #ifdef WIN32
171 166  
172   - bool java::load_jvm(GtkWidget *widget) {
  167 +bool load_jvm(GtkWidget *widget) {
173 168  
174   - if(jvm != NULL) {
175   - return true;
176   - }
  169 + if(jvm != NULL) {
  170 + return true;
  171 + }
177 172  
178   - // Dynamically load jvm library to avoid naming and path problems.
179   - HMODULE kernel;
180   - HANDLE WINAPI (*AddDllDirectory)(PCWSTR NewDirectory);
181   - BOOL WINAPI (*RemoveDllDirectory)(HANDLE Cookie);
  173 + // Dynamically load jvm library to avoid naming and path problems.
  174 + HMODULE kernel;
  175 + HANDLE WINAPI (*AddDllDirectory)(PCWSTR NewDirectory);
  176 + BOOL WINAPI (*RemoveDllDirectory)(HANDLE Cookie);
182 177  
183   - struct _dlldir {
184   - const gchar * env;
185   - const gchar * path;
186   - HANDLE cookie;
187   - } dlldir[] = {
188   - { "JRE_HOME", "bin\\client", 0 },
189   - { "JDK_HOME", "jre\\bin\\client", 0 }
190   - };
  178 + struct _dlldir {
  179 + const gchar * env;
  180 + const gchar * path;
  181 + HANDLE cookie;
  182 + } dlldir[] = {
  183 + { "JRE_HOME", "bin\\client", 0 },
  184 + { "JDK_HOME", "jre\\bin\\client", 0 }
  185 + };
191 186  
192   - kernel = LoadLibrary("kernel32.dll");
  187 + kernel = LoadLibrary("kernel32.dll");
193 188  
194   - if(kernel) {
  189 + if(kernel) {
195 190  
196   - AddDllDirectory = (HANDLE WINAPI (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
197   - if(AddDllDirectory) {
  191 + AddDllDirectory = (HANDLE WINAPI (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
  192 + if(AddDllDirectory) {
198 193  
199   - // Acrescenta mais caminhos para achar a dll
200   - for(size_t f = 0; f < G_N_ELEMENTS(dlldir); f++) {
  194 + // Acrescenta mais caminhos para achar a dll
  195 + for(size_t f = 0; f < G_N_ELEMENTS(dlldir); f++) {
201 196  
202   - const char *env = getenv(dlldir[f].env);
  197 + const char *env = getenv(dlldir[f].env);
203 198  
204   - debug("%s=\"%s\"",dlldir[f].env,env);
  199 + debug("%s=\"%s\"",dlldir[f].env,env);
205 200  
206   - if(env) {
  201 + if(env) {
207 202  
208   - gchar *p = g_build_filename(env,dlldir[f].path,NULL);
  203 + gchar *p = g_build_filename(env,dlldir[f].path,NULL);
209 204  
210   - lib3270_trace_event(v3270_get_session(widget),"Adding \"%s\" to DLL search path",p);
  205 + lib3270_trace_event(v3270_get_session(widget),"Adding \"%s\" to DLL search path",p);
211 206  
212   - wchar_t *path = (wchar_t *) malloc(4096*sizeof(wchar_t));
213   - mbstowcs(path, p, 4095);
214   - dlldir[f].cookie = AddDllDirectory(path);
215   - free(path);
  207 + wchar_t *path = (wchar_t *) malloc(4096*sizeof(wchar_t));
  208 + mbstowcs(path, p, 4095);
  209 + dlldir[f].cookie = AddDllDirectory(path);
  210 + free(path);
216 211  
217   - g_free(p);
  212 + g_free(p);
218 213  
219   - }
220 214 }
221   -
222   - } else {
223   -
224   - lib3270_trace_event(v3270_get_session(widget),"Can't find %s: %s","AddDllDirectory",session::win32_strerror(GetLastError()).c_str());
225   -
226 215 }
227 216  
228 217 } else {
229 218  
230   - lib3270_trace_event(v3270_get_session(widget),"Can't load %s: %s\n","kernel32.dll",session::win32_strerror(GetLastError()).c_str());
  219 + lib3270_trace_event(v3270_get_session(widget),"Can't find %s: %s","AddDllDirectory",session::win32_strerror(GetLastError()).c_str());
231 220  
232 221 }
233 222  
234   - hModule = LoadLibrary("jvm.dll");
235   - if(!hModule) {
236   - lib3270_trace_event(v3270_get_session(widget),"Can't load %s\n","jvm.dll",session::win32_strerror(GetLastError()).c_str());
  223 + } else {
237 224  
238   - for(size_t f = 0; !hModule && f < G_N_ELEMENTS(dlldir); f++) {
  225 + lib3270_trace_event(v3270_get_session(widget),"Can't load %s: %s\n","kernel32.dll",session::win32_strerror(GetLastError()).c_str());
239 226  
240   - const char *env = getenv(dlldir[f].env);
  227 + }
241 228  
242   - debug("%s=\"%s\"",dlldir[f].env,env);
  229 + hModule = LoadLibrary("jvm.dll");
  230 + if(!hModule) {
  231 + lib3270_trace_event(v3270_get_session(widget),"Can't load %s\n","jvm.dll",session::win32_strerror(GetLastError()).c_str());
243 232  
244   - if(env) {
  233 + for(size_t f = 0; !hModule && f < G_N_ELEMENTS(dlldir); f++) {
245 234  
246   - gchar *p = g_build_filename(env,dlldir[f].path,"jvm.dll",NULL);
247   - hModule = LoadLibrary(p);
248   - if(!hModule) {
249   - lib3270_trace_event(v3270_get_session(widget),"Can't load %s: %s\n",p,session::win32_strerror(GetLastError()).c_str());
250   - }
251   - g_free(p);
  235 + const char *env = getenv(dlldir[f].env);
252 236  
  237 + debug("%s=\"%s\"",dlldir[f].env,env);
  238 +
  239 + if(env) {
  240 +
  241 + gchar *p = g_build_filename(env,dlldir[f].path,"jvm.dll",NULL);
  242 + hModule = LoadLibrary(p);
  243 + if(!hModule) {
  244 + lib3270_trace_event(v3270_get_session(widget),"Can't load %s: %s\n",p,session::win32_strerror(GetLastError()).c_str());
253 245 }
  246 + g_free(p);
  247 +
254 248 }
255 249 }
  250 + }
256 251  
257   - if(!hModule) {
258   - failed(widget, _( "Can't load java virtual machine" ), "%s", session::win32_strerror(GetLastError()).c_str());
259   - }
  252 + if(!hModule) {
  253 + failed(widget, _( "Can't load java virtual machine" ), "%s", session::win32_strerror(GetLastError()).c_str());
  254 + }
260 255  
261   - if(kernel) {
  256 + if(kernel) {
262 257  
263   - RemoveDllDirectory = (BOOL WINAPI (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
264   - if(RemoveDllDirectory) {
  258 + RemoveDllDirectory = (BOOL WINAPI (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
  259 + if(RemoveDllDirectory) {
265 260  
266   - for(size_t f = 0; f < G_N_ELEMENTS(dlldir); f++) {
  261 + for(size_t f = 0; f < G_N_ELEMENTS(dlldir); f++) {
267 262  
268   - if(dlldir[f].cookie) {
  263 + if(dlldir[f].cookie) {
269 264  
270   - RemoveDllDirectory(dlldir[f].cookie);
  265 + RemoveDllDirectory(dlldir[f].cookie);
271 266  
272   - }
273 267 }
274   -
275 268 }
276 269  
277   - FreeLibrary(kernel);
278   -
279 270 }
280 271  
281   - if(!hModule) {
282   - return false;
283   - }
  272 + FreeLibrary(kernel);
284 273  
285   - // Consegui carregar a JVM, obtenho o método de controle
286   - jint JNICALL (*CreateJavaVM)(JavaVM **, void **, void *) = (jint JNICALL (*)(JavaVM **, void **, void *)) GetProcAddress(hModule,"JNI_CreateJavaVM");
  274 + }
287 275  
288   - if(!CreateJavaVM) {
289   - failed(widget, _( "Can't load java virtual machine creation method" ), "%s", session::win32_strerror(GetLastError()).c_str());
290   - return false;
291   - }
  276 + if(!hModule) {
  277 + return false;
  278 + }
292 279  
293   - // Crio a JVM
294   - JavaVMInitArgs vm_args;
295   - JavaVMOption options[5];
  280 + // Consegui carregar a JVM, obtenho o método de controle
  281 + jint JNICALL (*CreateJavaVM)(JavaVM **, void **, void *) = (jint JNICALL (*)(JavaVM **, void **, void *)) GetProcAddress(hModule,"JNI_CreateJavaVM");
296 282  
297   - jint rc = 0;
  283 + if(!CreateJavaVM) {
  284 + failed(widget, _( "Can't load java virtual machine creation method" ), "%s", session::win32_strerror(GetLastError()).c_str());
  285 + return false;
  286 + }
298 287  
299   - memset(&vm_args,0,sizeof(vm_args));
300   - memset(options,0,sizeof(options));
  288 + // Crio a JVM
  289 + JavaVMInitArgs vm_args;
  290 + JavaVMOption options[5];
301 291  
302   - vm_args.version = JNI_VERSION_1_4;
303   - vm_args.nOptions = 0;
304   - vm_args.options = options;
305   - vm_args.ignoreUnrecognized = JNI_FALSE;
  292 + jint rc = 0;
306 293  
307   - options[vm_args.nOptions].optionString = g_strdup("vfprintf");
308   - options[vm_args.nOptions].extraInfo = (void *) jni_vfprintf;
309   - vm_args.nOptions++;
  294 + memset(&vm_args,0,sizeof(vm_args));
  295 + memset(options,0,sizeof(options));
310 296  
311   - gchar * exports = NULL;
312   - char buffer[1024];
313   - gchar * myDir;
  297 + vm_args.version = JNI_VERSION_1_4;
  298 + vm_args.nOptions = 0;
  299 + vm_args.options = options;
  300 + vm_args.ignoreUnrecognized = JNI_FALSE;
314 301  
315   - if(GetModuleFileName(NULL,buffer,sizeof(buffer)) < sizeof(buffer)) {
  302 + options[vm_args.nOptions].optionString = g_strdup("vfprintf");
  303 + options[vm_args.nOptions].extraInfo = (void *) jni_vfprintf;
  304 + vm_args.nOptions++;
316 305  
317   - gchar * ptr = strrchr(buffer,G_DIR_SEPARATOR);
318   - if(ptr) {
319   - *ptr = 0;
320   - myDir = g_strdup(buffer);
321   - } else {
322   - myDir = g_strdup(".");
323   - }
  306 + gchar * exports = NULL;
  307 + char buffer[1024];
  308 + gchar * myDir;
324 309  
  310 + if(GetModuleFileName(NULL,buffer,sizeof(buffer)) < sizeof(buffer)) {
325 311  
  312 + gchar * ptr = strrchr(buffer,G_DIR_SEPARATOR);
  313 + if(ptr) {
  314 + *ptr = 0;
  315 + myDir = g_strdup(buffer);
326 316 } else {
327   -
328 317 myDir = g_strdup(".");
329   -
330 318 }
331 319  
332   - debug("myDir=%s",myDir);
333 320  
334   - exports = g_build_filename(myDir,"jvm-exports",NULL);
335   - g_mkdir_with_parents(exports,0777);
  321 + } else {
336 322  
337   - lib3270_trace_event(v3270_get_session(widget),"java.class.path=%s",exports);
338   - lib3270_trace_event(v3270_get_session(widget),"java.library.path=%s",myDir);
  323 + myDir = g_strdup(".");
339 324  
340   - options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=%s",exports);
341   - options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=%s",myDir);
  325 + }
342 326  
343   - g_free(myDir);
344   - g_free(exports);
  327 + debug("myDir=%s",myDir);
345 328  
346   - rc = CreateJavaVM(&jvm,(void **)&env,&vm_args);
347   - if(rc < 0) {
348   - failed(widget, _( "Can't create java VM" ), _( "The error code was %d" ), (int) rc);
349   - jvm = NULL;
350   - }
  329 + exports = g_build_filename(myDir,"jvm-exports",NULL);
  330 + g_mkdir_with_parents(exports,0777);
351 331  
352   - for(int f=0;f<vm_args.nOptions;f++) {
353   - trace("Releasing option %d: %s",f,options[f].optionString);
354   - g_free(options[f].optionString);
355   - }
  332 + lib3270_trace_event(v3270_get_session(widget),"java.class.path=%s",exports);
  333 + lib3270_trace_event(v3270_get_session(widget),"java.library.path=%s",myDir);
  334 +
  335 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=%s",exports);
  336 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=%s",myDir);
356 337  
  338 + g_free(myDir);
  339 + g_free(exports);
357 340  
358   - return jvm != NULL;
  341 + rc = CreateJavaVM(&jvm,(void **)&env,&vm_args);
  342 + if(rc < 0) {
  343 + failed(widget, _( "Can't create java VM" ), _( "The error code was %d" ), (int) rc);
  344 + jvm = NULL;
  345 + }
359 346  
  347 + for(int f=0;f<vm_args.nOptions;f++) {
  348 + trace("Releasing option %d: %s",f,options[f].optionString);
  349 + g_free(options[f].optionString);
360 350 }
361 351  
362 352  
  353 + return jvm != NULL;
  354 +
  355 +}
  356 +
  357 +
363 358  
364 359 #else
365 360  
366   - bool java::load_jvm(GtkWidget *widget) {
  361 +bool load_jvm(GtkWidget *widget) {
367 362  
368   - if(jvm != NULL) {
369   - return true;
370   - }
  363 + if(jvm != NULL) {
  364 + return true;
  365 + }
371 366  
372   - // Start JNI
373   - JavaVMInitArgs vm_args;
374   - JavaVMOption options[5];
375   - jint rc = 0;
  367 + // Start JNI
  368 + JavaVMInitArgs vm_args;
  369 + JavaVMOption options[5];
  370 + jint rc = 0;
376 371  
377 372  
378   - memset(&vm_args,0,sizeof(vm_args));
379   - memset(options,0,sizeof(options));
  373 + memset(&vm_args,0,sizeof(vm_args));
  374 + memset(options,0,sizeof(options));
380 375  
381   - vm_args.version = JNI_VERSION_1_4;
382   - vm_args.nOptions = 0;
383   - vm_args.options = options;
384   - vm_args.ignoreUnrecognized = JNI_FALSE;
  376 + vm_args.version = JNI_VERSION_1_4;
  377 + vm_args.nOptions = 0;
  378 + vm_args.options = options;
  379 + vm_args.ignoreUnrecognized = JNI_FALSE;
385 380  
386   - options[vm_args.nOptions].optionString = g_strdup("vfprintf");
387   - options[vm_args.nOptions].extraInfo = (void *) jni_vfprintf;
388   - vm_args.nOptions++;
  381 + options[vm_args.nOptions].optionString = g_strdup("vfprintf");
  382 + options[vm_args.nOptions].extraInfo = (void *) jni_vfprintf;
  383 + vm_args.nOptions++;
389 384  
390 385 #if defined(DEBUG)
391 386  
392 387 // options[vm_args.nOptions++].optionString = g_strdup("-verbose");
393   - options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=.bin/Debug:.bin/Debug/lib:%s",JNIDIR);
394   - options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=./src/java:.bin/java:%s",JARDIR);
  388 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=.bin/Debug:.bin/Debug/lib:%s",JNIDIR);
  389 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=./src/java:.bin/java:%s",JARDIR);
395 390  
396 391 #else
397 392  
398   - options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=%s",JNIDIR);
399   - options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=%s",JARDIR);
  393 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.library.path=%s",JNIDIR);
  394 + options[vm_args.nOptions++].optionString = g_strdup_printf("-Djava.class.path=%s",JARDIR);
400 395  
401 396 #endif // JNIDIR
402 397  
403   - // Linux, just create JVM
404   - rc = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
405   -
406   - if(rc) {
407   - jvm = NULL;
408   - failed(widget, _( "Can't create java virtual machine" ), _( "The return code was %d" ), (int) rc);
409   - }
  398 + // Linux, just create JVM
  399 + rc = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
410 400  
411   - return jvm != NULL;
  401 + if(rc) {
  402 + jvm = NULL;
  403 + failed(widget, _( "Can't create java virtual machine" ), _( "The return code was %d" ), (int) rc);
412 404 }
413 405  
  406 + return jvm != NULL;
  407 +}
  408 +
414 409  
415 410 #endif // WIN32
416 411  
417   - }
418 412  
419 413  
... ...