Commit 35ca683c3fe7ab065bafdd184c41896d52de0f89

Authored by Perry Werneck
1 parent 45611798
Exists in master

Implementing action objects.

Makefile.in
... ... @@ -32,7 +32,10 @@ SOURCES= \
32 32 $(wildcard src/module/*.c) \
33 33 $(wildcard src/module/*.cc) \
34 34 $(wildcard src/module/@OSNAME@/*.cc) \
35   - $(wildcard src/terminal/*.cc)
  35 + $(wildcard src/action/*.cc) \
  36 + $(wildcard src/action/*.c) \
  37 + $(wildcard src/session/*.cc) \
  38 + $(wildcard src/session/*.c)
36 39  
37 40 #---[ Tools ]----------------------------------------------------------------------------
38 41  
... ...
gitsync.sh
... ... @@ -9,18 +9,24 @@
9 9 # Setup:
10 10 #
11 11 # git remote add github https://github.com/PerryWerneck/lib3270.git
12   -# git fetch origin
13   -# git push github --all
14 12 #
15 13 #
16 14  
17 15 git push
18 16  
19 17 git fetch origin
20   -git checkout master
21   -git merge origin/master
  18 +git merge
22 19  
23   -for repo in $(git remote -v | grep -v origin | grep "(push)" | awk '{print $1}')
  20 +REPOS=$(git remote -v | grep -v origin | grep "(push)" | awk '{print $1}')
  21 +
  22 +for repo in ${REPOS}
  23 +do
  24 + echo "Getting updates from ${repo} ..."
  25 + git fetch ${repo}
  26 + git merge
  27 +done
  28 +
  29 +for repo in ${REPOS}
24 30 do
25 31 echo "Updating ${repo} ..."
26 32 git push ${repo}
... ...
py3270.cbp
... ... @@ -42,6 +42,11 @@
42 42 <Add option="`pkg-config --libs python dbus-1`" />
43 43 <Add library="pw3270cpp" />
44 44 </Linker>
  45 + <Unit filename="src/action/init.cc" />
  46 + <Unit filename="src/action/new.cc" />
  47 + <Unit filename="src/action/type.c">
  48 + <Option compilerVar="CC" />
  49 + </Unit>
45 50 <Unit filename="src/include/config.h" />
46 51 <Unit filename="src/include/config.h.in" />
47 52 <Unit filename="src/include/py3270.h" />
... ... @@ -50,12 +55,15 @@
50 55 </Unit>
51 56 <Unit filename="src/module/properties.cc" />
52 57 <Unit filename="src/module/tools.cc" />
53   - <Unit filename="src/terminal/actions.cc" />
54   - <Unit filename="src/terminal/attributes.cc" />
55   - <Unit filename="src/terminal/get.cc" />
56   - <Unit filename="src/terminal/init.cc" />
57   - <Unit filename="src/terminal/network.cc" />
58   - <Unit filename="src/terminal/set.cc" />
  58 + <Unit filename="src/session/actions.cc" />
  59 + <Unit filename="src/session/attributes.cc" />
  60 + <Unit filename="src/session/get.cc" />
  61 + <Unit filename="src/session/init.cc" />
  62 + <Unit filename="src/session/network.cc" />
  63 + <Unit filename="src/session/set.cc" />
  64 + <Unit filename="src/session/type.c">
  65 + <Option compilerVar="CC" />
  66 + </Unit>
59 67 <Extensions>
60 68 <code_completion />
61 69 <envvars />
... ...
src/action/init.cc 0 → 100644
... ... @@ -0,0 +1,45 @@
  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 <py3270.h>
  38 + #include <lib3270/ipc.h>
  39 +
  40 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  41 +
  42 +void py3270_action_type_init(PyTypeObject *type) {
  43 +
  44 +
  45 +}
... ...
src/action/new.cc 0 → 100644
... ... @@ -0,0 +1,44 @@
  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 <py3270.h>
  38 + #include <lib3270/ipc.h>
  39 +
  40 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  41 +
  42 +DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action) {
  43 +
  44 +}
... ...
src/action/type.c 0 → 100644
... ... @@ -0,0 +1,70 @@
  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 + * 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 <py3270.h>
  36 +
  37 +/*---[ Globals ]------------------------------------------------------------------------------------*/
  38 +
  39 +static PyMethodDef py3270_action_methods[] = {
  40 +
  41 + /*
  42 + {
  43 + "activatable",
  44 + (PyCFunction) py3270_action_activatable,
  45 + METH_NOARGS,
  46 + ""
  47 + },
  48 + */
  49 +
  50 + {
  51 + NULL
  52 + }
  53 +};
  54 +
  55 +// https://docs.python.org/3/c-api/typeobj.html
  56 +PyTypeObject py3270_action_type = {
  57 +
  58 + PyVarObject_HEAD_INIT(NULL, 0)
  59 +
  60 + .tp_name = "tn3270.Session.Action",
  61 + .tp_doc = "TN3270 Session Action Object",
  62 + .tp_basicsize = sizeof(pyAction),
  63 + .tp_itemsize = 0,
  64 + .tp_flags = Py_TPFLAGS_DEFAULT,
  65 +
  66 + .tp_methods = py3270_action_methods,
  67 +
  68 +};
  69 +
  70 +
... ...
src/include/py3270.h
... ... @@ -75,7 +75,9 @@
75 75 #include <functional>
76 76 #include <exception>
77 77 #include <stdexcept>
  78 + #include <vector>
78 79 #include <lib3270/ipc.h>
  80 + #include <lib3270/actions.h>
79 81  
80 82 using std::exception;
81 83 using std::runtime_error;
... ... @@ -97,11 +99,24 @@
97 99 Host *host;
98 100 } pySession;
99 101  
100   - DLL_PRIVATE void py3270_session_type_init(PyTypeObject *type);
  102 + typedef struct {
  103 + PyObject_HEAD
  104 + Host *host;
  105 + const struct _lib3270_action * action;
  106 + } pyAction;
  107 +
  108 + DLL_PRIVATE PyTypeObject py3270_session_type;
  109 + DLL_PRIVATE PyTypeObject py3270_action_type;
