From e91b1c1407aca4d1e9490727c405dd0e67ba8dbb Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 19 Aug 2019 17:09:32 -0300 Subject: [PATCH] Updating keyboard lock calls. --- client/src/core/linux/request.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ client/src/core/session.cc | 63 ++++++++++++++++++++++++++++++++------------------------------- client/src/core/windows/request.cc | 27 +++++++++++++++++++++++++++ client/src/host/actions.cc | 4 ++-- client/src/include/ipc-client-internals.h | 1 + client/src/session/local/actions.cc | 4 ++-- client/src/session/local/get.cc | 5 +++++ client/src/session/local/private.h | 4 +++- client/src/session/local/properties.cc | 23 +++++++++++++++++++++++ client/src/session/remote/actions.cc | 6 +++--- client/src/session/remote/get.cc | 6 ++++++ client/src/session/remote/private.h | 4 +++- client/src/session/remote/properties.cc | 8 ++++++++ client/src/testprogram/testprogram.cc | 2 +- common/src/include/lib3270/ipc.h | 12 +++++++++--- server/src/core/linux/gobject.c | 2 +- server/src/core/methods/methods.c | 32 ++++++++++++++++---------------- server/src/core/methods/private.h | 2 +- server/src/core/methods/wait.c | 4 ++-- 19 files changed, 200 insertions(+), 64 deletions(-) diff --git a/client/src/core/linux/request.cc b/client/src/core/linux/request.cc index 0f1ae78..1da9ab7 100644 --- a/client/src/core/linux/request.cc +++ b/client/src/core/linux/request.cc @@ -144,6 +144,51 @@ return *this; } + static int getUIntValue(DBusMessageIter &iter) { + + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT32) { + + dbus_uint32_t rc = 0; + dbus_message_iter_get_basic(&iter, &rc); + return (int) rc; + + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT16) { + + dbus_uint16_t rc = 0; + dbus_message_iter_get_basic(&iter, &rc); + return (int) rc; + + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) { + + DBusMessageIter sub; + int current_type; + + dbus_message_iter_recurse(&iter, &sub); + + while ((current_type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) { + + if (current_type == DBUS_TYPE_UINT32) { + + dbus_uint32_t rc = 0; + dbus_message_iter_get_basic(&sub, &rc); + return (int) rc; + + } else if (current_type == DBUS_TYPE_UINT16) { + dbus_uint16_t rc = 0; + dbus_message_iter_get_basic(&sub, &rc); + return (int) rc; + + } + dbus_message_iter_next(&sub); + } + + } + + debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&iter)) ); + throw std::runtime_error("Expected an integer data type"); + + } + static int getIntValue(DBusMessageIter &iter) { if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) { @@ -199,6 +244,16 @@ } + IPC::Request & IPC::Request::Request::pop(unsigned int &value) { + + value = getUIntValue(msg.iter); + dbus_message_iter_next(&msg.iter); + debug(__FUNCTION__,"= \"",value,"\""); + + return *this; + + } + } diff --git a/client/src/core/session.cc b/client/src/core/session.cc index 7b41b4a..973fde9 100644 --- a/client/src/core/session.cc +++ b/client/src/core/session.cc @@ -81,7 +81,7 @@ // Wait for unlock, ignore errors. sz = (size_t) (ptr-text); if(sz) { - if( (rc = waitForUnlock()) != 0) { + if( (rc = waitForKeyboardUnlock()) != 0) { return rc; } push(text,sz); @@ -94,7 +94,7 @@ case 'E': // Enter push(ENTER); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'F': // Erase EOF @@ -103,122 +103,122 @@ case '1': // PF1 push(PF_1); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '2': // PF2 push(PF_2); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '3': // PF3 push(PF_3); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '4': // PF4 push(PF_4); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '5': // PF5 push(PF_5); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '6': // PF6 push(PF_6); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '7': // PF7 push(PF_7); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '8': // PF8 push(PF_8); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '9': // PF9 push(PF_9); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'a': // PF10 push(PF_10); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'b': // PF11 push(PF_11); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'c': // PF12 push(PF_12); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'd': // PF13 push(PF_13); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'e': // PF14 push(PF_14); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'f': // PF15 push(PF_15); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'g': // PF16 push(PF_16); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'h': // PF17 push(PF_17); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'i': // PF18 push(PF_18); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'j': // PF19 push(PF_19); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'k': // PF20 push(PF_20); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'l': // PF21 push(PF_21); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'm': // PF22 push(PF_22); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'n': // PF23 push(PF_23); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'o': // PF24 push(PF_24); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case '@': // Send '@' character @@ -227,17 +227,17 @@ case 'x': // PA1 push(PA_1); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'y': // PA2 push(PA_2); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'z': // PA3 push(PA_3); - rc = waitForUnlock(); + rc = waitForKeyboardUnlock(); break; case 'B': // PC_LEFTTAB = "@B" @@ -356,8 +356,9 @@ sz = strlen(text); if(sz) { - waitForUnlock(); - push(text,sz); + rc = waitForKeyboardUnlock(); + if(!rc) + push(text,sz); } return rc; diff --git a/client/src/core/windows/request.cc b/client/src/core/windows/request.cc index e130b0c..9b15a09 100644 --- a/client/src/core/windows/request.cc +++ b/client/src/core/windows/request.cc @@ -146,6 +146,33 @@ return *this; } + IPC::Request & IPC::Request::Request::pop(unsigned int &value) { + + DataBlock * block = getNextBlock(); + + switch(block->type) { + case IPC::Request::UInt16: + value = * ((uint16_t *) (block+1)); + in.current += sizeof(uint16_t) + sizeof(DataBlock); + break; + + case IPC::Request::UInt32: + value = * ((uint32_t *) (block+1)); + in.current += sizeof(uint32_t) + sizeof(DataBlock); + break; + + case IPC::Request::UInt64: + value = * ((uint64_t *) (block+1)); + in.current += sizeof(uint64_t) + sizeof(DataBlock); + break; + + default: + throw std::runtime_error("Invalid format"); + } + + return *this; + } + IPC::Request & IPC::Request::call() { #ifdef DEBUG diff --git a/client/src/host/actions.cc b/client/src/host/actions.cc index cb1638e..2e71c5c 100644 --- a/client/src/host/actions.cc +++ b/client/src/host/actions.cc @@ -55,8 +55,8 @@ TN3270::Host & TN3270::Host::waitForReady(time_t timeout) { return *this; } -TN3270::Host & TN3270::Host::waitForUnlock(time_t timeout) { - this->session->waitForUnlock(timeout); +TN3270::Host & TN3270::Host::waitForKeyboardUnlock(time_t timeout) { + this->session->waitForKeyboardUnlock(timeout); return *this; } diff --git a/client/src/include/ipc-client-internals.h b/client/src/include/ipc-client-internals.h index 12fcbbc..fb59eca 100644 --- a/client/src/include/ipc-client-internals.h +++ b/client/src/include/ipc-client-internals.h @@ -258,6 +258,7 @@ // Pop values Request & pop(std::string &value); Request & pop(int &value); + Request & pop(unsigned int &value); }; diff --git a/client/src/session/local/actions.cc b/client/src/session/local/actions.cc index 953cec3..d514d7a 100644 --- a/client/src/session/local/actions.cc +++ b/client/src/session/local/actions.cc @@ -73,10 +73,10 @@ chkResponse(lib3270_wait_for_ready(this->hSession, timeout)); } - LIB3270_KEYBOARD_LOCK_STATE Local::Session::waitForUnlock(time_t timeout) const { + LIB3270_KEYBOARD_LOCK_STATE Local::Session::waitForKeyboardUnlock(time_t timeout) const { std::lock_guard lock(const_cast(this)->sync); - return lib3270_wait_for_unlock(this->hSession, timeout); + return lib3270_wait_for_keyboard_unlock(this->hSession, timeout); } void Local::Session::waitForChange(time_t seconds) const { diff --git a/client/src/session/local/get.cc b/client/src/session/local/get.cc index e55529b..530671e 100644 --- a/client/src/session/local/get.cc +++ b/client/src/session/local/get.cc @@ -103,6 +103,11 @@ } + LIB3270_KEYBOARD_LOCK_STATE Local::Session::getKeyboardUnlock() const { + std::lock_guard lock(const_cast(this)->sync); + return lib3270_get_keyboard_lock_state(hSession); + } + } diff --git a/client/src/session/local/private.h b/client/src/session/local/private.h index 11d939d..3b512e9 100644 --- a/client/src/session/local/private.h +++ b/client/src/session/local/private.h @@ -103,7 +103,7 @@ void wait(time_t seconds) const override; void waitForReady(time_t timeout) const override; void waitForChange(time_t timeout) const override; - LIB3270_KEYBOARD_LOCK_STATE waitForUnlock(time_t seconds) const override; + LIB3270_KEYBOARD_LOCK_STATE waitForKeyboardUnlock(time_t seconds) const override; // States ProgramMessage getProgramMessage() const override; @@ -112,6 +112,7 @@ // Properties. void getProperty(const char *name, int &value) const override; + void getProperty(const char *name, unsigned int &value) const override; void getProperty(const char *name, std::string &value) const override; void getProperty(const char *name, bool &value) const override; void setProperty(const char *name, const int value) override; @@ -120,6 +121,7 @@ std::string getVersion() const override; std::string getRevision() const override; std::string getLUName() const override; + LIB3270_KEYBOARD_LOCK_STATE getKeyboardUnlock() const override; std::string getHostURL() const override; void setHostURL(const char *url) override; diff --git a/client/src/session/local/properties.cc b/client/src/session/local/properties.cc index 523feb1..2c6e6c9 100644 --- a/client/src/session/local/properties.cc +++ b/client/src/session/local/properties.cc @@ -68,6 +68,29 @@ throw std::system_error(ENOENT, std::system_category()); } + void Local::Session::getProperty(const char *name, unsigned int &value) const { + + const LIB3270_UINT_PROPERTY * intprop = lib3270_get_unsigned_properties_list(); + for(size_t ix = 0; intprop[ix].name; ix++) { + + if(!strcasecmp(name,intprop[ix].name)) { + + std::lock_guard lock(const_cast(this)->sync); + + value = intprop[ix].get(hSession); + + if(value < 0 && errno != 0) { + throw std::system_error(errno, std::system_category()); + } + + + } + + } + + throw std::system_error(ENOENT, std::system_category()); + } + void Local::Session::getProperty(const char *name, std::string &value) const { const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); diff --git a/client/src/session/remote/actions.cc b/client/src/session/remote/actions.cc index 7aba47c..b0f8032 100644 --- a/client/src/session/remote/actions.cc +++ b/client/src/session/remote/actions.cc @@ -128,7 +128,7 @@ } - LIB3270_KEYBOARD_LOCK_STATE IPC::Session::waitForUnlock(time_t timeout) const { + LIB3270_KEYBOARD_LOCK_STATE IPC::Session::waitForKeyboardUnlock(time_t timeout) const { int rc; @@ -136,9 +136,9 @@ while(time(nullptr) < end) { - debug("Running waitForUnlock request..."); + debug("Running waitForKeyboardUnlock request..."); - Request(*this,"waitForUnlock") + Request(*this,"waitForKeyboardUnlock") .push((uint32_t) 1) .call() .pop(rc); diff --git a/client/src/session/remote/get.cc b/client/src/session/remote/get.cc index 61e00f0..809e1d9 100644 --- a/client/src/session/remote/get.cc +++ b/client/src/session/remote/get.cc @@ -109,6 +109,12 @@ } + LIB3270_KEYBOARD_LOCK_STATE IPC::Session::getKeyboardUnlock() const { + unsigned int value; + getProperty("kybdlock",value); + return (LIB3270_KEYBOARD_LOCK_STATE) value; + } + } diff --git a/client/src/session/remote/private.h b/client/src/session/remote/private.h index 2031a47..e7d3023 100644 --- a/client/src/session/remote/private.h +++ b/client/src/session/remote/private.h @@ -101,7 +101,7 @@ void wait(time_t seconds) const override; void waitForReady(time_t timeout) const override; void waitForChange(time_t timeout) const override; - LIB3270_KEYBOARD_LOCK_STATE waitForUnlock(time_t seconds) const override; + LIB3270_KEYBOARD_LOCK_STATE waitForKeyboardUnlock(time_t seconds) const override; // States ProgramMessage getProgramMessage() const override; @@ -110,6 +110,7 @@ // Properties. void getProperty(const char *name, int &value) const override; + void getProperty(const char *name, unsigned int &value) const override; void getProperty(const char *name, std::string &value) const override; void getProperty(const char *name, bool &value) const override; void setProperty(const char *name, const int value) override; @@ -118,6 +119,7 @@ std::string getVersion() const override; std::string getRevision() const override; std::string getLUName() const override; + LIB3270_KEYBOARD_LOCK_STATE getKeyboardUnlock() const override; std::string getHostURL() const override; void setHostURL(const char *url) override; diff --git a/client/src/session/remote/properties.cc b/client/src/session/remote/properties.cc index 0d66126..bc0d126 100644 --- a/client/src/session/remote/properties.cc +++ b/client/src/session/remote/properties.cc @@ -53,6 +53,14 @@ } + void IPC::Session::getProperty(const char *name, unsigned int &value) const { + + Request(*this,false,name) + .call() + .pop(value); + + } + void IPC::Session::getProperty(const char *name, std::string &value) const { Request(*this,false,name) diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index a24b7d3..65c2a2c 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -99,7 +99,7 @@ host.connect(nullptr); cout - << "Wait for unlock returns " << host.waitForUnlock() << std::endl + << "Wait for unlock returns " << host.getKeyboardUnlock() << std::endl << "Connection state is " << toCharString(host.getConnectionState()) << std::endl << "Program message is " << toCharString(host.getProgramMessage()) << std::endl << "Luname is " << host.getLUName() << std::endl diff --git a/common/src/include/lib3270/ipc.h b/common/src/include/lib3270/ipc.h index 7b79e6a..165bed2 100644 --- a/common/src/include/lib3270/ipc.h +++ b/common/src/include/lib3270/ipc.h @@ -288,6 +288,7 @@ // Properties. virtual void getProperty(const char *name, int &value) const = 0; + virtual void getProperty(const char *name, unsigned int &value) const = 0; virtual void getProperty(const char *name, std::string &value) const = 0; virtual void getProperty(const char *name, bool &value) const = 0; virtual void setProperty(const char *name, const int value) = 0; @@ -296,6 +297,7 @@ virtual std::string getVersion() const = 0; virtual std::string getRevision() const = 0; virtual std::string getLUName() const = 0; + virtual LIB3270_KEYBOARD_LOCK_STATE getKeyboardUnlock() const = 0; virtual std::string getHostURL() const = 0; virtual void setHostURL(const char *url) = 0; @@ -337,7 +339,7 @@ virtual void waitForChange(time_t seconds = DEFAULT_TIMEOUT) const = 0; /// @brief Wait for screen changes. - virtual LIB3270_KEYBOARD_LOCK_STATE waitForUnlock(time_t seconds = DEFAULT_TIMEOUT) const = 0; + virtual LIB3270_KEYBOARD_LOCK_STATE waitForKeyboardUnlock(time_t seconds = DEFAULT_TIMEOUT) const = 0; /// @brief Send PF. virtual void pfkey(unsigned short value) = 0; @@ -424,8 +426,8 @@ template Host & push(T value) { - session->push(value); sync(); + session->push(value); return *this; } @@ -440,7 +442,7 @@ Host & connect(const char *url = nullptr); Host & disconnect(); Host & waitForReady(time_t timeout = DEFAULT_TIMEOUT); - Host & waitForUnlock(time_t timeout = DEFAULT_TIMEOUT); + Host & waitForKeyboardUnlock(time_t timeout = DEFAULT_TIMEOUT); /// @brief Execute action by name. inline Host & action(const char *action_name) { @@ -511,6 +513,10 @@ return session->getLUName(); } + inline LIB3270_KEYBOARD_LOCK_STATE getKeyboardUnlock() const { + return session->getKeyboardUnlock(); + } + // Actions /// @brief Send PF. diff --git a/server/src/core/linux/gobject.c b/server/src/core/linux/gobject.c index c50cc81..1f55c99 100644 --- a/server/src/core/linux/gobject.c +++ b/server/src/core/linux/gobject.c @@ -155,7 +155,7 @@ void ipc3270_add_terminal_introspection(GString *introspection) { " " \ " " \ " " \ - " " \ + " " \ " " \ " " \ " " \ diff --git a/server/src/core/methods/methods.c b/server/src/core/methods/methods.c index 01c5811..e81483d 100644 --- a/server/src/core/methods/methods.c +++ b/server/src/core/methods/methods.c @@ -46,22 +46,22 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req { "connect", ipc3270_method_connect }, { "disconnect", ipc3270_method_disconnect }, - { "wait", ipc3270_method_wait }, - { "waitforready", ipc3270_method_wait_for_ready }, - { "waitforupdate", ipc3270_method_wait_for_update }, - { "waitforunlock", ipc3270_method_wait_for_unlock }, - - { "getString", ipc3270_method_get_string }, - { "getStringAt", ipc3270_method_get_string }, - { "getStringAtAddress", ipc3270_method_get_string }, - - { "setString", ipc3270_method_set_string }, - { "setStringAt", ipc3270_method_set_string }, - { "setStringAtAddress", ipc3270_method_set_string }, - - { "getFieldAttribute", ipc3270_method_get_field_attribute }, - { "getFieldAttributeAt", ipc3270_method_get_field_attribute }, - { "getFieldAttributeAtAddress", ipc3270_method_get_field_attribute }, + { "wait", ipc3270_method_wait }, + { "waitforready", ipc3270_method_wait_for_ready }, + { "waitforupdate", ipc3270_method_wait_for_update }, + { "waitforkeyboardunlock", ipc3270_method_wait_for_keyboard_unlock }, + + { "getString", ipc3270_method_get_string }, + { "getStringAt", ipc3270_method_get_string }, + { "getStringAtAddress", ipc3270_method_get_string }, + + { "setString", ipc3270_method_set_string }, + { "setStringAt", ipc3270_method_set_string }, + { "setStringAtAddress", ipc3270_method_set_string }, + + { "getFieldAttribute", ipc3270_method_get_field_attribute }, + { "getFieldAttributeAt", ipc3270_method_get_field_attribute }, + { "getFieldAttributeAtAddress", ipc3270_method_get_field_attribute }, }; diff --git a/server/src/core/methods/private.h b/server/src/core/methods/private.h index 8d9f1b8..89a9065 100644 --- a/server/src/core/methods/private.h +++ b/server/src/core/methods/private.h @@ -50,7 +50,7 @@ G_GNUC_INTERNAL int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response, GError **error); G_GNUC_INTERNAL int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *response, GError **error); G_GNUC_INTERNAL int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject *response, GError **error); - G_GNUC_INTERNAL int ipc3270_method_wait_for_unlock(GObject *session, GVariant *request, GObject *response, GError **error); + G_GNUC_INTERNAL int ipc3270_method_wait_for_keyboard_unlock(GObject *session, GVariant *request, GObject *response, GError **error); G_GNUC_INTERNAL int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError **error); diff --git a/server/src/core/methods/wait.c b/server/src/core/methods/wait.c index 46ee12b..0a065c4 100644 --- a/server/src/core/methods/wait.c +++ b/server/src/core/methods/wait.c @@ -57,11 +57,11 @@ int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject } -int ipc3270_method_wait_for_unlock(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) { +int ipc3270_method_wait_for_keyboard_unlock(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) { guint seconds = 1; g_variant_get(request, "(u)", &seconds); - ipc3270_response_append_int32(response, (int32_t) lib3270_wait_for_unlock(ipc3270_get_session(session),seconds)); + ipc3270_response_append_int32(response, (int32_t) lib3270_wait_for_keyboard_unlock(ipc3270_get_session(session),seconds)); return 0; } -- libgit2 0.21.2