From c501d7d9fa1675b038b24977b91daaa787e93e7d Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Sat, 31 Oct 2015 15:33:48 -0200 Subject: [PATCH] Implementando mais métodos. --- src/python/actions.cc | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/python/get.cc | 24 ++++++++++++++++++++++++ src/python/misc.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/python/private.h | 12 ++++++++++++ src/python/py3270.cbp | 2 ++ src/python/py3270.cc | 28 ++++++++++++++++++++-------- src/python/set.cc | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 324 insertions(+), 8 deletions(-) create mode 100644 src/python/actions.cc create mode 100644 src/python/set.cc diff --git a/src/python/actions.cc b/src/python/actions.cc new file mode 100644 index 0000000..5d8aebe --- /dev/null +++ b/src/python/actions.cc @@ -0,0 +1,129 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como actions.cc e possui - linhas de código. + * + * Contatos + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + * Referências: + * + * + * + * + */ + + #include "private.h" + + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + PyObject * terminal_pfkey(PyObject *self, PyObject *args) { + + int rc, key; + + if (!PyArg_ParseTuple(args, "i", &key)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->pfkey(key); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + } + + PyObject * terminal_pakey(PyObject *self, PyObject *args) { + + int rc, key; + + if (!PyArg_ParseTuple(args, "i", &key)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->pakey(key); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + } + + PyObject * terminal_enter(PyObject *self, PyObject *args) { + + int rc; + + try { + + rc = ((pw3270_TerminalObject *) self)->session->enter(); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + + } + + PyObject * terminal_action(PyObject *self, PyObject *args) { + + int rc; + const char *name; + + if (!PyArg_ParseTuple(args, "s", &name)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->action(name); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + + } + diff --git a/src/python/get.cc b/src/python/get.cc index fa4adac..30aaece 100644 --- a/src/python/get.cc +++ b/src/python/get.cc @@ -61,6 +61,30 @@ PyObject * terminal_is_ready(PyObject *self, PyObject *args) { } +PyObject * terminal_is_protected_at(PyObject *self, PyObject *args) { + + int rc, row, col; + + if (!PyArg_ParseTuple(args, "ii", &row, &col)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->get_is_protected_at(row,col); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyBool_FromLong( rc ); + +} + + PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args) { int row, col, rc; diff --git a/src/python/misc.cc b/src/python/misc.cc index 7df1c32..d9ccb8c 100644 --- a/src/python/misc.cc +++ b/src/python/misc.cc @@ -81,3 +81,54 @@ return PyLong_FromLong(rc); } + + PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args) { + + int rc; + int timeout = 60; + + if (!PyArg_ParseTuple(args, "|i", &timeout)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->wait_for_ready(timeout); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + } + + + PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args) { + + int row, col, rc; + int timeout = 10; + const char *text; + + if (!PyArg_ParseTuple(args, "iis|i", &row, &col, &text, &timeout)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->wait_for_string_at(row,col,text,timeout); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + } + diff --git a/src/python/private.h b/src/python/private.h index 42ed267..a6915d1 100644 --- a/src/python/private.h +++ b/src/python/private.h @@ -64,8 +64,20 @@ PyObject * terminal_disconnect(PyObject *self, PyObject *args); PyObject * terminal_get_string_at(PyObject *self, PyObject *args); + PyObject * terminal_set_string_at(PyObject *self, PyObject *args); PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args); + PyObject * terminal_pfkey(PyObject *self, PyObject *args); + PyObject * terminal_pakey(PyObject *self, PyObject *args); + PyObject * terminal_enter(PyObject *self, PyObject *args); + PyObject * terminal_action(PyObject *self, PyObject *args); + + PyObject * terminal_is_protected_at(PyObject *self, PyObject *args); + PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args); + + PyObject * terminal_wait_for_ready(PyObject *self, PyObject *args); + PyObject * terminal_wait_for_string_at(PyObject *self, PyObject *args); + } #endif // PRIVATE_H_INCLUDED diff --git a/src/python/py3270.cbp b/src/python/py3270.cbp index bb1250f..37aabf6 100644 --- a/src/python/py3270.cbp +++ b/src/python/py3270.cbp @@ -53,12 +53,14 @@ + + diff --git a/src/python/py3270.cc b/src/python/py3270.cc index 32fd33f..12ee60d 100644 --- a/src/python/py3270.cc +++ b/src/python/py3270.cc @@ -50,17 +50,29 @@ static PyObject * get_revision(PyObject *self, PyObject *args) { static PyMethodDef terminal_methods[] = { - { "Version", terminal_get_version, METH_NOARGS, "Get the lib3270 version string." }, - { "Revision", terminal_get_revision, METH_NOARGS, "Get the lib3270 revision number." }, + { "Version", terminal_get_version, METH_NOARGS, "Get the lib3270 version string." }, + { "Revision", terminal_get_revision, METH_NOARGS, "Get the lib3270 revision number." }, - { "IsConnected", terminal_is_connected, METH_NOARGS, "True if the terminal is connected to the host." }, - { "IsReady", terminal_is_ready, METH_NOARGS, "True if the terminal has finished network activity." }, + { "IsConnected", terminal_is_connected, METH_NOARGS, "True if the terminal is connected to the host." }, + { "IsReady", terminal_is_ready, METH_NOARGS, "True if the terminal has finished network activity." }, + { "IsProtected", terminal_is_protected_at, METH_VARARGS, "True if the position is read-only." }, - { "Connect", terminal_connect, METH_VARARGS, "Connect to the host." }, - { "Disconnect", terminal_disconnect, METH_NOARGS, "Disconnect from host." }, + { "SetCursorPosition", terminal_set_cursor_at, METH_VARARGS, "Set cursor position." }, - { "CmpStringAt", terminal_cmp_string_at, METH_VARARGS, "Compare string with terminal buffer at the position." }, - { "GetStringAt", terminal_get_string_at, METH_VARARGS, "Get string from terminal buffer." }, + { "WaitForStringAt", terminal_wait_for_string_at, METH_VARARGS, "Wait for string at position" }, + { "WaitForReady", terminal_wait_for_ready, METH_VARARGS, "Wait for network communication to finish" }, + + { "Connect", terminal_connect, METH_VARARGS, "Connect to the host." }, + { "Disconnect", terminal_disconnect, METH_NOARGS, "Disconnect from host." }, + + { "CmpStringAt", terminal_cmp_string_at, METH_VARARGS, "Compare string with terminal buffer at the position." }, + { "GetStringAt", terminal_get_string_at, METH_VARARGS, "Get string from terminal buffer." }, + { "SetStringAt", terminal_set_string_at, METH_VARARGS, "Set string in terminal buffer." }, + + { "PFKey", terminal_pfkey, METH_VARARGS, "Send PF key." }, + { "PAKey", terminal_pakey, METH_VARARGS, "Send PA key." }, + { "Enter", terminal_enter, METH_NOARGS, "Send Enter Key." }, + { "Action", terminal_action, METH_VARARGS, "Send Action by name." }, {NULL} // Sentinel diff --git a/src/python/set.cc b/src/python/set.cc new file mode 100644 index 0000000..759495d --- /dev/null +++ b/src/python/set.cc @@ -0,0 +1,86 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como set.cc e possui - linhas de código. + * + * Contatos + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + * Referências: + * + * + * + * + */ + + #include "private.h" + + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + PyObject * terminal_set_string_at(PyObject *self, PyObject *args) { + + int row, col, rc; + const char *text; + + if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + } + + PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args) { + + int row, col, rc; + + if (!PyArg_ParseTuple(args, "ii", &row, &col)) { + PyErr_SetString(terminalError, strerror(EINVAL)); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + } + -- libgit2 0.21.2