Commit a69872eaaa3ad0759d0e5648abb215daa04086f4
1 parent
137bb9df
Exists in
master
and in
5 other branches
Reimplementando plugin java
Showing
4 changed files
with
102 additions
and
119 deletions
Show diff stats
src/java/main.cc
| ... | ... | @@ -34,11 +34,6 @@ |
| 34 | 34 | |
| 35 | 35 | namespace PW3270_NAMESPACE { |
| 36 | 36 | |
| 37 | - void java::set_factory(PW3270_NAMESPACE::session * (*factory)(const char *name)) { | |
| 38 | - trace("%s(%p)",__FUNCTION__,factory); | |
| 39 | - session::set_plugin(factory); | |
| 40 | - } | |
| 41 | - | |
| 42 | 37 | jfieldID java::getHandleField(JNIEnv *env, jobject obj) { |
| 43 | 38 | jclass c = env->GetObjectClass(obj); |
| 44 | 39 | // J is the type signature for long: | ... | ... |
src/java/plugin.cc
| ... | ... | @@ -325,12 +325,76 @@ |
| 325 | 325 | |
| 326 | 326 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 327 | 327 | |
| 328 | +namespace PW3270_NAMESPACE { | |
| 329 | + | |
| 330 | + void java::lock() { | |
| 331 | +#if GTK_CHECK_VERSION(2,32,0) | |
| 332 | + g_mutex_lock(&mutex); | |
| 333 | +#else | |
| 334 | + g_static_mutex_lock(&mutex); | |
| 335 | +#endif // GTK_CHECK_VERSION | |
| 336 | + } | |
| 337 | + | |
| 338 | + void java::unlock() { | |
| 339 | +#if GTK_CHECK_VERSION(2,32,0) | |
| 340 | + g_mutex_unlock(&mutex); | |
| 341 | +#else | |
| 342 | + g_static_mutex_unlock(&mutex); | |
| 343 | +#endif // GTK_CHECK_VERSION | |
| 344 | + } | |
| 345 | + | |
| 346 | + bool java::trylock() { | |
| 347 | +#if GTK_CHECK_VERSION(2,32,0) | |
| 348 | + return g_mutex_trylock(&mutex); | |
| 349 | +#else | |
| 350 | + return g_static_mutex_trylock(&mutex); | |
| 351 | +#endif // GTK_CHECK_VERSION | |
| 352 | + } | |
| 353 | + | |
| 354 | +} | |
| 355 | + | |
| 356 | +using namespace PW3270_NAMESPACE; | |
| 357 | + | |
| 328 | 358 | extern "C" { |
| 329 | 359 | |
| 330 | - PW3270_NAMESPACE::session * factory(const char *name) { | |
| 360 | + static PW3270_NAMESPACE::session * factory(const char *name) { | |
| 331 | 361 | debug("---> %s",__FUNCTION__); |
| 332 | 362 | return new plugin(lib3270_get_default_session_handle()); |
| 333 | 363 | } |
| 334 | 364 | |
| 365 | + LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window) { | |
| 366 | + | |
| 367 | + trace("JAVA: %s",__FUNCTION__); | |
| 368 | + | |
| 369 | + #if GTK_CHECK_VERSION(2,32,0) | |
| 370 | + g_mutex_init(&mutex); | |
| 371 | + #endif // GTK_CHECK_VERSION | |
| 372 | + | |
| 373 | + session::set_plugin(factory); | |
| 374 | + | |
| 375 | + return 0; | |
| 376 | + } | |
| 377 | + | |
| 378 | + LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window) { | |
| 379 | + | |
| 380 | + java::lock(); | |
| 381 | + | |
| 382 | + if(java::jvm) { | |
| 383 | + java::jvm->DestroyJavaVM(); | |
| 384 | + java::jvm = NULL; | |
| 385 | + } | |
| 386 | + | |
| 387 | + java::unlock(); | |
| 388 | + | |
| 389 | + #if GTK_CHECK_VERSION(2,32,0) | |
| 390 | + g_mutex_clear(&mutex); | |
| 391 | + #endif // GTK_CHECK_VERSION | |
| 392 | + | |
| 393 | + trace("JAVA: %s",__FUNCTION__); | |
| 394 | + | |
| 395 | + return 0; | |
| 396 | + } | |
| 397 | + | |
| 398 | + | |
| 335 | 399 | } |
| 336 | 400 | ... | ... |
src/java/private.h
| ... | ... | @@ -52,8 +52,6 @@ |
| 52 | 52 | extern JavaVM * jvm; |
| 53 | 53 | extern JNIEnv * env; |
| 54 | 54 | |
| 55 | - void set_factory(PW3270_NAMESPACE::session * (*factory)(const char *name)); | |
| 56 | - | |
| 57 | 55 | PW3270_NAMESPACE::session * getHandle(JNIEnv *env, jobject obj); |
| 58 | 56 | jfieldID getHandleField(JNIEnv *env, jobject obj); |
| 59 | 57 | |
| ... | ... | @@ -75,12 +73,6 @@ |
| 75 | 73 | |
| 76 | 74 | } |
| 77 | 75 | |
| 78 | - extern "C" { | |
| 79 | - | |
| 80 | - LIB3270_EXPORT void set_java_session_factory(PW3270_NAMESPACE::session * (*factory)(const char *name)); | |
| 81 | - extern PW3270_NAMESPACE::session * factory(const char *name); | |
| 82 | - | |
| 83 | - } | |
| 84 | 76 | |
| 85 | 77 | |
| 86 | 78 | ... | ... |
src/java/startstop.cc
| ... | ... | @@ -58,16 +58,6 @@ |
| 58 | 58 | #include <pw3270/class.h> |
| 59 | 59 | #include <pw3270/trace.h> |
| 60 | 60 | |
| 61 | -/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
| 62 | - | |
| 63 | -#if GTK_CHECK_VERSION(2,32,0) | |
| 64 | - static GMutex mutex; | |
| 65 | - | |
| 66 | -#else | |
| 67 | - static GStaticMutex mutex = G_STATIC_MUTEX_INIT; | |
| 68 | - | |
| 69 | -#endif // GTK_CHECK_VERSION | |
| 70 | - | |
| 71 | 61 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 72 | 62 | |
| 73 | 63 | using namespace PW3270_NAMESPACE::java; |
| ... | ... | @@ -112,118 +102,60 @@ extern "C" { |
| 112 | 102 | return 0; |
| 113 | 103 | } |
| 114 | 104 | |
| 115 | - } | |
| 116 | - | |
| 117 | - LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window) | |
| 118 | - { | |
| 119 | - trace("JAVA: %s",__FUNCTION__); | |
| 120 | -#if GTK_CHECK_VERSION(2,32,0) | |
| 121 | - g_mutex_init(&mutex); | |
| 122 | -#endif // GTK_CHECK_VERSION | |
| 123 | - | |
| 124 | - set_factory(factory); | |
| 125 | - | |
| 126 | - return 0; | |
| 127 | - } | |
| 128 | - | |
| 129 | - LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window) | |
| 130 | - { | |
| 131 | - lock(); | |
| 105 | + LIB3270_EXPORT void pw3270_action_java_activated(GtkAction *action, GtkWidget *widget) { | |
| 132 | 106 | |
| 133 | - if(jvm) { | |
| 134 | - jvm->DestroyJavaVM(); | |
| 135 | - jvm = NULL; | |
| 136 | - } | |
| 107 | + gchar *filename = (gchar *) g_object_get_data(G_OBJECT(action),"src"); | |
| 137 | 108 | |
| 138 | - unlock(); | |
| 139 | - | |
| 140 | -#if GTK_CHECK_VERSION(2,32,0) | |
| 141 | - g_mutex_clear(&mutex); | |
| 142 | -#endif // GTK_CHECK_VERSION | |
| 143 | - trace("JAVA: %s",__FUNCTION__); | |
| 144 | - | |
| 145 | - | |
| 146 | - | |
| 147 | - return 0; | |
| 148 | - } | |
| 149 | - | |
| 150 | - LIB3270_EXPORT void pw3270_action_java_activated(GtkAction *action, GtkWidget *widget) | |
| 151 | - { | |
| 152 | - gchar *filename = (gchar *) g_object_get_data(G_OBJECT(action),"src"); | |
| 153 | - | |
| 154 | - lib3270_trace_event(v3270_get_session(widget),"Action %s activated on widget %p",gtk_action_get_name(action),widget); | |
| 155 | - | |
| 156 | - if(filename) | |
| 157 | - { | |
| 158 | - // Has filename, call it directly | |
| 159 | - call(widget,filename); | |
| 160 | - } | |
| 161 | - else | |
| 162 | - { | |
| 163 | - // No filename, ask user | |
| 164 | - static const struct _list | |
| 165 | - { | |
| 166 | - const gchar *name; | |
| 167 | - const gchar *pattern; | |
| 168 | - } list[] = | |
| 169 | - { | |
| 170 | - { N_( "Java class file" ), "*.class" } | |
| 171 | - }; | |
| 172 | - | |
| 173 | - GtkFileFilter * filter[G_N_ELEMENTS(list)+1]; | |
| 174 | - unsigned int f; | |
| 175 | - | |
| 176 | - memset(filter,0,sizeof(filter)); | |
| 177 | - | |
| 178 | - for(f=0;f<G_N_ELEMENTS(list);f++) | |
| 179 | - { | |
| 180 | - filter[f] = gtk_file_filter_new(); | |
| 181 | - gtk_file_filter_set_name(filter[f],gettext(list[f].name)); | |
| 182 | - gtk_file_filter_add_pattern(filter[f],list[f].pattern); | |
| 183 | - } | |
| 184 | - | |
| 185 | - filename = pw3270_get_filename(widget,"java","script",filter,_( "Select script to run" )); | |
| 109 | + lib3270_trace_event(v3270_get_session(widget),"Action %s activated on widget %p",gtk_action_get_name(action),widget); | |
| 186 | 110 | |
| 187 | 111 | if(filename) |
| 188 | 112 | { |
| 113 | + // Has filename, call it directly | |
| 189 | 114 | call(widget,filename); |
| 190 | - g_free(filename); | |
| 191 | 115 | } |
| 116 | + else | |
| 117 | + { | |
| 118 | + // No filename, ask user | |
| 119 | + static const struct _list | |
| 120 | + { | |
| 121 | + const gchar *name; | |
| 122 | + const gchar *pattern; | |
| 123 | + } list[] = | |
| 124 | + { | |
| 125 | + { N_( "Java class file" ), "*.class" } | |
| 126 | + }; | |
| 127 | + | |
| 128 | + GtkFileFilter * filter[G_N_ELEMENTS(list)+1]; | |
| 129 | + unsigned int f; | |
| 130 | + | |
| 131 | + memset(filter,0,sizeof(filter)); | |
| 132 | + | |
| 133 | + for(f=0;f<G_N_ELEMENTS(list);f++) | |
| 134 | + { | |
| 135 | + filter[f] = gtk_file_filter_new(); | |
| 136 | + gtk_file_filter_set_name(filter[f],gettext(list[f].name)); | |
| 137 | + gtk_file_filter_add_pattern(filter[f],list[f].pattern); | |
| 138 | + } | |
| 139 | + | |
| 140 | + filename = pw3270_get_filename(widget,"java","script",filter,_( "Select script to run" )); | |
| 141 | + | |
| 142 | + if(filename) | |
| 143 | + { | |
| 144 | + call(widget,filename); | |
| 145 | + g_free(filename); | |
| 146 | + } | |
| 192 | 147 | |
| 148 | + } | |
| 193 | 149 | |
| 194 | 150 | } |
| 195 | - | |
| 196 | 151 | } |
| 197 | 152 | |
| 153 | + | |
| 198 | 154 | namespace PW3270_NAMESPACE { |
| 199 | 155 | |
| 200 | 156 | JavaVM * java::jvm = NULL; |
| 201 | 157 | JNIEnv * java::env = NULL; |
| 202 | 158 | |
| 203 | - void java::lock() { | |
| 204 | -#if GTK_CHECK_VERSION(2,32,0) | |
| 205 | - g_mutex_lock(&mutex); | |
| 206 | -#else | |
| 207 | - g_static_mutex_lock(&mutex); | |
| 208 | -#endif // GTK_CHECK_VERSION | |
| 209 | - } | |
| 210 | - | |
| 211 | - void java::unlock() { | |
| 212 | -#if GTK_CHECK_VERSION(2,32,0) | |
| 213 | - g_mutex_unlock(&mutex); | |
| 214 | -#else | |
| 215 | - g_static_mutex_unlock(&mutex); | |
| 216 | -#endif // GTK_CHECK_VERSION | |
| 217 | - } | |
| 218 | - | |
| 219 | - bool java::trylock() { | |
| 220 | -#if GTK_CHECK_VERSION(2,32,0) | |
| 221 | - return g_mutex_trylock(&mutex); | |
| 222 | -#else | |
| 223 | - return g_static_mutex_trylock(&mutex); | |
| 224 | -#endif // GTK_CHECK_VERSION | |
| 225 | - } | |
| 226 | - | |
| 227 | 159 | void java::failed(GtkWidget *widget, const char *msg, const char *format, ...) { |
| 228 | 160 | |
| 229 | 161 | GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)), | ... | ... |