101 110  
102 111 DLL_PRIVATE PyObject * py3270_get_module_version(PyObject *self, PyObject *args);
103 112 DLL_PRIVATE PyObject * py3270_get_module_revision(PyObject *self, PyObject *args);
104 113  
  114 + // Types
  115 + DLL_PRIVATE void py3270_action_type_init(PyTypeObject *type);
  116 + DLL_PRIVATE void py3270_session_type_init(PyTypeObject *type);
  117 +
  118 +
  119 + // Session object
105 120 DLL_PRIVATE PyObject * py3270_session_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds);
106 121 DLL_PRIVATE void py3270_session_dealloc(PyObject * self);
107 122  
... ... @@ -111,8 +126,6 @@
111 126 DLL_PRIVATE PyObject * py3270_session_getter(PyObject *self, void *name);
112 127 DLL_PRIVATE int py3270_session_setter(PyObject *self, PyObject *value, void *name);
113 128  
114   -// DLL_PRIVATE PyObject * py3270_session_getattr(PyObject *self, char *attr_name);
115   -
116 129 DLL_PRIVATE PyObject * py3270_session_connect(PyObject *self, PyObject *args);
117 130 DLL_PRIVATE PyObject * py3270_session_disconnect(PyObject *self, PyObject *args);
118 131  
... ... @@ -120,6 +133,10 @@
120 133 DLL_PRIVATE PyObject * py3270_session_set(PyObject *self, PyObject *args);
121 134 DLL_PRIVATE PyObject * py3270_session_str(PyObject *self);
122 135  
  136 + // Action object
  137 + DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action);
  138 +
  139 +
123 140 /*
124 141  
125 142 DLL_PRIVATE PyObject * py3270_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds);
... ...
src/module/init.c
... ... @@ -70,75 +70,46 @@ static struct PyModuleDef definition = {
70 70 .m_free = (freefunc) cleanup
71 71 };
72 72  
73   -//# Tornar essa tabela pública e testar em getattr, se for um método usar PyMethod_New para retornar um método.
74   -
75   -static PyMethodDef py3270_session_methods[] = {
76   - {
77   - "connect",
78   - (PyCFunction) py3270_session_connect,
79   - METH_VARARGS,
80   - ""
81   - },
82   -
83   - {
84   - "disconnect",
85   - (PyCFunction) py3270_session_disconnect,
86   - METH_NOARGS,
87   - ""
88   - },
89   -
90   - {
91   - "set",
92   - (PyCFunction) py3270_session_set,
93   - METH_VARARGS,
94   - ""
95   - },
96   -
97   - {
98   - "get",
99   - (PyCFunction) py3270_session_get,
100   - METH_VARARGS,
101   - ""
102   - },
103   -
104   - {
105   - NULL
106   - }
107   -};
  73 +/*
  74 +static PyTypeObject ActionType = {
108 75  
109   -// https://docs.python.org/3/c-api/typeobj.html
110   -static PyTypeObject SessionType = {
111 76 PyVarObject_HEAD_INIT(NULL, 0)
112   - .tp_name = "tn3270.Session",
113   - .tp_doc = "TN3270 Session Object",
114   - .tp_basicsize = sizeof(pySession),
  77 +
  78 + .tp_name = "tn3270.Action",
  79 + .tp_doc = "TN3270 Action Object",
  80 + .tp_basicsize = sizeof(pyAction),
115 81 .tp_itemsize = 0,
116   - .tp_flags = Py_TPFLAGS_HAVE_FINALIZE|Py_TPFLAGS_DEFAULT,
  82 + .tp_flags = Py_TPFLAGS_DEFAULT,
117 83  
118   - .tp_new = py3270_session_alloc,
119   - .tp_dealloc = py3270_session_dealloc,
  84 +// .tp_new = py3270_session_alloc,
  85 +// .tp_dealloc = py3270_session_dealloc,
120 86  
121   - .tp_init = py3270_session_init,
122   - .tp_finalize = py3270_session_finalize,
  87 +// .tp_init = py3270_session_init,
  88 +// .tp_finalize = py3270_session_finalize,
123 89  
124   - .tp_str = py3270_session_str,
  90 +// .tp_str = py3270_session_str,
125 91  
126   - .tp_methods = py3270_session_methods,
  92 +// .tp_methods = py3270_session_methods,
127 93  
128 94 };
  95 +*/
