Commit 76b9754ff180d948249bf71b4ee3800d806d3d19
1 parent
3ef7dede
Exists in
master
Debugging python extension.
Showing
7 changed files
with
115 additions
and
213 deletions
Show diff stats
src/include/py3270.h
| ... | ... | @@ -147,6 +147,10 @@ |
| 147 | 147 | DLL_PRIVATE PyObject * py3270_session_find(PyObject *self, PyObject *args); |
| 148 | 148 | DLL_PRIVATE PyObject * py3270_session_count(PyObject *self, PyObject *args); |
| 149 | 149 | |
| 150 | + DLL_PRIVATE PyObject * py3270_session_pfkey(PyObject *self, PyObject *args); | |
| 151 | + DLL_PRIVATE PyObject * py3270_session_pakey(PyObject *self, PyObject *args); | |
| 152 | + DLL_PRIVATE PyObject * py3270_session_set_cursor_position(PyObject *self, PyObject *args); | |
| 153 | + | |
| 150 | 154 | // Action object |
| 151 | 155 | DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action); |
| 152 | 156 | DLL_PRIVATE void py3270_action_dealloc(PyObject * self); | ... | ... |
src/session/actions.cc
| ... | ... | @@ -25,105 +25,81 @@ |
| 25 | 25 | * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) |
| 26 | 26 | * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) |
| 27 | 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 | 28 | */ |
| 34 | 29 | |
| 35 | 30 | #include <py3270.h> |
| 36 | 31 | |
| 37 | 32 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 38 | 33 | |
| 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); | |
| 34 | +PyObject * py3270_session_pfkey(PyObject *self, PyObject *args) { | |
| 60 | 35 | |
| 61 | - } | |
| 36 | + return py3270_session_call(self, [args](TN3270::Host &host){ | |
| 62 | 37 | |
| 63 | - PyObject * terminal_pakey(PyObject *self, PyObject *args) { | |
| 38 | + unsigned int keycode; | |
| 64 | 39 | |
| 65 | - int rc, key; | |
| 40 | + if (!PyArg_ParseTuple(args, "I", &keycode)) | |
| 41 | + return (PyObject *) NULL; | |
| 66 | 42 | |
| 67 | - if (!PyArg_ParseTuple(args, "i", &key)) { | |
| 68 | - PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 69 | - return NULL; | |
| 70 | - } | |
| 43 | + host.pfkey((unsigned short) keycode); | |
| 71 | 44 | |
| 72 | - try { | |
| 45 | + return PyLong_FromLong(0); | |
| 73 | 46 | |
| 74 | - rc = ((pw3270_TerminalObject *) self)->session->pakey(key); | |
| 47 | + }); | |
| 75 | 48 | |
| 76 | - } catch(std::exception &e) { | |
| 49 | +} | |
| 77 | 50 | |
| 78 | - PyErr_SetString(terminalError, e.what()); | |
| 79 | - return NULL; | |
| 80 | - } | |
| 51 | +PyObject * py3270_session_pakey(PyObject *self, PyObject *args) { | |
| 81 | 52 | |
| 82 | - return PyLong_FromLong(rc); | |
| 53 | + return py3270_session_call(self, [args](TN3270::Host &host){ | |
| 83 | 54 | |
| 84 | - } | |
| 55 | + unsigned int keycode; | |
| 85 | 56 | |
| 86 | - PyObject * terminal_enter(PyObject *self, PyObject *args) { | |
| 57 | + if (!PyArg_ParseTuple(args, "I", &keycode)) | |
| 58 | + return (PyObject *) NULL; | |
| 87 | 59 | |
| 88 | - int rc; | |
| 60 | + host.pakey((unsigned short) keycode); | |
| 89 | 61 | |
| 90 | - try { | |
| 62 | + return PyLong_FromLong(0); | |
| 91 | 63 | |
| 92 | - rc = ((pw3270_TerminalObject *) self)->session->enter(); | |
| 64 | + }); | |
| 93 | 65 | |
| 94 | - } catch(std::exception &e) { | |
| 66 | +} | |
| 95 | 67 | |
| 96 | - PyErr_SetString(terminalError, e.what()); | |
| 97 | - return NULL; | |
| 98 | - } | |
| 68 | +PyObject * py3270_session_set_cursor_position(PyObject *self, PyObject *args) { | |
| 99 | 69 | |
| 100 | - return PyLong_FromLong(rc); | |
| 70 | + return py3270_session_call(self, [args](TN3270::Host &host){ | |
| 101 | 71 | |
| 72 | + switch(PyTuple_Size(args)) { | |
| 73 | + case 1: // Only Address | |
| 74 | + { | |
| 75 | + int baddr; | |
| 102 | 76 | |
| 103 | - } | |
| 77 | + if(!PyArg_ParseTuple(args, "i", &baddr)) | |
| 78 | + return (PyObject *) NULL; | |
| 104 | 79 | |
| 105 | - PyObject * terminal_action(PyObject *self, PyObject *args) { | |
| 80 | + host.setCursor(baddr); | |
| 81 | + } | |
| 82 | + break; | |
| 106 | 83 | |
| 107 | - int rc; | |
| 108 | - const char *name; | |
| 84 | + case 2: // Row, col | |
| 85 | + { | |
| 86 | + unsigned int row, col; | |
| 109 | 87 | |
| 110 | - if (!PyArg_ParseTuple(args, "s", &name)) { | |
| 111 | - PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 112 | - return NULL; | |
| 113 | - } | |
| 88 | + if (!PyArg_ParseTuple(args, "II", &row, &col)) | |
| 89 | + return (PyObject *) NULL; | |
| 114 | 90 | |
| 115 | - try { | |
| 91 | + host.setCursor(row,col); | |
| 116 | 92 | |
| 117 | - rc = ((pw3270_TerminalObject *) self)->session->action(name); | |
| 93 | + } | |
| 94 | + break; | |
| 118 | 95 | |
| 119 | - } catch(std::exception &e) { | |
| 96 | + default: | |
| 97 | + throw std::system_error(EINVAL, std::system_category()); | |
| 120 | 98 | |
| 121 | - PyErr_SetString(terminalError, e.what()); | |
| 122 | - return NULL; | |
| 123 | - } | |
| 99 | + } | |
| 124 | 100 | |
| 125 | - return PyLong_FromLong(rc); | |
| 101 | + return PyLong_FromLong(0); | |
| 126 | 102 | |
| 103 | + }); | |
| 127 | 104 | |
| 128 | - } | |
| 129 | -*/ | |
| 105 | +} | ... | ... |
src/session/attributes.cc
| ... | ... | @@ -115,7 +115,7 @@ int py3270_session_setter(PyObject *self, PyObject *value, void *name) { |
| 115 | 115 | |
| 116 | 116 | } catch( ... ) { |
| 117 | 117 | |
| 118 | - PyErr_SetString(PyExc_RuntimeError, "Unexpected error setting timeout"); | |
| 118 | + PyErr_SetString(PyExc_RuntimeError, "Unexpected error setting attribute"); | |
| 119 | 119 | return -1; |
| 120 | 120 | |
| 121 | 121 | } | ... | ... |
src/session/init.cc
| ... | ... | @@ -18,16 +18,14 @@ |
| 18 | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin |
| 19 | 19 | * St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | 20 | * |
| 21 | - * Este programa está nomeado como py3270.cc e possui - linhas de código. | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | 22 | * |
| 23 | 23 | * Contatos: |
| 24 | 24 | * |
| 25 | 25 | * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) |
| 26 | 26 | * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) |
| 27 | 27 | * |
| 28 | - * Implementa métodos básicos inicio/final do objeto python | |
| 29 | - * | |
| 30 | - * Referências: | |
| 28 | + * Referênces: | |
| 31 | 29 | * |
| 32 | 30 | * <https://docs.python.org/2/extending/newtypes.html> |
| 33 | 31 | * <https://docs.python.org/2.7/extending/extending.html#a-simple-example> |
| ... | ... | @@ -93,10 +91,9 @@ void py3270_session_type_init(PyTypeObject *type) { |
| 93 | 91 | |
| 94 | 92 | } |
| 95 | 93 | |
| 94 | + // Copy lib3270's actions | |
| 96 | 95 | for(auto action : actions) { |
| 97 | 96 | |
| 98 | -// debug("Creating action %s",action->name); | |
| 99 | - | |
| 100 | 97 | py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) action); |
| 101 | 98 | |
| 102 | 99 | type->tp_getset[ix].get = py3270_action_new_from_session; |
| ... | ... | @@ -105,12 +102,11 @@ void py3270_session_type_init(PyTypeObject *type) { |
| 105 | 102 | ix++; |
| 106 | 103 | |
| 107 | 104 | } |
| 108 | - } | |
| 109 | 105 | |
| 106 | + } | |
| 110 | 107 | |
| 111 | 108 | } |
| 112 | 109 | |
| 113 | - | |
| 114 | 110 | int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) { |
| 115 | 111 | |
| 116 | 112 | pySession * session = (pySession *) self; |
| ... | ... | @@ -127,25 +123,6 @@ int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) { |
| 127 | 123 | |
| 128 | 124 | session->host = new TN3270::Host(id); |
| 129 | 125 | |
| 130 | - /* | |
| 131 | - // Load lib3270's actions | |
| 132 | - { | |
| 133 | - auto actions = TN3270::getActions(); | |
| 134 | - | |
| 135 | - for(auto action : actions) { | |
| 136 | - | |
| 137 | - pyAction * object = (pyAction *) _PyObject_New(&py3270_action_type); | |
| 138 | - | |
| 139 | - object->host = session->host; | |
| 140 | - object->action = action; | |
| 141 | - | |
| 142 | - PyObject_SetAttr(self, PyUnicode_FromString(action->name), (PyObject *) object); | |
| 143 | - | |
| 144 | - } | |
| 145 | - | |
| 146 | - } | |
| 147 | - */ | |
| 148 | - | |
| 149 | 126 | return 0; |
| 150 | 127 | |
| 151 | 128 | } catch(const std::exception &e) { |
| ... | ... | @@ -184,81 +161,3 @@ void py3270_session_dealloc(PyObject * self) { |
| 184 | 161 | Py_TYPE(self)->tp_free(self); |
| 185 | 162 | |
| 186 | 163 | } |
| 187 | - | |
| 188 | - /* | |
| 189 | - | |
| 190 | - const char *id = ""; | |
| 191 | - | |
| 192 | - if (!PyArg_ParseTuple(args, "s", &id)) | |
| 193 | - id = ""; | |
| 194 | - | |
| 195 | - | |
| 196 | - if(session) { | |
| 197 | - | |
| 198 | - try { | |
| 199 | - | |
| 200 | - session->host = new TN3270::Host(id); | |
| 201 | - | |
| 202 | - } catch(const exception &e) { | |
| 203 | - | |
| 204 | - PyErr_SetString(PyExc_RuntimeError, e.what()); | |
| 205 | - | |
| 206 | - } catch( ... ) { | |
| 207 | - | |
| 208 | - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module"); | |
| 209 | - | |
| 210 | - } | |
| 211 | - | |
| 212 | - } | |
| 213 | - | |
| 214 | - type->tp_free(session); | |
| 215 | - | |
| 216 | - return NULL; | |
| 217 | - | |
| 218 | -} | |
| 219 | - | |
| 220 | -void py3270_session_dealloc(pySession * self) { | |
| 221 | - | |
| 222 | - if(self->host) { | |
| 223 | - delete self->host; | |
| 224 | - } | |
| 225 | - | |
| 226 | - Py_TYPE(self)->tp_free((PyObject *) self); | |
| 227 | - | |
| 228 | -} | |
| 229 | - */ | |
| 230 | - | |
| 231 | - | |
| 232 | -/* | |
| 233 | -PyObject * terminal_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { | |
| 234 | - | |
| 235 | - PW3270_NAMESPACE::session * session; | |
| 236 | - const char *id = ""; | |
| 237 | - | |
| 238 | - if (!PyArg_ParseTuple(args, "s", &id)) { | |
| 239 | - id = ""; | |
| 240 | - } | |
| 241 | - | |
| 242 | - trace("%s(%s)",__FUNCTION__,id); | |
| 243 | - | |
| 244 | - try { | |
| 245 | - | |
| 246 | - session = PW3270_NAMESPACE::session::create(id); | |
| 247 | - | |
| 248 | - } catch(std::exception &e) { | |
| 249 | - | |
| 250 | - trace("%s failed: %s",__FUNCTION__,e.what()); | |
| 251 | - PyErr_SetString(terminalError, e.what()); | |
| 252 | - return NULL; | |
| 253 | - | |
| 254 | - } | |
| 255 | - | |
| 256 | - pw3270_TerminalObject *self = (pw3270_TerminalObject *) type->tp_alloc(type, 0); | |
| 257 | - | |
| 258 | - self->session = session; | |
| 259 | - | |
| 260 | - return (PyObject *)self; | |
| 261 | -} | |
| 262 | - | |
| 263 | - | |
| 264 | -*/ | ... | ... |
src/session/tools.cc
| ... | ... | @@ -18,20 +18,13 @@ |
| 18 | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin |
| 19 | 19 | * St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | 20 | * |
| 21 | - * Este programa está nomeado como misc.cc e possui - linhas de código. | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | 22 | * |
| 23 | 23 | * Contatos: |
| 24 | 24 | * |
| 25 | 25 | * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) |
| 26 | 26 | * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) |
| 27 | 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 | 28 | */ |
| 36 | 29 | |
| 37 | 30 | #include <py3270.h> | ... | ... |
src/session/type.c
| ... | ... | @@ -38,45 +38,80 @@ |
| 38 | 38 | |
| 39 | 39 | static PyMethodDef py3270_session_methods[] = { |
| 40 | 40 | { |
| 41 | - "connect", | |
| 42 | - (PyCFunction) py3270_session_connect, | |
| 43 | - METH_VARARGS, | |
| 44 | - "" | |
| 41 | + .ml_name = "connect", | |
| 42 | + .ml_meth = (PyCFunction) py3270_session_connect, | |
| 43 | + .ml_flags = METH_VARARGS, | |
| 44 | + .ml_doc = "" | |
| 45 | 45 | }, |
| 46 | 46 | |
| 47 | 47 | { |
| 48 | - "wait", | |
| 49 | - (PyCFunction) py3270_session_wait, | |
| 50 | - METH_VARARGS, | |
| 51 | - "" | |
| 48 | + .ml_name = "wait", | |
| 49 | + .ml_meth = (PyCFunction) py3270_session_wait, | |
| 50 | + .ml_flags = METH_VARARGS, | |
| 51 | + .ml_doc = "" | |
| 52 | 52 | }, |
| 53 | 53 | |
| 54 | 54 | { |
| 55 | - "set", | |
| 56 | - (PyCFunction) py3270_session_set, | |
| 57 | - METH_VARARGS, | |
| 58 | - "" | |
| 55 | + .ml_name = "set", | |
| 56 | + .ml_meth = (PyCFunction) py3270_session_set, | |
| 57 | + .ml_flags = METH_VARARGS, | |
| 58 | + .ml_doc = "" | |
| 59 | 59 | }, |
| 60 | 60 | |
| 61 | 61 | { |
| 62 | - "get", | |
| 63 | - (PyCFunction) py3270_session_get, | |
| 64 | - METH_VARARGS, | |
| 65 | - "" | |
| 62 | + .ml_name = "get", | |
| 63 | + .ml_meth = (PyCFunction) py3270_session_get, | |
| 64 | + .ml_flags = METH_VARARGS, | |
| 65 | + .ml_doc = "" | |
| 66 | 66 | }, |
| 67 | 67 | |
| 68 | 68 | { |
| 69 | - "find", | |
| 70 | - (PyCFunction) py3270_session_find, | |
| 71 | - METH_VARARGS, | |
| 72 | - "" | |
| 69 | + .ml_name = "find", | |
| 70 | + .ml_meth = (PyCFunction) py3270_session_find, | |
| 71 | + .ml_flags = METH_VARARGS, | |
| 72 | + .ml_doc = "" | |
| 73 | 73 | }, |
| 74 | 74 | |
| 75 | 75 | { |
| 76 | - "count", | |
| 77 | - (PyCFunction) py3270_session_count, | |
| 78 | - METH_VARARGS, | |
| 79 | - "" | |
| 76 | + .ml_name = "count", | |
| 77 | + .ml_meth = (PyCFunction) py3270_session_count, | |
| 78 | + .ml_flags = METH_VARARGS, | |
| 79 | + .ml_doc = "" | |
| 80 | + }, | |
| 81 | + | |
| 82 | + { | |
| 83 | + .ml_name = "setcursor", | |
| 84 | + .ml_meth = (PyCFunction) py3270_session_set_cursor_position, | |
| 85 | + .ml_flags = METH_VARARGS, | |
| 86 | + .ml_doc = "" | |
| 87 | + }, | |
| 88 | + | |
| 89 | + { | |
| 90 | + .ml_name = "pf", | |
| 91 | + .ml_meth = (PyCFunction) py3270_session_pfkey, | |
| 92 | + .ml_flags = METH_VARARGS, | |
| 93 | + .ml_doc = "" | |
| 94 | + }, | |
| 95 | + | |
| 96 | + { | |
| 97 | + .ml_name = "pa", | |
| 98 | + .ml_meth = (PyCFunction) py3270_session_pakey, | |
| 99 | + .ml_flags = METH_VARARGS, | |
| 100 | + .ml_doc = "" | |
| 101 | + }, | |
| 102 | + | |
| 103 | + { | |
| 104 | + .ml_name = "pfkey", | |
| 105 | + .ml_meth = (PyCFunction) py3270_session_pfkey, | |
| 106 | + .ml_flags = METH_VARARGS, | |
| 107 | + .ml_doc = "" | |
| 108 | + }, | |
| 109 | + | |
| 110 | + { | |
| 111 | + .ml_name = "pakey", | |
| 112 | + .ml_meth = (PyCFunction) py3270_session_pakey, | |
| 113 | + .ml_flags = METH_VARARGS, | |
| 114 | + .ml_doc = "" | |
| 80 | 115 | }, |
| 81 | 116 | |
| 82 | 117 | { | ... | ... |
testprograms/sample.py
| ... | ... | @@ -12,23 +12,18 @@ session.timeout = 10 |
| 12 | 12 | |
| 13 | 13 | print("Using tn3270 version " + session.version + " revision " + session.revision) |
| 14 | 14 | |
| 15 | -print(session.timeout) | |
| 16 | - | |
| 17 | 15 | #print(session.cstate) |
| 18 | 16 | #print(session.width) |
| 19 | 17 | #print(session.connected) |
| 20 | -print(session.url) | |
| 21 | -session.url = "http://www.google.com" | |
| 22 | -print(session.url) | |
| 23 | 18 | |
| 24 | 19 | #print(session.reconnect) |
| 25 | 20 | |
| 26 | 21 | # |
| 27 | 22 | # Can reconnect? If yes do it! |
| 28 | 23 | # |
| 29 | -#if session.reconnect.activatable: | |
| 30 | -# print("Reconnecting...") | |
| 31 | -# session.reconnect().wait(10) | |
| 24 | +if session.reconnect.activatable: | |
| 25 | + print("Reconnecting...") | |
| 26 | + session.reconnect().wait(10) | |
| 32 | 27 | |
| 33 | 28 | #print(session.connected) |
| 34 | 29 | #print(session.find('sisbb')) | ... | ... |