Commit f2cb8889abeb77db5fa0d27505db60198cac1c88
1 parent
0d4cada2
Exists in
master
and in
5 other branches
Incluindo suporte à chamada de ações pelo nome (para uso em scripts)
Showing
17 changed files
with
154 additions
and
106 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -193,6 +193,9 @@ |
| 193 | 193 | <Unit filename="src/lib3270/3270ds.h" /> |
| 194 | 194 | <Unit filename="src/lib3270/Makefile.in" /> |
| 195 | 195 | <Unit filename="src/lib3270/X11keysym.h" /> |
| 196 | + <Unit filename="src/lib3270/actions.c"> | |
| 197 | + <Option compilerVar="CC" /> | |
| 198 | + </Unit> | |
| 196 | 199 | <Unit filename="src/lib3270/ansi.c"> |
| 197 | 200 | <Option compilerVar="CC" /> |
| 198 | 201 | </Unit> | ... | ... |
src/classlib/local.cc
| ... | ... | @@ -158,6 +158,7 @@ |
| 158 | 158 | int (*_erase_eof)(H3270 *hSession); |
| 159 | 159 | int (*_erase_eol)(H3270 *hSession); |
| 160 | 160 | int (*_erase_input)(H3270 *hSession); |
| 161 | + int (*_action)(H3270 *hSession, const char *name); | |
| 161 | 162 | |
| 162 | 163 | const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz); |
| 163 | 164 | const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz); |
| ... | ... | @@ -223,6 +224,7 @@ |
| 223 | 224 | { (void **) & _ebc2asc, "lib3270_ebc2asc" }, |
| 224 | 225 | { (void **) & _asc2ebc, "lib3270_asc2ebc" }, |
| 225 | 226 | |
| 227 | + { (void **) & _action, "lib3270_action" }, | |
| 226 | 228 | }; |
| 227 | 229 | |
| 228 | 230 | for(unsigned int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++) |
| ... | ... | @@ -468,6 +470,11 @@ |
| 468 | 470 | return _ebc2asc(hSession,str,sz); |
| 469 | 471 | } |
| 470 | 472 | |
| 473 | + int action(const char *name) | |
| 474 | + { | |
| 475 | + return _action(hSession,name); | |
| 476 | + } | |
| 477 | + | |
| 471 | 478 | }; |
| 472 | 479 | |
| 473 | 480 | session * session::create_local(void) throw (std::exception) | ... | ... |
src/classlib/remote.cc
| ... | ... | @@ -1156,6 +1156,33 @@ |
| 1156 | 1156 | |
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | + int action(const char *str) | |
| 1160 | + { | |
| 1161 | + | |
| 1162 | +#if defined(WIN32) | |
| 1163 | + | |
| 1164 | + size_t len = strlen(str); | |
| 1165 | + struct hllapi_packet_text * query; | |
| 1166 | + size_t cbSize = sizeof(struct hllapi_packet_text)+len; | |
| 1167 | + | |
| 1168 | + query = (struct hllapi_packet_text *) malloc(cbSize); | |
| 1169 | + query->packet_id = HLLAPI_PACKET_ACTION; | |
| 1170 | + strcpy(query->text,str); | |
| 1171 | + | |
| 1172 | + return query_intval((void *) query, cbSize, true); | |
| 1173 | + | |
| 1174 | +#elif defined(HAVE_DBUS) | |
| 1175 | + | |
| 1176 | + return query_intval("action", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 1177 | +#else | |
| 1178 | + | |
| 1179 | + return -1; | |
| 1180 | + | |
| 1181 | +#endif | |
| 1182 | + | |
| 1183 | + } | |
| 1184 | + | |
| 1185 | + | |
| 1159 | 1186 | int get_field_start(int baddr) |
| 1160 | 1187 | { |
| 1161 | 1188 | #if defined(WIN32) | ... | ... |
src/include/lib3270.h
| ... | ... | @@ -1028,6 +1028,9 @@ |
| 1028 | 1028 | LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr); |
| 1029 | 1029 | LIB3270_EXPORT int lib3270_is_protected_at(H3270 *h, unsigned int row, unsigned int col); |
| 1030 | 1030 | |
| 1031 | + LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name); | |
| 1032 | + | |
| 1033 | + | |
| 1031 | 1034 | /** |
| 1032 | 1035 | * Alloc/Realloc memory buffer. |
| 1033 | 1036 | * | ... | ... |
src/include/pw3270/class.h
src/include/pw3270/ipcpackets.h
src/java/actions.cc
| ... | ... | @@ -147,3 +147,25 @@ JNIEXPORT jint JNICALL Java_pw3270_terminal_print(JNIEnv *env, jobject obj) { |
| 147 | 147 | return rc; |
| 148 | 148 | |
| 149 | 149 | } |
| 150 | + | |
| 151 | +JNIEXPORT jint JNICALL Java_pw3270_terminal_action(JNIEnv *env, jobject obj, jstring j_name) { | |
| 152 | + | |
| 153 | + jint rc = -1; | |
| 154 | + const char * name = env->GetStringUTFChars(j_name, 0); | |
| 155 | + | |
| 156 | + try { | |
| 157 | + | |
| 158 | + rc = java::getHandle(env,obj)->action(name); | |
| 159 | + | |
| 160 | + } catch(std::exception &e) { | |
| 161 | + | |
| 162 | + env->ReleaseStringUTFChars( j_name, name); | |
| 163 | + env->ThrowNew(env->FindClass("java/lang/Exception"), e.what()); | |
| 164 | + return -1; | |
| 165 | + | |
| 166 | + } | |
| 167 | + | |
| 168 | + env->ReleaseStringUTFChars( j_name, name); | |
| 169 | + return rc; | |
| 170 | + | |
| 171 | +} | ... | ... |
src/java/plugin.cc
src/java/terminal.java
| ... | ... | @@ -350,6 +350,16 @@ public class terminal |
| 350 | 350 | public native int popup_dialog(int id, String title, String message, String secondary); |
| 351 | 351 | |
| 352 | 352 | /** |
| 353 | + * Launch a lib3270 action by name. | |
| 354 | + * | |
| 355 | + * @param name Name of the action to fire. | |
| 356 | + * | |
| 357 | + * @return Return code of the action call. | |
| 358 | + * | |
| 359 | + */ | |
| 360 | + public native int action(String name); | |
| 361 | + | |
| 362 | + /** | |
| 353 | 363 | * File selection dialog. |
| 354 | 364 | * |
| 355 | 365 | * @param action Dialog action. | ... | ... |
src/lib3270/actions.c
| ... | ... | @@ -18,122 +18,67 @@ |
| 18 | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple |
| 19 | 19 | * Place, Suite 330, Boston, MA, 02111-1307, USA |
| 20 | 20 | * |
| 21 | - * Este programa está nomeado como actions.c e possui 877 linhas de código. | |
| 21 | + * Este programa está nomeado como actions.c e possui - linhas de código. | |
| 22 | 22 | * |
| 23 | 23 | * Contatos: |
| 24 | 24 | * |
| 25 | 25 | * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) |
| 26 | 26 | * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) |
| 27 | - * licinio@bb.com.br (Licínio Luis Branco) | |
| 28 | - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
| 29 | - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) | |
| 30 | 27 | * |
| 31 | 28 | */ |
| 32 | 29 | |
| 33 | -/* | |
| 34 | - * actions.c | |
| 35 | - * The X actions table and action debugging code. | |
| 36 | - */ | |
| 37 | - | |
| 38 | 30 | #include "globals.h" |
| 39 | -#include "appres.h" | |
| 31 | +#include <lib3270/trace.h> | |
| 40 | 32 | |
| 41 | -#include "actionsc.h" | |
| 42 | -#include "hostc.h" | |
| 43 | -#include "kybdc.h" | |
| 44 | -#include "popupsc.h" | |
| 45 | -#include "printc.h" | |
| 46 | -#include "resources.h" | |
| 47 | -#include "togglesc.h" | |
| 48 | -#include "trace_dsc.h" | |
| 49 | -#include "utilc.h" | |
| 50 | -#include "xioc.h" | |
| 33 | +/*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ | |
| 51 | 34 | |
| 52 | -#if defined(X3270_FT) /*[*/ | |
| 53 | -#include "ftc.h" | |
| 54 | -#endif /*]*/ | |
| 55 | -// #if defined(X3270_DISPLAY) | |
| 56 | -// #include "keypadc.h" | |
| 57 | -//#endif | |
| 58 | -#if defined(X3270_DISPLAY) || defined(C3270) || defined(WC3270) /*[*/ | |
| 59 | -#include "screenc.h" | |
| 60 | -#endif /*]*/ | |
| 35 | +/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ | |
| 61 | 36 | |
| 62 | -#error Deprecated | |
| 37 | +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ | |
| 63 | 38 | |
| 64 | -/* | |
| 39 | +/** | |
| 40 | + * @brief Launch an action by name. | |
| 41 | + * | |
| 42 | + */ | |
| 43 | +LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name) | |
| 44 | +{ | |
| 45 | + #undef DECLARE_LIB3270_ACTION | |
| 46 | + #undef DECLARE_LIB3270_CLEAR_SELECTION_ACTION | |
| 47 | + #undef DECLARE_LIB3270_KEY_ACTION | |
| 48 | + #undef DECLARE_LIB3270_CURSOR_ACTION | |
| 49 | + #undef DECLARE_LIB3270_FKEY_ACTION | |
| 65 | 50 | |
| 66 | -#if defined(X3270_DISPLAY) | |
| 67 | -#include <X11/keysym.h> | |
| 51 | + #define DECLARE_LIB3270_ACTION( name ) { #name, lib3270_ ## name }, | |
| 52 | + #define DECLARE_LIB3270_CLEAR_SELECTION_ACTION( name ) { #name, lib3270_ ## name }, | |
| 53 | + #define DECLARE_LIB3270_KEY_ACTION( name ) { #name, lib3270_ ## name }, | |
| 54 | + #define DECLARE_LIB3270_CURSOR_ACTION( name ) { #name, lib3270_cursor_ ## name }, | |
| 55 | + #define DECLARE_LIB3270_FKEY_ACTION( name ) // name | |
| 68 | 56 | |
| 69 | -#define MODMAP_SIZE 8 | |
| 70 | -#define MAP_SIZE 13 | |
| 71 | -#define MAX_MODS_PER 4 | |
| 72 | -static struct { | |
| 73 | - const char *name[MAX_MODS_PER]; | |
| 74 | - unsigned int mask; | |
| 75 | - Boolean is_meta; | |
| 76 | -} skeymask[MAP_SIZE] = { | |
| 77 | - { { "Shift" }, ShiftMask, False }, | |
| 78 | - { { (char *)NULL } //, LockMask, False }, | |
| 79 | - { { "Ctrl" }, ControlMask, False }, | |
| 80 | - { { CN }, Mod1Mask, False }, | |
| 81 | - { { CN }, Mod2Mask, False }, | |
| 82 | - { { CN }, Mod3Mask, False }, | |
| 83 | - { { CN }, Mod4Mask, False }, | |
| 84 | - { { CN }, Mod5Mask, False }, | |
| 85 | - { { "Button1" }, Button1Mask, False }, | |
| 86 | - { { "Button2" }, Button2Mask, False }, | |
| 87 | - { { "Button3" }, Button3Mask, False }, | |
| 88 | - { { "Button4" }, Button4Mask, False }, | |
| 89 | - { { "Button5" }, Button5Mask, False } | |
| 90 | -}; | |
| 91 | -static Boolean know_mods = False; | |
| 92 | -#endif */ | |
| 57 | + static const struct _action | |
| 58 | + { | |
| 59 | + const char * name; | |
| 60 | + int (*call)(H3270 *h); | |
| 61 | + } action[] = | |
| 62 | + { | |
| 63 | + #include <lib3270/action_table.h> | |
| 64 | + }; | |
| 93 | 65 | |
| 94 | -/* Actions that are aliases for other actions. */ | |
| 95 | -/* | |
| 96 | -static char *aliased_actions[] = { | |
| 97 | - "Close", "HardPrint", "Open", NULL | |
| 98 | -}; | |
| 99 | -*/ | |
| 66 | + size_t f; | |
| 100 | 67 | |
| 101 | -/* | |
| 102 | -enum iaction ia_cause; | |
| 103 | -const char *ia_name[] = { | |
| 104 | - "String", "Paste", "Screen redraw", "Keypad", "Default", "Key", | |
| 105 | - "Macro", "Script", "Peek", "Typeahead", "File transfer", "Command", | |
| 106 | - "Keymap", "Idle" | |
| 107 | -}; | |
| 108 | -*/ | |
| 68 | + CHECK_SESSION_HANDLE(hSession); | |
| 109 | 69 | |
| 110 | -/* | |
| 111 | - * Return a name for an action. | |
| 112 | - */ /* | |
| 113 | -const char * action_name(XtActionProc action) | |
| 114 | -{ | |
| 115 | - // TODO (perry#1#): Remove all calls to action_name; move all action processing to main program. | |
| 116 | - return "Action"; | |
| 117 | -} | |
| 118 | -*/ | |
| 119 | -/* | |
| 120 | - * Check the number of argument to an action, and possibly pop up a usage | |
| 121 | - * message. | |
| 122 | - * | |
| 123 | - * Returns 0 if the argument count is correct, -1 otherwise. | |
| 124 | - */ /* | |
| 125 | -int | |
| 126 | -check_usage(XtActionProc action, Cardinal nargs, Cardinal nargs_min, | |
| 127 | - Cardinal nargs_max) | |
| 128 | -{ | |
| 129 | - if (nargs >= nargs_min && nargs <= nargs_max) | |
| 130 | - return 0; | |
| 131 | - if (nargs_min == nargs_max) | |
| 132 | - popup_an_error("Action requires %d argument%s",action, nargs_min, nargs_min == 1 ? "" : "s"); | |
| 133 | - else | |
| 134 | - popup_an_error("Action requires %d or %d arguments",nargs_min, nargs_max); | |
| 135 | -// cancel_if_idle_command(); | |
| 136 | - return -1; | |
| 137 | -} */ | |
| 70 | + for(f=0; f< (sizeof(action)/sizeof(action[0])); f++) | |
| 71 | + { | |
| 72 | + if(!strcasecmp(name,action[f].name)) | |
| 73 | + { | |
| 74 | + lib3270_trace_event(hSession,"Action %s activated\n",name); | |
| 75 | + return action[f].call(hSession); | |
| 76 | + } | |
| 77 | + | |
| 78 | + } | |
| 138 | 79 | |
| 80 | + lib3270_trace_event(hSession,"Unknown action %s\n",name); | |
| 81 | + errno = ENOENT; | |
| 82 | + return -1; | |
| 139 | 83 | |
| 84 | +} | ... | ... |
src/lib3270/sources.mak
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | TERMINAL_SOURCES = bounds.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \ |
| 29 | 29 | host.c sf.c ansi.c resolver.c charset.c \ |
| 30 | 30 | version.c session.c state.c html.c trace_ds.c see.c \ |
| 31 | - paste.c ssl.c | |
| 31 | + paste.c ssl.c actions.c | |
| 32 | 32 | |
| 33 | 33 | # tables.c utf8.c |
| 34 | 34 | ... | ... |
src/plugins/dbus3270/gobject.c
| ... | ... | @@ -430,9 +430,14 @@ void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *cont |
| 430 | 430 | dbus_g_method_return(context,lib3270_get_is_protected_at(pw3270_dbus_get_session_handle(object),row,col)); |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) | |
| 434 | + { | |
| 435 | + trace("%s object=%p context=%p",__FUNCTION__,object,context); | |
| 436 | + dbus_g_method_return(context,lib3270_action(pw3270_dbus_get_session_handle(object),text)); | |
| 437 | + } | |
| 433 | 438 | |
| 434 | -void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context) | |
| 435 | -{ | |
| 439 | + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context) | |
| 440 | + { | |
| 436 | 441 | gchar *text; |
| 437 | 442 | |
| 438 | 443 | trace("%s object=%p context=%p",__FUNCTION__,object,context); | ... | ... |
src/plugins/dbus3270/pw3270dbus.xml
| ... | ... | @@ -197,6 +197,12 @@ |
| 197 | 197 | <arg type="s" name="to" direction="out" /> |
| 198 | 198 | </method> |
| 199 | 199 | |
| 200 | + <method name="action"> | |
| 201 | + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> | |
| 202 | + <arg type="s" name="name" direction="in" /> | |
| 203 | + <arg type="i" name="result" direction="out" /> | |
| 204 | + </method> | |
| 205 | + | |
| 200 | 206 | <method name="filetransfer"> |
| 201 | 207 | <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> |
| 202 | 208 | <arg type="s" name="local" direction="in" /> | ... | ... |
src/plugins/dbus3270/service.h
| ... | ... | @@ -90,13 +90,15 @@ |
| 90 | 90 | void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); |
| 91 | 91 | void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); |
| 92 | 92 | |
| 93 | - void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); | |
| 93 | + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); | |
| 94 | 94 | void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); |
| 95 | 95 | |
| 96 | 96 | void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context); |
| 97 | 97 | |
| 98 | 98 | void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context); |
| 99 | 99 | |
| 100 | + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); | |
| 101 | + | |
| 100 | 102 | // Actions |
| 101 | 103 | void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 102 | 104 | void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); | ... | ... |
src/plugins/hllapi/pluginmain.c
| ... | ... | @@ -386,6 +386,12 @@ |
| 386 | 386 | send_text(source,(char *) lib3270_get_host_charset(lib3270_get_default_session_handle())); |
| 387 | 387 | break; |
| 388 | 388 | |
| 389 | + case HLLAPI_PACKET_ACTION: | |
| 390 | + send_result(source,lib3270_action(lib3270_get_default_session_handle(), | |
| 391 | + (const char *) ((struct hllapi_packet_text *) source->buffer)->text); | |
| 392 | + break; | |
| 393 | + | |
| 394 | + | |
| 389 | 395 | default: |
| 390 | 396 | send_result(source, EINVAL); |
| 391 | 397 | g_message("Invalid remote request (id=%d)",source->buffer[0]); | ... | ... |
src/plugins/rx3270/pluginmain.cc
| ... | ... | @@ -148,6 +148,7 @@ |
| 148 | 148 | int file_transfer(LIB3270_FT_OPTION options, const gchar *local, const gchar *remote, int lrecl = 0, int blksize = 0, int primspace = 0, int secspace = 0, int dft = 4096); |
| 149 | 149 | |
| 150 | 150 | int quit(void); |
| 151 | + int action(const char *name); | |
| 151 | 152 | |
| 152 | 153 | protected: |
| 153 | 154 | |
| ... | ... | @@ -766,6 +767,11 @@ int plugin::quit(void) |
| 766 | 767 | return 0; |
| 767 | 768 | } |
| 768 | 769 | |
| 770 | +int plugin::action(const char *name) | |
| 771 | +{ | |
| 772 | + return lib3270_action(hSession,name); | |
| 773 | +} | |
| 774 | + | |
| 769 | 775 | int plugin::set_host_charset(const char *charset) |
| 770 | 776 | { |
| 771 | 777 | return lib3270_set_host_charset(hSession,charset); | ... | ... |
src/pw3270/actions.c
| ... | ... | @@ -57,7 +57,7 @@ |
| 57 | 57 | |
| 58 | 58 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 59 | 59 | |
| 60 | -static void lib3270_action(GtkAction *action, GtkWidget *widget) | |
| 60 | +static void do_lib3270_action(GtkAction *action, GtkWidget *widget) | |
| 61 | 61 | { |
| 62 | 62 | int (*call)(H3270 *h) = (int (*)(H3270 *h)) g_object_get_data(G_OBJECT(action),"lib3270_call"); |
| 63 | 63 | |
| ... | ... | @@ -270,7 +270,7 @@ static void connect_standard_action(GtkAction *action, GtkWidget *widget, const |
| 270 | 270 | if(!g_ascii_strcasecmp(name,lib3270_entry[f].name)) |
| 271 | 271 | { |
| 272 | 272 | g_object_set_data(G_OBJECT(action),"lib3270_call",lib3270_entry[f].call); |
| 273 | - g_signal_connect(action,"activate",G_CALLBACK(lib3270_action),widget); | |
| 273 | + g_signal_connect(action,"activate",G_CALLBACK(do_lib3270_action),widget); | |
| 274 | 274 | return; |
| 275 | 275 | } |
| 276 | 276 | } |
| ... | ... | @@ -834,7 +834,7 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash |
| 834 | 834 | case ACTION_TYPE_LIB3270: |
| 835 | 835 | action = new_action(nm,names,values); |
| 836 | 836 | g_object_set_data(G_OBJECT(action),"lib3270_call",callback[id]); |
| 837 | - g_signal_connect(action,"activate",G_CALLBACK(lib3270_action),widget); | |
| 837 | + g_signal_connect(action,"activate",G_CALLBACK(do_lib3270_action),widget); | |
| 838 | 838 | break; |
| 839 | 839 | |
| 840 | 840 | case ACTION_TYPE_STRING: | ... | ... |