Commit b094d22b54a449197b53e5585665ba0bc069966b

Authored by perry.werneck@gmail.com
1 parent 8c031cd6

Melhorando método connect da classe de apoio

src/classlib/Makefile.in
@@ -121,6 +121,8 @@ install-sdk: $(BINRLS)/$(LIBNAME) @@ -121,6 +121,8 @@ install-sdk: $(BINRLS)/$(LIBNAME)
121 @$(MKDIR) $(DESTDIR)$(libdir) 121 @$(MKDIR) $(DESTDIR)$(libdir)
122 @$(INSTALL_DATA) $(BINRLS)/$(LIBNAME) $(DESTDIR)$(libdir) 122 @$(INSTALL_DATA) $(BINRLS)/$(LIBNAME) $(DESTDIR)$(libdir)
123 123
  124 +cleanDebug: clean
  125 +
124 clean: 126 clean:
125 @rm -fr $(OBJDIR) 127 @rm -fr $(OBJDIR)
126 @rm -fr $(BINDIR) 128 @rm -fr $(BINDIR)
src/classlib/local.cc
@@ -418,9 +418,9 @@ @@ -418,9 +418,9 @@
418 return _get_connection_state(hSession); 418 return _get_connection_state(hSession);
419 } 419 }
420 420
421 - int connect(bool wait) 421 + int connect(void)
422 { 422 {
423 - return _connect(hSession,(int) wait); 423 + return _connect(hSession,0);
424 } 424 }
425 425
426 int set_url(const char *uri) 426 int set_url(const char *uri)
src/classlib/remote.cc
@@ -712,7 +712,7 @@ @@ -712,7 +712,7 @@
712 return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); 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 int rc; 717 int rc;
718 718
@@ -736,12 +736,6 @@ @@ -736,12 +736,6 @@
736 rc = -1; 736 rc = -1;
737 737
738 #endif 738 #endif
739 -  
740 - trace("%s: rc=%d",__FUNCTION__,rc);  
741 -  
742 - if(!rc && wait)  
743 - return wait_for_ready(120);  
744 -  
745 return rc; 739 return rc;
746 740
747 } 741 }
@@ -783,8 +777,8 @@ @@ -783,8 +777,8 @@
783 777
784 while(time(0) < end) 778 while(time(0) < end)
785 { 779 {
786 - //if(!is_connected())  
787 - // return ENOTCONN; 780 + if(!is_connected())
  781 + return ENOTCONN;
788 782
789 if(is_ready()) 783 if(is_ready())
790 return 0; 784 return 0;
@@ -871,8 +865,12 @@ @@ -871,8 +865,12 @@
871 int iterate(bool wait) 865 int iterate(bool wait)
872 { 866 {
873 #if defined(WIN32) 867 #if defined(WIN32)
  868 + if(wait)
  869 + Sleep(250);
874 return 0; 870 return 0;
875 #elif defined(HAVE_DBUS) 871 #elif defined(HAVE_DBUS)
  872 + if(wait)
  873 + usleep(250);
876 return 0; 874 return 0;
877 #else 875 #else
878 return -1; 876 return -1;
src/classlib/session.cc
@@ -34,6 +34,10 @@ @@ -34,6 +34,10 @@
34 34
35 #include <pw3270/class.h> 35 #include <pw3270/class.h>
36 36
  37 +#ifndef WIN32
  38 + #include <unistd.h>
  39 +#endif // !WIN32
  40 +
37 #ifdef HAVE_SYSLOG 41 #ifdef HAVE_SYSLOG
38 #include <syslog.h> 42 #include <syslog.h>
39 #endif // HAVE_SYSLOG 43 #endif // HAVE_SYSLOG
@@ -481,7 +485,7 @@ @@ -481,7 +485,7 @@
481 return set_url(host); 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 int rc = 0; 490 int rc = 0;
487 491
@@ -491,8 +495,22 @@ @@ -491,8 +495,22 @@
491 trace("%s: set_url(%s) = %d",__FUNCTION__,host,rc); 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 return rc; 515 return rc;
498 } 516 }
src/classlib/testprogram.cc
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 41
42 { 42 {
43 string s; 43 string s;
44 - session *session = session::start("pw3270:a"); 44 + session *session = session::start("");
45 // session *session = session::start("new"); 45 // session *session = session::start("new");
46 46
47 cout << "pw3270 version: " << session->get_version() << endl; 47 cout << "pw3270 version: " << session->get_version() << endl;
@@ -60,7 +60,7 @@ @@ -60,7 +60,7 @@
60 s = session->get_host_charset(); 60 s = session->get_host_charset();
61 cout << "\tHost charset: " << s.c_str() << endl; 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 cout << "\tWaitForReady: " << session->wait_for_ready(10) << endl; 65 cout << "\tWaitForReady: " << session->wait_for_ready(10) << endl;
66 66
@@ -75,6 +75,7 @@ @@ -75,6 +75,7 @@
75 sleep(2); 75 sleep(2);
76 76
77 // Create another session 77 // Create another session
  78 + /*
78 { 79 {
79 session *session = session::start("pw3270:a"); 80 session *session = session::start("pw3270:a");
80 81
@@ -82,6 +83,7 @@ @@ -82,6 +83,7 @@
82 delete session; 83 delete session;
83 84
84 } 85 }
  86 + */
85 87
86 88
87 return 0; 89 return 0;
src/include/pw3270/class.h
@@ -134,9 +134,9 @@ @@ -134,9 +134,9 @@
134 virtual string get_display_charset(void); 134 virtual string get_display_charset(void);
135 135
136 // Connection & Network 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 virtual int set_url(const char *hostname) = 0; 140 virtual int set_url(const char *hostname) = 0;
141 virtual int disconnect(void) = 0; 141 virtual int disconnect(void) = 0;
142 virtual int wait_for_ready(int seconds) = 0; 142 virtual int wait_for_ready(int seconds) = 0;
src/include/pw3270/hllapi.h
@@ -100,7 +100,35 @@ extern &quot;C&quot; { @@ -100,7 +100,35 @@ extern &quot;C&quot; {
100 100
101 #else 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 #endif // _WIN32 133 #endif // _WIN32
106 134
src/plugins/hllapi/Makefile.in
@@ -66,23 +66,17 @@ DEBUG_CFLAGS=-DDEBUG=1 -g -Wall @@ -66,23 +66,17 @@ DEBUG_CFLAGS=-DDEBUG=1 -g -Wall
66 LIB3270_MODE ?= Default 66 LIB3270_MODE ?= Default
67 67
68 ifeq ($(LIB3270_MODE),Debug) 68 ifeq ($(LIB3270_MODE),Debug)
69 - PW3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l@PACKAGE_TARNAME@ -l3270  
70 PW3270_CFLAGS=-I../../../src/include 69 PW3270_CFLAGS=-I../../../src/include
71 - LIB3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l3270  
72 LIB3270_CFLAGS=-I../../../src/include 70 LIB3270_CFLAGS=-I../../../src/include
73 endif 71 endif
74 72
75 ifeq ($(LIB3270_MODE),Release) 73 ifeq ($(LIB3270_MODE),Release)
76 - PW3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l@PACKAGE_TARNAME@ -l3270  
77 PW3270_CFLAGS=-I../../../src/include 74 PW3270_CFLAGS=-I../../../src/include
78 - LIB3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l3270  
79 LIB3270_CFLAGS=-I../../../src/include 75 LIB3270_CFLAGS=-I../../../src/include
80 endif 76 endif
81 77
82 ifeq ($(LIB3270_MODE),Default) 78 ifeq ($(LIB3270_MODE),Default)
83 - LIB3270_LIBS ?= `pkg-config --libs lib3270`  
84 LIB3270_CFLAGS ?= `pkg-config --cflags lib3270` 79 LIB3270_CFLAGS ?= `pkg-config --cflags lib3270`
85 - PW3270_LIBS ?= `pkg-config --libs pw3270 lib3270`  
86 PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` 80 PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270`
87 endif 81 endif
88 82
src/plugins/hllapi/calls.cc
@@ -37,7 +37,8 @@ @@ -37,7 +37,8 @@
37 37
38 /*--[ Globals ]--------------------------------------------------------------------------------------*/ 38 /*--[ Globals ]--------------------------------------------------------------------------------------*/
39 39
40 - static session * hSession = NULL; 40 + static session * hSession = NULL;
  41 + static time_t hllapi_timeout = 120;
41 42
42 /*--[ Implement ]------------------------------------------------------------------------------------*/ 43 /*--[ Implement ]------------------------------------------------------------------------------------*/
43 44
@@ -100,7 +101,7 @@ @@ -100,7 +101,7 @@
100 101
101 try 102 try
102 { 103 {
103 - rc = session::get_default()->connect(uri,wait); 104 + rc = session::get_default()->connect(uri,hllapi_timeout);
104 } 105 }
105 catch(std::exception &e) 106 catch(std::exception &e)
106 { 107 {
src/plugins/hllapi/client.h
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 45
46 void * hllapi_pipe_init(const char *id); 46 void * hllapi_pipe_init(const char *id);
47 void hllapi_pipe_deinit(void *h); 47 void hllapi_pipe_deinit(void *h);
48 - const char * hllapi_pipe_get_revision(void); 48 + const char * hllapi_pipe_get_revision(void);
49 void hllapi_pipe_release_memory(void *p); 49 void hllapi_pipe_release_memory(void *p);
50 int hllapi_pipe_connect(void *h, const char *n, int wait); 50 int hllapi_pipe_connect(void *h, const char *n, int wait);
51 void hllapi_pipe_disconnect(void *h); 51 void hllapi_pipe_disconnect(void *h);
src/plugins/rx3270/pluginmain.cc
@@ -90,7 +90,7 @@ @@ -90,7 +90,7 @@
90 LIB3270_CSTATE get_cstate(void); 90 LIB3270_CSTATE get_cstate(void);
91 int disconnect(void); 91 int disconnect(void);
92 int set_url(const char *uri); 92 int set_url(const char *uri);
93 - int connect(bool wait = true); 93 + int connect(void);
94 bool is_connected(void); 94 bool is_connected(void);
95 bool is_ready(void); 95 bool is_ready(void);
96 96
@@ -543,9 +543,9 @@ extern &quot;C&quot; @@ -543,9 +543,9 @@ extern &quot;C&quot;
543 return 0; 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 bool plugin::is_connected(void) 551 bool plugin::is_connected(void)