Commit 43cf27edb64a2c3ed32ed6a08dcddfdc91c444db

Authored by Perry Werneck
1 parent 8fe79446
Exists in master

Copiando fontes do projeto original.

.gitignore
1 1 *~
  2 +*.layout
  3 +.bin
  4 +.obj
  5 +ChangeLog
  6 +aclocal.m4
  7 +autom4te.cache
  8 +config.*
  9 +configure
  10 +*.depend
  11 +stamp-h1
2 12  
... ...
python-pw3270.cbp 0 → 100644
... ... @@ -0,0 +1,57 @@
  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="Python binding for pw3270/lib3270" />
  6 + <Option pch_mode="2" />
  7 + <Option compiler="gcc" />
  8 + <Build>
  9 + <Target title="Debug">
  10 + <Option output=".bin/Debug/py3270" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
  11 + <Option object_output=".obj/Debug/" />
  12 + <Option type="3" />
  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/py3270" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
  21 + <Option object_output=".obj/Release/" />
  22 + <Option type="3" />
  23 + <Option compiler="gcc" />
  24 + <Compiler>
  25 + <Add option="-O2" />
  26 + <Add option="-DNDEBUG=1" />
  27 + </Compiler>
  28 + <Linker>
  29 + <Add option="-s" />
  30 + </Linker>
  31 + </Target>
  32 + </Build>
  33 + <Compiler>
  34 + <Add option="-Wall" />
  35 + <Add option="`pkg-config --cflags python`" />
  36 + <Add option="-fPIC" />
  37 + </Compiler>
  38 + <Linker>
  39 + <Add option="`pkg-config --libs python`" />
  40 + <Add library="pw3270cpp" />
  41 + </Linker>
  42 + <Unit filename="src/actions.cc" />
  43 + <Unit filename="src/config.h.in" />
  44 + <Unit filename="src/get.cc" />
  45 + <Unit filename="src/init.cc" />
  46 + <Unit filename="src/misc.cc" />
  47 + <Unit filename="src/private.h" />
  48 + <Unit filename="src/py3270.cc" />
  49 + <Unit filename="src/set.cc" />
  50 + <Extensions>
  51 + <code_completion />
  52 + <envvars />
  53 + <debugger />
  54 + <lib_finder disable_auto="1" />
  55 + </Extensions>
  56 + </Project>
  57 +</CodeBlocks_project_file>
... ...
src/actions.cc 0 → 100644
... ... @@ -0,0 +1,129 @@
  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 actions.cc 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 + * Referências:
  29 + *
  30 + * <https://docs.python.org/2/extending/newtypes.html>
  31 + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example>
  32 + *
  33 + */
  34 +
  35 + #include "private.h"
  36 +
  37 +
  38 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  39 +
  40 + PyObject * terminal_pfkey(PyObject *self, PyObject *args) {
  41 +
  42 + int rc, key;
  43 +
  44 + if (!PyArg_ParseTuple(args, "i", &key)) {
  45 + PyErr_SetString(terminalError, strerror(EINVAL));
  46 + return NULL;
  47 + }
  48 +
  49 + try {
  50 +
  51 + rc = ((pw3270_TerminalObject *) self)->session->pfkey(key);
  52 +
  53 + } catch(std::exception &e) {
  54 +
  55 + PyErr_SetString(terminalError, e.what());
  56 + return NULL;
  57 + }
  58 +
  59 + return PyLong_FromLong(rc);
  60 +
  61 + }
  62 +
  63 + PyObject * terminal_pakey(PyObject *self, PyObject *args) {
  64 +
  65 + int rc, key;
  66 +
  67 + if (!PyArg_ParseTuple(args, "i", &key)) {
  68 + PyErr_SetString(terminalError, strerror(EINVAL));
  69 + return NULL;
  70 + }
  71 +
  72 + try {
  73 +
  74 + rc = ((pw3270_TerminalObject *) self)->session->pakey(key);
  75 +
  76 + } catch(std::exception &e) {
  77 +
  78 + PyErr_SetString(terminalError, e.what());
  79 + return NULL;
  80 + }
  81 +
  82 + return PyLong_FromLong(rc);
  83 +
  84 + }
  85 +
  86 + PyObject * terminal_enter(PyObject *self, PyObject *args) {
  87 +
  88 + int rc;
  89 +
  90 + try {
  91 +
  92 + rc = ((pw3270_TerminalObject *) self)->session->enter();
  93 +
  94 + } catch(std::exception &e) {
  95 +
  96 + PyErr_SetString(terminalError, e.what());
  97 + return NULL;
  98 + }
  99 +
  100 + return PyLong_FromLong(rc);
  101 +
  102 +
  103 + }
  104 +
  105 + PyObject * terminal_action(PyObject *self, PyObject *args) {
  106 +
  107 + int rc;
  108 + const char *name;
  109 +
  110 + if (!PyArg_ParseTuple(args, "s", &name)) {
  111 + PyErr_SetString(terminalError, strerror(EINVAL));
  112 + return NULL;
  113 + }
  114 +
  115 + try {
  116 +
  117 + rc = ((pw3270_TerminalObject *) self)->session->action(name);
  118 +
  119 + } catch(std::exception &e) {
  120 +
  121 + PyErr_SetString(terminalError, e.what());
  122 + return NULL;
  123 + }
  124 +
  125 + return PyLong_FromLong(rc);
  126 +
  127 +
  128 + }
  129 +
