Commit c501d7d9fa1675b038b24977b91daaa787e93e7d
1 parent
cf371929
Exists in
master
and in
5 other branches
Implementando mais métodos.
Showing
7 changed files
with
324 additions
and
8 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,129 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como actions.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + * Referências: | |
| 29 | + * | |
| 30 | + * <https://docs.python.org/2/extending/newtypes.html> | |
| 31 | + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example> | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | + #include "private.h" | |
| 36 | + | |
| 37 | + | |
| 38 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 39 | + | |
| 40 | + PyObject * terminal_pfkey(PyObject *self, PyObject *args) { | |
| 41 | + | |
| 42 | + int rc, key; | |
| 43 | + | |
| 44 | + if (!PyArg_ParseTuple(args, "i", &key)) { | |
| 45 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 46 | + return NULL; | |
| 47 | + } | |
| 48 | + | |
| 49 | + try { | |
| 50 | + | |
| 51 | + rc = ((pw3270_TerminalObject *) self)->session->pfkey(key); | |
| 52 | + | |
| 53 | + } catch(std::exception &e) { | |
| 54 | + | |
| 55 | + PyErr_SetString(terminalError, e.what()); | |
| 56 | + return NULL; | |
| 57 | + } | |
| 58 | + | |
| 59 | + return PyLong_FromLong(rc); | |
| 60 | + | |
| 61 | + } | |
| 62 | + | |
| 63 | + PyObject * terminal_pakey(PyObject *self, PyObject *args) { | |
| 64 | + | |
| 65 | + int rc, key; | |
| 66 | + | |
| 67 | + if (!PyArg_ParseTuple(args, "i", &key)) { | |
| 68 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 69 | + return NULL; | |
| 70 | + } | |
| 71 | + | |
| 72 | + try { | |
| 73 | + | |
| 74 | + rc = ((pw3270_TerminalObject *) self)->session->pakey(key); | |
| 75 | + | |
| 76 | + } catch(std::exception &e) { | |
| 77 | + | |
| 78 | + PyErr_SetString(terminalError, e.what()); | |
| 79 | + return NULL; | |
| 80 | + } | |
| 81 | + | |
| 82 | + return PyLong_FromLong(rc); | |
| 83 | + | |
| 84 | + } | |
| 85 | + | |
| 86 | + PyObject * terminal_enter(PyObject *self, PyObject *args) { | |
| 87 | + | |
| 88 | + int rc; | |
| 89 | + | |
| 90 | + try { | |
| 91 | + | |
| 92 | + rc = ((pw3270_TerminalObject *) self)->session->enter(); | |
| 93 | + | |
| 94 | + } catch(std::exception &e) { | |
| 95 | + | |
| 96 | + PyErr_SetString(terminalError, e.what()); | |
| 97 | + return NULL; | |
| 98 | + } | |
| 99 | + | |
| 100 | + return PyLong_FromLong(rc); | |
| 101 | + | |
| 102 | + | |
| 103 | + } | |
| 104 | + | |
| 105 | + PyObject * terminal_action(PyObject *self, PyObject *args) { | |
| 106 | + | |
| 107 | + int rc; | |
| 108 | + const char *name; | |
| 109 | + | |
| 110 | + if (!PyArg_ParseTuple(args, "s", &name)) { | |
| 111 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 112 | + return NULL; | |
| 113 | + } | |
| 114 | + | |
| 115 | + try { | |
| 116 | + | |
| 117 | + rc = ((pw3270_TerminalObject *) self)->session->action(name); | |
| 118 | + | |
| 119 | + } catch(std::exception &e) { | |
| 120 | + | |
| 121 | + PyErr_SetString(terminalError, e.what()); | |
| 122 | + return NULL; | |
| 123 | + } | |
| 124 | + | |
| 125 | + return PyLong_FromLong(rc); | |
| 126 | + | |
| 127 | + | |
| 128 | + } | |
| 129 | + | ... | ... |
src/python/get.cc
| ... | ... | @@ -61,6 +61,30 @@ PyObject * terminal_is_ready(PyObject *self, PyObject *args) { |
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | +PyObject * terminal_is_protected_at(PyObject *self, PyObject *args) { | |
| 65 | + | |
| 66 | + int rc, row, col; | |
| 67 | + | |
| 68 | + if (!PyArg_ParseTuple(args, "ii", &row, &col)) { | |
| 69 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 70 | + return NULL; | |
| 71 | + } | |
| 72 | + | |
| 73 | + try { | |
| 74 | + | |
| 75 | + rc = ((pw3270_TerminalObject *) self)->session->get_is_protected_at(row,col); | |
| 76 | + | |
| 77 | + } catch(std::exception &e) { | |
| 78 | + | |
| 79 | + PyErr_SetString(terminalError, e.what()); | |
| 80 | + return NULL; | |
| 81 | + } | |
| 82 | + | |
| 83 | + return PyBool_FromLong( rc ); | |
| 84 | + | |
| 85 | +} | |
| 86 | + | |
| 87 | + | |
| 64 | 88 | PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args) { |
| 65 | 89 | |
| 66 | 90 | int row, col, rc; | ... | ... |
src/python/misc.cc
| ... | ... | @@ -81,3 +81,54 @@ |
| 81 | 81 | return PyLong_FromLong(rc); |
| 82 | 82 | |
| 83 | 83 | } |
| 84 | + | |
| 85 | + PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args) { | |
| 86 | + | |
| 87 | + int rc; | |
| 88 | + int timeout = 60; | |
| 89 | + | |
| 90 | + if (!PyArg_ParseTuple(args, "|i", &timeout)) { | |
| 91 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 92 | + return NULL; | |
| 93 | + } | |
| 94 | + | |
| 95 | + try { | |
| 96 | + | |
| 97 | + rc = ((pw3270_TerminalObject *) self)->session->wait_for_ready(timeout); | |
| 98 | + | |
| 99 | + } catch(std::exception &e) { | |
| 100 | + | |
| 101 | + PyErr_SetString(terminalError, e.what()); | |
| 102 | + return NULL; | |
| 103 | + } | |
| 104 | + | |
| 105 | + return PyLong_FromLong(rc); | |
| 106 | + | |
| 107 | + } | |
| 108 | + | |
| 109 | + | |
| 110 | + PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args) { | |
| 111 | + | |
| 112 | + int row, col, rc; | |
| 113 | + int timeout = 10; | |
| 114 | + const char *text; | |
| 115 | + | |
| 116 | + if (!PyArg_ParseTuple(args, "iis|i", &row, &col, &text, &timeout)) { | |
| 117 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 118 | + return NULL; | |
| 119 | + } | |
| 120 | + | |
| 121 | + try { | |
| 122 | + | |
| 123 | + rc = ((pw3270_TerminalObject *) self)->session->wait_for_string_at(row,col,text,timeout); | |
| 124 | + | |
| 125 | + } catch(std::exception &e) { | |
| 126 | + | |
| 127 | + PyErr_SetString(terminalError, e.what()); | |
| 128 | + return NULL; | |
| 129 | + } | |
| 130 | + | |
| 131 | + return PyLong_FromLong(rc); | |
| 132 | + | |
| 133 | + } | |
| 134 | + | ... | ... |
src/python/private.h
| ... | ... | @@ -64,8 +64,20 @@ |
| 64 | 64 | PyObject * terminal_disconnect(PyObject *self, PyObject *args); |
| 65 | 65 | |
| 66 | 66 | PyObject * terminal_get_string_at(PyObject *self, PyObject *args); |
| 67 | + PyObject * terminal_set_string_at(PyObject *self, PyObject *args); | |
| 67 | 68 | PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args); |
| 68 | 69 | |
| 70 | + PyObject * terminal_pfkey(PyObject *self, PyObject *args); | |
| 71 | + PyObject * terminal_pakey(PyObject *self, PyObject *args); | |
| 72 | + PyObject * terminal_enter(PyObject *self, PyObject *args); | |
| 73 | + PyObject * terminal_action(PyObject *self, PyObject *args); | |
| 74 | + | |
| 75 | + PyObject * terminal_is_protected_at(PyObject *self, PyObject *args); | |
| 76 | + PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args); | |
| 77 | + | |
| 78 | + PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args); | |
| 79 | + PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args); | |
| 80 | + | |
| 69 | 81 | } |
| 70 | 82 | |
| 71 | 83 | #endif // PRIVATE_H_INCLUDED | ... | ... |
src/python/py3270.cbp
| ... | ... | @@ -53,12 +53,14 @@ |
| 53 | 53 | <Unit filename="../classlib/session.cc" /> |
| 54 | 54 | <Unit filename="../include/lib3270/config.h" /> |
| 55 | 55 | <Unit filename="../include/pw3270/class.h" /> |
| 56 | + <Unit filename="actions.cc" /> | |
| 56 | 57 | <Unit filename="get.cc" /> |
| 57 | 58 | <Unit filename="init.cc" /> |
| 58 | 59 | <Unit filename="misc.cc" /> |
| 59 | 60 | <Unit filename="private.h" /> |
| 60 | 61 | <Unit filename="py3270.cc" /> |
| 61 | 62 | <Unit filename="sample.py" /> |
| 63 | + <Unit filename="set.cc" /> | |
| 62 | 64 | <Extensions> |
| 63 | 65 | <code_completion /> |
| 64 | 66 | <envvars /> | ... | ... |
src/python/py3270.cc
| ... | ... | @@ -50,17 +50,29 @@ static PyObject * get_revision(PyObject *self, PyObject *args) { |
| 50 | 50 | |
| 51 | 51 | static PyMethodDef terminal_methods[] = { |
| 52 | 52 | |
| 53 | - { "Version", terminal_get_version, METH_NOARGS, "Get the lib3270 version string." }, | |
| 54 | - { "Revision", terminal_get_revision, METH_NOARGS, "Get the lib3270 revision number." }, | |
| 53 | + { "Version", terminal_get_version, METH_NOARGS, "Get the lib3270 version string." }, | |
| 54 | + { "Revision", terminal_get_revision, METH_NOARGS, "Get the lib3270 revision number." }, | |
| 55 | 55 | |
| 56 | - { "IsConnected", terminal_is_connected, METH_NOARGS, "True if the terminal is connected to the host." }, | |
| 57 | - { "IsReady", terminal_is_ready, METH_NOARGS, "True if the terminal has finished network activity." }, | |
| 56 | + { "IsConnected", terminal_is_connected, METH_NOARGS, "True if the terminal is connected to the host." }, | |
| 57 | + { "IsReady", terminal_is_ready, METH_NOARGS, "True if the terminal has finished network activity." }, | |
| 58 | + { "IsProtected", terminal_is_protected_at, METH_VARARGS, "True if the position is read-only." }, | |
| 58 | 59 | |
| 59 | - { "Connect", terminal_connect, METH_VARARGS, "Connect to the host." }, | |
| 60 | - { "Disconnect", terminal_disconnect, METH_NOARGS, "Disconnect from host." }, | |
| 60 | + { "SetCursorPosition", terminal_set_cursor_at, METH_VARARGS, "Set cursor position." }, | |
| 61 | 61 | |
| 62 | - { "CmpStringAt", terminal_cmp_string_at, METH_VARARGS, "Compare string with terminal buffer at the position." }, | |
| 63 | - { "GetStringAt", terminal_get_string_at, METH_VARARGS, "Get string from terminal buffer." }, | |
| 62 | + { "WaitForStringAt", terminal_wait_for_string_at, METH_VARARGS, "Wait for string at position" }, | |
| 63 | + { "WaitForReady", terminal_wait_for_ready, METH_VARARGS, "Wait for network communication to finish" }, | |
| 64 | + | |
| 65 | + { "Connect", terminal_connect, METH_VARARGS, "Connect to the host." }, | |
| 66 | + { "Disconnect", terminal_disconnect, METH_NOARGS, "Disconnect from host." }, | |
| 67 | + | |
| 68 | + { "CmpStringAt", terminal_cmp_string_at, METH_VARARGS, "Compare string with terminal buffer at the position." }, | |
| 69 | + { "GetStringAt", terminal_get_string_at, METH_VARARGS, "Get string from terminal buffer." }, | |
| 70 | + { "SetStringAt", terminal_set_string_at, METH_VARARGS, "Set string in terminal buffer." }, | |
| 71 | + | |
| 72 | + { "PFKey", terminal_pfkey, METH_VARARGS, "Send PF key." }, | |
| 73 | + { "PAKey", terminal_pakey, METH_VARARGS, "Send PA key." }, | |
| 74 | + { "Enter", terminal_enter, METH_NOARGS, "Send Enter Key." }, | |
| 75 | + { "Action", terminal_action, METH_VARARGS, "Send Action by name." }, | |
| 64 | 76 | |
| 65 | 77 | {NULL} // Sentinel |
| 66 | 78 | ... | ... |
| ... | ... | @@ -0,0 +1,86 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como set.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + * Referências: | |
| 29 | + * | |
| 30 | + * <https://docs.python.org/2/extending/newtypes.html> | |
| 31 | + * <https://docs.python.org/2.7/extending/extending.html#a-simple-example> | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | + #include "private.h" | |
| 36 | + | |
| 37 | + | |
| 38 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 39 | + | |
| 40 | + PyObject * terminal_set_string_at(PyObject *self, PyObject *args) { | |
| 41 | + | |
| 42 | + int row, col, rc; | |
| 43 | + const char *text; | |
| 44 | + | |
| 45 | + if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) { | |
| 46 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 47 | + return NULL; | |
| 48 | + } | |
| 49 | + | |
| 50 | + try { | |
| 51 | + | |
| 52 | + rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text); | |
| 53 | + | |
| 54 | + } catch(std::exception &e) { | |
| 55 | + | |
| 56 | + PyErr_SetString(terminalError, e.what()); | |
| 57 | + return NULL; | |
| 58 | + } | |
| 59 | + | |
| 60 | + return PyLong_FromLong(rc); | |
| 61 | + | |
| 62 | + } | |
| 63 | + | |
| 64 | + PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args) { | |
| 65 | + | |
| 66 | + int row, col, rc; | |
| 67 | + | |
| 68 | + if (!PyArg_ParseTuple(args, "ii", &row, &col)) { | |
| 69 | + PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 70 | + return NULL; | |
| 71 | + } | |
| 72 | + | |
| 73 | + try { | |
| 74 | + | |
| 75 | + rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col); | |
| 76 | + | |
| 77 | + } catch(std::exception &e) { | |
| 78 | + | |
| 79 | + PyErr_SetString(terminalError, e.what()); | |
| 80 | + return NULL; | |
| 81 | + } | |
| 82 | + | |
| 83 | + return PyLong_FromLong(rc); | |
| 84 | + | |
| 85 | + } | |
| 86 | + | ... | ... |