From b094d22b54a449197b53e5585665ba0bc069966b Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Sat, 19 Apr 2014 14:30:15 +0000 Subject: [PATCH] Melhorando método connect da classe de apoio --- src/classlib/Makefile.in | 2 ++ src/classlib/local.cc | 4 ++-- src/classlib/remote.cc | 16 +++++++--------- src/classlib/session.cc | 24 +++++++++++++++++++++--- src/classlib/testprogram.cc | 6 ++++-- src/include/pw3270/class.h | 6 +++--- src/include/pw3270/hllapi.h | 30 +++++++++++++++++++++++++++++- src/plugins/hllapi/Makefile.in | 6 ------ src/plugins/hllapi/calls.cc | 5 +++-- src/plugins/hllapi/client.h | 2 +- src/plugins/rx3270/pluginmain.cc | 6 +++--- 11 files changed, 75 insertions(+), 32 deletions(-) diff --git a/src/classlib/Makefile.in b/src/classlib/Makefile.in index 908cb23..63904a7 100644 --- a/src/classlib/Makefile.in +++ b/src/classlib/Makefile.in @@ -121,6 +121,8 @@ install-sdk: $(BINRLS)/$(LIBNAME) @$(MKDIR) $(DESTDIR)$(libdir) @$(INSTALL_DATA) $(BINRLS)/$(LIBNAME) $(DESTDIR)$(libdir) +cleanDebug: clean + clean: @rm -fr $(OBJDIR) @rm -fr $(BINDIR) diff --git a/src/classlib/local.cc b/src/classlib/local.cc index 1807e3c..f5799e5 100644 --- a/src/classlib/local.cc +++ b/src/classlib/local.cc @@ -418,9 +418,9 @@ return _get_connection_state(hSession); } - int connect(bool wait) + int connect(void) { - return _connect(hSession,(int) wait); + return _connect(hSession,0); } int set_url(const char *uri) diff --git a/src/classlib/remote.cc b/src/classlib/remote.cc index e09dd26..10bc42e 100644 --- a/src/classlib/remote.cc +++ b/src/classlib/remote.cc @@ -712,7 +712,7 @@ return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); } - int connect(bool wait) + int connect(void) { int rc; @@ -736,12 +736,6 @@ rc = -1; #endif - - trace("%s: rc=%d",__FUNCTION__,rc); - - if(!rc && wait) - return wait_for_ready(120); - return rc; } @@ -783,8 +777,8 @@ while(time(0) < end) { - //if(!is_connected()) - // return ENOTCONN; + if(!is_connected()) + return ENOTCONN; if(is_ready()) return 0; @@ -871,8 +865,12 @@ int iterate(bool wait) { #if defined(WIN32) + if(wait) + Sleep(250); return 0; #elif defined(HAVE_DBUS) + if(wait) + usleep(250); return 0; #else return -1; diff --git a/src/classlib/session.cc b/src/classlib/session.cc index 2dbee1a..c7a03ff 100644 --- a/src/classlib/session.cc +++ b/src/classlib/session.cc @@ -34,6 +34,10 @@ #include +#ifndef WIN32 + #include +#endif // !WIN32 + #ifdef HAVE_SYSLOG #include #endif // HAVE_SYSLOG @@ -481,7 +485,7 @@ return set_url(host); } - int session::connect(const char *host, bool wait) + int session::connect(const char *host, time_t wait) { int rc = 0; @@ -491,8 +495,22 @@ trace("%s: set_url(%s) = %d",__FUNCTION__,host,rc); } - if(!rc) - rc = connect(wait); + rc = connect(); + trace("%s: connect=%d",__FUNCTION__,rc); + + if(!rc && wait) + { + time_t timeout = time(0)+wait; + rc = ETIMEDOUT; + + while(time(0) < timeout && rc == ETIMEDOUT) + { + trace("%s: Waiting",__FUNCTION__); + if(is_connected()) + rc = 0; + iterate(true); + } + } return rc; } diff --git a/src/classlib/testprogram.cc b/src/classlib/testprogram.cc index 29b0ed2..9af23ba 100644 --- a/src/classlib/testprogram.cc +++ b/src/classlib/testprogram.cc @@ -41,7 +41,7 @@ { string s; - session *session = session::start("pw3270:a"); + session *session = session::start(""); // session *session = session::start("new"); cout << "pw3270 version: " << session->get_version() << endl; @@ -60,7 +60,7 @@ s = session->get_host_charset(); cout << "\tHost charset: " << s.c_str() << endl; - session->connect(false); + cout << "Connect: " << session->connect("fandezhi.efglobe.com:23",60) << endl << endl; cout << "\tWaitForReady: " << session->wait_for_ready(10) << endl; @@ -75,6 +75,7 @@ sleep(2); // Create another session + /* { session *session = session::start("pw3270:a"); @@ -82,6 +83,7 @@ delete session; } + */ return 0; diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index d413961..9aefb65 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -134,9 +134,9 @@ virtual string get_display_charset(void); // Connection & Network - int connect(const char *host, bool wait = true); - int set_host(const char *host); - virtual int connect(bool wait = true) = 0; + int connect(const char *host, time_t wait = 0); + int set_host(const char *host); + virtual int connect(void) = 0; virtual int set_url(const char *hostname) = 0; virtual int disconnect(void) = 0; virtual int wait_for_ready(int seconds) = 0; diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h index 2295b94..7c54b93 100644 --- a/src/include/pw3270/hllapi.h +++ b/src/include/pw3270/hllapi.h @@ -100,7 +100,35 @@ extern "C" { #else - #error NOT IMPLEMENTED + typedef unsigned short DWORD + + LIB3270_EXPORT int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc); + + LIB3270_EXPORT DWORD __stdcall hllapi_init(LPSTR mode); + LIB3270_EXPORT DWORD __stdcall hllapi_deinit(void); + + LIB3270_EXPORT DWORD __stdcall hllapi_get_revision(void); + LIB3270_EXPORT DWORD __stdcall hllapi_get_datadir(LPSTR datadir); + + LIB3270_EXPORT DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait); + LIB3270_EXPORT DWORD __stdcall hllapi_disconnect(void); + LIB3270_EXPORT DWORD __stdcall hllapi_get_message_id(void); + LIB3270_EXPORT DWORD __stdcall hllapi_is_connected(void); + LIB3270_EXPORT DWORD __stdcall hllapi_get_state(void); + LIB3270_EXPORT DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer); + LIB3270_EXPORT DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len); + LIB3270_EXPORT DWORD __stdcall hllapi_enter(void); + LIB3270_EXPORT DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text); + LIB3270_EXPORT DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); + LIB3270_EXPORT DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting); + LIB3270_EXPORT DWORD __stdcall hllapi_wait_for_ready(WORD seconds); + LIB3270_EXPORT DWORD __stdcall hllapi_wait(WORD seconds); + LIB3270_EXPORT DWORD __stdcall hllapi_pfkey(WORD key); + LIB3270_EXPORT DWORD __stdcall hllapi_pakey(WORD key); + LIB3270_EXPORT DWORD __stdcall hllapi_setcursor(WORD key); + LIB3270_EXPORT DWORD __stdcall hllapi_getcursor(); + LIB3270_EXPORT DWORD __stdcall hllapi_erase_eof(void); + LIB3270_EXPORT DWORD __stdcall hllapi_print(void); #endif // _WIN32 diff --git a/src/plugins/hllapi/Makefile.in b/src/plugins/hllapi/Makefile.in index f73ae67..a23d7b6 100644 --- a/src/plugins/hllapi/Makefile.in +++ b/src/plugins/hllapi/Makefile.in @@ -66,23 +66,17 @@ DEBUG_CFLAGS=-DDEBUG=1 -g -Wall LIB3270_MODE ?= Default ifeq ($(LIB3270_MODE),Debug) - PW3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l@PACKAGE_TARNAME@ -l3270 PW3270_CFLAGS=-I../../../src/include - LIB3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l3270 LIB3270_CFLAGS=-I../../../src/include endif ifeq ($(LIB3270_MODE),Release) - PW3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l@PACKAGE_TARNAME@ -l3270 PW3270_CFLAGS=-I../../../src/include - LIB3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l3270 LIB3270_CFLAGS=-I../../../src/include endif ifeq ($(LIB3270_MODE),Default) - LIB3270_LIBS ?= `pkg-config --libs lib3270` LIB3270_CFLAGS ?= `pkg-config --cflags lib3270` - PW3270_LIBS ?= `pkg-config --libs pw3270 lib3270` PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` endif diff --git a/src/plugins/hllapi/calls.cc b/src/plugins/hllapi/calls.cc index 3ce36fd..382cb4b 100644 --- a/src/plugins/hllapi/calls.cc +++ b/src/plugins/hllapi/calls.cc @@ -37,7 +37,8 @@ /*--[ Globals ]--------------------------------------------------------------------------------------*/ - static session * hSession = NULL; + static session * hSession = NULL; + static time_t hllapi_timeout = 120; /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -100,7 +101,7 @@ try { - rc = session::get_default()->connect(uri,wait); + rc = session::get_default()->connect(uri,hllapi_timeout); } catch(std::exception &e) { diff --git a/src/plugins/hllapi/client.h b/src/plugins/hllapi/client.h index af57aad..677904d 100644 --- a/src/plugins/hllapi/client.h +++ b/src/plugins/hllapi/client.h @@ -45,7 +45,7 @@ void * hllapi_pipe_init(const char *id); void hllapi_pipe_deinit(void *h); - const char * hllapi_pipe_get_revision(void); + const char * hllapi_pipe_get_revision(void); void hllapi_pipe_release_memory(void *p); int hllapi_pipe_connect(void *h, const char *n, int wait); void hllapi_pipe_disconnect(void *h); diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc index 0787623..d9140c4 100644 --- a/src/plugins/rx3270/pluginmain.cc +++ b/src/plugins/rx3270/pluginmain.cc @@ -90,7 +90,7 @@ LIB3270_CSTATE get_cstate(void); int disconnect(void); int set_url(const char *uri); - int connect(bool wait = true); + int connect(void); bool is_connected(void); bool is_ready(void); @@ -543,9 +543,9 @@ extern "C" return 0; } - int plugin::connect(bool wait) + int plugin::connect(void) { - return lib3270_connect(hSession,wait); + return lib3270_connect(hSession,0); } bool plugin::is_connected(void) -- libgit2 0.21.2