... ...
src/get.cc 0 → 100644
... ... @@ -0,0 +1,154 @@
  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 get.cc 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 + * Referências:
  29 + *
  30 + * <https://docs.python.org/2/extending/newtypes.html>
  31 + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example>
  32 + *
  33 + */
  34 +
  35 + #include "private.h"
  36 +
  37 +
  38 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  39 +
  40 +PyObject * terminal_get_version(PyObject *self, PyObject *args) {
  41 +
  42 + return PyString_FromString( ((pw3270_TerminalObject *) self)->session->get_version().c_str() );
  43 +
  44 +}
  45 +
  46 +PyObject * terminal_get_revision(PyObject *self, PyObject *args) {
  47 +
  48 + return PyString_FromString( ((pw3270_TerminalObject *) self)->session->get_revision().c_str() );
  49 +
  50 +}
  51 +
  52 +PyObject * terminal_is_connected(PyObject *self, PyObject *args) {
  53 +
  54 + return PyBool_FromLong( ((pw3270_TerminalObject *) self)->session->is_connected() );
  55 +
  56 +}
  57 +
  58 +PyObject * terminal_is_ready(PyObject *self, PyObject *args) {
  59 +
  60 + return PyBool_FromLong( ((pw3270_TerminalObject *) self)->session->is_ready() );
  61 +
  62 +}
  63 +
  64 +PyObject * terminal_is_protected_at(PyObject *self, PyObject *args) {
  65 +
  66 + int rc, row, col;
  67 +
  68 + if (!PyArg_ParseTuple(args, "ii", &row, &col)) {
  69 + PyErr_SetString(terminalError, strerror(EINVAL));
  70 + return NULL;
  71 + }
  72 +
  73 + try {
  74 +
  75 + rc = ((pw3270_TerminalObject *) self)->session->get_is_protected_at(row,col);
  76 +
  77 + } catch(std::exception &e) {
  78 +
  79 + PyErr_SetString(terminalError, e.what());
  80 + return NULL;
  81 + }
  82 +
  83 + return PyBool_FromLong( rc );
  84 +
  85 +}
  86 +
  87 +
  88 +PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args) {
  89 +
  90 + int row, col, rc;
  91 + const char *text;
  92 +
  93 + if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) {
  94 + PyErr_SetString(terminalError, strerror(EINVAL));
  95 + return NULL;
  96 + }
  97 +
  98 + try {
  99 +
  100 + rc = ((pw3270_TerminalObject *) self)->session->cmp_string_at(row,col,text);
  101 +
  102 + } catch(std::exception &e) {
  103 +
  104 + PyErr_SetString(terminalError, e.what());
  105 + return NULL;
  106 + }
  107 +
  108 + return PyLong_FromLong(rc);
  109 +
  110 +}
  111 +
  112 +PyObject * terminal_get_string_at(PyObject *self, PyObject *args) {
  113 +
  114 + int row, col, sz;
  115 + string rc;
  116 +
  117 + if (!PyArg_ParseTuple(args, "iii", &row, &col, &sz)) {
  118 + PyErr_SetString(terminalError, strerror(EINVAL));
  119 + return NULL;
  120 + }
  121 +
  122 + try {
  123 +
  124 + rc = ((pw3270_TerminalObject *) self)->session->get_string_at(row,col,sz);
  125 +
  126 + } catch(std::exception &e) {
  127 +
  128 + PyErr_SetString(terminalError, e.what());
  129 + return NULL;
  130 + }
  131 +
  132 + return PyString_FromString(rc.c_str());
  133 +
  134 +}
  135 +
  136 +PyObject * terminal_get_contents(PyObject *self) {
  137 +
  138 + string rc;
  139 +
  140 + try {
  141 +
  142 + rc = ((pw3270_TerminalObject *) self)->session->get_string();
  143 +
  144 + } catch(std::exception &e) {
  145 +
  146 + PyErr_SetString(terminalError, e.what());
  147 + return NULL;
  148 + }
  149 +
  150 + return PyString_FromString(rc.c_str());
  151 +
  152 +
  153 +
  154 +}
