Commit b094d22b54a449197b53e5585665ba0bc069966b
1 parent
8c031cd6
Exists in
master
and in
5 other branches
Melhorando método connect da classe de apoio
Showing
11 changed files
with
75 additions
and
32 deletions
Show diff stats
src/classlib/Makefile.in
src/classlib/local.cc
src/classlib/remote.cc
| ... | ... | @@ -712,7 +712,7 @@ |
| 712 | 712 | return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - int connect(bool wait) | |
| 715 | + int connect(void) | |
| 716 | 716 | { |
| 717 | 717 | int rc; |
| 718 | 718 | |
| ... | ... | @@ -736,12 +736,6 @@ |
| 736 | 736 | rc = -1; |
| 737 | 737 | |
| 738 | 738 | #endif |
| 739 | - | |
| 740 | - trace("%s: rc=%d",__FUNCTION__,rc); | |
| 741 | - | |
| 742 | - if(!rc && wait) | |
| 743 | - return wait_for_ready(120); | |
| 744 | - | |
| 745 | 739 | return rc; |
| 746 | 740 | |
| 747 | 741 | } |
| ... | ... | @@ -783,8 +777,8 @@ |
| 783 | 777 | |
| 784 | 778 | while(time(0) < end) |
| 785 | 779 | { |
| 786 | - //if(!is_connected()) | |
| 787 | - // return ENOTCONN; | |
| 780 | + if(!is_connected()) | |
| 781 | + return ENOTCONN; | |
| 788 | 782 | |
| 789 | 783 | if(is_ready()) |
| 790 | 784 | return 0; |
| ... | ... | @@ -871,8 +865,12 @@ |
| 871 | 865 | int iterate(bool wait) |
| 872 | 866 | { |
| 873 | 867 | #if defined(WIN32) |
| 868 | + if(wait) | |
| 869 | + Sleep(250); | |
| 874 | 870 | return 0; |
| 875 | 871 | #elif defined(HAVE_DBUS) |
| 872 | + if(wait) | |
| 873 | + usleep(250); | |
| 876 | 874 | return 0; |
| 877 | 875 | #else |
| 878 | 876 | return -1; | ... | ... |
src/classlib/session.cc
| ... | ... | @@ -34,6 +34,10 @@ |
| 34 | 34 | |
| 35 | 35 | #include <pw3270/class.h> |
| 36 | 36 | |
| 37 | +#ifndef WIN32 | |
| 38 | + #include <unistd.h> | |
| 39 | +#endif // !WIN32 | |
| 40 | + | |
| 37 | 41 | #ifdef HAVE_SYSLOG |
| 38 | 42 | #include <syslog.h> |
| 39 | 43 | #endif // HAVE_SYSLOG |
| ... | ... | @@ -481,7 +485,7 @@ |
| 481 | 485 | return set_url(host); |
| 482 | 486 | } |
| 483 | 487 | |
| 484 | - int session::connect(const char *host, bool wait) | |
| 488 | + int session::connect(const char *host, time_t wait) | |
| 485 | 489 | { |
| 486 | 490 | int rc = 0; |
| 487 | 491 | |
| ... | ... | @@ -491,8 +495,22 @@ |
| 491 | 495 | trace("%s: set_url(%s) = %d",__FUNCTION__,host,rc); |
| 492 | 496 | } |
| 493 | 497 | |
| 494 | - if(!rc) | |
| 495 | - rc = connect(wait); | |
| 498 | + rc = connect(); | |
| 499 | + trace("%s: connect=%d",__FUNCTION__,rc); | |
| 500 | + | |
| 501 | + if(!rc && wait) | |
| 502 | + { | |
| 503 | + time_t timeout = time(0)+wait; | |
| 504 | + rc = ETIMEDOUT; | |
| 505 | + | |
| 506 | + while(time(0) < timeout && rc == ETIMEDOUT) | |
| 507 | + { | |
| 508 | + trace("%s: Waiting",__FUNCTION__); | |
| 509 | + if(is_connected()) | |
| 510 | + rc = 0; | |
| 511 | + iterate(true); | |
| 512 | + } | |
| 513 | + } | |
| 496 | 514 | |
| 497 | 515 | return rc; |
| 498 | 516 | } | ... | ... |
src/classlib/testprogram.cc
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 | |
| 42 | 42 | { |
| 43 | 43 | string s; |
| 44 | - session *session = session::start("pw3270:a"); | |
| 44 | + session *session = session::start(""); | |
| 45 | 45 | // session *session = session::start("new"); |
| 46 | 46 | |
| 47 | 47 | cout << "pw3270 version: " << session->get_version() << endl; |
| ... | ... | @@ -60,7 +60,7 @@ |
| 60 | 60 | s = session->get_host_charset(); |
| 61 | 61 | cout << "\tHost charset: " << s.c_str() << endl; |
| 62 | 62 | |
| 63 | - session->connect(false); | |
| 63 | + cout << "Connect: " << session->connect("fandezhi.efglobe.com:23",60) << endl << endl; | |
| 64 | 64 | |
| 65 | 65 | cout << "\tWaitForReady: " << session->wait_for_ready(10) << endl; |
| 66 | 66 | |
| ... | ... | @@ -75,6 +75,7 @@ |
| 75 | 75 | sleep(2); |
| 76 | 76 | |
| 77 | 77 | // Create another session |
| 78 | + /* | |
| 78 | 79 | { |
| 79 | 80 | session *session = session::start("pw3270:a"); |
| 80 | 81 | |
| ... | ... | @@ -82,6 +83,7 @@ |
| 82 | 83 | delete session; |
| 83 | 84 | |
| 84 | 85 | } |
| 86 | + */ | |
| 85 | 87 | |
| 86 | 88 | |
| 87 | 89 | return 0; | ... | ... |
src/include/pw3270/class.h
| ... | ... | @@ -134,9 +134,9 @@ |
| 134 | 134 | virtual string get_display_charset(void); |
| 135 | 135 | |
| 136 | 136 | // Connection & Network |
| 137 | - int connect(const char *host, bool wait = true); | |
| 138 | - int set_host(const char *host); | |
| 139 | - virtual int connect(bool wait = true) = 0; | |
| 137 | + int connect(const char *host, time_t wait = 0); | |
| 138 | + int set_host(const char *host); | |
| 139 | + virtual int connect(void) = 0; | |
| 140 | 140 | virtual int set_url(const char *hostname) = 0; |
| 141 | 141 | virtual int disconnect(void) = 0; |
| 142 | 142 | virtual int wait_for_ready(int seconds) = 0; | ... | ... |
src/include/pw3270/hllapi.h
| ... | ... | @@ -100,7 +100,35 @@ extern "C" { |
| 100 | 100 | |
| 101 | 101 | #else |
| 102 | 102 | |
| 103 | - #error NOT IMPLEMENTED | |
| 103 | + typedef unsigned short DWORD | |
| 104 | + | |
| 105 | + LIB3270_EXPORT int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc); | |
| 106 | + | |
| 107 | + LIB3270_EXPORT DWORD __stdcall hllapi_init(LPSTR mode); | |
| 108 | + LIB3270_EXPORT DWORD __stdcall hllapi_deinit(void); | |
| 109 | + | |
| 110 | + LIB3270_EXPORT DWORD __stdcall hllapi_get_revision(void); | |
| 111 | + LIB3270_EXPORT DWORD __stdcall hllapi_get_datadir(LPSTR datadir); | |
| 112 | + | |
| 113 | + LIB3270_EXPORT DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait); | |
| 114 | + LIB3270_EXPORT DWORD __stdcall hllapi_disconnect(void); | |
| 115 | + LIB3270_EXPORT DWORD __stdcall hllapi_get_message_id(void); | |
| 116 | + LIB3270_EXPORT DWORD __stdcall hllapi_is_connected(void); | |
| 117 | + LIB3270_EXPORT DWORD __stdcall hllapi_get_state(void); | |
| 118 | + LIB3270_EXPORT DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer); | |
| 119 | + LIB3270_EXPORT DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len); | |
| 120 | + LIB3270_EXPORT DWORD __stdcall hllapi_enter(void); | |
| 121 | + LIB3270_EXPORT DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text); | |
| 122 | + LIB3270_EXPORT DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); | |
| 123 | + LIB3270_EXPORT DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting); | |
| 124 | + LIB3270_EXPORT DWORD __stdcall hllapi_wait_for_ready(WORD seconds); | |
| 125 | + LIB3270_EXPORT DWORD __stdcall hllapi_wait(WORD seconds); | |
| 126 | + LIB3270_EXPORT DWORD __stdcall hllapi_pfkey(WORD key); | |
| 127 | + LIB3270_EXPORT DWORD __stdcall hllapi_pakey(WORD key); | |
| 128 | + LIB3270_EXPORT DWORD __stdcall hllapi_setcursor(WORD key); | |
| 129 | + LIB3270_EXPORT DWORD __stdcall hllapi_getcursor(); | |
| 130 | + LIB3270_EXPORT DWORD __stdcall hllapi_erase_eof(void); | |
| 131 | + LIB3270_EXPORT DWORD __stdcall hllapi_print(void); | |
| 104 | 132 | |
| 105 | 133 | #endif // _WIN32 |
| 106 | 134 | ... | ... |
src/plugins/hllapi/Makefile.in
| ... | ... | @@ -66,23 +66,17 @@ DEBUG_CFLAGS=-DDEBUG=1 -g -Wall |
| 66 | 66 | LIB3270_MODE ?= Default |
| 67 | 67 | |
| 68 | 68 | ifeq ($(LIB3270_MODE),Debug) |
| 69 | - PW3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l@PACKAGE_TARNAME@ -l3270 | |
| 70 | 69 | PW3270_CFLAGS=-I../../../src/include |
| 71 | - LIB3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l3270 | |
| 72 | 70 | LIB3270_CFLAGS=-I../../../src/include |
| 73 | 71 | endif |
| 74 | 72 | |
| 75 | 73 | ifeq ($(LIB3270_MODE),Release) |
| 76 | - PW3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l@PACKAGE_TARNAME@ -l3270 | |
| 77 | 74 | PW3270_CFLAGS=-I../../../src/include |
| 78 | - LIB3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l3270 | |
| 79 | 75 | LIB3270_CFLAGS=-I../../../src/include |
| 80 | 76 | endif |
| 81 | 77 | |
| 82 | 78 | ifeq ($(LIB3270_MODE),Default) |
| 83 | - LIB3270_LIBS ?= `pkg-config --libs lib3270` | |
| 84 | 79 | LIB3270_CFLAGS ?= `pkg-config --cflags lib3270` |
| 85 | - PW3270_LIBS ?= `pkg-config --libs pw3270 lib3270` | |
| 86 | 80 | PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` |
| 87 | 81 | endif |
| 88 | 82 | ... | ... |
src/plugins/hllapi/calls.cc
| ... | ... | @@ -37,7 +37,8 @@ |
| 37 | 37 | |
| 38 | 38 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
| 39 | 39 | |
| 40 | - static session * hSession = NULL; | |
| 40 | + static session * hSession = NULL; | |
| 41 | + static time_t hllapi_timeout = 120; | |
| 41 | 42 | |
| 42 | 43 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 43 | 44 | |
| ... | ... | @@ -100,7 +101,7 @@ |
| 100 | 101 | |
| 101 | 102 | try |
| 102 | 103 | { |
| 103 | - rc = session::get_default()->connect(uri,wait); | |
| 104 | + rc = session::get_default()->connect(uri,hllapi_timeout); | |
| 104 | 105 | } |
| 105 | 106 | catch(std::exception &e) |
| 106 | 107 | { | ... | ... |
src/plugins/hllapi/client.h
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | |
| 46 | 46 | void * hllapi_pipe_init(const char *id); |
| 47 | 47 | void hllapi_pipe_deinit(void *h); |
| 48 | - const char * hllapi_pipe_get_revision(void); | |
| 48 | + const char * hllapi_pipe_get_revision(void); | |
| 49 | 49 | void hllapi_pipe_release_memory(void *p); |
| 50 | 50 | int hllapi_pipe_connect(void *h, const char *n, int wait); |
| 51 | 51 | void hllapi_pipe_disconnect(void *h); | ... | ... |
src/plugins/rx3270/pluginmain.cc
| ... | ... | @@ -90,7 +90,7 @@ |
| 90 | 90 | LIB3270_CSTATE get_cstate(void); |
| 91 | 91 | int disconnect(void); |
| 92 | 92 | int set_url(const char *uri); |
| 93 | - int connect(bool wait = true); | |
| 93 | + int connect(void); | |
| 94 | 94 | bool is_connected(void); |
| 95 | 95 | bool is_ready(void); |
| 96 | 96 | |
| ... | ... | @@ -543,9 +543,9 @@ extern "C" |
| 543 | 543 | return 0; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - int plugin::connect(bool wait) | |
| 546 | + int plugin::connect(void) | |
| 547 | 547 | { |
| 548 | - return lib3270_connect(hSession,wait); | |
| 548 | + return lib3270_connect(hSession,0); | |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | bool plugin::is_connected(void) | ... | ... |