From 08e1c4dd3fb62a4751f3328ae711e1b87acef760 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Sat, 7 Dec 2013 16:07:11 +0000 Subject: [PATCH] Implementando novo mecanismo de conexao --- src/classlib/remote.cc | 39 ++++++++++++++++++++++++++++++++++++--- src/classlib/session.cc | 13 +++++++++++++ src/include/pw3270/class.h | 1 + src/plugins/hllapi/calls.cc | 4 +--- src/plugins/rx3270/pluginmain.cc | 6 ++++++ src/plugins/rx3270/rexx_methods.cc | 5 +---- src/plugins/rx3270/typed_routines.cc | 7 +------ 7 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/classlib/remote.cc b/src/classlib/remote.cc index 27c5821..f91fe3f 100644 --- a/src/classlib/remote.cc +++ b/src/classlib/remote.cc @@ -653,31 +653,64 @@ int connect(bool wait) { + int rc; + #if defined(WIN32) - size_t cbSize = sizeof(struct hllapi_packet_connect)+strlen(uri); + size_t cbSize = sizeof(struct hllapi_packet_connect); struct hllapi_packet_connect * pkt = (struct hllapi_packet_connect *) malloc(cbSize); pkt->packet_id = HLLAPI_PACKET_CONNECT; pkt->wait = (unsigned char) wait; - return query_intval((void *) pkt,cbSize,true); + rc = query_intval((void *) pkt,cbSize,true); #elif defined(HAVE_DBUS) int rc = query_intval("connect", DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID); +#else + rc = -1; + +#endif + if(!rc && wait) return wait_for_ready(120); return rc; -#else + } + + int set_host(const char *uri) + { + int rc; + +#if defined(WIN32) + + size_t cbSize = sizeof(struct hllapi_packet_text)+strlen(uri); + struct hllapi_packet_text * pkt = (struct hllapi_packet_text *) malloc(cbSize); + + pkt->packet_id = HLLAPI_PACKET_SET_HOST; + strcpy(pkt->text,uri); + + rc = query_intval((void *) pkt,cbSize,true); + +#elif defined(HAVE_DBUS) + + #warning Implementar return -1; +#else + + rc = -1; + #endif + + return rc; + } + int wait_for_ready(int seconds) { #if defined(WIN32) diff --git a/src/classlib/session.cc b/src/classlib/session.cc index fba4cc4..8ca6247 100644 --- a/src/classlib/session.cc +++ b/src/classlib/session.cc @@ -469,6 +469,19 @@ return EINVAL; } + int session::connect(const char *host, bool wait) + { + int rc = 0; + + if(host && *host) + rc = set_host(host); + + if(!rc) + rc = connect(wait); + + return rc; + } + #ifdef WIN32 string session::win32_strerror(int e) { diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index fa96b45..5cb984b 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -128,6 +128,7 @@ virtual string * get_display_charset(void); // Connection & Network + int connect(const char *host, bool wait = true); virtual int connect(bool wait = true) = 0; virtual int set_host(const char *hostname) = 0; virtual int disconnect(void) = 0; diff --git a/src/plugins/hllapi/calls.cc b/src/plugins/hllapi/calls.cc index e3926c3..258620c 100644 --- a/src/plugins/hllapi/calls.cc +++ b/src/plugins/hllapi/calls.cc @@ -100,9 +100,7 @@ try { - if(uri && *uri) - session::get_default()->set_host(uri); - rc = session::get_default()->connect(wait); + rc = session::get_default()->connect(uri,wait); } catch(std::exception &e) { diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc index 67b648c..7e1bb25 100644 --- a/src/plugins/rx3270/pluginmain.cc +++ b/src/plugins/rx3270/pluginmain.cc @@ -89,6 +89,7 @@ const string get_version(void); LIB3270_CSTATE get_cstate(void); int disconnect(void); + int set_host(const char *uri); int connect(bool wait = true); bool is_connected(void); bool is_ready(void); @@ -778,6 +779,11 @@ const char * plugin::asc2ebc(unsigned char *str, int sz) return lib3270_asc2ebc(hSession,str,sz); } +int plugin::set_host(const char *uri) +{ + return lib3270_set_host(hSession,uri) != NULL; +} + const char * plugin::ebc2asc(unsigned char *str, int sz) { return lib3270_ebc2asc(hSession,str,sz); diff --git a/src/plugins/rx3270/rexx_methods.cc b/src/plugins/rx3270/rexx_methods.cc index 23a911c..30aacfc 100644 --- a/src/plugins/rx3270/rexx_methods.cc +++ b/src/plugins/rx3270/rexx_methods.cc @@ -101,10 +101,7 @@ RexxMethod3(int, rx3270_method_connect, CSELF, sessionPtr, CSTRING, uri, OPTIONA if(!hSession) return -1; - if(uri) - hSession->set_hostname(uri); - - return hSession->connect(wait != 0); + return hSession->connect(uri,wait != 0); } RexxMethod1(int, rx3270_method_disconnect, CSELF, sessionPtr) diff --git a/src/plugins/rx3270/typed_routines.cc b/src/plugins/rx3270/typed_routines.cc index fee6097..156b616 100644 --- a/src/plugins/rx3270/typed_routines.cc +++ b/src/plugins/rx3270/typed_routines.cc @@ -93,12 +93,7 @@ RexxRoutine0(int, rx3270Disconnect) RexxRoutine2(int, rx3270Connect, CSTRING, hostname, int, wait) { - session * hSession = session::get_default(); - - if(hostname && *hostname) - hSession->set_hostname(hostname); - - return hSession->connect(wait); + return session::get_default()->connect(hostname,wait); } RexxRoutine0(int, rx3270isConnected) -- libgit2 0.21.2