Commit 801af2ab7f48ee4796812f7141b4860f29166eae
1 parent
0e3d730a
Exists in
master
and in
5 other branches
Implementando mais metodos nas biblioteca hllapi
Showing
7 changed files
with
63 additions
and
8 deletions
Show diff stats
src/include/pw3270/hllapi.h
@@ -69,6 +69,7 @@ extern "C" { | @@ -69,6 +69,7 @@ extern "C" { | ||
69 | HLLAPI_PACKET_SET_CURSOR_POSITION, | 69 | HLLAPI_PACKET_SET_CURSOR_POSITION, |
70 | HLLAPI_PACKET_GET_CURSOR_POSITION, | 70 | HLLAPI_PACKET_GET_CURSOR_POSITION, |
71 | HLLAPI_PACKET_INPUT_STRING, | 71 | HLLAPI_PACKET_INPUT_STRING, |
72 | + HLLAPI_PACKET_IS_CONNECTED, | ||
72 | 73 | ||
73 | HLLAPI_PACKET_INVALID | 74 | HLLAPI_PACKET_INVALID |
74 | 75 |
src/plugins/remotectl/calls.c
@@ -74,9 +74,9 @@ | @@ -74,9 +74,9 @@ | ||
74 | { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, | 74 | { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, |
75 | { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, | 75 | { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, |
76 | { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, | 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 | { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, | 80 | { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, |
81 | { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, | 81 | { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, |
82 | { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, | 82 | { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, |
src/plugins/remotectl/client.h
@@ -51,8 +51,7 @@ | @@ -51,8 +51,7 @@ | ||
51 | int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); | 51 | int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); |
52 | int hllapi_pipe_pfkey(void *h, int key); | 52 | int hllapi_pipe_pfkey(void *h, int key); |
53 | int hllapi_pipe_pakey(void *h, int key); | 53 | int hllapi_pipe_pakey(void *h, int key); |
54 | - | ||
55 | -/* | ||
56 | int hllapi_pipe_wait_for_ready(void *h, int seconds); | 54 | int hllapi_pipe_wait_for_ready(void *h, int seconds); |
57 | int hllapi_pipe_sleep(void *h, int seconds); | 55 | int hllapi_pipe_sleep(void *h, int seconds); |
58 | -*/ | 56 | + int hllapi_pipe_is_connected(void *h); |
57 | + |
src/plugins/remotectl/packets.h
src/plugins/remotectl/pluginmain.c
@@ -185,6 +185,10 @@ | @@ -185,6 +185,10 @@ | ||
185 | send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle())); | 185 | send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle())); |
186 | break; | 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 | case HLLAPI_PACKET_ENTER: | 192 | case HLLAPI_PACKET_ENTER: |
189 | send_result(source,lib3270_enter(lib3270_get_default_session_handle())); | 193 | send_result(source,lib3270_enter(lib3270_get_default_session_handle())); |
190 | break; | 194 | break; |
src/plugins/remotectl/remote.c
@@ -31,7 +31,8 @@ | @@ -31,7 +31,8 @@ | ||
31 | #include <malloc.h> | 31 | #include <malloc.h> |
32 | #include <string.h> | 32 | #include <string.h> |
33 | #include <errno.h> | 33 | #include <errno.h> |
34 | - #include <stdio.h> | 34 | + #include <stdio.h> |
35 | + #include <time.h> | ||
35 | #include <lib3270/log.h> | 36 | #include <lib3270/log.h> |
36 | 37 | ||
37 | #include "client.h" | 38 | #include "client.h" |
@@ -240,3 +241,43 @@ | @@ -240,3 +241,43 @@ | ||
240 | { | 241 | { |
241 | free(p); | 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,7 +42,12 @@ | ||
42 | 42 | ||
43 | printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); | 43 | printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); |
44 | printf("revision=%d\n",(int) hllapi_get_revision()); | 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 | printf("deinit=%d\n",(int) hllapi_deinit()); | 52 | printf("deinit=%d\n",(int) hllapi_deinit()); |
48 | 53 |