From 801af2ab7f48ee4796812f7141b4860f29166eae Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 1 Mar 2013 02:23:23 +0000 Subject: [PATCH] Implementando mais metodos nas biblioteca hllapi --- src/include/pw3270/hllapi.h | 1 + src/plugins/remotectl/calls.c | 6 +++--- src/plugins/remotectl/client.h | 5 ++--- src/plugins/remotectl/packets.h | 5 +++++ src/plugins/remotectl/pluginmain.c | 4 ++++ src/plugins/remotectl/remote.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/plugins/remotectl/testprogram.c | 7 ++++++- 7 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h index 473bdfe..0bf63b3 100644 --- a/src/include/pw3270/hllapi.h +++ b/src/include/pw3270/hllapi.h @@ -69,6 +69,7 @@ extern "C" { HLLAPI_PACKET_SET_CURSOR_POSITION, HLLAPI_PACKET_GET_CURSOR_POSITION, HLLAPI_PACKET_INPUT_STRING, + HLLAPI_PACKET_IS_CONNECTED, HLLAPI_PACKET_INVALID diff --git a/src/plugins/remotectl/calls.c b/src/plugins/remotectl/calls.c index e1729f2..32b83ba 100644 --- a/src/plugins/remotectl/calls.c +++ b/src/plugins/remotectl/calls.c @@ -74,9 +74,9 @@ { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, - { (void **) &host_is_connected, (void *) NULL, "lib3270_in_tn3270e" }, - { (void **) &wait_for_ready, (void *) NULL, "lib3270_wait_for_ready" }, - { (void **) &script_sleep, (void *) NULL, "lib3270_wait" }, + { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, + { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, + { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, diff --git a/src/plugins/remotectl/client.h b/src/plugins/remotectl/client.h index ff82e68..1328f97 100644 --- a/src/plugins/remotectl/client.h +++ b/src/plugins/remotectl/client.h @@ -51,8 +51,7 @@ int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); int hllapi_pipe_pfkey(void *h, int key); int hllapi_pipe_pakey(void *h, int key); - -/* int hllapi_pipe_wait_for_ready(void *h, int seconds); int hllapi_pipe_sleep(void *h, int seconds); -*/ + int hllapi_pipe_is_connected(void *h); + diff --git a/src/plugins/remotectl/packets.h b/src/plugins/remotectl/packets.h index d40b1a3..50c0b7c 100644 --- a/src/plugins/remotectl/packets.h +++ b/src/plugins/remotectl/packets.h @@ -89,6 +89,11 @@ struct hllapi_packet_query_at unsigned short len; }; +struct hllapi_packet_wait +{ + int packet_id; + int timeout; +}; #pragma pack() diff --git a/src/plugins/remotectl/pluginmain.c b/src/plugins/remotectl/pluginmain.c index fc13b52..38c1be1 100644 --- a/src/plugins/remotectl/pluginmain.c +++ b/src/plugins/remotectl/pluginmain.c @@ -185,6 +185,10 @@ send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle())); break; + case HLLAPI_PACKET_IS_CONNECTED: + send_result(source,lib3270_in_tn3270e(lib3270_get_default_session_handle())); + break; + case HLLAPI_PACKET_ENTER: send_result(source,lib3270_enter(lib3270_get_default_session_handle())); break; diff --git a/src/plugins/remotectl/remote.c b/src/plugins/remotectl/remote.c index 0c18c5e..5beacf6 100644 --- a/src/plugins/remotectl/remote.c +++ b/src/plugins/remotectl/remote.c @@ -31,7 +31,8 @@ #include #include #include - #include + #include + #include #include #include "client.h" @@ -240,3 +241,43 @@ { free(p); } + + int hllapi_pipe_wait_for_ready(void *h, int seconds) + { + time_t end = time(0)+seconds; + + while(time(0) < end) + { + if(!hllapi_pipe_is_connected(h)) + return ENOTCONN; + + if(hllapi_pipe_get_message(h) == 0) + return 0; + Sleep(250); + } + + return ETIMEDOUT; + } + + int hllapi_pipe_is_connected(void *h) + { + static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return (LIB3270_MESSAGE) response.rc; + } + + int hllapi_pipe_sleep(void *h, int seconds) + { + time_t end = time(0)+seconds; + + while(time(0) < end) + { + if(!hllapi_pipe_is_connected(h)) + return ENOTCONN; + Sleep(500); + } + + return 0; + } diff --git a/src/plugins/remotectl/testprogram.c b/src/plugins/remotectl/testprogram.c index 0f0b1d0..4afcc63 100644 --- a/src/plugins/remotectl/testprogram.c +++ b/src/plugins/remotectl/testprogram.c @@ -42,7 +42,12 @@ printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); printf("revision=%d\n",(int) hllapi_get_revision()); - printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23")); + printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23",0)); + printf("wait=%d\n",(int) hllapi_wait(3)); + printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); + +// printf("disconnect=%d\n",(int) hllapi_disconnect("fandezhi.efglobe.com:23",1)); + printf("deinit=%d\n",(int) hllapi_deinit()); -- libgit2 0.21.2