129 96  
130 97 /*---[ Implement ]----------------------------------------------------------------------------------*/
131 98  
132 99 PyMODINIT_FUNC PyInit_tn3270(void)
133 100 {
134 101 // Initialize custom attributes & methods.
135   - py3270_session_type_init(&SessionType);
  102 + py3270_session_type_init(&py3270_session_type);
  103 + if (PyType_Ready(&py3270_session_type) < 0)
  104 + return NULL;
  105 +
  106 + py3270_action_type_init(&py3270_action_type);
  107 + if (PyType_Ready(&py3270_action_type) < 0)
  108 + return NULL;
136 109  
137 110 //
138 111 // Initialize module.
139 112 //
140   - if (PyType_Ready(&SessionType) < 0)
141   - return NULL;
142 113  
143 114 Py_Initialize();
144 115  
... ... @@ -152,9 +123,9 @@ PyMODINIT_FUNC PyInit_tn3270(void)
152 123 //
153 124 // Create custom type
154 125 //
155   - Py_INCREF(&SessionType);
156   - if (PyModule_AddObject(module, "Session", (PyObject *) &SessionType) < 0) {
157   - Py_DECREF(&SessionType);
  126 + Py_INCREF(&py3270_session_type);
  127 + if (PyModule_AddObject(module, "Session", (PyObject *) &py3270_session_type) < 0) {
  128 + Py_DECREF(&py3270_session_type);
158 129 Py_DECREF(module);
159 130 return NULL;
160 131 }
... ... @@ -166,9 +137,9 @@ static void cleanup(PyObject *module) {
166 137  
167 138 debug("Cleaning up module %p", module);
168 139  
169   - if(SessionType.tp_getset) {
170   - free(SessionType.tp_getset);
171   - SessionType.tp_getset = NULL;
  140 + if(py3270_session_type.tp_getset) {
  141 + free(py3270_session_type.tp_getset);
  142 + py3270_session_type.tp_getset = NULL;
172 143 }
173 144  
174 145 }
... ...
src/session/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 <py3270.h>
  36 +
  37 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  38 +
  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/session/attributes.cc 0 → 100644
... ... @@ -0,0 +1,92 @@
  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 <py3270.h>
  36 +
  37 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  38 +
  39 +PyObject * py3270_session_getter(PyObject *self, void *name) {
  40 +
  41 +// debug("%s(%s)",__FUNCTION__,(const char *) name);
  42 +
  43 + return py3270_session_call(self, [name](TN3270::Host &host){
  44 +
  45 + auto attribute = host[(const char *) name];
  46 +
  47 + switch(attribute.getType()) {
  48 + case TN3270::Attribute::String:
  49 + return PyUnicode_FromString(attribute.toString().c_str());
  50 +
  51 + case TN3270::Attribute::Boolean:
  52 + return PyBool_FromLong(attribute.getBoolean());
  53 +
  54 + case TN3270::Attribute::Uchar:
  55 + throw std::system_error(ENOTSUP, std::system_category());
  56 +
  57 + case TN3270::Attribute::Int16:
  58 + throw std::system_error(ENOTSUP, std::system_category());
  59 +
  60 + case TN3270::Attribute::Uint16:
  61 + throw std::system_error(ENOTSUP, std::system_category());
  62 +
  63 + case TN3270::Attribute::Int32:
  64 + return PyLong_FromLong(attribute.getInt32());
  65 +
  66 + case TN3270::Attribute::Int32x:
  67 + throw std::system_error(ENOTSUP, std::system_category());
  68 +
  69 + case TN3270::Attribute::Uint32:
  70 + return PyLong_FromLong(attribute.getUint32());
  71 +
  72 + case TN3270::Attribute::Int64:
  73 + throw std::system_error(ENOTSUP, std::system_category());
  74 +
  75 + case TN3270::Attribute::Uint64:
  76 + throw std::system_error(ENOTSUP, std::system_category());
  77 +
  78 + default:
  79 + throw runtime_error("Unexpected atttribute type");
  80 + }
  81 +
  82 + return PyLong_FromLong(0);
  83 +
  84 + });
  85 +
  86 +}
  87 +
  88 +int py3270_session_setter(PyObject *self, PyObject *value, void *name) {
  89 +
  90 + return 0;
  91 +}
  92 +
... ...
src/session/get.cc 0 → 100644
... ... @@ -0,0 +1,95 @@
  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 <py3270.h>
  36 +
  37 + using std::string;
  38 +
  39 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  40 +
  41 + PyObject * py3270_session_get(PyObject *self, PyObject *args) {
  42 +
  43 + return py3270_session_call(self, [args](TN3270::Host &host){
  44 +
  45 + string text;
  46 +
  47 + switch(PyTuple_Size(args)) {
  48 + case 0: // Get the entire screen
  49 + text = host.toString();
  50 + break;
  51 +
  52 + case 2: // Address and length.
  53 + {
  54 + int baddr, length;
  55 +
  56 + if (!PyArg_ParseTuple(args, "ii", &baddr, &length))
  57 + return (PyObject *) NULL;
  58 +
  59 + text = host.toString(baddr, length);
  60 + }
  61 + break;
  62 +
  63 + case 3: // Row, col and length
  64 + {
  65 + unsigned int row, col;
  66 + int length;
  67 +
  68 + if (!PyArg_ParseTuple(args, "IIi", &row, &col, &length))
  69 + return (PyObject *) NULL;
  70 +
  71 + text = host.toString(row, col, length);
  72 + }
  73 + break;
  74 +
  75 + default:
  76 + throw std::system_error(EINVAL, std::system_category());
  77 +
  78 + }
  79 +
  80 + return PyUnicode_FromString(text.c_str());
  81 +
  82 + });
  83 +
  84 + }
  85 +
  86 + PyObject * py3270_session_str(PyObject *self) {
  87 +
  88 + return py3270_session_call(self, [](TN3270::Host &host){
  89 +
  90 + return PyUnicode_FromString(host.toString().c_str());
  91 +
  92 + });
  93 +
  94 + }
  95 +
... ...
src/session/init.cc 0 → 100644
... ... @@ -0,0 +1,253 @@
  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 <py3270.h>
  38 + #include <lib3270/ipc.h>
  39 +
  40 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  41 +
  42 +static void cleanup(pySession * session) {
  43 +
  44 + if(session->host) {
  45 + delete session->host;
  46 + session->host = nullptr;
  47 + }
  48 +
  49 +}
  50 +
  51 +static void py3270_session_attribute_init(struct PyGetSetDef *attribute, const LIB3270_PROPERTY * descriptor) {
  52 +
  53 + attribute->name = (char *) descriptor->name;
  54 + attribute->doc = (char *) (descriptor->description ? descriptor->description : descriptor->summary);
  55 +
  56 +}
  57 +
  58 +void py3270_session_type_init(PyTypeObject *type) {
  59 +
  60 + // Load attributes
  61 + {
  62 + auto attributes = TN3270::getAttributes();
  63 + auto actions = TN3270::getActions();
  64 + size_t ix = 0;
  65 +
  66 + size_t szData = sizeof(struct PyGetSetDef) * (attributes.size() + actions.size() + 1);
  67 +
  68 + type->tp_getset = (struct PyGetSetDef *) malloc(szData);
  69 + memset(type->tp_getset,0,szData);
  70 +
  71 + for(auto attribute : attributes) {
  72 +
  73 +// debug("Creating attribute %s",attribute->name);
  74 +
  75 + py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) attribute);
  76 +
  77 + type->tp_getset[ix].get = py3270_session_getter;
  78 + type->tp_getset[ix].set = py3270_session_setter;
  79 + type->tp_getset[ix].closure = (void *) attribute->name;
  80 +
  81 + ix++;
  82 +
  83 + }
  84 +
  85 + for(auto action : actions) {
  86 +
  87 + debug("Creating action %s",action->name);
  88 +
  89 + py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) action);
  90 +
  91 + type->tp_getset[ix].get = py3270_action_new_from_session;
  92 + type->tp_getset[ix].closure = (void *) action;
  93 +
  94 + ix++;
  95 +
  96 + }
  97 + }
  98 +
  99 +
  100 +}
  101 +
  102 +
  103 +int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) {
  104 +
  105 + pySession * session = (pySession *) self;
  106 + debug("%s session=%p host=%p",__FUNCTION__,session,session->host);
  107 +
  108 + try {
  109 +
  110 + cleanup(session);
  111 +
  112 + const char *id = "";
  113 +
  114 + if (!PyArg_ParseTuple(args, "s", &id))
  115 + id = "";
  116 +
  117 + session->host = new TN3270::Host(id);
  118 +
  119 + /*
  120 + // Load lib3270's actions
  121 + {
  122 + auto actions = TN3270::getActions();
  123 +
  124 + for(auto action : actions) {
  125 +
  126 + pyAction * object = (pyAction *) _PyObject_New(&py3270_action_type);
  127 +
  128 + object->host = session->host;
  129 + object->action = action;
  130 +
  131 + PyObject_SetAttr(self, PyUnicode_FromString(action->name), (PyObject *) object);
  132 +
  133 + }
  134 +
  135 + }
  136 + */
  137 +
  138 + return 0;
  139 +
  140 + } catch(const std::exception &e) {
  141 +
  142 + PyErr_SetString(PyExc_RuntimeError, e.what());
  143 +
  144 + } catch(...) {
  145 +
  146 + PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");
  147 +
  148 + }
  149 +
  150 + return -1;
  151 +
  152 +}
  153 +
  154 +void py3270_session_finalize(PyObject *self) {
  155 +
  156 + debug("%s",__FUNCTION__);
  157 + cleanup((pySession *) self);
  158 +
  159 +}
  160 +
  161 +PyObject * py3270_session_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds) {
  162 +
  163 + debug("%s",__FUNCTION__);
  164 + return type->tp_alloc(type,0);
  165 +
  166 +}
  167 +
  168 +void py3270_session_dealloc(PyObject * self) {
  169 +
  170 + debug("%s",__FUNCTION__);
  171 +
  172 + cleanup((pySession *) self);
  173 + Py_TYPE(self)->tp_free(self);
  174 +
  175 +}
  176 +
  177 + /*
  178 +
  179 + const char *id = "";
  180 +
  181 + if (!PyArg_ParseTuple(args, "s", &id))
  182 + id = "";
  183 +
  184 +
  185 + if(session) {
  186 +
  187 + try {
  188 +
  189 + session->host = new TN3270::Host(id);
  190 +
  191 + } catch(const exception &e) {
  192 +
  193 + PyErr_SetString(PyExc_RuntimeError, e.what());
  194 +
  195 + } catch( ... ) {
  196 +
  197 + PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");
  198 +
  199 + }
  200 +
  201 + }
  202 +
  203 + type->tp_free(session);
  204 +
  205 + return NULL;
  206 +
  207 +}
  208 +
  209 +void py3270_session_dealloc(pySession * self) {
  210 +
  211 + if(self->host) {
  212 + delete self->host;
  213 + }
  214 +
  215 + Py_TYPE(self)->tp_free((PyObject *) self);
  216 +
  217 +}
  218 + */
  219 +
  220 +
  221 +/*
  222 +PyObject * terminal_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
  223 +
  224 + PW3270_NAMESPACE::session * session;
  225 + const char *id = "";
  226 +
  227 + if (!PyArg_ParseTuple(args, "s", &id)) {
  228 + id = "";
  229 + }
  230 +
  231 + trace("%s(%s)",__FUNCTION__,id);
  232 +
  233 + try {
  234 +
  235 + session = PW3270_NAMESPACE::session::create(id);
  236 +
  237 + } catch(std::exception &e) {
  238 +
  239 + trace("%s failed: %s",__FUNCTION__,e.what());
  240 + PyErr_SetString(terminalError, e.what());
  241 + return NULL;
  242 +
  243 + }
  244 +
  245 + pw3270_TerminalObject *self = (pw3270_TerminalObject *) type->tp_alloc(type, 0);
  246 +
  247 + self->session = session;
  248 +
  249 + return (PyObject *)self;
  250 +}
  251 +
  252 +
  253 +*/
