diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h index 14e8f27..254b155 100644 --- a/src/include/lib3270++.h +++ b/src/include/lib3270++.h @@ -213,6 +213,9 @@ } // Get properties. + virtual void getProperty(const char *name, int &value) const = 0; + virtual void getProperty(const char *name, std::string &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 6ae6b6e..75b23fe 100644 --- a/src/lib3270++/ipc/session.cc +++ b/src/lib3270++/ipc/session.cc @@ -137,11 +137,19 @@ } ProgramMessage IPC::Session::getProgramMessage() const { - throw std::system_error(EINVAL, std::system_category()); + + int program_message; + getProperty("program_message",program_message); + return (ProgramMessage) program_message; + } ConnectionState IPC::Session::getConnectionState() const { - throw std::system_error(EINVAL, std::system_category()); + + int cstate; + getProperty("cstate",cstate); + return (ConnectionState) cstate; + } /// @brief Set field at current position, jumps to next writable field. @@ -211,21 +219,38 @@ } + void IPC::Session::getProperty(const char *name, 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) + .call() + .pop(value); + + } + /// @brief Get lib3270 version. std::string IPC::Session::getVersion() const { string rc; - - Request request{*this,false,"version"}; - request.call().pop(rc); - + getProperty("version",rc); return rc; + } /// @brief Get lib3270 revision. std::string IPC::Session::getRevision() const { - throw std::system_error(ENOTSUP, std::system_category()); - return ""; + + string rc; + getProperty("revision",rc); + return rc; + } } diff --git a/src/lib3270++/linux/request.cc b/src/lib3270++/linux/request.cc index e836fea..fcd18c7 100644 --- a/src/lib3270++/linux/request.cc +++ b/src/lib3270++/linux/request.cc @@ -177,6 +177,8 @@ } + dbus_message_iter_next(&msg.iter); + value.assign(str); debug(__FUNCTION__,"= \"",str,"\""); @@ -184,6 +186,60 @@ return *this; } + static int getIntValue(DBusMessageIter &iter) { + + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) { + + dbus_int32_t rc = 0; + dbus_message_iter_get_basic(&iter, &rc); + return (int) rc; + + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT16) { + + dbus_int16_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_INT32) { + + dbus_int32_t rc = 0; + dbus_message_iter_get_basic(&sub, &rc); + return (int) rc; + + } else if (current_type == DBUS_TYPE_INT16) { + dbus_int16_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"); + + } + + IPC::Request & IPC::Request::Request::pop(int &value) { + + value = getIntValue(msg.iter); + dbus_message_iter_next(&msg.iter); + debug(__FUNCTION__,"= \"",value,"\""); + + return *this; + + } } diff --git a/src/lib3270++/local/session.cc b/src/lib3270++/local/session.cc index 20edec5..88d688d 100644 --- a/src/lib3270++/local/session.cc +++ b/src/lib3270++/local/session.cc @@ -148,6 +148,14 @@ return rc; } + void Local::Session::getProperty(const char *name, int &value) const { + throw std::system_error(ENOTSUP, std::system_category()); + } + + void Local::Session::getProperty(const char *name, std::string &value) const { + throw std::system_error(ENOTSUP, std::system_category()); + } + ProgramMessage Local::Session::getProgramMessage() const { std::lock_guard lock(const_cast(this)->sync); return (ProgramMessage) lib3270_get_program_message(this->hSession); diff --git a/src/lib3270++/private.h b/src/lib3270++/private.h index eb13e06..889ea5b 100644 --- a/src/lib3270++/private.h +++ b/src/lib3270++/private.h @@ -177,6 +177,9 @@ void waitForReady(time_t timeout = 5) throw() override; // Get properties. + void getProperty(const char *name, int &value) const override; + void getProperty(const char *name, std::string &value) const override; + std::string getVersion() const override; std::string getRevision() const override; @@ -270,8 +273,8 @@ Request & push(const char *arg); // Pop values - Request & pop(std::string &value); + Request & pop(int &value); }; @@ -307,6 +310,9 @@ void waitForReady(time_t timeout = 5) throw() override; // Get properties. + void getProperty(const char *name, int &value) const override; + void getProperty(const char *name, std::string &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 61da88f..d4f5a7a 100644 --- a/src/lib3270++/testprogram/testprogram.cc +++ b/src/lib3270++/testprogram/testprogram.cc @@ -49,7 +49,12 @@ cout << "Version: " << host.getVersion() -// << " Revision: " << host.getRevision() + << "\tRevision: " << host.getRevision() + << std::endl; + + cout + << "Connection state is " << host.getConnectionState() + << "\tProgram message is " << host.getProgramMessage() << std::endl; // host.connect(getenv("LIB3270_DEFAULT_HOST")); -- libgit2 0.21.2