From 19d4f4f6cc5e73d4899805ce546b9db2eae34289 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 10 Jan 2019 14:16:19 -0200 Subject: [PATCH] Updating properties and getter/setter c++ methods. --- src/include/lib3270++.h | 1 + src/lib3270++/ipc/session.cc | 4 ++++ src/lib3270++/local/session.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/lib3270++/private.h | 2 ++ src/lib3270++/testprogram/testprogram.cc | 2 +- src/lib3270/properties.c | 14 ++++++++++++++ 6 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h index 254b155..e75e060 100644 --- a/src/include/lib3270++.h +++ b/src/include/lib3270++.h @@ -215,6 +215,7 @@ // Get properties. virtual void getProperty(const char *name, 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 std::string getVersion() const = 0; virtual std::string getRevision() const = 0; diff --git a/src/lib3270++/ipc/session.cc b/src/lib3270++/ipc/session.cc index 75b23fe..3a1f9a4 100644 --- a/src/lib3270++/ipc/session.cc +++ b/src/lib3270++/ipc/session.cc @@ -235,6 +235,10 @@ } + void IPC::Session::getProperty(const char *name, bool &value) const { + throw std::system_error(ENOENT, std::system_category()); + } + /// @brief Get lib3270 version. std::string IPC::Session::getVersion() const { diff --git a/src/lib3270++/local/session.cc b/src/lib3270++/local/session.cc index 88d688d..c2c4e14 100644 --- a/src/lib3270++/local/session.cc +++ b/src/lib3270++/local/session.cc @@ -38,9 +38,10 @@ #include "../private.h" #include + #include + #include extern "C" { - #include #include } @@ -149,11 +150,68 @@ } void Local::Session::getProperty(const char *name, int &value) const { - throw std::system_error(ENOTSUP, std::system_category()); + + const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_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 { - throw std::system_error(ENOTSUP, std::system_category()); + + const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); + + for(size_t ix = 0; strprop[ix].name; ix++) { + + if(!strcasecmp(name,strprop[ix].name)) { + + std::lock_guard lock(const_cast(this)->sync); + + // Found it! + const char * str = strprop[ix].get(hSession); + + if(str) { + value.assign(str); + return; + } + + throw std::system_error(errno, std::system_category()); + + } + + } + + throw std::system_error(ENOENT, std::system_category()); + } + + void Local::Session::getProperty(const char *name, bool &value) const { + + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(name); + if(toggle != (LIB3270_TOGGLE) -1) { + + // Is a Tn3270 toggle, get it! + std::lock_guard lock(const_cast(this)->sync); + value = lib3270_get_toggle(hSession,toggle); + + } + + throw std::system_error(ENOENT, std::system_category()); } ProgramMessage Local::Session::getProgramMessage() const { diff --git a/src/lib3270++/private.h b/src/lib3270++/private.h index 889ea5b..54e6ca4 100644 --- a/src/lib3270++/private.h +++ b/src/lib3270++/private.h @@ -179,6 +179,7 @@ // Get properties. void getProperty(const char *name, int &value) const override; void getProperty(const char *name, std::string &value) const override; + void getProperty(const char *name, bool &value) const override; std::string getVersion() const override; std::string getRevision() const override; @@ -312,6 +313,7 @@ // Get properties. void getProperty(const char *name, int &value) const override; void getProperty(const char *name, std::string &value) const override; + void getProperty(const char *name, bool &value) const override; std::string getVersion() const override; std::string getRevision() const override; diff --git a/src/lib3270++/testprogram/testprogram.cc b/src/lib3270++/testprogram/testprogram.cc index d4f5a7a..9e728ea 100644 --- a/src/lib3270++/testprogram/testprogram.cc +++ b/src/lib3270++/testprogram/testprogram.cc @@ -45,7 +45,7 @@ int main(int argc, const char *argv[]) { - TN3270::Host host{"pw3270:a"}; + TN3270::Host host; //{"pw3270:a"}; cout << "Version: " << host.getVersion() diff --git a/src/lib3270/properties.c b/src/lib3270/properties.c index 4edbd87..d4a39c1 100644 --- a/src/lib3270/properties.c +++ b/src/lib3270/properties.c @@ -297,6 +297,20 @@ NULL // Set value. }, + { + "version", // Property name. + N_( "lib3270 version" ), // Property description. + lib3270_get_version, // Get value. + NULL // Set value. + }, + + { + "revision", // Property name. + N_( "lib3270 revision" ), // Property description. + lib3270_get_revision, // Get value. + NULL // Set value. + }, + /* { "", // Property name. -- libgit2 0.21.2