... ...
src/session/network.cc 0 → 100644
... ... @@ -0,0 +1,166 @@
  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 <py3270.h>
  38 +
  39 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  40 +
  41 + PyObject * py3270_session_connect(PyObject *self, PyObject *args) {
  42 +
  43 + return py3270_session_call(self, [args](TN3270::Host &host){
  44 +
  45 + const char * url = "";
  46 +
  47 + if(!PyArg_ParseTuple(args, "s", &url)) {
  48 + throw runtime_error("connect requires a host URL");
  49 + }
  50 +
  51 + host.connect(url);
  52 +
  53 + return 0;
  54 +
  55 + });
  56 +
  57 + }
  58 +
  59 + PyObject * py3270_session_disconnect(PyObject *self, PyObject *args) {
  60 +
  61 + return py3270_session_call(self, [args](TN3270::Host &host){
  62 +
  63 + host.disconnect();
  64 +
  65 + return 0;
  66 +
  67 + });
  68 +
  69 + }
  70 +
  71 +
  72 +/*
  73 + PyObject * terminal_connect(PyObject *self, PyObject *args) {
  74 +
  75 + int rc = -1;
  76 + int wait = 60;
  77 + const char * host = "";
  78 +
  79 + if (!PyArg_ParseTuple(args, "s|i", &host, &wait)) {
  80 + PyErr_SetString(terminalError, "connect requires a host URL");
  81 + return NULL;
  82 + }
  83 +
  84 + try {
  85 +
  86 + rc = ((pw3270_TerminalObject *) self)->session->connect(host,wait);
  87 +
  88 + } catch(std::exception &e) {
  89 +
  90 + PyErr_SetString(terminalError, e.what());
  91 + return NULL;
  92 + }
  93 +
  94 + return PyLong_FromLong(rc);
  95 +
  96 + }
  97 +
  98 + PyObject * terminal_disconnect(PyObject *self, PyObject *args) {
  99 +
  100 + int rc = -1;
  101 +
  102 + try {
  103 +
  104 + rc = ((pw3270_TerminalObject *) self)->session->disconnect();
  105 +
  106 + } catch(std::exception &e) {
  107 +
  108 + PyErr_SetString(terminalError, e.what());
  109 + return NULL;
  110 + }
  111 +
  112 + return PyLong_FromLong(rc);
  113 +
  114 + }
  115 +
  116 + PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args) {
  117 +
  118 + int rc;
  119 + int timeout = 60;
  120 +
  121 + if (!PyArg_ParseTuple(args, "|i", &timeout)) {
  122 + PyErr_SetString(terminalError, strerror(EINVAL));
  123 + return NULL;
  124 + }
  125 +
  126 + try {
  127 +
  128 + rc = ((pw3270_TerminalObject *) self)->session->wait_for_ready(timeout);
  129 +
  130 + } catch(std::exception &e) {
  131 +
  132 + PyErr_SetString(terminalError, e.what());
  133 + return NULL;
  134 + }
  135 +
  136 + return PyLong_FromLong(rc);
  137 +
  138 + }
  139 +
  140 +
  141 + PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args) {
  142 +
  143 + int row, col, rc;
  144 + int timeout = 10;
  145 + const char *text;
  146 +
  147 + if (!PyArg_ParseTuple(args, "iis|i", &row, &col, &text, &timeout)) {
  148 + PyErr_SetString(terminalError, strerror(EINVAL));
  149 + return NULL;
  150 + }
  151 +
  152 + try {
  153 +
  154 + rc = ((pw3270_TerminalObject *) self)->session->wait_for_string_at(row,col,text,timeout);
  155 +
  156 + } catch(std::exception &e) {
  157 +
  158 + PyErr_SetString(terminalError, e.what());
  159 + return NULL;
  160 + }
  161 +
  162 + return PyLong_FromLong(rc);
  163 +
  164 + }
  165 +
  166 +*/