... ...
src/init.cc 0 → 100644
... ... @@ -0,0 +1,87 @@
  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 py3270.cc 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 + * Implementa métodos básicos inicio/final do objeto python
  29 + *
  30 + * Referências:
  31 + *
  32 + * <https://docs.python.org/2/extending/newtypes.html>
  33 + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example>
  34 + *
  35 + */
  36 +
  37 + #include "private.h"
  38 +
  39 +
  40 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  41 +
  42 +PyObject * terminal_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
  43 +
  44 + PW3270_NAMESPACE::session * session;
  45 + const char *id = "";
  46 +
  47 + if (!PyArg_ParseTuple(args, "s", &id)) {
  48 + id = "";
  49 + }
  50 +
  51 + trace("%s(%s)",__FUNCTION__,id);
  52 +
  53 + try {
  54 +
  55 + session = PW3270_NAMESPACE::session::create(id);
  56 +
  57 + } catch(std::exception &e) {
  58 +
  59 + trace("%s failed: %s",__FUNCTION__,e.what());
  60 + PyErr_SetString(terminalError, e.what());
  61 + return NULL;
  62 +
  63 + }
  64 +
  65 + pw3270_TerminalObject *self = (pw3270_TerminalObject *) type->tp_alloc(type, 0);
  66 +
  67 + self->session = session;
  68 +
  69 + return (PyObject *)self;
  70 +}
  71 +
  72 +
  73 +int terminal_init(pw3270_TerminalObject *self, PyObject *args, PyObject *kwds) {
  74 +
  75 + return 0;
  76 +
  77 +}
  78 +
  79 +void terminal_dealloc(pw3270_TerminalObject * self) {
  80 +
  81 + trace("%s",__FUNCTION__);
  82 +
  83 + delete self->session;
  84 +
  85 + self->ob_type->tp_free((PyObject*)self);
  86 +
  87 +}
