diff --git a/src/include/py3270.h b/src/include/py3270.h index ea493a6..c33817f 100644 --- a/src/include/py3270.h +++ b/src/include/py3270.h @@ -147,6 +147,10 @@ DLL_PRIVATE PyObject * py3270_session_find(PyObject *self, PyObject *args); DLL_PRIVATE PyObject * py3270_session_count(PyObject *self, PyObject *args); + DLL_PRIVATE PyObject * py3270_session_pfkey(PyObject *self, PyObject *args); + DLL_PRIVATE PyObject * py3270_session_pakey(PyObject *self, PyObject *args); + DLL_PRIVATE PyObject * py3270_session_set_cursor_position(PyObject *self, PyObject *args); + // Action object DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action); DLL_PRIVATE void py3270_action_dealloc(PyObject * self); diff --git a/src/session/actions.cc b/src/session/actions.cc index cffd5d6..fe4a50b 100644 --- a/src/session/actions.cc +++ b/src/session/actions.cc @@ -25,105 +25,81 @@ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * - * Referências: - * - * - * - * */ #include /*---[ 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 * py3270_session_pfkey(PyObject *self, PyObject *args) { - } + return py3270_session_call(self, [args](TN3270::Host &host){ - PyObject * terminal_pakey(PyObject *self, PyObject *args) { + unsigned int keycode; - int rc, key; + if (!PyArg_ParseTuple(args, "I", &keycode)) + return (PyObject *) NULL; - if (!PyArg_ParseTuple(args, "i", &key)) { - PyErr_SetString(terminalError, strerror(EINVAL)); - return NULL; - } + host.pfkey((unsigned short) keycode); - try { + return PyLong_FromLong(0); - rc = ((pw3270_TerminalObject *) self)->session->pakey(key); + }); - } catch(std::exception &e) { +} - PyErr_SetString(terminalError, e.what()); - return NULL; - } +PyObject * py3270_session_pakey(PyObject *self, PyObject *args) { - return PyLong_FromLong(rc); + return py3270_session_call(self, [args](TN3270::Host &host){ - } + unsigned int keycode; - PyObject * terminal_enter(PyObject *self, PyObject *args) { + if (!PyArg_ParseTuple(args, "I", &keycode)) + return (PyObject *) NULL; - int rc; + host.pakey((unsigned short) keycode); - try { + return PyLong_FromLong(0); - rc = ((pw3270_TerminalObject *) self)->session->enter(); + }); - } catch(std::exception &e) { +} - PyErr_SetString(terminalError, e.what()); - return NULL; - } +PyObject * py3270_session_set_cursor_position(PyObject *self, PyObject *args) { - return PyLong_FromLong(rc); + return py3270_session_call(self, [args](TN3270::Host &host){ + switch(PyTuple_Size(args)) { + case 1: // Only Address + { + int baddr; - } + if(!PyArg_ParseTuple(args, "i", &baddr)) + return (PyObject *) NULL; - PyObject * terminal_action(PyObject *self, PyObject *args) { + host.setCursor(baddr); + } + break; - int rc; - const char *name; + case 2: // Row, col + { + unsigned int row, col; - if (!PyArg_ParseTuple(args, "s", &name)) { - PyErr_SetString(terminalError, strerror(EINVAL)); - return NULL; - } + if (!PyArg_ParseTuple(args, "II", &row, &col)) + return (PyObject *) NULL; - try { + host.setCursor(row,col); - rc = ((pw3270_TerminalObject *) self)->session->action(name); + } + 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); + return PyLong_FromLong(0); + }); - } -*/ +} diff --git a/src/session/attributes.cc b/src/session/attributes.cc index 50011fe..a10a0e7 100644 --- a/src/session/attributes.cc +++ b/src/session/attributes.cc @@ -115,7 +115,7 @@ int py3270_session_setter(PyObject *self, PyObject *value, void *name) { } catch( ... ) { - PyErr_SetString(PyExc_RuntimeError, "Unexpected error setting timeout"); + PyErr_SetString(PyExc_RuntimeError, "Unexpected error setting attribute"); return -1; } diff --git a/src/session/init.cc b/src/session/init.cc index 7794635..c409538 100644 --- a/src/session/init.cc +++ b/src/session/init.cc @@ -18,16 +18,14 @@ * 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 py3270.cc e possui - linhas de código. + * Este programa está nomeado como - e possui - linhas de código. * * Contatos: * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: + * Referênces: * * * @@ -93,10 +91,9 @@ void py3270_session_type_init(PyTypeObject *type) { } + // Copy lib3270's actions for(auto action : actions) { -// debug("Creating action %s",action->name); - py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) action); type->tp_getset[ix].get = py3270_action_new_from_session; @@ -105,12 +102,11 @@ void py3270_session_type_init(PyTypeObject *type) { ix++; } - } + } } - int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) { pySession * session = (pySession *) self; @@ -127,25 +123,6 @@ int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) { session->host = new TN3270::Host(id); - /* - // Load lib3270's actions - { - auto actions = TN3270::getActions(); - - for(auto action : actions) { - - pyAction * object = (pyAction *) _PyObject_New(&py3270_action_type); - - object->host = session->host; - object->action = action; - - PyObject_SetAttr(self, PyUnicode_FromString(action->name), (PyObject *) object); - - } - - } - */ - return 0; } catch(const std::exception &e) { @@ -184,81 +161,3 @@ void py3270_session_dealloc(PyObject * self) { Py_TYPE(self)->tp_free(self); } - - /* - - const char *id = ""; - - if (!PyArg_ParseTuple(args, "s", &id)) - id = ""; - - - if(session) { - - try { - - session->host = new TN3270::Host(id); - - } catch(const exception &e) { - - PyErr_SetString(PyExc_RuntimeError, e.what()); - - } catch( ... ) { - - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module"); - - } - - } - - type->tp_free(session); - - return NULL; - -} - -void py3270_session_dealloc(pySession * self) { - - if(self->host) { - delete self->host; - } - - Py_TYPE(self)->tp_free((PyObject *) self); - -} - */ - - -/* -PyObject * terminal_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - - PW3270_NAMESPACE::session * session; - const char *id = ""; - - if (!PyArg_ParseTuple(args, "s", &id)) { - id = ""; - } - - trace("%s(%s)",__FUNCTION__,id); - - try { - - session = PW3270_NAMESPACE::session::create(id); - - } catch(std::exception &e) { - - trace("%s failed: %s",__FUNCTION__,e.what()); - PyErr_SetString(terminalError, e.what()); - return NULL; - - } - - pw3270_TerminalObject *self = (pw3270_TerminalObject *) type->tp_alloc(type, 0); - - self->session = session; - - return (PyObject *)self; -} - - -*/ diff --git a/src/session/tools.cc b/src/session/tools.cc index 29f6c50..7567f87 100644 --- a/src/session/tools.cc +++ b/src/session/tools.cc @@ -18,20 +18,13 @@ * 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 misc.cc e possui - linhas de código. + * Este programa está nomeado como - e possui - linhas de código. * * Contatos: * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: - * - * - * - * */ #include diff --git a/src/session/type.c b/src/session/type.c index 3c92bfa..01a8d15 100644 --- a/src/session/type.c +++ b/src/session/type.c @@ -38,45 +38,80 @@ static PyMethodDef py3270_session_methods[] = { { - "connect", - (PyCFunction) py3270_session_connect, - METH_VARARGS, - "" + .ml_name = "connect", + .ml_meth = (PyCFunction) py3270_session_connect, + .ml_flags = METH_VARARGS, + .ml_doc = "" }, { - "wait", - (PyCFunction) py3270_session_wait, - METH_VARARGS, - "" + .ml_name = "wait", + .ml_meth = (PyCFunction) py3270_session_wait, + .ml_flags = METH_VARARGS, + .ml_doc = "" }, { - "set", - (PyCFunction) py3270_session_set, - METH_VARARGS, - "" + .ml_name = "set", + .ml_meth = (PyCFunction) py3270_session_set, + .ml_flags = METH_VARARGS, + .ml_doc = "" }, { - "get", - (PyCFunction) py3270_session_get, - METH_VARARGS, - "" + .ml_name = "get", + .ml_meth = (PyCFunction) py3270_session_get, + .ml_flags = METH_VARARGS, + .ml_doc = "" }, { - "find", - (PyCFunction) py3270_session_find, - METH_VARARGS, - "" + .ml_name = "find", + .ml_meth = (PyCFunction) py3270_session_find, + .ml_flags = METH_VARARGS, + .ml_doc = "" }, { - "count", - (PyCFunction) py3270_session_count, - METH_VARARGS, - "" + .ml_name = "count", + .ml_meth = (PyCFunction) py3270_session_count, + .ml_flags = METH_VARARGS, + .ml_doc = "" + }, + + { + .ml_name = "setcursor", + .ml_meth = (PyCFunction) py3270_session_set_cursor_position, + .ml_flags = METH_VARARGS, + .ml_doc = "" + }, + + { + .ml_name = "pf", + .ml_meth = (PyCFunction) py3270_session_pfkey, + .ml_flags = METH_VARARGS, + .ml_doc = "" + }, + + { + .ml_name = "pa", + .ml_meth = (PyCFunction) py3270_session_pakey, + .ml_flags = METH_VARARGS, + .ml_doc = "" + }, + + { + .ml_name = "pfkey", + .ml_meth = (PyCFunction) py3270_session_pfkey, + .ml_flags = METH_VARARGS, + .ml_doc = "" + }, + + { + .ml_name = "pakey", + .ml_meth = (PyCFunction) py3270_session_pakey, + .ml_flags = METH_VARARGS, + .ml_doc = "" }, { diff --git a/testprograms/sample.py b/testprograms/sample.py index 9eb41ba..fd414b3 100644 --- a/testprograms/sample.py +++ b/testprograms/sample.py @@ -12,23 +12,18 @@ session.timeout = 10 print("Using tn3270 version " + session.version + " revision " + session.revision) -print(session.timeout) - #print(session.cstate) #print(session.width) #print(session.connected) -print(session.url) -session.url = "http://www.google.com" -print(session.url) #print(session.reconnect) # # Can reconnect? If yes do it! # -#if session.reconnect.activatable: -# print("Reconnecting...") -# session.reconnect().wait(10) +if session.reconnect.activatable: + print("Reconnecting...") + session.reconnect().wait(10) #print(session.connected) #print(session.find('sisbb')) -- libgit2 0.21.2