... ...
src/session/set.cc 0 → 100644
... ... @@ -0,0 +1,141 @@
  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 <py3270.h>
  36 +
  37 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  38 +
  39 + PyObject * py3270_session_set(PyObject *self, PyObject *args) {
  40 +
  41 + return py3270_session_call(self, [args](TN3270::Host &host){
  42 +
  43 + switch(PyTuple_Size(args)) {
  44 + case 1: // Only text.
  45 + {
  46 + const char *text;
  47 +
  48 + if(!PyArg_ParseTuple(args, "s", &text))
  49 + return (PyObject *) NULL;
  50 +
  51 + host.push(text,-1);
  52 +
  53 + }
  54 + break;
  55 +
  56 + case 2: // Address and text.
  57 + {
  58 + int baddr;
  59 + const char *text;
  60 +
  61 + if(!PyArg_ParseTuple(args, "is", &baddr, &text))
  62 + return (PyObject *) NULL;
  63 +
  64 + host.push(baddr, text);
  65 + }
  66 + break;
  67 +
  68 + case 3: // Row, col and text
  69 + {
  70 + unsigned int row, col;
  71 + const char *text;
  72 +
  73 + if (!PyArg_ParseTuple(args, "IIs", &row, &col, &text))
  74 + return (PyObject *) NULL;
  75 +
  76 + host.push(row,col,text);
  77 +
  78 + }
  79 + break;
  80 +
  81 + default:
  82 + throw std::system_error(EINVAL, std::system_category());
  83 +
  84 + }
  85 +
  86 + return PyLong_FromLong(0);
  87 +
  88 + });
  89 +
  90 + }
  91 +
  92 +
  93 +/*
  94 + PyObject * terminal_set_string_at(PyObject *self, PyObject *args) {
  95 +
  96 + int row, col, rc;
  97 + const char *text;
  98 +
  99 + if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) {
  100 + PyErr_SetString(terminalError, strerror(EINVAL));
  101 + return NULL;
  102 + }
  103 +
  104 + try {
  105 +
  106 + rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text);
  107 +
  108 + } catch(std::exception &e) {
  109 +
  110 + PyErr_SetString(terminalError, e.what());
  111 + return NULL;
  112 + }
  113 +
  114 + return PyLong_FromLong(rc);
  115 +
  116 + }
  117 +
  118 + PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args) {
  119 +
  120 + int row, col, rc;
  121 +
  122 + if (!PyArg_ParseTuple(args, "ii", &row, &col)) {
  123 + PyErr_SetString(terminalError, strerror(EINVAL));
  124 + return NULL;
  125 + }
  126 +
  127 + try {
  128 +
  129 + rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col);
  130 +
  131 + } catch(std::exception &e) {
  132 +
  133 + PyErr_SetString(terminalError, e.what());
  134 + return NULL;
  135 + }
  136 +
  137 + return PyLong_FromLong(rc);
  138 +
  139 + }
  140 +
  141 +*/
