From 9532ba2ca4dfd849f56fcbc2815041a095ac0296 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 7 Jan 2019 15:03:23 -0200 Subject: [PATCH] Working on IPC client module. --- Makefile.in | 9 ++++++--- ipc/session.cc | 216 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib3270++.cbp | 1 + private.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- session.cc | 2 +- testprogram/testprogram.cc | 4 +++- 6 files changed, 275 insertions(+), 7 deletions(-) create mode 100644 ipc/session.cc diff --git a/Makefile.in b/Makefile.in index 21a2fe2..d032d09 100644 --- a/Makefile.in +++ b/Makefile.in @@ -31,6 +31,7 @@ LIBNAME=lib@LIB3270_NAME@++ SOURCES= \ $(wildcard *.cc) \ $(wildcard local/*.cc) \ + $(wildcard ipc/*.cc) \ $(wildcard @OSNAME@/*.c) \ $(wildcard @OSNAME@/*.rc) @@ -90,14 +91,16 @@ DEPENDS= \ CFLAGS= \ @CFLAGS@ \ -g \ - -I../include - -DBUILD_DATE=`date +%Y%m%d` + -I../include \ + -DBUILD_DATE=`date +%Y%m%d` \ + @DBUS_CFLAGS@ LIBS= \ @LIBS@ \ @LIBSSL_LIBS@ \ @LIBICONV@ \ - @INTL_LIBS@ + @INTL_LIBS@ \ + @DBUS_LIBS@ #---[ Debug Rules ]---------------------------------------------------------------------- diff --git a/ipc/session.cc b/ipc/session.cc new file mode 100644 index 0000000..6e0a79d --- /dev/null +++ b/ipc/session.cc @@ -0,0 +1,216 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/ipc/session.cc + * + * @brief Implements lib3270 access using IPC calls. + * + * @author perry.werneck@gmail.com + * + */ + + #include "../private.h" + #include + + using std::string; + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +#ifndef _WIN32 + + static void throws_if_error(DBusError &err) { + + if(dbus_error_is_set(&err)) { + string message = err.message; + dbus_error_free(&err); + throw std::runtime_error(message.c_str()); + } + + return; + + } + +#endif // _WIN32 + + namespace TN3270 { + + IPC::Session::Session(const char *id) : Abstract::Session() { + +#ifdef _WIN32 + +#else + // Create D-Bus session. + DBusError err; + + dbus_error_init(&err); + this->conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + + debug("dbus_bus_get conn=",conn); + + throws_if_error(err); + + if(!conn) + throw std::runtime_error("DBUS Connection failed"); + + auto sep = strchr(id,':'); + if(!sep) { + throw std::system_error(EINVAL, std::system_category()); + } + + this->name = "br.com.bb."; + this->name += string(id,(sep - id)); + this->name += "."; + this->name += (sep+1); + this->path = "/br/com/bb/tn3270/session"; + + debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\""); + +#endif // _WIN32 + + } + + IPC::Session::~Session() { + +#ifdef _WIN32 + +#else + +#endif // _WIN32 + + } + + /* + void IPC::Session::wait(time_t timeout) { + + + } + */ + + void IPC::Session::connect(const char *url) { + Request request(*this,"connect"); + request.push(url).call(); + } + + void IPC::Session::disconnect() { + Request request(*this,"disconnect"); + request.call(); + } + + // Wait for session state. + void IPC::Session::waitForReady(time_t timeout) throw() { + throw std::system_error(EINVAL, std::system_category()); + } + + std::string IPC::Session::toString(int baddr, size_t len, char lf) const { + throw std::system_error(EINVAL, std::system_category()); + } + + std::string IPC::Session::toString(int row, int col, size_t sz, char lf) const { + throw std::system_error(EINVAL, std::system_category()); + } + + ProgramMessage IPC::Session::getProgramMessage() const { + throw std::system_error(EINVAL, std::system_category()); + } + + ConnectionState IPC::Session::getConnectionState() const { + throw std::system_error(EINVAL, std::system_category()); + } + + /// @brief Set field at current position, jumps to next writable field. + TN3270::Session & IPC::Session::push(const char *text) { + throw std::system_error(EINVAL, std::system_category()); + } + + TN3270::Session & IPC::Session::push(int baddr, const std::string &text) { + + + return *this; + } + + TN3270::Session & IPC::Session::push(int row, int col, const std::string &text) { + + + return *this; + } + + TN3270::Session & IPC::Session::push(const PFKey key) { + + + return *this; + } + + TN3270::Session & IPC::Session::push(const PAKey key) { + + + return *this; + } + + TN3270::Session & IPC::Session::push(const Action action) { + + return *this; + } + + TN3270::Session & IPC::Session::pop(int baddr, std::string &text) { + + + return *this; + } + + TN3270::Session & IPC::Session::pop(int row, int col, std::string &text) { + + return *this; + } + + TN3270::Session & IPC::Session::pop(std::string &text) { + + return *this; + } + + /// @brief Set cursor address. + /// + /// @param addr Cursor address. + void IPC::Session::setCursorPosition(unsigned short addr) { + + + } + + /// @brief Set cursor position. + /// + /// @param row New cursor row. + /// @param col New cursor column. + void IPC::Session::setCursorPosition(unsigned short row, unsigned short col) { + + + } + + } + + diff --git a/lib3270++.cbp b/lib3270++.cbp index 362c31a..3f86d67 100644 --- a/lib3270++.cbp +++ b/lib3270++.cbp @@ -50,6 +50,7 @@ + diff --git a/private.h b/private.h index c387fc1..52bdc40 100644 --- a/private.h +++ b/private.h @@ -46,8 +46,11 @@ #include #include #include + #else + #include #endif // WIN32 + #include #include #include #include @@ -73,6 +76,31 @@ #define SYSTEM_CHARSET "UTF-8" #endif // WIN32 +#ifdef DEBUG + + inline void console(std::ostream &out) { + out << std::endl; + } + + template + void console(std::ostream &out, T value, Targs... Fargs) { + out << value; + console(out, Fargs...); + } + + template + void log(T value, Targs... Fargs) { + console(std::clog,value,Fargs...); + } + + #define debug(...) log(__FILE__, "(", __LINE__, ") ", __VA_ARGS__); + +#else + + #define debug(...) /* __VA_ARGS__ */ + +#endif + namespace TN3270 { namespace Abstract { @@ -180,6 +208,8 @@ /// @brief IPC Based acess (Access and active instance of pw3270 or pw3270d) namespace IPC { + class Session; + /// @brief PW3270 IPC Request/Response. class Request { private: @@ -203,22 +233,37 @@ static DWORD pack(std::vector &args, uint8_t * outBuffer, size_t szBuffer); #else + DBusMessage * msg; + DBusConnection * conn; + #endif // _WIN32 public: - Request(const char *name); + Request(Session &session, const char *method); + + Request & call(); + Request & push(const char *arg); }; class TN3270_PRIVATE Session : public TN3270::Abstract::Session { private: + + friend class Request; + #ifdef _WIN32 /// @brief Pipe Handle. HANDLE hPipe; #else + DBusConnection * conn; + std::string name; ///< @brief D-Bus Object name. + std::string path; ///< @brief D-Bus Object path. + #endif // _WIN32 + void call(Request &request); + public: Session(const char *id); @@ -255,7 +300,8 @@ TN3270::Session & pop(int baddr, std::string &text) override; TN3270::Session & pop(int row, int col, std::string &text) override; TN3270::Session & pop(std::string &text) override; - } + + }; } diff --git a/session.cc b/session.cc index 9806141..539c82e 100644 --- a/session.cc +++ b/session.cc @@ -50,7 +50,7 @@ return new Local::Session(); } - throw std::system_error(EINVAL, std::system_category()); + return new IPC::Session(id); } diff --git a/testprogram/testprogram.cc b/testprogram/testprogram.cc index 8336762..dd795df 100644 --- a/testprogram/testprogram.cc +++ b/testprogram/testprogram.cc @@ -45,14 +45,16 @@ int main(int argc, const char *argv[]) { - TN3270::Host host; + TN3270::Host host("pw3270:a"); + /* host.connect(getenv("LIB3270_DEFAULT_HOST")); cout << host << endl; host << TN3270::ENTER; cout << host << endl; + */ return 0; } -- libgit2 0.21.2