Commit 98721dff2b55f6114ef1c0bdeb0eebc0b09313bf

Authored by Perry Werneck
1 parent 35ca683c
Exists in master

Implementing action object.

@@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
44 </Linker> 44 </Linker>
45 <Unit filename="src/action/init.cc" /> 45 <Unit filename="src/action/init.cc" />
46 <Unit filename="src/action/new.cc" /> 46 <Unit filename="src/action/new.cc" />
  47 + <Unit filename="src/action/tools.cc" />
47 <Unit filename="src/action/type.c"> 48 <Unit filename="src/action/type.c">
48 <Option compilerVar="CC" /> 49 <Option compilerVar="CC" />
49 </Unit> 50 </Unit>
@@ -54,13 +55,13 @@ @@ -54,13 +55,13 @@
54 <Option compilerVar="CC" /> 55 <Option compilerVar="CC" />
55 </Unit> 56 </Unit>
56 <Unit filename="src/module/properties.cc" /> 57 <Unit filename="src/module/properties.cc" />
57 - <Unit filename="src/module/tools.cc" />  
58 <Unit filename="src/session/actions.cc" /> 58 <Unit filename="src/session/actions.cc" />
59 <Unit filename="src/session/attributes.cc" /> 59 <Unit filename="src/session/attributes.cc" />
60 <Unit filename="src/session/get.cc" /> 60 <Unit filename="src/session/get.cc" />
61 <Unit filename="src/session/init.cc" /> 61 <Unit filename="src/session/init.cc" />
62 <Unit filename="src/session/network.cc" /> 62 <Unit filename="src/session/network.cc" />
63 <Unit filename="src/session/set.cc" /> 63 <Unit filename="src/session/set.cc" />
  64 + <Unit filename="src/session/tools.cc" />
64 <Unit filename="src/session/type.c"> 65 <Unit filename="src/session/type.c">
65 <Option compilerVar="CC" /> 66 <Option compilerVar="CC" />
66 </Unit> 67 </Unit>
src/action/init.cc
@@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
36 36
37 #include <py3270.h> 37 #include <py3270.h>
38 #include <lib3270/ipc.h> 38 #include <lib3270/ipc.h>
  39 + #include <lib3270/ipc/action.h>
39 40
40 /*---[ Implement ]----------------------------------------------------------------------------------*/ 41 /*---[ Implement ]----------------------------------------------------------------------------------*/
41 42
@@ -43,3 +44,34 @@ void py3270_action_type_init(PyTypeObject *type) { @@ -43,3 +44,34 @@ void py3270_action_type_init(PyTypeObject *type) {
43 44
44 45
45 } 46 }
  47 +
  48 +static void cleanup(pyAction * self) {
  49 +
  50 + if(self->action) {
  51 + delete self->action;
  52 + self->action = nullptr;
  53 + }
  54 +
  55 +}
  56 +
  57 +void py3270_action_dealloc(PyObject * self) {
  58 + debug("%s",__FUNCTION__);
  59 + cleanup((pyAction *) self);
  60 +}
  61 +
  62 +void py3270_action_finalize(PyObject *self) {
  63 + debug("%s",__FUNCTION__);
  64 + cleanup((pyAction *) self);
  65 +}
  66 +
  67 +PyObject * py3270_action_activatable(PyObject *self, PyObject *args) {
  68 +
  69 + return py3270_action_call(self, [](TN3270::Action &action) {
  70 +
  71 + return PyBool_FromLong(action.activatable());
  72 +
  73 + });
  74 +
  75 +
  76 +}
  77 +
src/action/new.cc
@@ -41,4 +41,10 @@ @@ -41,4 +41,10 @@
41 41
42 DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action) { 42 DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action) {
43 43
  44 + pyAction * object = (pyAction *) _PyObject_New(&py3270_action_type);
  45 +
  46 + object->action = ((pySession *) session)->host->getAction((const LIB3270_ACTION *) action);
  47 +
  48 + return (PyObject *) object;
  49 +
44 } 50 }
src/action/tools.cc 0 → 100644
@@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
  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_action_call(PyObject *self, std::function<PyObject * (TN3270::Action &Action)> worker) noexcept {
  42 +
  43 + try {
  44 +
  45 + TN3270::Action *action = ((pyAction * ) self)->action;
  46 + return worker(*action);
  47 +
  48 + } catch(const exception &e) {
  49 +
  50 + PyErr_SetString(PyExc_RuntimeError, e.what());
  51 +
  52 + } catch( ... ) {
  53 +
  54 + PyErr_SetString(PyExc_RuntimeError, "Unexpected error in action object");
  55 +
  56 + }
  57 +
  58 + return NULL;
  59 +
  60 +}
  61 +