... ...
src/session/type.c 0 → 100644
... ... @@ -0,0 +1,96 @@
  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 + * 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 <py3270.h>
  36 +
  37 +/*---[ Globals ]------------------------------------------------------------------------------------*/
  38 +
  39 +static PyMethodDef py3270_session_methods[] = {
  40 + {
  41 + "connect",
  42 + (PyCFunction) py3270_session_connect,
  43 + METH_VARARGS,
  44 + ""
  45 + },
  46 +
  47 + {
  48 + "disconnect",
  49 + (PyCFunction) py3270_session_disconnect,
  50 + METH_NOARGS,
  51 + ""
  52 + },
  53 +
  54 + {
  55 + "set",
  56 + (PyCFunction) py3270_session_set,
  57 + METH_VARARGS,
  58 + ""
  59 + },
  60 +
  61 + {
  62 + "get",
  63 + (PyCFunction) py3270_session_get,
  64 + METH_VARARGS,
  65 + ""
  66 + },
  67 +
  68 + {
  69 + NULL
  70 + }
  71 +};
  72 +
  73 +// https://docs.python.org/3/c-api/typeobj.html
  74 +PyTypeObject py3270_session_type = {
  75 +
  76 + PyVarObject_HEAD_INIT(NULL, 0)
  77 +
  78 + .tp_name = "tn3270.Session",
  79 + .tp_doc = "TN3270 Session Object",
  80 + .tp_basicsize = sizeof(pySession),
  81 + .tp_itemsize = 0,
  82 + .tp_flags = Py_TPFLAGS_HAVE_FINALIZE|Py_TPFLAGS_DEFAULT,
  83 +
  84 + .tp_new = py3270_session_alloc,
  85 + .tp_dealloc = py3270_session_dealloc,
  86 +
  87 + .tp_init = py3270_session_init,
  88 + .tp_finalize = py3270_session_finalize,
  89 +
  90 + .tp_str = py3270_session_str,
  91 +
  92 + .tp_methods = py3270_session_methods,
  93 +
  94 +};
  95 +
  96 +
