Commit 801af2ab7f48ee4796812f7141b4860f29166eae

Authored by perry.werneck@gmail.com
1 parent 0e3d730a

Implementando mais metodos nas biblioteca hllapi

src/include/pw3270/hllapi.h
... ... @@ -69,6 +69,7 @@ extern "C" {
69 69 HLLAPI_PACKET_SET_CURSOR_POSITION,
70 70 HLLAPI_PACKET_GET_CURSOR_POSITION,
71 71 HLLAPI_PACKET_INPUT_STRING,
  72 + HLLAPI_PACKET_IS_CONNECTED,
72 73  
73 74 HLLAPI_PACKET_INVALID
74 75  
... ...
src/plugins/remotectl/calls.c
... ... @@ -74,9 +74,9 @@
74 74 { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" },
75 75 { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" },
76 76 { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" },
77   - { (void **) &host_is_connected, (void *) NULL, "lib3270_in_tn3270e" },
78   - { (void **) &wait_for_ready, (void *) NULL, "lib3270_wait_for_ready" },
79   - { (void **) &script_sleep, (void *) NULL, "lib3270_wait" },
  77 + { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" },
  78 + { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" },
  79 + { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" },
80 80 { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" },
81 81 { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" },
82 82 { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" },
... ...
src/plugins/remotectl/client.h
... ... @@ -51,8 +51,7 @@
51 51 int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text);
52 52 int hllapi_pipe_pfkey(void *h, int key);
53 53 int hllapi_pipe_pakey(void *h, int key);
54   -
55   -/*
56 54 int hllapi_pipe_wait_for_ready(void *h, int seconds);
57 55 int hllapi_pipe_sleep(void *h, int seconds);
58   -*/
  56 + int hllapi_pipe_is_connected(void *h);
  57 +
... ...
src/plugins/remotectl/packets.h
... ... @@ -89,6 +89,11 @@ struct hllapi_packet_query_at
89 89 unsigned short len;
90 90 };
91 91  
  92 +struct hllapi_packet_wait
  93 +{
  94 + int packet_id;
  95 + int timeout;
  96 +};
92 97  
93 98  
94 99 #pragma pack()
... ...
src/plugins/remotectl/pluginmain.c
... ... @@ -185,6 +185,10 @@
185 185 send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle()));
186 186 break;
187 187  
  188 + case HLLAPI_PACKET_IS_CONNECTED:
  189 + send_result(source,lib3270_in_tn3270e(lib3270_get_default_session_handle()));
  190 + break;
  191 +
188 192 case HLLAPI_PACKET_ENTER:
189 193 send_result(source,lib3270_enter(lib3270_get_default_session_handle()));
190 194 break;
... ...
src/plugins/remotectl/remote.c
... ... @@ -31,7 +31,8 @@
31 31 #include <malloc.h>
32 32 #include <string.h>
33 33 #include <errno.h>
34   - #include <stdio.h>
  34 + #include <stdio.h>
  35 + #include <time.h>
35 36 #include <lib3270/log.h>
36 37  
37 38 #include "client.h"
... ... @@ -240,3 +241,43 @@
240 241 {
241 242 free(p);
242 243 }
  244 +
  245 + int hllapi_pipe_wait_for_ready(void *h, int seconds)
  246 + {
  247 + time_t end = time(0)+seconds;
  248 +
  249 + while(time(0) < end)
  250 + {
  251 + if(!hllapi_pipe_is_connected(h))
  252 + return ENOTCONN;
  253 +
  254 + if(hllapi_pipe_get_message(h) == 0)
  255 + return 0;
  256 + Sleep(250);
  257 + }
  258 +
  259 + return ETIMEDOUT;
  260 + }
  261 +
  262 + int hllapi_pipe_is_connected(void *h)
  263 + {
  264 + static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED };
  265 + struct hllapi_packet_result response;
  266 + DWORD cbSize = sizeof(query);
  267 + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  268 + return (LIB3270_MESSAGE) response.rc;
  269 + }
  270 +
  271 + int hllapi_pipe_sleep(void *h, int seconds)
  272 + {
  273 + time_t end = time(0)+seconds;
  274 +
  275 + while(time(0) < end)
  276 + {
  277 + if(!hllapi_pipe_is_connected(h))
  278 + return ENOTCONN;
  279 + Sleep(500);
  280 + }
  281 +
  282 + return 0;
  283 + }
... ...
src/plugins/remotectl/testprogram.c
... ... @@ -42,7 +42,12 @@
42 42  
43 43 printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session));
44 44 printf("revision=%d\n",(int) hllapi_get_revision());
45   - printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23"));
  45 + printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23",0));
  46 + printf("wait=%d\n",(int) hllapi_wait(3));
  47 + printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No");
  48 +
  49 +// printf("disconnect=%d\n",(int) hllapi_disconnect("fandezhi.efglobe.com:23",1));
  50 +
46 51  
47 52 printf("deinit=%d\n",(int) hllapi_deinit());
48 53  
... ...