src/action/type.c
@@ -38,14 +38,12 @@ @@ -38,14 +38,12 @@
38 38
39 static PyMethodDef py3270_action_methods[] = { 39 static PyMethodDef py3270_action_methods[] = {
40 40
41 - /*  
42 { 41 {
43 "activatable", 42 "activatable",
44 (PyCFunction) py3270_action_activatable, 43 (PyCFunction) py3270_action_activatable,
45 METH_NOARGS, 44 METH_NOARGS,
46 "" 45 ""
47 }, 46 },
48 - */  
49 47
50 { 48 {
51 NULL 49 NULL
@@ -58,13 +56,17 @@ PyTypeObject py3270_action_type = { @@ -58,13 +56,17 @@ PyTypeObject py3270_action_type = {
58 PyVarObject_HEAD_INIT(NULL, 0) 56 PyVarObject_HEAD_INIT(NULL, 0)
59 57
60 .tp_name = "tn3270.Session.Action", 58 .tp_name = "tn3270.Session.Action",
61 - .tp_doc = "TN3270 Session Action Object", 59 + .tp_doc = "TN3270 Action Object",
62 .tp_basicsize = sizeof(pyAction), 60 .tp_basicsize = sizeof(pyAction),
63 .tp_itemsize = 0, 61 .tp_itemsize = 0,
64 .tp_flags = Py_TPFLAGS_DEFAULT, 62 .tp_flags = Py_TPFLAGS_DEFAULT,
65 63
66 .tp_methods = py3270_action_methods, 64 .tp_methods = py3270_action_methods,
67 65
  66 + .tp_dealloc = py3270_action_dealloc,
  67 + .tp_finalize = py3270_action_finalize,
  68 +
  69 +
68 }; 70 };
69 71
70 72
src/include/py3270.h
@@ -77,20 +77,25 @@ @@ -77,20 +77,25 @@
77 #include <stdexcept> 77 #include <stdexcept>
78 #include <vector> 78 #include <vector>
79 #include <lib3270/ipc.h> 79 #include <lib3270/ipc.h>
  80 + #include <lib3270/ipc/action.h>
80 #include <lib3270/actions.h> 81 #include <lib3270/actions.h>
81 82
82 using std::exception; 83 using std::exception;
83 using std::runtime_error; 84 using std::runtime_error;
84 using TN3270::Host; 85 using TN3270::Host;
  86 + using TN3270::Action;
85 87
86 DLL_PRIVATE PyObject * py3270_session_call(PyObject *self, std::function<PyObject * (TN3270::Host &host)> worker) noexcept; 88 DLL_PRIVATE PyObject * py3270_session_call(PyObject *self, std::function<PyObject * (TN3270::Host &host)> worker) noexcept;
87 DLL_PRIVATE PyObject * py3270_session_call(PyObject *self, std::function<int (TN3270::Host &host)> worker) noexcept; 89 DLL_PRIVATE PyObject * py3270_session_call(PyObject *self, std::function<int (TN3270::Host &host)> worker) noexcept;
88 90
  91 + DLL_PRIVATE PyObject * py3270_action_call(PyObject *self, std::function<PyObject * (TN3270::Action &action)> worker) noexcept;
  92 +
89 extern "C" { 93 extern "C" {
90 94
91 #else 95 #else
92 96
93 typedef void Host; 97 typedef void Host;
  98 + typedef void Action;
94 99
95 #endif 100 #endif
96 101
@@ -101,8 +106,7 @@ @@ -101,8 +106,7 @@
101 106
102 typedef struct { 107 typedef struct {
103 PyObject_HEAD 108 PyObject_HEAD
104 - Host *host;  
105 - const struct _lib3270_action * action; 109 + Action *action;
106 } pyAction; 110 } pyAction;
107 111
108 DLL_PRIVATE PyTypeObject py3270_session_type; 112 DLL_PRIVATE PyTypeObject py3270_session_type;
@@ -136,6 +140,10 @@ @@ -136,6 +140,10 @@
136 // Action object 140 // Action object
137 DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action); 141 DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action);
138 142
  143 + DLL_PRIVATE void py3270_action_dealloc(PyObject * self);
  144 + DLL_PRIVATE void py3270_action_finalize(PyObject *self);
  145 +
  146 + DLL_PRIVATE PyObject * py3270_action_activatable(PyObject *self, PyObject *args);
139 147
140 /* 148 /*
141 149
src/module/tools.cc
@@ -1,82 +0,0 @@ @@ -1,82 +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_call(PyObject *self, std::function<PyObject * (TN3270::Host &host)> worker) noexcept {  
42 -  
43 - try {  
44 -  
45 - TN3270::Host *host = ((pySession * ) self)->host;  
46 - return worker(*host);  
47 -  
48 - } catch(const exception &e) {  
49 -  
50 - PyErr_SetString(PyExc_RuntimeError, e.what());  
51 -  
52 - } catch( ... ) {  
53 -  
54 - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");  
55 -  
56 - }  
57 -  
58 - return NULL;  
59 -  
60 -}  
61 -  
62 -PyObject * py3270_session_call(PyObject *self, std::function<int (TN3270::Host &host)> worker) noexcept {  
63 -  
64 - try {  
65 -  
66 - TN3270::Host *host = ((pySession * ) self)->host;  
67 - return PyLong_FromLong(worker(*host));  
68 -  
69 - } catch(const exception &e) {  
70 -  
71 - PyErr_SetString(PyExc_RuntimeError, e.what());  
72 -  
73 - } catch( ... ) {  
74 -  
75 - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");  
76 -  
77 - }  
78 -  
79 - return NULL;  
80 -  
81 -}  
82 -  
src/session/init.cc
@@ -70,7 +70,7 @@ void py3270_session_type_init(PyTypeObject *type) { @@ -70,7 +70,7 @@ void py3270_session_type_init(PyTypeObject *type) {
70 70
71 for(auto attribute : attributes) { 71 for(auto attribute : attributes) {
72 72
73 -// debug("Creating attribute %s",attribute->name); 73 + debug("Creating attribute %s",attribute->name);
74 74
75 py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) attribute); 75 py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) attribute);
76 76
src/session/tools.cc 0 → 100644
@@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
  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_call(PyObject *self, std::function<PyObject * (TN3270::Host &host)> worker) noexcept {
  42 +
  43 + try {
  44 +
  45 + TN3270::Host *host = ((pySession * ) self)->host;
  46 + return worker(*host);
  47 +
  48 + } catch(const exception &e) {
  49 +
  50 + PyErr_SetString(PyExc_RuntimeError, e.what());
  51 +
  52 + } catch( ... ) {
  53 +
  54 + PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");
  55 +
  56 + }
  57 +
  58 + return NULL;
  59 +
  60 +}
  61 +
  62 +PyObject * py3270_session_call(PyObject *self, std::function<int (TN3270::Host &host)> worker) noexcept {
  63 +
  64 + try {
  65 +
  66 + TN3270::Host *host = ((pySession * ) self)->host;
  67 + return PyLong_FromLong(worker(*host));
  68 +
  69 + } catch(const exception &e) {
  70 +
  71 + PyErr_SetString(PyExc_RuntimeError, e.what());
  72 +
  73 + } catch( ... ) {
  74 +
  75 + PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module");
  76 +
  77 + }
  78 +
  79 + return NULL;
  80 +
  81 +}
  82 +
testprograms/sample.py
@@ -20,10 +20,18 @@ print(session.url) @@ -20,10 +20,18 @@ print(session.url)
20 20
21 print(session.connected) 21 print(session.connected)
22 22
  23 +#print('----------------------')
  24 +#print(dir(session))
  25 +#print('----------------------')
  26 +
  27 +test = session.reconnect
23 print('----------------------') 28 print('----------------------')
24 -print(dir(session)) 29 +print(dir(test))
25 print('----------------------') 30 print('----------------------')
26 31
  32 +print(test.activatable())
  33 +
  34 +
27 #print(session.get(14,22,38)) 35 #print(session.get(14,22,38))
28 36
29 #print("-----------------------------------------------------------------------") 37 #print("-----------------------------------------------------------------------")