From b8f2f9aae155ccfbeb304432fe16445e7c3558a6 Mon Sep 17 00:00:00 2001 From: PerryWerneck Date: Thu, 2 Mar 2017 23:20:40 -0300 Subject: [PATCH] Implementando novo método remoto. --- src/include/pw3270cpp.h | 5 ++++- src/libpw3270cpp/local.cc | 17 +++++++++++++++-- src/libpw3270cpp/remote.cc | 1 - src/libpw3270cpp/service.cc | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- src/libpw3270cpp/session.cc | 18 ++++-------------- src/libpw3270cpp/testprogram.cc | 6 ++---- 6 files changed, 104 insertions(+), 48 deletions(-) diff --git a/src/include/pw3270cpp.h b/src/include/pw3270cpp.h index 9f9efaa..3a44aa2 100644 --- a/src/include/pw3270cpp.h +++ b/src/include/pw3270cpp.h @@ -180,8 +180,11 @@ virtual string get_display_charset(void); // Connection & Network - virtual int connect(const char *host = "", time_t wait = 0) = 0; + virtual int connect() = 0; + virtual int connect(const char *url, time_t wait = 0); int set_host(const char *host); + virtual int set_url(const char *uri) = 0; + virtual string get_url() = 0; virtual int disconnect(void) = 0; virtual int wait_for_ready(int seconds) = 0; diff --git a/src/libpw3270cpp/local.cc b/src/libpw3270cpp/local.cc index 8eb78ad..242068f 100644 --- a/src/libpw3270cpp/local.cc +++ b/src/libpw3270cpp/local.cc @@ -127,7 +127,7 @@ int (*_disconnect)(H3270 *h); - int (*_connect)(H3270 *h,int wait); + int (*_connect)(H3270 *h, const char *url, int wait); const char (*_set_url)(H3270 *h, const char *n); const char * (*_get_url)(H3270 *h, char *str, int len); int (*_is_connected)(H3270 *h); @@ -197,7 +197,7 @@ { (void **) & _get_version, "lib3270_get_version" }, { (void **) & _disconnect, "lib3270_disconnect" }, - { (void **) & _connect, "lib3270_connect" }, + { (void **) & _connect, "lib3270_connect_url" }, { (void **) & _set_url, "lib3270_set_url" }, { (void **) & _get_url, "lib3270_get_url" }, { (void **) & _main_iterate, "lib3270_main_iterate" }, @@ -288,6 +288,18 @@ return _get_secure(hSession); }; + int connect(const char *host, time_t wait = 0) { + this->lock(); + int rc = _connect(hSession,host,wait); + this->unlock(); + return rc; + } + + int connect() { + return connect(""); + } + + /* int connect(void) { this->lock(); @@ -296,6 +308,7 @@ return rc; } + */ int set_url(const char *uri) { diff --git a/src/libpw3270cpp/remote.cc b/src/libpw3270cpp/remote.cc index a4cfd82..8184307 100644 --- a/src/libpw3270cpp/remote.cc +++ b/src/libpw3270cpp/remote.cc @@ -817,7 +817,6 @@ return (LIB3270_SSL_STATE) query_intval(HLLAPI_PACKET_GET_SSL_STATE); } - int connect(void) { int rc; diff --git a/src/libpw3270cpp/service.cc b/src/libpw3270cpp/service.cc index c6b48af..a3da6a3 100644 --- a/src/libpw3270cpp/service.cc +++ b/src/libpw3270cpp/service.cc @@ -60,7 +60,8 @@ #define DBUS_INTERFACE "br.com.bb.pw3270.service" DBusConnection * conn; - string id; + string name; + const char * id; DBusMessage * createMessage(const char *method) { @@ -184,6 +185,17 @@ return getInteger(call(msg)); } + string getString(const char *method, int first_arg_type, ...) + { + va_list var_args; + DBusMessage * msg = createMessage(method); + + va_start(var_args, first_arg_type); + dbus_message_append_args_valist(msg,first_arg_type,var_args); + va_end(var_args); + + return getString(call(msg)); + } protected: @@ -194,17 +206,43 @@ virtual string get_text_at(int row, int col, size_t sz) { + dbus_int32_t r = (dbus_int32_t) row; + dbus_int32_t c = (dbus_int32_t) col; + dbus_int32_t s = (dbus_int32_t) sz; + + return getString( "getTextAt", + DBUS_TYPE_STRING, this->id, + DBUS_TYPE_INT32, &r, + DBUS_TYPE_INT32, &c, + DBUS_TYPE_INT32, &s, + DBUS_TYPE_INVALID); } virtual int set_text_at(int row, int col, const char *str) { + dbus_int32_t r = (dbus_int32_t) row; + dbus_int32_t c = (dbus_int32_t) col; + return getInteger( "setTextAt", + DBUS_TYPE_STRING, this->id, + DBUS_TYPE_INT32, &r, + DBUS_TYPE_INT32, &c, + DBUS_TYPE_STRING, str, + DBUS_TYPE_INVALID); } - virtual int cmp_text_at(int row, int col, const char *text) + virtual int cmp_text_at(int row, int col, const char *str) { + dbus_int32_t r = (dbus_int32_t) row; + dbus_int32_t c = (dbus_int32_t) col; + return getInteger( "cmpTextAt", + DBUS_TYPE_STRING, this->id, + DBUS_TYPE_INT32, &r, + DBUS_TYPE_INT32, &c, + DBUS_TYPE_STRING, str, + DBUS_TYPE_INVALID); } virtual int emulate_input(const char *str) @@ -235,16 +273,17 @@ if(*session != '?') { // Já tem sessão definida, usa. - this->id = session; + this->name = session; } else { // Obter um ID de sessão no serviço - this->id = getString("createSession"); + this->name = getString("createSession"); } - trace("Session=%s",this->id.c_str()); + trace("Session=%s",this->name.c_str()); + this->id = this->name.c_str(); } virtual ~client() @@ -254,48 +293,48 @@ virtual bool is_connected(void) { - return getInteger("isConnected", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return getInteger("isConnected", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual bool is_ready(void) { - return getInteger("isReady", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return getInteger("isReady", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual LIB3270_CSTATE get_cstate(void) { - return (LIB3270_CSTATE) getInteger("getConnectionState", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return (LIB3270_CSTATE) getInteger("getConnectionState", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual LIB3270_MESSAGE get_program_message(void) { - return (LIB3270_MESSAGE) getInteger("getProgramMessage", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return (LIB3270_MESSAGE) getInteger("getProgramMessage", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual LIB3270_SSL_STATE get_secure(void) { - return (LIB3270_SSL_STATE) getInteger("getSecureState", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return (LIB3270_SSL_STATE) getInteger("getSecureState", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual int get_width(void) { - return getInteger("getScreenWidth", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return getInteger("getScreenWidth", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual int get_height(void) { - return getInteger("getScreenHeight", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return getInteger("getScreenHeight", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual int get_length(void) { - return getInteger("getScreenLength", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return getInteger("getScreenLength", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual void set_unlock_delay(unsigned short ms) { dbus_int32_t val = (dbus_int32_t) ms; - getInteger("setUnlockDelay", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INT32, val, DBUS_TYPE_INVALID); + getInteger("setUnlockDelay", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); } virtual int set_host_charset(const char *charset) @@ -308,14 +347,26 @@ } - virtual int connect(void) + virtual int connect() { - return getInteger("connect", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_STRING, "", DBUS_TYPE_INVALID); + return connect("",0); + } + + virtual int connect(const char *url, time_t wait) + { + int rc = getInteger("connect", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_STRING, &url, DBUS_TYPE_INVALID); + + if(!rc && wait) { + rc = wait_for_ready(wait); + } + + return rc; + } virtual int set_url(const char *hostname) { - return getInteger("setURL", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_STRING, hostname, DBUS_TYPE_INVALID); + return getInteger("setURL", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_STRING, &hostname, DBUS_TYPE_INVALID); } virtual string get_url() @@ -325,7 +376,7 @@ virtual int disconnect(void) { - return getInteger("disconnect", DBUS_TYPE_STRING, this->id.c_str(), DBUS_TYPE_INVALID); + return getInteger("disconnect", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } virtual int wait_for_ready(int seconds) @@ -398,27 +449,29 @@ } - virtual int enter(void) + virtual int enter(void) { - + return getInteger("enter", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INVALID); } - virtual int pfkey(int key) + virtual int pfkey(int key) { - + dbus_int32_t val = (dbus_int32_t) key; + getInteger("pfKey", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); } - virtual int pakey(int key) + virtual int pakey(int key) { - + dbus_int32_t val = (dbus_int32_t) key; + getInteger("paKey", DBUS_TYPE_STRING, &this->id, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); } - virtual int quit(void) + virtual int quit(void) { } - virtual int action(const char *name) + virtual int action(const char *name) { } diff --git a/src/libpw3270cpp/session.cc b/src/libpw3270cpp/session.cc index fdd15ba..fc41d2f 100644 --- a/src/libpw3270cpp/session.cc +++ b/src/libpw3270cpp/session.cc @@ -621,14 +621,13 @@ return set_url(host); } - int session::connect(const char *host, time_t wait) + int session::connect(const char *url, time_t wait) { int rc = 0; - if(host && *host) + if(url && *url) { - rc = set_url(host); - trace("%s: set_url(%s) = %d",__FUNCTION__,host,rc); + set_url(url); } rc = connect(); @@ -636,16 +635,7 @@ 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); - } + rc = wait_for_ready(wait); } return rc; diff --git a/src/libpw3270cpp/testprogram.cc b/src/libpw3270cpp/testprogram.cc index 2bc53e0..943d7f5 100644 --- a/src/libpw3270cpp/testprogram.cc +++ b/src/libpw3270cpp/testprogram.cc @@ -46,12 +46,9 @@ // session *session = session::start(""); // session *session = session::start("new"); - return 0; - cout << "pw3270 version: " << session->get_version() << endl; cout << "pw3270 revision: " << session->get_revision() << endl << endl; - /* if(session->is_connected()) cout << "\tConnected to host" << endl; else @@ -64,7 +61,8 @@ s = session->get_host_charset(); cout << "\tHost charset: " << s.c_str() << endl; - */ + + return 0; cout << "Connect: " << session->connect("fandezhi.efglobe.com:23",60) << endl << endl; -- libgit2 0.21.2