... ...
src/misc.cc 0 → 100644
... ... @@ -0,0 +1,134 @@
  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 misc.cc 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 + * Implementa métodos básicos inicio/final do objeto python
  29 + *
  30 + * Referências:
  31 + *
  32 + * <https://docs.python.org/2/extending/newtypes.html>
  33 + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example>
  34 + *
  35 + */
  36 +
  37 + #include "private.h"
  38 +
  39 +
  40 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  41 +
  42 + PyObject * terminal_connect(PyObject *self, PyObject *args) {
  43 +
  44 + int rc = -1;
  45 + int wait = 60;
  46 + const char * host = "";
  47 +
  48 + if (!PyArg_ParseTuple(args, "s|i", &host, &wait)) {
  49 + PyErr_SetString(terminalError, "connect requires a host URL");
  50 + return NULL;
  51 + }
  52 +
  53 + try {
  54 +
  55 + rc = ((pw3270_TerminalObject *) self)->session->connect(host,wait);
  56 +
  57 + } catch(std::exception &e) {
  58 +
  59 + PyErr_SetString(terminalError, e.what());
  60 + return NULL;
  61 + }
  62 +
  63 + return PyLong_FromLong(rc);
  64 +
  65 + }
  66 +
  67 + PyObject * terminal_disconnect(PyObject *self, PyObject *args) {
  68 +
  69 + int rc = -1;
  70 +
  71 + try {
  72 +
  73 + rc = ((pw3270_TerminalObject *) self)->session->disconnect();
  74 +
  75 + } catch(std::exception &e) {
  76 +
  77 + PyErr_SetString(terminalError, e.what());
  78 + return NULL;
  79 + }
  80 +
  81 + return PyLong_FromLong(rc);
  82 +
  83 + }
  84 +
  85 + PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args) {
  86 +
  87 + int rc;
  88 + int timeout = 60;
  89 +
  90 + if (!PyArg_ParseTuple(args, "|i", &timeout)) {
  91 + PyErr_SetString(terminalError, strerror(EINVAL));
  92 + return NULL;
  93 + }
  94 +
  95 + try {
  96 +
  97 + rc = ((pw3270_TerminalObject *) self)->session->wait_for_ready(timeout);
  98 +
  99 + } catch(std::exception &e) {
  100 +
  101 + PyErr_SetString(terminalError, e.what());
  102 + return NULL;
  103 + }
  104 +
  105 + return PyLong_FromLong(rc);
  106 +
  107 + }
  108 +
  109 +
  110 + PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args) {
  111 +
  112 + int row, col, rc;
  113 + int timeout = 10;
  114 + const char *text;
  115 +
  116 + if (!PyArg_ParseTuple(args, "iis|i", &row, &col, &text, &timeout)) {
  117 + PyErr_SetString(terminalError, strerror(EINVAL));
  118 + return NULL;
  119 + }
  120 +
  121 + try {
  122 +
  123 + rc = ((pw3270_TerminalObject *) self)->session->wait_for_string_at(row,col,text,timeout);
  124 +
  125 + } catch(std::exception &e) {
  126 +
  127 + PyErr_SetString(terminalError, e.what());
  128 + return NULL;
  129 + }
  130 +
  131 + return PyLong_FromLong(rc);
  132 +
  133 + }
  134 +
... ...
src/private.h 0 → 100644
... ... @@ -0,0 +1,87 @@
  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 private.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 +#ifndef PRIVATE_H_INCLUDED
  31 +
  32 + #define PRIVATE_H_INCLUDED
  33 +
  34 + // http://stackoverflow.com/questions/28683358/error-hypot-has-not-been-declared-in-cmath-while-trying-to-embed-python
  35 + #include <cmath>
  36 +
  37 + #include <Python.h>
  38 +
  39 + #include <lib3270/config.h>
  40 + #include <pw3270/class.h>
  41 +
  42 + using namespace std;
  43 +
  44 + typedef struct {
  45 +
  46 + PyObject_HEAD
  47 +
  48 + PW3270_NAMESPACE::session * session;
  49 +
  50 + } pw3270_TerminalObject;
  51 +
  52 + extern PyObject * terminalError;
  53 +
  54 + extern "C" {
  55 +
  56 + PyObject * terminal_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
  57 + int terminal_init(pw3270_TerminalObject *self, PyObject *args, PyObject *kwds);
  58 + void terminal_dealloc(pw3270_TerminalObject * self);
  59 +
  60 + PyObject * terminal_get_version(PyObject *self, PyObject *args);
  61 + PyObject * terminal_get_revision(PyObject *self, PyObject *args);
  62 +
  63 + PyObject * terminal_is_connected(PyObject *self, PyObject *args);
  64 + PyObject * terminal_is_ready(PyObject *self, PyObject *args);
  65 +
  66 + PyObject * terminal_connect(PyObject *self, PyObject *args);
  67 + PyObject * terminal_disconnect(PyObject *self, PyObject *args);
  68 +
  69 + PyObject * terminal_get_string_at(PyObject *self, PyObject *args);
  70 + PyObject * terminal_get_contents(PyObject *self);
  71 + PyObject * terminal_set_string_at(PyObject *self, PyObject *args);
  72 + PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args);
  73 +
  74 + PyObject * terminal_pfkey(PyObject *self, PyObject *args);
  75 + PyObject * terminal_pakey(PyObject *self, PyObject *args);
  76 + PyObject * terminal_enter(PyObject *self, PyObject *args);
  77 + PyObject * terminal_action(PyObject *self, PyObject *args);
  78 +
  79 + PyObject * terminal_is_protected_at(PyObject *self, PyObject *args);
  80 + PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args);
  81 +
  82 + PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args);
  83 + PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args);
  84 +
  85 + }
  86 +
  87 +#endif // PRIVATE_H_INCLUDED
