diff --git a/client/src/core/attribute.cc b/client/src/core/attribute.cc index 73e7e14..1992d8b 100644 --- a/client/src/core/attribute.cc +++ b/client/src/core/attribute.cc @@ -53,6 +53,10 @@ this->type = type; this->worker = worker; + get.name = [](const void *worker) { + return "unnamed"; + }; + get.asString = [](const Attribute &attr, const void *worker) { throw std::system_error(ENOTSUP, std::system_category()); diff --git a/client/src/core/session.cc b/client/src/core/session.cc index f21294a..fe5d21e 100644 --- a/client/src/core/session.cc +++ b/client/src/core/session.cc @@ -413,10 +413,16 @@ throw std::system_error(ENOTSUP, std::system_category()); } - void Session::getAttributes(std::vector attributes) const { + void Session::getAttributes(std::vector & attributes) const { throw std::system_error(ENOTSUP, std::system_category()); } + std::vector Session::getAttributes() const { + std::vector attributes; + this->getAttributes(attributes); + return attributes; + } + void Session::getAttribute(const char *name, int &value) const { value = getAttribute(name).getInt32(); } diff --git a/client/src/host/properties.cc b/client/src/host/properties.cc index f71d9d8..5c1a8cb 100644 --- a/client/src/host/properties.cc +++ b/client/src/host/properties.cc @@ -48,3 +48,14 @@ TN3270::Attribute TN3270::Host::getAttribute(const char *name) const { return this->session->getAttribute(name); } + +std::vector TN3270::Host::getAttributes() const { + + if(!this->session) + throw std::system_error(ENODATA, std::system_category()); + + return this->session->getAttributes(); + +} + + diff --git a/client/src/include/lib3270/ipc.h b/client/src/include/lib3270/ipc.h index 1736075..f1bcdae 100644 --- a/client/src/include/lib3270/ipc.h +++ b/client/src/include/lib3270/ipc.h @@ -266,6 +266,8 @@ protected: struct { + std::function name; + std::function asString; std::function asInt32; std::function asUint32; @@ -288,6 +290,10 @@ return this->hSession; } + inline const char * getName() const { + return this->get.name(this->worker); + } + inline std::string getString() const { return get.asString(*this,worker); } @@ -470,7 +476,8 @@ // Attributes virtual Attribute getAttribute(const char *name) const; - virtual void getAttributes(std::vector attributes) const; + virtual void getAttributes(std::vector & attributes) const; + std::vector getAttributes() const; virtual void getAttribute(const char *name, int &value) const; virtual void getAttribute(const char *name, unsigned int &value) const; @@ -705,6 +712,7 @@ // Get properties Attribute getAttribute(const char *name) const; + std::vector getAttributes() const; inline Attribute operator[](const char *name) const { return getAttribute(name); diff --git a/client/src/session/local/attribute.cc b/client/src/session/local/attribute.cc index c72e4a4..9a37c0c 100644 --- a/client/src/session/local/attribute.cc +++ b/client/src/session/local/attribute.cc @@ -51,6 +51,10 @@ public: IntAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : Attribute(hSession, Attribute::Int32, (void *) worker) { + get.name = [](const void *worker) { + return ((const LIB3270_INT_PROPERTY *) worker)->name; + }; + get.asString = [](const Attribute & attr, const void *worker) { return std::to_string(attr.getInt32()); }; @@ -85,6 +89,10 @@ public: UnsignedIntAttribute(H3270 *hSession, const LIB3270_UINT_PROPERTY *worker) : Attribute(hSession, Attribute::Uint32, (void *) worker) { + get.name = [](const void *worker) { + return ((const LIB3270_UINT_PROPERTY *) worker)->name; + }; + get.asString = [](const Attribute & attr, const void *worker) { return std::to_string(attr.getUint32()); }; @@ -119,6 +127,10 @@ public: StringAttribute(H3270 *hSession, const LIB3270_STRING_PROPERTY *worker) : Attribute(hSession, Attribute::String, (void *) worker) { + get.name = [](const void *worker) { + return ((const LIB3270_STRING_PROPERTY *) worker)->name; + }; + get.asString = [](const Attribute & attr, const void *worker) { const char * str = ((const LIB3270_STRING_PROPERTY *) worker)->get(attr.getTN3270Session()); @@ -152,6 +164,10 @@ public: BooleanAttribute(H3270 *hSession, const LIB3270_INT_PROPERTY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) { + get.name = [](const void *worker) { + return ((const LIB3270_INT_PROPERTY *) worker)->name; + }; + get.asString = [](const Attribute & attr, const void *worker) { return attr.getBoolean() ? "true" : "false"; }; @@ -178,6 +194,10 @@ public: ToggleAttribute(H3270 *hSession, const LIB3270_TOGGLE_ENTRY *worker) : Attribute(hSession, Attribute::Boolean, (void *) worker) { + get.name = [](const void *worker) { + return ((const LIB3270_TOGGLE_ENTRY *) worker)->name; + }; + get.asString = [](const Attribute & attr, const void *worker) { return attr.getBoolean() ? "true" : "false"; }; @@ -278,7 +298,7 @@ } - void Local::Session::getAttributes(std::vector attributes) const { + void Local::Session::getAttributes(std::vector & attributes) const { std::lock_guard lock(const_cast(this)->sync); diff --git a/client/src/session/local/private.h b/client/src/session/local/private.h index fe4f8c3..a6a9983 100644 --- a/client/src/session/local/private.h +++ b/client/src/session/local/private.h @@ -114,7 +114,7 @@ // Attributes Attribute getAttribute(const char *name) const override; - void getAttributes(std::vector attributes) const override; + void getAttributes(std::vector & attributes) const override; std::string getVersion() const override; std::string getRevision() const override; diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index e8205d1..c670e31 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -85,6 +85,30 @@ } */ + // Test Attributes + static void testAttributes(const char *session) { + + TN3270::Host host{session,nullptr,10}; + + for(auto attribute : host.getAttributes()) { + + cout << attribute.getName() << ":\t"; + + try { + + cout << attribute.toString(); + + } catch(const std::exception &e) { + + cout << e.what(); + } + + cout << endl; + + } + + } + // test host object static void testHost(const char *session) { @@ -166,7 +190,8 @@ cout << "Session: " << session << endl; - testHost(session); + // testHost(session); + testAttributes(session); return 0; } -- libgit2 0.21.2