From f6378bbec50d81d7eea4bac5a0051bef21122676 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 18 Sep 2019 15:49:55 -0300 Subject: [PATCH] Working on dynamic typed attributes. --- client/src/core/attribute.cc | 29 +++++++++++++---------------- client/src/include/lib3270/ipc.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- client/src/session/local/attribute.cc | 43 ++++++++++++++++++++++++++----------------- client/src/testprogram/testprogram.cc | 3 --- 4 files changed, 83 insertions(+), 37 deletions(-) diff --git a/client/src/core/attribute.cc b/client/src/core/attribute.cc index 9e64ad9..73e7e14 100644 --- a/client/src/core/attribute.cc +++ b/client/src/core/attribute.cc @@ -72,28 +72,25 @@ return (bool) attr.get.asInt32(attr, worker) != 0; }; - } + set.asString = [](const Attribute & attr, const void *worker, const char *value) { + throw std::system_error(ENOTSUP, std::system_category()); + }; - Attribute::~Attribute() { - } + set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { + throw std::system_error(ENOTSUP, std::system_category()); + }; - /* - std::string Attribute::getString() const { - printf("*************** %s\n",__FUNCTION__); - throw std::system_error(ENOTSUP, std::system_category()); - } + set.asUint32 = [](const Attribute & attr, const void *worker, const uint32_t value) { + attr.set.asInt32(attr,worker,(int32_t) value); + }; - int32_t Attribute::getInt32() const { - throw std::system_error(ENOTSUP, std::system_category()); - } + set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { + attr.set.asInt32(attr,worker,(int32_t) value); + }; - uint32_t Attribute::getUint32() const { - throw std::system_error(ENOTSUP, std::system_category()); } - bool Attribute::getBool() const { - throw std::system_error(ENOTSUP, std::system_category()); + Attribute::~Attribute() { } - */ } diff --git a/client/src/include/lib3270/ipc.h b/client/src/include/lib3270/ipc.h index 2f7b6c0..a45f18c 100644 --- a/client/src/include/lib3270/ipc.h +++ b/client/src/include/lib3270/ipc.h @@ -272,12 +272,19 @@ std::function asBoolean; } get; + struct { + std::function asString; + std::function asInt32; + std::function asUint32; + std::function asBoolean; + } set; + Attribute(H3270 *hSession, Type type, void * worker); public: ~Attribute(); - inline const H3270 * getTN3270Session() const { + inline H3270 * getTN3270Session() const { return this->hSession; } @@ -301,6 +308,42 @@ return get.asString(*this, worker); } + inline void setString(const char * value) { + set.asString(*this,worker,value); + } + + inline void setInt32(const int32_t value) { + set.asInt32(*this,worker,value); + } + + inline void setUint32(const uint32_t value) { + set.asUint32(*this,worker,value); + } + + inline void setBoolean(const bool value) { + set.asBoolean(*this,worker,value); + } + + inline Attribute & operator=(const char * value) { + set.asString(*this,worker,value); + return *this; + } + + inline Attribute & operator=(const int32_t value) { + set.asInt32(*this,worker,value); + return *this; + } + + inline Attribute & operator=(const uint32_t value) { + set.asUint32(*this,worker,value); + return *this; + } + + inline Attribute & operator=(const bool value) { + set.asBoolean(*this,worker,value); + return *this; + } + inline bool operator==(Type type) const noexcept { return this->type == type; } diff --git a/client/src/session/local/attribute.cc b/client/src/session/local/attribute.cc index 25be538..25b7d40 100644 --- a/client/src/session/local/attribute.cc +++ b/client/src/session/local/attribute.cc @@ -173,31 +173,40 @@ } - /* - std::string getString() const override { - } + }; - int32_t getInt32() const override { + // Toggle attribute + class ToggleAttribute : public Attribute { + public: + ToggleAttribute(H3270 *hSession, const LIB3270_TOGGLE_ENTRY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) { - errno = 0; - int value = ((const LIB3270_INT_PROPERTY *) worker)->get(hSession); + get.asString = [](const Attribute & attr, const void *worker) { + return attr.getBoolean() ? "true" : "false"; + }; - if(errno != 0) { - throw std::system_error(errno, std::system_category()); - } + get.asInt32 = [](const Attribute & attr, const void *worker) { - return ((int32_t) value) != 0; + errno = 0; - } + int value = lib3270_get_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id); - uint32_t getUint32() const override { - return (uint32_t) descriptor->get(this->hSession); - } + if(errno != 0) { + throw std::system_error(errno, std::system_category()); + } + + return (int32_t) value; + + }; + + set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { + lib3270_set_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id, (int) value); + }; + + set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { + lib3270_set_toggle(attr.getTN3270Session(),((const LIB3270_TOGGLE_ENTRY *) worker)->id, (int) value); + }; - bool getBool() const override { - return getInt32() != 0; } - */ }; diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index 958371c..e8205d1 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -98,7 +98,6 @@ << "\tConnected: " << host["Connected"] << std::endl; - /* host.connect(nullptr); cout @@ -130,8 +129,6 @@ host.disconnect(); - */ - } catch(const std::exception &e) { cerr << std::endl << e.what() << std::endl << std::endl; -- libgit2 0.21.2