From 14b4a07654af63a2ae79f8a4ef15d61acc2862ed Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 26 Nov 2018 14:02:05 -0200 Subject: [PATCH] Fixing memory leaks, working on C++ API. --- .gitignore | 1 + src/include/lib3270++.h | 25 +++++++++++-------------- src/lib3270++/host.cc | 22 ++++++++++++++++++++++ src/lib3270++/lib3270++.cbp | 4 +++- src/lib3270++/local/session.cc | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- src/lib3270++/private.h | 6 +++--- src/lib3270++/testprogram/testprogram.cc | 7 +++++++ src/lib3270/session.c | 2 ++ src/lib3270/testprogram/testprogram.c | 3 +++ 9 files changed, 109 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index aaab80d..eb8e0c0 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ SRPMS resources.rc makeruntime.sh scripts +vgcore.* diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h index 99f19ad..1404430 100644 --- a/src/include/lib3270++.h +++ b/src/include/lib3270++.h @@ -203,9 +203,8 @@ virtual void waitForReady(time_t timeout = 5) throw() = 0; // Gets - virtual std::string toString() const = 0; - virtual std::string toString(int baddr = 0, size_t len = -1, bool lf = false) = 0; - virtual std::string toString(int row, int col, size_t sz, bool lf = false) = 0; + virtual std::string toString(int baddr = 0, size_t len = -1, char lf = '\n') const = 0; + virtual std::string toString(int row, int col, size_t sz, char lf = '\n') const = 0; inline operator std::string() const { return toString(); @@ -281,9 +280,7 @@ return session->getConnectionState() == state; } - inline void connect(const char *url) { - this->session->connect(url); - } + void connect(const char *url); inline ProgramMessage getProgramMessage() const { return session->getProgramMessage(); @@ -335,10 +332,7 @@ return *this; } - inline Host & push(const Action action) { - session->push(action); - return *this; - } + Host & push(const Action action); // Get contents. @@ -357,6 +351,8 @@ return *this; } + std::string toString() const; + // Event listeners inline Host & insert(Event::Type type, std::function listener) noexcept { session->insert(type, listener); @@ -381,16 +377,17 @@ return session.pop(value); } - template + template inline TN3270_PUBLIC TN3270::Host & operator<<(TN3270::Host& host, const T value) { return host.push(value); } - template - inline TN3270_PUBLIC TN3270::Host & operator>>(TN3270::Host& host, const T value) { - return host.pop(value); + inline std::ostream & operator<<(std::ostream &stream, const TN3270::Host& host) { + stream << host.toString(); + return stream; } + #endif #endif // LIB3270_H_INCLUDED diff --git a/src/lib3270++/host.cc b/src/lib3270++/host.cc index 82a05b5..a6ecfc0 100644 --- a/src/lib3270++/host.cc +++ b/src/lib3270++/host.cc @@ -55,8 +55,15 @@ this->session = nullptr; } + void Host::connect(const char *url) { + this->session->connect(url); + sync(); + } + + /// @brief Writes characters to the associated file from the put area int Host::sync() { + this->session->waitForReady(); return 0; } @@ -74,5 +81,20 @@ } + Host & Host::push(const Action action) { + session->push(action); + sync(); + return *this; + } + + std::string Host::toString() const { + + if(this->session->getConnectionState() == TN3270::DISCONNECTED) { + throw std::system_error(ENOTCONN, std::system_category()); + } + + return this->session->toString(); + } + } diff --git a/src/lib3270++/lib3270++.cbp b/src/lib3270++/lib3270++.cbp index 2b6f978..566cef6 100644 --- a/src/lib3270++/lib3270++.cbp +++ b/src/lib3270++/lib3270++.cbp @@ -8,7 +8,7 @@