Commit 5ce65207cda8569803a0858a3937dd0cbeaa2abd

Authored by Perry Werneck
0 parents
Exists in master and in 1 other branch develop

Planejando novo componente C++.

abstract.cc 0 → 100644
  1 +++ a/abstract.cc
... ... @@ -0,0 +1,75 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como lib3270++.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +/**
  31 + * @file src/lib3270++/abstract.cc
  32 + *
  33 + * @brief
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + Abstract::Session::Session() {
  47 +
  48 +#ifdef HAVE_ICONV
  49 + this->iconv.local = (iconv_t) (-1);
  50 + this->iconv.host = (iconv_t) (-1);
  51 +#endif
  52 +
  53 + this->baddr = 0;
  54 +
  55 + }
  56 +
  57 + Abstract::Session::~Session() {
  58 +
  59 +#ifdef HAVE_ICONV
  60 +
  61 + if(this->iconv.local != (iconv_t) (-1))
  62 + iconv_close(this->iconv.local);
  63 +
  64 + if(this->iconv.host != (iconv_t) (-1))
  65 + iconv_close(this->iconv.host);
  66 +
  67 +#endif
  68 +
  69 + }
  70 +
  71 + }
  72 +
  73 +
  74 +
  75 +
... ...
host.cc 0 → 100644
  1 +++ a/host.cc
... ... @@ -0,0 +1,78 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como lib3270++.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +/**
  31 + * @file src/lib3270++/host.cc
  32 + *
  33 + * @brief
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + Host::Host(const char *id, const char *url) {
  47 + this->session = Session::create(id);
  48 + if(url) {
  49 + this->connect(url);
  50 + }
  51 + }
  52 +
  53 + Host::~Host() {
  54 + delete this->session;
  55 + this->session = nullptr;
  56 + }
  57 +
  58 + /// @brief Writes characters to the associated file from the put area
  59 + int Host::sync() {
  60 + return 0;
  61 + }
  62 +
  63 + /// @brief Writes characters to the associated output sequence from the put area.
  64 + int Host::overflow(int c) {
  65 +
  66 + if (c != EOF) {
  67 + char str[] = { static_cast<char>(c), 0 };
  68 + this->session->push((const char *) str);
  69 + } else {
  70 + sync();
  71 + }
  72 +
  73 + return c;
  74 +
  75 + }
  76 +
  77 + }
  78 +
... ...
lib3270++.cbp 0 → 100644
  1 +++ a/lib3270++.cbp
... ... @@ -0,0 +1,56 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2 +<CodeBlocks_project_file>
  3 + <FileVersion major="1" minor="6" />
  4 + <Project>
  5 + <Option title="C++ Bindings for lib3270" />
  6 + <Option pch_mode="2" />
  7 + <Option compiler="gcc" />
  8 + <Build>
  9 + <Target title="Debug">
  10 + <Option output=".bin/Debug/C++ Bindings for lib3270" prefix_auto="1" extension_auto="1" />
  11 + <Option object_output=".obj/Debug/" />
  12 + <Option type="1" />
  13 + <Option compiler="gcc" />
  14 + <Compiler>
  15 + <Add option="-g" />
  16 + <Add option="-DDEBUG=1" />
  17 + </Compiler>
  18 + </Target>
  19 + <Target title="Release">
  20 + <Option output=".bin/Release/C++ Bindings for lib3270" prefix_auto="1" extension_auto="1" />
  21 + <Option object_output=".obj/Release/" />
  22 + <Option type="1" />
  23 + <Option compiler="gcc" />
  24 + <Compiler>
  25 + <Add option="-O2" />
  26 + <Add option="-std=c++11" />
  27 + <Add option="-DNDEBUG=1" />
  28 + </Compiler>
  29 + <Linker>
  30 + <Add option="-s" />
  31 + </Linker>
  32 + </Target>
  33 + </Build>
  34 + <Compiler>
  35 + <Add option="-Wall" />
  36 + <Add option="`pkg-config --clags lib3270`" />
  37 + <Add directory="../include" />
  38 + </Compiler>
  39 + <Linker>
  40 + <Add option="`pkg-config --libs lib3270`" />
  41 + </Linker>
  42 + <Unit filename="../include/lib3270++.h" />
  43 + <Unit filename="../include/lib3270.h" />
  44 + <Unit filename="abstract.cc" />
  45 + <Unit filename="host.cc" />
  46 + <Unit filename="local.cc" />
  47 + <Unit filename="private.h" />
  48 + <Unit filename="session.cc" />
  49 + <Extensions>
  50 + <code_completion />
  51 + <envvars />
  52 + <debugger />
  53 + <lib_finder disable_auto="1" />
  54 + </Extensions>
  55 + </Project>
  56 +</CodeBlocks_project_file>
... ...
local.cc 0 → 100644
  1 +++ a/local.cc
... ... @@ -0,0 +1,132 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como lib3270++.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +/**
  31 + * @file src/lib3270++/local.cc
  32 + *
  33 + * @brief
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + LocalSession::LocalSession() : Abstract::Session() {
  47 + this->hSession = lib3270_session_new("");
  48 + lib3270_set_user_data(this->hSession,(void *) this);
  49 + }
  50 +
  51 + LocalSession::~LocalSession() {
  52 + lib3270_session_free(this->hSession);
  53 + this->hSession = nullptr;
  54 + }
  55 +
  56 + void LocalSession::connect(const char *url) {
  57 + lib3270_connect_url(hSession,url,0);
  58 + }
  59 +
  60 + void LocalSession::disconnect() {
  61 + lib3270_disconnect(hSession);
  62 + }
  63 +
  64 + // Wait for session state.
  65 + void LocalSession::waitForReady(time_t timeout) throw() {
  66 +
  67 + int rc = lib3270_wait_for_ready(this->hSession, timeout);
  68 +
  69 + if(rc) {
  70 + throw std::system_error(rc, std::system_category());
  71 + }
  72 +
  73 + }
  74 +
  75 + // Gets
  76 + std::string LocalSession::toString() const {
  77 + }
  78 +
  79 + std::string LocalSession::toString(int baddr, size_t len, bool lf) {
  80 + }
  81 +
  82 + std::string LocalSession::toString(int row, int col, size_t sz, bool lf) {
  83 + }
  84 +
  85 + ProgramMessage LocalSession::getProgramMessage() const {
  86 + return (ProgramMessage) lib3270_get_program_message(this->hSession);
  87 + }
  88 +
  89 + ConnectionState LocalSession::getConnectionState() const {
  90 + return (ConnectionState) lib3270_get_connection_state(this->hSession);
  91 + }
  92 +
  93 + /// @brief Set field at current posicion, jumps to next writable field.
  94 + TN3270::Session & LocalSession::push(const char *text) {
  95 + return *this;
  96 + }
  97 +
  98 + TN3270::Session & LocalSession::push(int baddr, const std::string &text) {
  99 + return *this;
  100 + }
  101 +
  102 + TN3270::Session & LocalSession::push(int row, int col, const std::string &text) {
  103 + return *this;
  104 + }
  105 +
  106 + TN3270::Session & LocalSession::push(const PFKey key) {
  107 + return *this;
  108 + }
  109 +
  110 + TN3270::Session & LocalSession::push(const PAKey key) {
  111 + return *this;
  112 + }
  113 +
  114 + TN3270::Session & LocalSession::push(const Action action) {
  115 + return *this;
  116 + }
  117 +
  118 + TN3270::Session & LocalSession::pop(int baddr, std::string &text) {
  119 + return *this;
  120 + }
  121 +
  122 + TN3270::Session & LocalSession::pop(int row, int col, std::string &text) {
  123 + return *this;
  124 + }
  125 +
  126 + TN3270::Session & LocalSession::pop(std::string &text) {
  127 + return *this;
  128 + }
  129 +
  130 + }
  131 +
  132 +
... ...
private.h 0 → 100644
  1 +++ a/private.h
... ... @@ -0,0 +1,127 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como lib3270++.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +/**
  31 + * @file src/lib3270++/private.h
  32 + *
  33 + * @brief
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 +#ifndef PRIVATE_H_INCLUDED
  40 +
  41 + #define PRIVATE_H_INCLUDED
  42 +
  43 + #include <config.h>
  44 + #include <lib3270++.h>
  45 + #include <system_error>
  46 +
  47 +
  48 +#ifdef HAVE_ICONV
  49 + #include <iconv.h>
  50 +#endif // HAVE_ICONV
  51 +
  52 + namespace TN3270 {
  53 +
  54 + namespace Abstract {
  55 +
  56 + class TN3270_PRIVATE Session : public TN3270::Session {
  57 + private:
  58 +
  59 +#ifdef HAVE_ICONV
  60 + struct {
  61 +
  62 + /// @brief Convert strings from host codepage to local codepage.
  63 + iconv_t local;
  64 +
  65 + /// @brief Convert string from local codepage to host codepage.
  66 + iconv_t host;
  67 +
  68 + } iconv;
  69 +#endif
  70 +
  71 + protected:
  72 +
  73 + /// @brief Current in/out position.
  74 + int baddr;
  75 +
  76 + Session();
  77 + virtual ~Session();
  78 +
  79 + };
  80 +
  81 + }
  82 +
  83 + class TN3270_PRIVATE LocalSession : public Abstract::Session {
  84 + private:
  85 +
  86 + /// @brief Handle of the related instance of lib3270
  87 + H3270 * hSession;
  88 +
  89 + public:
  90 + LocalSession();
  91 + virtual ~LocalSession();
  92 +
  93 + // Connect/disconnect
  94 + void connect(const char *url) override;
  95 + void disconnect() override;
  96 +
  97 + // Wait for session state.
  98 + void waitForReady(time_t timeout = 5) throw() override;
  99 +
  100 + // Gets
  101 + std::string toString() const override;
  102 + std::string toString(int baddr = 0, size_t len = -1, bool lf = false) override;
  103 + std::string toString(int row, int col, size_t sz, bool lf = false) override;
  104 +
  105 + ProgramMessage getProgramMessage() const override;
  106 +
  107 + ConnectionState getConnectionState() const override;
  108 +
  109 + /// @brief Set field at current posicion, jumps to next writable field.
  110 + TN3270::Session & push(const char *text) override;
  111 +
  112 + TN3270::Session & push(int baddr, const std::string &text) override;
  113 + TN3270::Session & push(int row, int col, const std::string &text) override;
  114 + TN3270::Session & push(const PFKey key) override;
  115 + TN3270::Session & push(const PAKey key) override;
  116 + TN3270::Session & push(const Action action) override;
  117 +
  118 + // Get contents.
  119 + TN3270::Session & pop(int baddr, std::string &text) override;
  120 + TN3270::Session & pop(int row, int col, std::string &text) override;
  121 + TN3270::Session & pop(std::string &text) override;
  122 +
  123 + };
  124 +
  125 + }
  126 +
  127 +#endif // PRIVATE_H_INCLUDED
... ...
session.cc 0 → 100644
  1 +++ a/session.cc
... ... @@ -0,0 +1,57 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como lib3270++.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +/**
  31 + * @file src/lib3270++/session.cc
  32 + *
  33 + * @brief
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + Session::Session() {
  47 +
  48 + }
  49 +
  50 + Session::~Session() {
  51 +
  52 + }
  53 +
  54 + }
  55 +
  56 +
  57 +
... ...