... ...
src/py3270.cc 0 → 100644
... ... @@ -0,0 +1,162 @@
  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 py3270.cc 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 + * Implementa métodos básicos para a extensão python.
  29 + *
  30 + * Referências:
  31 + *
  32 + * <https://docs.python.org/2/extending/newtypes.html>
  33 + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example>
  34 + *
  35 + */
  36 +
  37 + #include "private.h"
  38 +
  39 +/*---[ Globals ]------------------------------------------------------------------------------------*/
  40 +
  41 + PyObject * terminalError = NULL;
  42 +
  43 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  44 +
  45 +static PyObject * get_revision(PyObject *self, PyObject *args) {
  46 +
  47 + return PyLong_FromLong(atoi(PACKAGE_REVISION));
  48 +
  49 +}
  50 +
  51 +static PyMethodDef terminal_methods[] = {
  52 +
  53 + { "Version", terminal_get_version, METH_NOARGS, "Get the lib3270 version string." },
  54 + { "Revision", terminal_get_revision, METH_NOARGS, "Get the lib3270 revision number." },
  55 +
  56 + { "IsConnected", terminal_is_connected, METH_NOARGS, "True if the terminal is connected to the host." },
  57 + { "IsReady", terminal_is_ready, METH_NOARGS, "True if the terminal has finished network activity." },
  58 + { "IsProtected", terminal_is_protected_at, METH_VARARGS, "True if the position is read-only." },
  59 +
  60 + { "SetCursorPosition", terminal_set_cursor_at, METH_VARARGS, "Set cursor position." },
  61 +
  62 + { "WaitForStringAt", terminal_wait_for_string_at, METH_VARARGS, "Wait for string at position" },
  63 + { "WaitForReady", terminal_wait_for_ready, METH_VARARGS, "Wait for network communication to finish" },
  64 +
  65 + { "Connect", terminal_connect, METH_VARARGS, "Connect to the host." },
  66 + { "Disconnect", terminal_disconnect, METH_NOARGS, "Disconnect from host." },
  67 +
  68 + { "CmpStringAt", terminal_cmp_string_at, METH_VARARGS, "Compare string with terminal buffer at the position." },
  69 + { "GetStringAt", terminal_get_string_at, METH_VARARGS, "Get string from terminal buffer." },
  70 + { "SetStringAt", terminal_set_string_at, METH_VARARGS, "Set string in terminal buffer." },
  71 +
  72 + { "PFKey", terminal_pfkey, METH_VARARGS, "Send PF key." },
  73 + { "PAKey", terminal_pakey, METH_VARARGS, "Send PA key." },
  74 + { "Enter", terminal_enter, METH_NOARGS, "Send Enter Key." },
  75 + { "Action", terminal_action, METH_VARARGS, "Send Action by name." },
  76 +
  77 + {NULL} // Sentinel
  78 +
  79 +};
  80 +
  81 +/*
  82 +static PyMemberDef terminal_members[] = {
  83 +
  84 + { NULL } // Sentinel
  85 +
  86 +};
  87 +*/
  88 +
  89 +static PyTypeObject pw3270_TerminalType = {
  90 + PyObject_HEAD_INIT(NULL)
  91 + 0, /*ob_size*/
  92 + "py3270.terminal", /*tp_name*/
  93 + sizeof(pw3270_TerminalObject), /*tp_basicsize*/
  94 + 0, /*tp_itemsize*/
  95 + (destructor) terminal_dealloc, /*tp_dealloc*/
  96 + 0, /*tp_print*/
  97 + 0, /*tp_getattr*/
  98 + 0, /*tp_setattr*/
  99 + 0, /*tp_compare*/
  100 + 0, /*tp_repr*/
  101 + 0, /*tp_as_number*/
  102 + 0, /*tp_as_sequence*/
  103 + 0, /*tp_as_mapping*/
  104 + 0, /*tp_hash */
  105 + 0, /*tp_call*/
  106 + terminal_get_contents, /*tp_str*/
  107 + 0, /*tp_getattro*/
  108 + 0, /*tp_setattro*/
  109 + 0, /*tp_as_buffer*/
  110 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
  111 + "3270 terminal object", /* tp_doc */
  112 + 0, /* tp_traverse */
  113 + 0, /* tp_clear */
  114 + 0, /* tp_richcompare */
  115 + 0, /* tp_weaklistoffset */
  116 + 0, /* tp_iter */
  117 + 0, /* tp_iternext */
  118 + terminal_methods, /* tp_methods */
  119 + 0, // terminal_members, /* tp_members */
  120 + 0, /* tp_getset */
  121 + 0, /* tp_base */
  122 + 0, /* tp_dict */
  123 + 0, /* tp_descr_get */
  124 + 0, /* tp_descr_set */
  125 + 0, /* tp_dictoffset */
  126 + (initproc) terminal_init, /* tp_init */
  127 + 0, /* tp_alloc */
  128 + terminal_new, /* tp_new */
  129 +
  130 +};
  131 +
  132 +static PyMethodDef MyMethods[] = {
  133 +
  134 + { "Revision", get_revision, METH_VARARGS, "Get module revision." },
  135 +
  136 + {NULL, NULL, 0, NULL} /* Sentinel */
  137 +
  138 +};
  139 +
  140 +PyMODINIT_FUNC initpy3270(void) {
  141 +
  142 + // Cria o módulo
  143 +
  144 + PyObject *m = Py_InitModule("py3270", MyMethods);
  145 +
  146 + if (m == NULL)
  147 + return;
  148 +
  149 + // Adiciona objeto para tratamento de erros.
  150 + terminalError = PyErr_NewException((char *) "py3270.error", NULL, NULL);
  151 +
  152 + (void) Py_INCREF(terminalError);
  153 + PyModule_AddObject(m, "error", terminalError);
  154 +
  155 + // Adiciona terminal
  156 + if(PyType_Ready(&pw3270_TerminalType) < 0)
  157 + return
  158 +
  159 + (void) Py_INCREF(&pw3270_TerminalType);
  160 + PyModule_AddObject(m, "Terminal", (PyObject *)&pw3270_TerminalType);
  161 +
  162 +}
