From b6f8c26c427d1acadfbb2dd889777065a183c5df Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 27 Sep 2019 10:32:13 -0300 Subject: [PATCH] Implementing "waitforstring" method. --- src/action/methods.cc | 24 +----------------------- src/action/new.cc | 4 ++-- src/include/py3270.h | 4 +++- src/session/wait.cc | 92 ++++++++++++++++++++++++++++++++++++++------------------------------------------------------ testprograms/sample.py | 7 ++----- 5 files changed, 46 insertions(+), 85 deletions(-) diff --git a/src/action/methods.cc b/src/action/methods.cc index c784d10..c0e8c4b 100644 --- a/src/action/methods.cc +++ b/src/action/methods.cc @@ -97,31 +97,9 @@ DLL_PRIVATE PyObject * py3270_action_wait(PyObject *self, PyObject *args) { return py3270_action_call(self, [args, self](TN3270::Action &action) { - switch(PyTuple_Size(args)) { - case 0: - action.wait(); - break; + py3270_wait( * ((pyAction *) self)->session->host, args); - case 1: - { - unsigned int seconds; - - if (!PyArg_ParseTuple(args, "I", &seconds)) - return (PyObject *) NULL; - - action.wait(seconds); - - } - break; - - default: - throw std::system_error(EINVAL, std::system_category()); - - } - - debug("%s: ob_refcnt@%p=%ld",__FUNCTION__,self,self->ob_refcnt); Py_INCREF(self); - return self; }); diff --git a/src/action/new.cc b/src/action/new.cc index 8eb1ff2..7622056 100644 --- a/src/action/new.cc +++ b/src/action/new.cc @@ -43,8 +43,8 @@ DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *a pyAction * pObj = (pyAction *) _PyObject_New(&py3270_action_type); - pObj->session = session; - pObj->action = ((pySession *) session)->host->getAction((const LIB3270_ACTION *) action); + pObj->session = (pySession *) session; + pObj->action = pObj->session->host->getAction((const LIB3270_ACTION *) action); debug("%s: ob_refcnt@%p=%ld",__FUNCTION__,pObj,((PyObject *) pObj)->ob_refcnt); diff --git a/src/include/py3270.h b/src/include/py3270.h index 3a74901..3a2ceef 100644 --- a/src/include/py3270.h +++ b/src/include/py3270.h @@ -90,6 +90,8 @@ DLL_PRIVATE PyObject * py3270_action_call(PyObject *self, std::function worker) noexcept; + DLL_PRIVATE void py3270_wait(Host &host, PyObject *args); + extern "C" { #else @@ -106,7 +108,7 @@ typedef struct { PyObject_HEAD - PyObject * session; + pySession * session; Action * action; } pyAction; diff --git a/src/session/wait.cc b/src/session/wait.cc index 9cb2b71..b534486 100644 --- a/src/session/wait.cc +++ b/src/session/wait.cc @@ -36,84 +36,68 @@ /*---[ Implement ]----------------------------------------------------------------------------------*/ - PyObject * py3270_session_wait(PyObject *self, PyObject *args) { - - return py3270_session_call(self, [args](TN3270::Host &host){ - - switch(PyTuple_Size(args)) { - case 0: // No time defined, use the default one. - host.waitForReady(); - break; + void py3270_wait(TN3270::Host &host, PyObject *args) { - case 1: // Has argument, wait for it. - { - unsigned int seconds; + switch(PyTuple_Size(args)) { + case 0: // No time defined, use the default one. + host.waitForReady(); + break; - if(!PyArg_ParseTuple(args, "I", &seconds)) - return (PyObject *) NULL; + case 1: // Only one argument, its the time. + { + unsigned int seconds; - host.waitForReady(seconds); - } - break; - - default: - throw std::system_error(EINVAL, std::system_category()); + if(!PyArg_ParseTuple(args, "I", &seconds)) + throw std::system_error(EINVAL, std::system_category()); + host.waitForReady(seconds); } + break; - return PyLong_FromLong(0); + case 2: // 2 arguments, it's the address and content. + { + int baddr; + const char *text; - }); + if(!PyArg_ParseTuple(args, "is", &baddr, &text)) + throw std::system_error(EINVAL, std::system_category()); - } - - -/* - PyObject * terminal_set_string_at(PyObject *self, PyObject *args) { + host.wait(baddr,text); + } + break; - int row, col, rc; - const char *text; + case 3: // 3 arguments, it's the row, col, and content. + { + unsigned int row, col; + const char *text; - if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) { - PyErr_SetString(terminalError, strerror(EINVAL)); - return NULL; - } + if (!PyArg_ParseTuple(args, "IIs", &row, &col, &text)) + throw std::system_error(EINVAL, std::system_category()); - try { + host.wait(row,col,text); - rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text); + } + break; - } catch(std::exception &e) { + default: + throw std::system_error(EINVAL, std::system_category()); - 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 { + PyObject * py3270_session_wait(PyObject *self, PyObject *args) { - rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col); + return py3270_session_call(self, [self, args](TN3270::Host &host){ - } catch(std::exception &e) { + py3270_wait(host, args); - PyErr_SetString(terminalError, e.what()); - return NULL; - } + Py_INCREF(self); + return self; - return PyLong_FromLong(rc); + }); } -*/ diff --git a/testprograms/sample.py b/testprograms/sample.py index e4aa4ac..e21c9af 100644 --- a/testprograms/sample.py +++ b/testprograms/sample.py @@ -23,8 +23,6 @@ if session.reconnect.activatable: print("Reconnecting...") session.reconnect().wait(10) -#session.connect('') - print(session.connected) #print('----------------------') @@ -37,10 +35,9 @@ print("-----------------------------------------------------------------------") print(session) print("-----------------------------------------------------------------------") -session.enter().wait(2) - +session.enter().wait(14,2,"Senha") -#session.set("value") +session.set("value") print("-----------------------------------------------------------------------") print(session) -- libgit2 0.21.2