Commit 00e98f6ee3f76b8b894d779aeed2eab59aeb989d
1 parent
d5cf098d
Exists in
master
and in
5 other branches
Reimplementando HLLAPI no novo formato
Showing
7 changed files
with
112 additions
and
21 deletions
Show diff stats
src/include/pw3270/hllapi.h
| @@ -78,6 +78,7 @@ extern "C" { | @@ -78,6 +78,7 @@ extern "C" { | ||
| 78 | __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void); | 78 | __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void); |
| 79 | __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void); | 79 | __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void); |
| 80 | __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer); | 80 | __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer); |
| 81 | + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len); | ||
| 81 | __declspec (dllexport) DWORD __stdcall hllapi_enter(void); | 82 | __declspec (dllexport) DWORD __stdcall hllapi_enter(void); |
| 82 | __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text); | 83 | __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text); |
| 83 | __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); | 84 | __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); |
src/plugins/remotectl/calls.c
| @@ -55,6 +55,8 @@ | @@ -55,6 +55,8 @@ | ||
| 55 | static int (*script_sleep)(void *h, int seconds) = NULL; | 55 | static int (*script_sleep)(void *h, int seconds) = NULL; |
| 56 | static LIB3270_MESSAGE (*get_message)(void *h) = NULL; | 56 | static LIB3270_MESSAGE (*get_message)(void *h) = NULL; |
| 57 | static char * (*get_text)(void *h, int row, int col, int len) = NULL; | 57 | static char * (*get_text)(void *h, int row, int col, int len) = NULL; |
| 58 | + static char * (*get_text_at_offset)(void *h, int offset, int len) = NULL; | ||
| 59 | + | ||
| 58 | static void * (*release_memory)(void *p) = NULL; | 60 | static void * (*release_memory)(void *p) = NULL; |
| 59 | static int (*action_enter)(void *h) = NULL; | 61 | static int (*action_enter)(void *h) = NULL; |
| 60 | static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL; | 62 | static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL; |
| @@ -71,25 +73,25 @@ | @@ -71,25 +73,25 @@ | ||
| 71 | const char * name; | 73 | const char * name; |
| 72 | } entry_point[] = | 74 | } entry_point[] = |
| 73 | { | 75 | { |
| 74 | - { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, | ||
| 75 | - { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, | ||
| 76 | - { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, | ||
| 77 | - { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, | ||
| 78 | - { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, | ||
| 79 | - { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, | ||
| 80 | - { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, | ||
| 81 | - { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, | ||
| 82 | - { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, | ||
| 83 | - { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, | ||
| 84 | - { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, | ||
| 85 | - { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, | ||
| 86 | - { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, | ||
| 87 | - { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, | ||
| 88 | - { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, | ||
| 89 | - { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, | ||
| 90 | - { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, | ||
| 91 | - { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, | ||
| 92 | - | 76 | + { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, |
| 77 | + { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, | ||
| 78 | + { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, | ||
| 79 | + { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, | ||
| 80 | + { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, | ||
| 81 | + { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, | ||
| 82 | + { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, | ||
| 83 | + { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, | ||
| 84 | + { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, | ||
| 85 | + { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, | ||
| 86 | + { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, | ||
| 87 | + { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, | ||
| 88 | + { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, | ||
| 89 | + { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, | ||
| 90 | + { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, | ||
| 91 | + { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, | ||
| 92 | + { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, | ||
| 93 | + { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, | ||
| 94 | + { (void **) &get_text_at_offset, (void *) hllapi_pipe_get_text, "lib3270_get_text" }, | ||
| 93 | { NULL, NULL } | 95 | { NULL, NULL } |
| 94 | }; | 96 | }; |
| 95 | 97 | ||
| @@ -402,3 +404,33 @@ | @@ -402,3 +404,33 @@ | ||
| 402 | return -EINVAL; | 404 | return -EINVAL; |
| 403 | return getcursor(hSession)+1; | 405 | return getcursor(hSession)+1; |
| 404 | } | 406 | } |
| 407 | + | ||
| 408 | + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len) | ||
| 409 | + { | ||
| 410 | + char *text; | ||
| 411 | + | ||
| 412 | + trace("%s(%d,%d)",__FUNCTION__,pos,len); | ||
| 413 | + | ||
| 414 | + if(len < 0) | ||
| 415 | + len = strlen(buffer); | ||
| 416 | + | ||
| 417 | + if(!(get_text_at_offset && hSession)) | ||
| 418 | + return EINVAL; | ||
| 419 | + | ||
| 420 | + if(len > strlen(buffer)) | ||
| 421 | + len = strlen(buffer); | ||
| 422 | + | ||
| 423 | + trace("len=%d",len); | ||
| 424 | + text = get_text_at_offset(hSession,pos-1,len); | ||
| 425 | + | ||
| 426 | + trace("text=\n%s\n",text); | ||
| 427 | + | ||
| 428 | + if(!text) | ||
| 429 | + return -1; | ||
| 430 | + | ||
| 431 | + memcpy(buffer,text,len); | ||
| 432 | + | ||
| 433 | + release_memory(text); | ||
| 434 | + | ||
| 435 | + return 0; | ||
| 436 | + } |
src/plugins/remotectl/client.h
| @@ -46,6 +46,7 @@ | @@ -46,6 +46,7 @@ | ||
| 46 | void hllapi_pipe_disconnect(void *h); | 46 | void hllapi_pipe_disconnect(void *h); |
| 47 | LIB3270_MESSAGE hllapi_pipe_get_message(void *h); | 47 | LIB3270_MESSAGE hllapi_pipe_get_message(void *h); |
| 48 | char * hllapi_pipe_get_text_at(void *h, int row, int col, int len); | 48 | char * hllapi_pipe_get_text_at(void *h, int row, int col, int len); |
| 49 | + char * hllapi_pipe_get_text(void *h, int offset, int len); | ||
| 49 | int hllapi_pipe_enter(void *h); | 50 | int hllapi_pipe_enter(void *h); |
| 50 | int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str); | 51 | int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str); |
| 51 | int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); | 52 | int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); |
src/plugins/remotectl/hllapi.c
| @@ -43,6 +43,7 @@ | @@ -43,6 +43,7 @@ | ||
| 43 | static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc); | 43 | static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc); |
| 44 | static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc); | 44 | static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc); |
| 45 | static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc); | 45 | static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc); |
| 46 | + static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc); | ||
| 46 | 47 | ||
| 47 | static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); | 48 | static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); |
| 48 | static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); | 49 | static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); |
| @@ -59,7 +60,8 @@ | @@ -59,7 +60,8 @@ | ||
| 59 | { HLLAPI_CMD_DISCONNECTPS, disconnect_ps }, | 60 | { HLLAPI_CMD_DISCONNECTPS, disconnect_ps }, |
| 60 | { HLLAPI_CMD_GETREVISION, get_library_revision }, | 61 | { HLLAPI_CMD_GETREVISION, get_library_revision }, |
| 61 | { HLLAPI_CMD_QUERYCURSOR, get_cursor_position }, | 62 | { HLLAPI_CMD_QUERYCURSOR, get_cursor_position }, |
| 62 | - { HLLAPI_CMD_SETCURSOR, set_cursor_position }, | 63 | + { HLLAPI_CMD_SETCURSOR, set_cursor_position }, |
| 64 | + { HLLAPI_CMD_COPYPSTOSTR, copy_ps_to_str }, | ||
| 63 | }; | 65 | }; |
| 64 | 66 | ||
| 65 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 67 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| @@ -149,6 +151,12 @@ static int set_cursor_position(char *buffer, unsigned short *length, unsigned sh | @@ -149,6 +151,12 @@ static int set_cursor_position(char *buffer, unsigned short *length, unsigned sh | ||
| 149 | return 0; | 151 | return 0; |
| 150 | } | 152 | } |
| 151 | 153 | ||
| 154 | +static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc) | ||
| 155 | +{ | ||
| 156 | + // Length Length of the target data string. | ||
| 157 | + // PS Position Position within the host presentation space of the first byte in your target data string. | ||
| 158 | + return hllapi_get_screen(*rc,buffer,*length); | ||
| 159 | +} | ||
| 152 | 160 | ||
| 153 | /* | 161 | /* |
| 154 | static int cmd_connect_ps(const char *name) | 162 | static int cmd_connect_ps(const char *name) |
src/plugins/remotectl/packets.h
| @@ -32,6 +32,7 @@ | @@ -32,6 +32,7 @@ | ||
| 32 | HLLAPI_PACKET_CONNECT, | 32 | HLLAPI_PACKET_CONNECT, |
| 33 | HLLAPI_PACKET_DISCONNECT, | 33 | HLLAPI_PACKET_DISCONNECT, |
| 34 | HLLAPI_PACKET_GET_PROGRAM_MESSAGE, | 34 | HLLAPI_PACKET_GET_PROGRAM_MESSAGE, |
| 35 | + HLLAPI_PACKET_GET_TEXT_AT_OFFSET, | ||
| 35 | HLLAPI_PACKET_GET_TEXT_AT, | 36 | HLLAPI_PACKET_GET_TEXT_AT, |
| 36 | HLLAPI_PACKET_SET_TEXT_AT, | 37 | HLLAPI_PACKET_SET_TEXT_AT, |
| 37 | HLLAPI_PACKET_CMP_TEXT_AT, | 38 | HLLAPI_PACKET_CMP_TEXT_AT, |
| @@ -56,6 +57,12 @@ struct hllapi_packet_result | @@ -56,6 +57,12 @@ struct hllapi_packet_result | ||
| 56 | int rc; | 57 | int rc; |
| 57 | }; | 58 | }; |
| 58 | 59 | ||
| 60 | +struct hllapi_packet_text_result | ||
| 61 | +{ | ||
| 62 | + int rc; | ||
| 63 | + char text[1]; | ||
| 64 | +}; | ||
| 65 | + | ||
| 59 | struct hllapi_packet_query | 66 | struct hllapi_packet_query |
| 60 | { | 67 | { |
| 61 | unsigned char packet_id; | 68 | unsigned char packet_id; |
| @@ -123,6 +130,14 @@ struct hllapi_packet_addr | @@ -123,6 +130,14 @@ struct hllapi_packet_addr | ||
| 123 | unsigned short addr; | 130 | unsigned short addr; |
| 124 | }; | 131 | }; |
| 125 | 132 | ||
| 133 | +struct hllapi_packet_query_offset | ||
| 134 | +{ | ||
| 135 | + unsigned char packet_id; | ||
| 136 | + unsigned short addr; | ||
| 137 | + unsigned short len; | ||
| 138 | +}; | ||
| 139 | + | ||
| 140 | + | ||
| 126 | 141 | ||
| 127 | #pragma pack() | 142 | #pragma pack() |
| 128 | 143 |
src/plugins/remotectl/pluginmain.c
| @@ -154,7 +154,9 @@ | @@ -154,7 +154,9 @@ | ||
| 154 | pkt->packet_id = errno ? errno : -1; | 154 | pkt->packet_id = errno ? errno : -1; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | - WriteFile(source->hPipe,&pkt,szBlock,&szBlock,NULL); | 157 | + WriteFile(source->hPipe,pkt,szBlock,&szBlock,NULL); |
| 158 | + | ||
| 159 | + g_free(pkt); | ||
| 158 | } | 160 | } |
| 159 | 161 | ||
| 160 | static void send_result(pipe_source *source, int rc) | 162 | static void send_result(pipe_source *source, int rc) |
| @@ -223,6 +225,12 @@ | @@ -223,6 +225,12 @@ | ||
| 223 | ((struct hllapi_packet_at *) source->buffer)->len)); | 225 | ((struct hllapi_packet_at *) source->buffer)->len)); |
| 224 | break; | 226 | break; |
| 225 | 227 | ||
| 228 | + case HLLAPI_PACKET_GET_TEXT_AT_OFFSET: | ||
| 229 | + send_text(source,lib3270_get_text( lib3270_get_default_session_handle(), | ||
| 230 | + ((struct hllapi_packet_query_offset *) source->buffer)->addr, | ||
| 231 | + ((struct hllapi_packet_query_offset *) source->buffer)->len)); | ||
| 232 | + break; | ||
| 233 | + | ||
| 226 | case HLLAPI_PACKET_CMP_TEXT_AT: | 234 | case HLLAPI_PACKET_CMP_TEXT_AT: |
| 227 | send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(), | 235 | send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(), |
| 228 | ((struct hllapi_packet_text_at *) source->buffer)->row, | 236 | ((struct hllapi_packet_text_at *) source->buffer)->row, |
src/plugins/remotectl/remote.c
| @@ -306,3 +306,29 @@ | @@ -306,3 +306,29 @@ | ||
| 306 | TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | 306 | TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); |
| 307 | return response.rc; | 307 | return response.rc; |
| 308 | } | 308 | } |
| 309 | + | ||
| 310 | + char * hllapi_pipe_get_text(void *h, int offset, int len) | ||
| 311 | + { | ||
| 312 | + struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, offset, len }; | ||
| 313 | + struct hllapi_packet_text * response; | ||
| 314 | + DWORD cbSize = sizeof(struct hllapi_packet_text)+len; | ||
| 315 | + char * text = NULL; | ||
| 316 | + | ||
| 317 | + trace("cbSize=%d",(int) cbSize); | ||
| 318 | + | ||
| 319 | + response = malloc(cbSize+2); | ||
| 320 | + memset(response,0,cbSize+2); | ||
| 321 | + | ||
| 322 | + if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(query), response, cbSize, &cbSize,NULL)) | ||
| 323 | + return NULL; | ||
| 324 | + | ||
| 325 | + trace("rc=%d",response->packet_id); | ||
| 326 | + | ||
| 327 | + if(response->packet_id) | ||
| 328 | + errno = response->packet_id; | ||
| 329 | + else | ||
| 330 | + text = strdup(response->text); | ||
| 331 | + | ||
| 332 | + free(response); | ||
| 333 | + return text; | ||
| 334 | + } |