... ...
src/set.cc 0 → 100644
... ... @@ -0,0 +1,86 @@
  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 set.cc 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 + * Referências:
  29 + *
  30 + * <https://docs.python.org/2/extending/newtypes.html>
  31 + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example>
  32 + *
  33 + */
  34 +
  35 + #include "private.h"
  36 +
  37 +
  38 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  39 +
  40 + PyObject * terminal_set_string_at(PyObject *self, PyObject *args) {
  41 +
  42 + int row, col, rc;
  43 + const char *text;
  44 +
  45 + if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) {
  46 + PyErr_SetString(terminalError, strerror(EINVAL));
  47 + return NULL;
  48 + }
  49 +
  50 + try {
  51 +
  52 + rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text);
  53 +
  54 + } catch(std::exception &e) {
  55 +
  56 + PyErr_SetString(terminalError, e.what());
  57 + return NULL;
  58 + }
  59 +
  60 + return PyLong_FromLong(rc);
  61 +
  62 + }
  63 +
  64 + PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args) {
  65 +
  66 + int row, col, rc;
  67 +
  68 + if (!PyArg_ParseTuple(args, "ii", &row, &col)) {
  69 + PyErr_SetString(terminalError, strerror(EINVAL));
  70 + return NULL;
  71 + }
  72 +
  73 + try {
  74 +
  75 + rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col);
  76 +
  77 + } catch(std::exception &e) {
  78 +
  79 + PyErr_SetString(terminalError, e.what());
  80 + return NULL;
  81 + }
  82 +
  83 + return PyLong_FromLong(rc);
  84 +
  85 + }
  86 +
... ...