... ...
src/terminal/actions.cc
... ... @@ -1,129 +0,0 @@
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 <py3270.h>
36   -
37   -/*---[ Implement ]----------------------------------------------------------------------------------*/
38   -
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/terminal/attributes.cc
... ... @@ -1,92 +0,0 @@
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 <py3270.h>
36   -
37   -/*---[ Implement ]----------------------------------------------------------------------------------*/
38   -
39   -PyObject * py3270_session_getter(PyObject *self, void *name) {
40   -
41   -// debug("%s(%s)",__FUNCTION__,(const char *) name);
42   -
43   - return py3270_session_call(self, [name](TN3270::Host &host){
44   -
45   - auto attribute = host[(const char *) name];
46   -
47   - switch(attribute.getType()) {
48   - case TN3270::Attribute::String:
49   - return PyUnicode_FromString(attribute.toString().c_str());
50   -
51   - case TN3270::Attribute::Boolean:
52   - return PyBool_FromLong(attribute.getBoolean());
53   -
54   - case TN3270::Attribute::Uchar:
55   - throw std::system_error(ENOTSUP, std::system_category());
56   -
57   - case TN3270::Attribute::Int16:
58   - throw std::system_error(ENOTSUP, std::system_category());
59   -
60   - case TN3270::Attribute::Uint16:
61   - throw std::system_error(ENOTSUP, std::system_category());
62   -
63   - case TN3270::Attribute::Int32:
64   - return PyLong_FromLong(attribute.getInt32());
65   -
66   - case TN3270::Attribute::Int32x:
67   - throw std::system_error(ENOTSUP, std::system_category());
68   -
69   - case TN3270::Attribute::Uint32:
70   - return PyLong_FromLong(attribute.getUint32());
71   -
72   - case TN3270::Attribute::Int64:
73   - throw std::system_error(ENOTSUP, std::system_category());
74   -
75   - case TN3270::Attribute::Uint64:
76   - throw std::system_error(ENOTSUP, std::system_category());
77   -
78   - default:
79   - throw runtime_error("Unexpected atttribute type");
80   - }
81   -
82   - return PyLong_FromLong(0);
83   -
84   - });
85   -
86   -}
87   -
88   -int py3270_session_setter(PyObject *self, PyObject *value, void *name) {
89   -
90   - return 0;
91   -}
92   -
src/terminal/get.cc
... ... @@ -1,95 +0,0 @@
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 <py3270.h>
36   -
37   - using std::string;
38   -
39   -/*---[ Implement ]----------------------------------------------------------------------------------*/
40   -
41   - PyObject * py3270_session_get(PyObject *self, PyObject *args) {
42   -
43   - return py3270_session_call(self, [args](TN3270::Host &host){
44   -
45   - string text;
46   -
47   - switch(PyTuple_Size(args)) {
48   - case 0: // Get the entire screen
49   - text = host.toString();
50   - break;
51   -
52   - case 2: // Address and length.
53   - {
54   - int baddr, length;
55   -
56   - if (!PyArg_ParseTuple(args, "ii", &baddr, &length))
57   - return (PyObject *) NULL;
58   -
59   - text = host.toString(baddr, length);
60   - }
61   - break;
62   -
63   - case 3: // Row, col and length
64   - {
65   - unsigned int row, col;
66   - int length;
67   -
68   - if (!PyArg_ParseTuple(args, "IIi", &row, &col, &length))
69   - return (PyObject *) NULL;
70   -
71   - text = host.toString(row, col, length);
72   - }
73   - break;
74   -
75   - default:
76   - throw std::system_error(EINVAL, std::system_category());
77   -
78   - }
79   -
80   - return PyUnicode_FromString(text.c_str());
81   -
82   - });
83   -
84   - }
85   -
86   - PyObject * py3270_session_str(PyObject *self) {
87   -
88   - return py3270_session_call(self, [](TN3270::Host &host){
89   -
90   - return PyUnicode_FromString(host.toString().c_str());
91   -
92   - });
93   -
94   - }
95   -
src/terminal/init.cc
... ... @@ -1,211 +0,0 @@
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 <py3270.h>
38   - #include <lib3270/ipc.h>
39   -
40   -/*---[ Implement ]----------------------------------------------------------------------------------*/
41   -
42   -static void cleanup(pySession * session) {
43   -
44   - if(session->host) {
45   - delete session->host;
46   - session->host = nullptr;
47   - }
48   -
49   -}
50   -
51   -void py3270_session_type_init(PyTypeObject *type) {
52   -
53   - // Load lib3270's attributes
54   - {
55   - auto attributes = TN3270::getAttributes();
56   - size_t szData = sizeof(struct PyGetSetDef) * (attributes.size()+1);
57   -
58   - type->tp_getset = (struct PyGetSetDef *) malloc(szData);
59   - memset(type->tp_getset,0,szData);
60   -
61   - size_t ix = 0;
62   - for(auto attribute : attributes) {
63   -
64   -// debug("Creating attribute %s",attribute->name);
65   -
66   - type->tp_getset[ix].name = (char *) attribute->name;
67   - type->tp_getset[ix].doc = (char *) (attribute->description ? attribute->description : attribute->summary);
68   - type->tp_getset[ix].get = py3270_session_getter;
69   - type->tp_getset[ix].set = py3270_session_setter;
70   - type->tp_getset[ix].closure = (void *) attribute->name;
71   - ix++;
72   - }
73   -
74   -
75   - }
76   -
77   -}
78   -
79   -
80   -int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) {
81   -
82   - pySession * session = (pySession *) self;
83   - debug("%s session=%p host=%p",__FUNCTION__,session,session->host);
84   -
85   - try {
86   -
87   - cleanup(session);
88   -
89   - const char *id = "";
90   -
91   - if (!PyArg_ParseTuple(args, "s", &id))
92   - id = "";
93   -
94   - session->host = new TN3270::Host(id);
95   -
96   - return 0;
97   -
98   - } catch(const std::exception &e) {
99   -
100   - PyErr_SetString(PyExc_RuntimeError, e.what());
101   -
102   - } catch(...) {
103   -
104   - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");
105   -
106   - }
107   -
108   - return -1;
109   -
110   -}
111   -
112   -void py3270_session_finalize(PyObject *self) {
113   -
114   - debug("%s",__FUNCTION__);
115   - cleanup((pySession *) self);
116   -
117   -}
118   -
119   -PyObject * py3270_session_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds) {
120   -
121   - debug("%s",__FUNCTION__);
122   - return type->tp_alloc(type,0);
123   -
124   -}
125   -
126   -void py3270_session_dealloc(PyObject * self) {
127   -
128   - debug("%s",__FUNCTION__);
129   -
130   - cleanup((pySession *) self);
131   - Py_TYPE(self)->tp_free(self);
132   -
133   -}
134   -
135   - /*
136   -
137   - const char *id = "";
138   -
139   - if (!PyArg_ParseTuple(args, "s", &id))
140   - id = "";
141   -
142   -
143   - if(session) {
144   -
145   - try {
146   -
147   - session->host = new TN3270::Host(id);
148   -
149   - } catch(const exception &e) {
150   -
151   - PyErr_SetString(PyExc_RuntimeError, e.what());
152   -
153   - } catch( ... ) {
154   -
155   - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");
156   -
157   - }
158   -
159   - }
160   -
161   - type->tp_free(session);
162   -
163   - return NULL;
164   -
165   -}
166   -
167   -void py3270_session_dealloc(pySession * self) {
168   -
169   - if(self->host) {
170   - delete self->host;
171   - }
172   -
173   - Py_TYPE(self)->tp_free((PyObject *) self);
174   -
175   -}
176   - */
177   -
178   -
179   -/*
180   -PyObject * terminal_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
181   -
182   - PW3270_NAMESPACE::session * session;
183   - const char *id = "";
184   -
185   - if (!PyArg_ParseTuple(args, "s", &id)) {
186   - id = "";
187   - }
188   -
189   - trace("%s(%s)",__FUNCTION__,id);
190   -
191   - try {
192   -
193   - session = PW3270_NAMESPACE::session::create(id);
194   -
195   - } catch(std::exception &e) {
196   -
197   - trace("%s failed: %s",__FUNCTION__,e.what());
198   - PyErr_SetString(terminalError, e.what());
199   - return NULL;
200   -
201   - }
202   -
203   - pw3270_TerminalObject *self = (pw3270_TerminalObject *) type->tp_alloc(type, 0);
204   -
205   - self->session = session;
206   -
207   - return (PyObject *)self;
208   -}
209   -
210   -
211   -*/
src/terminal/network.cc
... ... @@ -1,166 +0,0 @@
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 <py3270.h>
38   -
39   -/*---[ Implement ]----------------------------------------------------------------------------------*/
40   -
41   - PyObject * py3270_session_connect(PyObject *self, PyObject *args) {
42   -
43   - return py3270_session_call(self, [args](TN3270::Host &host){
44   -
45   - const char * url = "";
46   -
47   - if(!PyArg_ParseTuple(args, "s", &url)) {
48   - throw runtime_error("connect requires a host URL");
49   - }
50   -
51   - host.connect(url);
52   -
53   - return 0;
54   -
55   - });
56   -
57   - }
58   -
59   - PyObject * py3270_session_disconnect(PyObject *self, PyObject *args) {
60   -
61   - return py3270_session_call(self, [args](TN3270::Host &host){
62   -
63   - host.disconnect();
64   -
65   - return 0;
66   -
67   - });
68   -
69   - }
70   -
71   -
72   -/*
73   - PyObject * terminal_connect(PyObject *self, PyObject *args) {
74   -
75   - int rc = -1;
76   - int wait = 60;
77   - const char * host = "";
78   -
79   - if (!PyArg_ParseTuple(args, "s|i", &host, &wait)) {
80   - PyErr_SetString(terminalError, "connect requires a host URL");
81   - return NULL;
82   - }
83   -
84   - try {
85   -
86   - rc = ((pw3270_TerminalObject *) self)->session->connect(host,wait);
87   -
88   - } catch(std::exception &e) {
89   -
90   - PyErr_SetString(terminalError, e.what());
91   - return NULL;
92   - }
93   -
94   - return PyLong_FromLong(rc);
95   -
96   - }
97   -
98   - PyObject * terminal_disconnect(PyObject *self, PyObject *args) {
99   -
100   - int rc = -1;
101   -
102   - try {
103   -
104   - rc = ((pw3270_TerminalObject *) self)->session->disconnect();
105   -
106   - } catch(std::exception &e) {
107   -
108   - PyErr_SetString(terminalError, e.what());
109   - return NULL;
110   - }
111   -
112   - return PyLong_FromLong(rc);
113   -
114   - }
115   -
116   - PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args) {
117   -
118   - int rc;
119   - int timeout = 60;
120   -
121   - if (!PyArg_ParseTuple(args, "|i", &timeout)) {
122   - PyErr_SetString(terminalError, strerror(EINVAL));
123   - return NULL;
124   - }
125   -
126   - try {
127   -
128   - rc = ((pw3270_TerminalObject *) self)->session->wait_for_ready(timeout);
129   -
130   - } catch(std::exception &e) {
131   -
132   - PyErr_SetString(terminalError, e.what());
133   - return NULL;
134   - }
135   -
136   - return PyLong_FromLong(rc);
137   -
138   - }
139   -
140   -
141   - PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args) {
142   -
143   - int row, col, rc;
144   - int timeout = 10;
145   - const char *text;
146   -
147   - if (!PyArg_ParseTuple(args, "iis|i", &row, &col, &text, &timeout)) {
148   - PyErr_SetString(terminalError, strerror(EINVAL));
149   - return NULL;
150   - }
151   -
152   - try {
153   -
154   - rc = ((pw3270_TerminalObject *) self)->session->wait_for_string_at(row,col,text,timeout);
155   -
156   - } catch(std::exception &e) {
157   -
158   - PyErr_SetString(terminalError, e.what());
159   - return NULL;
160   - }
161   -
162   - return PyLong_FromLong(rc);
163   -
164   - }
165   -
166   -*/
src/terminal/set.cc
... ... @@ -1,141 +0,0 @@
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 <py3270.h>
36   -
37   -/*---[ Implement ]----------------------------------------------------------------------------------*/
38   -
39   - PyObject * py3270_session_set(PyObject *self, PyObject *args) {
40   -
41   - return py3270_session_call(self, [args](TN3270::Host &host){
42   -
43   - switch(PyTuple_Size(args)) {
44   - case 1: // Only text.
45   - {
46   - const char *text;
47   -
48   - if(!PyArg_ParseTuple(args, "s", &text))
49   - return (PyObject *) NULL;
50   -
51   - host.push(text,-1);
52   -
53   - }
54   - break;
55   -
56   - case 2: // Address and text.
57   - {
58   - int baddr;
59   - const char *text;
60   -
61   - if(!PyArg_ParseTuple(args, "is", &baddr, &text))
62   - return (PyObject *) NULL;
63   -
64   - host.push(baddr, text);
65   - }
66   - break;
67   -
68   - case 3: // Row, col and text
69   - {
70   - unsigned int row, col;
71   - const char *text;
72   -
73   - if (!PyArg_ParseTuple(args, "IIs", &row, &col, &text))
74   - return (PyObject *) NULL;
75   -
76   - host.push(row,col,text);
77   -
78   - }
79   - break;
80   -
81   - default:
82   - throw std::system_error(EINVAL, std::system_category());
83   -
84   - }
85   -
86   - return PyLong_FromLong(0);
87   -
88   - });
89   -
90   - }
91   -
92   -
93   -/*
94   - PyObject * terminal_set_string_at(PyObject *self, PyObject *args) {
95   -
96   - int row, col, rc;
97   - const char *text;
98   -
99   - if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) {
100   - PyErr_SetString(terminalError, strerror(EINVAL));
101   - return NULL;
102   - }
103   -
104   - try {
105   -
106   - rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text);
107   -
108   - } catch(std::exception &e) {
109   -
110   - PyErr_SetString(terminalError, e.what());
111   - return NULL;
112   - }
113   -
114   - return PyLong_FromLong(rc);
115   -
116   - }
117   -
118   - PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args) {
119   -
120   - int row, col, rc;
121   -
122   - if (!PyArg_ParseTuple(args, "ii", &row, &col)) {
123   - PyErr_SetString(terminalError, strerror(EINVAL));
124   - return NULL;
125   - }
126   -
127   - try {
128   -
129   - rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col);
130   -
131   - } catch(std::exception &e) {
132   -
133   - PyErr_SetString(terminalError, e.what());
134   - return NULL;
135   - }
136   -
137   - return PyLong_FromLong(rc);
138   -
139   - }
140   -
141   -*/
testprograms/sample.py
1 1 #!/usr/bin/python
2 2 #-*- coding: utf-8
3 3  
4   -import inspect
  4 +#import inspect
5 5 import tn3270
6 6  
7 7 print("Using TN3270 Version " + tn3270.version())
... ... @@ -16,25 +16,25 @@ print(session.width)
16 16 print(session.connected)
17 17 print(session.url)
18 18  
19   -session.connect('')
  19 +#session.connect('')
20 20  
21 21 print(session.connected)
22 22  
23   -#print('----------------------')
24   -#print(dir(session))
25   -#print('----------------------')
  23 +print('----------------------')
  24 +print(dir(session))
  25 +print('----------------------')
26 26  
27 27 #print(session.get(14,22,38))
28 28  
29   -print("-----------------------------------------------------------------------")
30   -print(session)
31   -print("-----------------------------------------------------------------------")
  29 +#print("-----------------------------------------------------------------------")
  30 +#print(session)
  31 +#print("-----------------------------------------------------------------------")
32 32  
33   -session.set("value")
  33 +#session.set("value")
34 34  
35   -print("-----------------------------------------------------------------------")
36   -print(session)
37   -print("-----------------------------------------------------------------------")
  35 +#print("-----------------------------------------------------------------------")
  36 +#print(session)
  37 +#print("-----------------------------------------------------------------------")
38 38  
39 39 del session
40 40 input("Press enter to exit")
... ...