diff --git a/Makefile.in b/Makefile.in index d093460..ac13193 100644 --- a/Makefile.in +++ b/Makefile.in @@ -32,7 +32,10 @@ SOURCES= \ $(wildcard src/module/*.c) \ $(wildcard src/module/*.cc) \ $(wildcard src/module/@OSNAME@/*.cc) \ - $(wildcard src/terminal/*.cc) + $(wildcard src/action/*.cc) \ + $(wildcard src/action/*.c) \ + $(wildcard src/session/*.cc) \ + $(wildcard src/session/*.c) #---[ Tools ]---------------------------------------------------------------------------- diff --git a/gitsync.sh b/gitsync.sh index cacb378..3d89d0a 100755 --- a/gitsync.sh +++ b/gitsync.sh @@ -9,18 +9,24 @@ # Setup: # # git remote add github https://github.com/PerryWerneck/lib3270.git -# git fetch origin -# git push github --all # # git push git fetch origin -git checkout master -git merge origin/master +git merge -for repo in $(git remote -v | grep -v origin | grep "(push)" | awk '{print $1}') +REPOS=$(git remote -v | grep -v origin | grep "(push)" | awk '{print $1}') + +for repo in ${REPOS} +do + echo "Getting updates from ${repo} ..." + git fetch ${repo} + git merge +done + +for repo in ${REPOS} do echo "Updating ${repo} ..." git push ${repo} diff --git a/py3270.cbp b/py3270.cbp index ea6f8f2..0a011aa 100644 --- a/py3270.cbp +++ b/py3270.cbp @@ -42,6 +42,11 @@ + + + + @@ -50,12 +55,15 @@ - - - - - - + + + + + + + + diff --git a/src/action/init.cc b/src/action/init.cc new file mode 100644 index 0000000..e16b8c9 --- /dev/null +++ b/src/action/init.cc @@ -0,0 +1,45 @@ +/* + * "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 py3270.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) + * + * Implementa métodos básicos inicio/final do objeto python + * + * Referências: + * + * + * + * + */ + + #include + #include + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +void py3270_action_type_init(PyTypeObject *type) { + + +} diff --git a/src/action/new.cc b/src/action/new.cc new file mode 100644 index 0000000..b501308 --- /dev/null +++ b/src/action/new.cc @@ -0,0 +1,44 @@ +/* + * "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 py3270.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) + * + * Implementa métodos básicos inicio/final do objeto python + * + * Referências: + * + * + * + * + */ + + #include + #include + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action) { + +} diff --git a/src/action/type.c b/src/action/type.c new file mode 100644 index 0000000..b0d476b --- /dev/null +++ b/src/action/type.c @@ -0,0 +1,70 @@ +/* + * "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 py3270.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 + +/*---[ Globals ]------------------------------------------------------------------------------------*/ + +static PyMethodDef py3270_action_methods[] = { + + /* + { + "activatable", + (PyCFunction) py3270_action_activatable, + METH_NOARGS, + "" + }, + */ + + { + NULL + } +}; + +// https://docs.python.org/3/c-api/typeobj.html +PyTypeObject py3270_action_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "tn3270.Session.Action", + .tp_doc = "TN3270 Session Action Object", + .tp_basicsize = sizeof(pyAction), + .tp_itemsize = 0, + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_methods = py3270_action_methods, + +}; + + diff --git a/src/include/py3270.h b/src/include/py3270.h index fbfbee5..822816f 100644 --- a/src/include/py3270.h +++ b/src/include/py3270.h @@ -75,7 +75,9 @@ #include #include #include + #include #include + #include using std::exception; using std::runtime_error; @@ -97,11 +99,24 @@ Host *host; } pySession; - DLL_PRIVATE void py3270_session_type_init(PyTypeObject *type); + typedef struct { + PyObject_HEAD + Host *host; + const struct _lib3270_action * action; + } pyAction; + + DLL_PRIVATE PyTypeObject py3270_session_type; + DLL_PRIVATE PyTypeObject py3270_action_type; DLL_PRIVATE PyObject * py3270_get_module_version(PyObject *self, PyObject *args); DLL_PRIVATE PyObject * py3270_get_module_revision(PyObject *self, PyObject *args); + // Types + DLL_PRIVATE void py3270_action_type_init(PyTypeObject *type); + DLL_PRIVATE void py3270_session_type_init(PyTypeObject *type); + + + // Session object DLL_PRIVATE PyObject * py3270_session_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds); DLL_PRIVATE void py3270_session_dealloc(PyObject * self); @@ -111,8 +126,6 @@ DLL_PRIVATE PyObject * py3270_session_getter(PyObject *self, void *name); DLL_PRIVATE int py3270_session_setter(PyObject *self, PyObject *value, void *name); -// DLL_PRIVATE PyObject * py3270_session_getattr(PyObject *self, char *attr_name); - DLL_PRIVATE PyObject * py3270_session_connect(PyObject *self, PyObject *args); DLL_PRIVATE PyObject * py3270_session_disconnect(PyObject *self, PyObject *args); @@ -120,6 +133,10 @@ DLL_PRIVATE PyObject * py3270_session_set(PyObject *self, PyObject *args); DLL_PRIVATE PyObject * py3270_session_str(PyObject *self); + // Action object + DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action); + + /* DLL_PRIVATE PyObject * py3270_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds); diff --git a/src/module/init.c b/src/module/init.c index ab557c6..cf721de 100644 --- a/src/module/init.c +++ b/src/module/init.c @@ -70,75 +70,46 @@ static struct PyModuleDef definition = { .m_free = (freefunc) cleanup }; -//# Tornar essa tabela pública e testar em getattr, se for um método usar PyMethod_New para retornar um método. - -static PyMethodDef py3270_session_methods[] = { - { - "connect", - (PyCFunction) py3270_session_connect, - METH_VARARGS, - "" - }, - - { - "disconnect", - (PyCFunction) py3270_session_disconnect, - METH_NOARGS, - "" - }, - - { - "set", - (PyCFunction) py3270_session_set, - METH_VARARGS, - "" - }, - - { - "get", - (PyCFunction) py3270_session_get, - METH_VARARGS, - "" - }, - - { - NULL - } -}; +/* +static PyTypeObject ActionType = { -// https://docs.python.org/3/c-api/typeobj.html -static PyTypeObject SessionType = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "tn3270.Session", - .tp_doc = "TN3270 Session Object", - .tp_basicsize = sizeof(pySession), + + .tp_name = "tn3270.Action", + .tp_doc = "TN3270 Action Object", + .tp_basicsize = sizeof(pyAction), .tp_itemsize = 0, - .tp_flags = Py_TPFLAGS_HAVE_FINALIZE|Py_TPFLAGS_DEFAULT, + .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_new = py3270_session_alloc, - .tp_dealloc = py3270_session_dealloc, +// .tp_new = py3270_session_alloc, +// .tp_dealloc = py3270_session_dealloc, - .tp_init = py3270_session_init, - .tp_finalize = py3270_session_finalize, +// .tp_init = py3270_session_init, +// .tp_finalize = py3270_session_finalize, - .tp_str = py3270_session_str, +// .tp_str = py3270_session_str, - .tp_methods = py3270_session_methods, +// .tp_methods = py3270_session_methods, }; +*/ /*---[ Implement ]----------------------------------------------------------------------------------*/ PyMODINIT_FUNC PyInit_tn3270(void) { // Initialize custom attributes & methods. - py3270_session_type_init(&SessionType); + py3270_session_type_init(&py3270_session_type); + if (PyType_Ready(&py3270_session_type) < 0) + return NULL; + + py3270_action_type_init(&py3270_action_type); + if (PyType_Ready(&py3270_action_type) < 0) + return NULL; // // Initialize module. // - if (PyType_Ready(&SessionType) < 0) - return NULL; Py_Initialize(); @@ -152,9 +123,9 @@ PyMODINIT_FUNC PyInit_tn3270(void) // // Create custom type // - Py_INCREF(&SessionType); - if (PyModule_AddObject(module, "Session", (PyObject *) &SessionType) < 0) { - Py_DECREF(&SessionType); + Py_INCREF(&py3270_session_type); + if (PyModule_AddObject(module, "Session", (PyObject *) &py3270_session_type) < 0) { + Py_DECREF(&py3270_session_type); Py_DECREF(module); return NULL; } @@ -166,9 +137,9 @@ static void cleanup(PyObject *module) { debug("Cleaning up module %p", module); - if(SessionType.tp_getset) { - free(SessionType.tp_getset); - SessionType.tp_getset = NULL; + if(py3270_session_type.tp_getset) { + free(py3270_session_type.tp_getset); + py3270_session_type.tp_getset = NULL; } } diff --git a/src/session/actions.cc b/src/session/actions.cc new file mode 100644 index 0000000..cffd5d6 --- /dev/null +++ b/src/session/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 + +/*---[ 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/session/attributes.cc b/src/session/attributes.cc new file mode 100644 index 0000000..7f5c06b --- /dev/null +++ b/src/session/attributes.cc @@ -0,0 +1,92 @@ +/* + * "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 get.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 + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +PyObject * py3270_session_getter(PyObject *self, void *name) { + +// debug("%s(%s)",__FUNCTION__,(const char *) name); + + return py3270_session_call(self, [name](TN3270::Host &host){ + + auto attribute = host[(const char *) name]; + + switch(attribute.getType()) { + case TN3270::Attribute::String: + return PyUnicode_FromString(attribute.toString().c_str()); + + case TN3270::Attribute::Boolean: + return PyBool_FromLong(attribute.getBoolean()); + + case TN3270::Attribute::Uchar: + throw std::system_error(ENOTSUP, std::system_category()); + + case TN3270::Attribute::Int16: + throw std::system_error(ENOTSUP, std::system_category()); + + case TN3270::Attribute::Uint16: + throw std::system_error(ENOTSUP, std::system_category()); + + case TN3270::Attribute::Int32: + return PyLong_FromLong(attribute.getInt32()); + + case TN3270::Attribute::Int32x: + throw std::system_error(ENOTSUP, std::system_category()); + + case TN3270::Attribute::Uint32: + return PyLong_FromLong(attribute.getUint32()); + + case TN3270::Attribute::Int64: + throw std::system_error(ENOTSUP, std::system_category()); + + case TN3270::Attribute::Uint64: + throw std::system_error(ENOTSUP, std::system_category()); + + default: + throw runtime_error("Unexpected atttribute type"); + } + + return PyLong_FromLong(0); + + }); + +} + +int py3270_session_setter(PyObject *self, PyObject *value, void *name) { + + return 0; +} + diff --git a/src/session/get.cc b/src/session/get.cc new file mode 100644 index 0000000..d9616ac --- /dev/null +++ b/src/session/get.cc @@ -0,0 +1,95 @@ +/* + * "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 get.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 + + using std::string; + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + PyObject * py3270_session_get(PyObject *self, PyObject *args) { + + return py3270_session_call(self, [args](TN3270::Host &host){ + + string text; + + switch(PyTuple_Size(args)) { + case 0: // Get the entire screen + text = host.toString(); + break; + + case 2: // Address and length. + { + int baddr, length; + + if (!PyArg_ParseTuple(args, "ii", &baddr, &length)) + return (PyObject *) NULL; + + text = host.toString(baddr, length); + } + break; + + case 3: // Row, col and length + { + unsigned int row, col; + int length; + + if (!PyArg_ParseTuple(args, "IIi", &row, &col, &length)) + return (PyObject *) NULL; + + text = host.toString(row, col, length); + } + break; + + default: + throw std::system_error(EINVAL, std::system_category()); + + } + + return PyUnicode_FromString(text.c_str()); + + }); + + } + + PyObject * py3270_session_str(PyObject *self) { + + return py3270_session_call(self, [](TN3270::Host &host){ + + return PyUnicode_FromString(host.toString().c_str()); + + }); + + } + diff --git a/src/session/init.cc b/src/session/init.cc new file mode 100644 index 0000000..3e94c55 --- /dev/null +++ b/src/session/init.cc @@ -0,0 +1,253 @@ +/* + * "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 py3270.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) + * + * Implementa métodos básicos inicio/final do objeto python + * + * Referências: + * + * + * + * + */ + + #include + #include + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +static void cleanup(pySession * session) { + + if(session->host) { + delete session->host; + session->host = nullptr; + } + +} + +static void py3270_session_attribute_init(struct PyGetSetDef *attribute, const LIB3270_PROPERTY * descriptor) { + + attribute->name = (char *) descriptor->name; + attribute->doc = (char *) (descriptor->description ? descriptor->description : descriptor->summary); + +} + +void py3270_session_type_init(PyTypeObject *type) { + + // Load attributes + { + auto attributes = TN3270::getAttributes(); + auto actions = TN3270::getActions(); + size_t ix = 0; + + size_t szData = sizeof(struct PyGetSetDef) * (attributes.size() + actions.size() + 1); + + type->tp_getset = (struct PyGetSetDef *) malloc(szData); + memset(type->tp_getset,0,szData); + + for(auto attribute : attributes) { + +// debug("Creating attribute %s",attribute->name); + + py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) attribute); + + type->tp_getset[ix].get = py3270_session_getter; + type->tp_getset[ix].set = py3270_session_setter; + type->tp_getset[ix].closure = (void *) attribute->name; + + ix++; + + } + + 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; + type->tp_getset[ix].closure = (void *) action; + + ix++; + + } + } + + +} + + +int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) { + + pySession * session = (pySession *) self; + debug("%s session=%p host=%p",__FUNCTION__,session,session->host); + + try { + + cleanup(session); + + const char *id = ""; + + if (!PyArg_ParseTuple(args, "s", &id)) + id = ""; + + 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) { + + PyErr_SetString(PyExc_RuntimeError, e.what()); + + } catch(...) { + + PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module"); + + } + + return -1; + +} + +void py3270_session_finalize(PyObject *self) { + + debug("%s",__FUNCTION__); + cleanup((pySession *) self); + +} + +PyObject * py3270_session_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds) { + + debug("%s",__FUNCTION__); + return type->tp_alloc(type,0); + +} + +void py3270_session_dealloc(PyObject * self) { + + debug("%s",__FUNCTION__); + + cleanup((pySession *) 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/network.cc b/src/session/network.cc new file mode 100644 index 0000000..45b1ba1 --- /dev/null +++ b/src/session/network.cc @@ -0,0 +1,166 @@ +/* + * "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 misc.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) + * + * Implementa métodos básicos inicio/final do objeto python + * + * Referências: + * + * + * + * + */ + + #include + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + PyObject * py3270_session_connect(PyObject *self, PyObject *args) { + + return py3270_session_call(self, [args](TN3270::Host &host){ + + const char * url = ""; + + if(!PyArg_ParseTuple(args, "s", &url)) { + throw runtime_error("connect requires a host URL"); + } + + host.connect(url); + + return 0; + + }); + + } + + PyObject * py3270_session_disconnect(PyObject *self, PyObject *args) { + + return py3270_session_call(self, [args](TN3270::Host &host){ + + host.disconnect(); + + return 0; + + }); + + } + + +/* + PyObject * terminal_connect(PyObject *self, PyObject *args) { + + int rc = -1; + int wait = 60; + const char * host = ""; + + if (!PyArg_ParseTuple(args, "s|i", &host, &wait)) { + PyErr_SetString(terminalError, "connect requires a host URL"); + return NULL; + } + + try { + + rc = ((pw3270_TerminalObject *) self)->session->connect(host,wait); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + return PyLong_FromLong(rc); + + } + + PyObject * terminal_disconnect(PyObject *self, PyObject *args) { + + int rc = -1; + + try { + + rc = ((pw3270_TerminalObject *) self)->session->disconnect(); + + } catch(std::exception &e) { + + PyErr_SetString(terminalError, e.what()); + return NULL; + } + + 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/session/set.cc b/src/session/set.cc new file mode 100644 index 0000000..aa45e43 --- /dev/null +++ b/src/session/set.cc @@ -0,0 +1,141 @@ +/* + * "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 + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + PyObject * py3270_session_set(PyObject *self, PyObject *args) { + + return py3270_session_call(self, [args](TN3270::Host &host){ + + switch(PyTuple_Size(args)) { + case 1: // Only text. + { + const char *text; + + if(!PyArg_ParseTuple(args, "s", &text)) + return (PyObject *) NULL; + + host.push(text,-1); + + } + break; + + case 2: // Address and text. + { + int baddr; + const char *text; + + if(!PyArg_ParseTuple(args, "is", &baddr, &text)) + return (PyObject *) NULL; + + host.push(baddr, text); + } + break; + + case 3: // Row, col and text + { + unsigned int row, col; + const char *text; + + if (!PyArg_ParseTuple(args, "IIs", &row, &col, &text)) + return (PyObject *) NULL; + + host.push(row,col,text); + + } + break; + + default: + throw std::system_error(EINVAL, std::system_category()); + + } + + return PyLong_FromLong(0); + + }); + + } + + +/* + 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); + + } + +*/ diff --git a/src/session/type.c b/src/session/type.c new file mode 100644 index 0000000..d916dba --- /dev/null +++ b/src/session/type.c @@ -0,0 +1,96 @@ +/* + * "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 py3270.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 + +/*---[ Globals ]------------------------------------------------------------------------------------*/ + +static PyMethodDef py3270_session_methods[] = { + { + "connect", + (PyCFunction) py3270_session_connect, + METH_VARARGS, + "" + }, + + { + "disconnect", + (PyCFunction) py3270_session_disconnect, + METH_NOARGS, + "" + }, + + { + "set", + (PyCFunction) py3270_session_set, + METH_VARARGS, + "" + }, + + { + "get", + (PyCFunction) py3270_session_get, + METH_VARARGS, + "" + }, + + { + NULL + } +}; + +// https://docs.python.org/3/c-api/typeobj.html +PyTypeObject py3270_session_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "tn3270.Session", + .tp_doc = "TN3270 Session Object", + .tp_basicsize = sizeof(pySession), + .tp_itemsize = 0, + .tp_flags = Py_TPFLAGS_HAVE_FINALIZE|Py_TPFLAGS_DEFAULT, + + .tp_new = py3270_session_alloc, + .tp_dealloc = py3270_session_dealloc, + + .tp_init = py3270_session_init, + .tp_finalize = py3270_session_finalize, + + .tp_str = py3270_session_str, + + .tp_methods = py3270_session_methods, + +}; + + diff --git a/src/terminal/actions.cc b/src/terminal/actions.cc deleted file mode 100644 index cffd5d6..0000000 --- a/src/terminal/actions.cc +++ /dev/null @@ -1,129 +0,0 @@ -/* - * "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 - -/*---[ 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/terminal/attributes.cc b/src/terminal/attributes.cc deleted file mode 100644 index 7f5c06b..0000000 --- a/src/terminal/attributes.cc +++ /dev/null @@ -1,92 +0,0 @@ -/* - * "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 get.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 - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - -PyObject * py3270_session_getter(PyObject *self, void *name) { - -// debug("%s(%s)",__FUNCTION__,(const char *) name); - - return py3270_session_call(self, [name](TN3270::Host &host){ - - auto attribute = host[(const char *) name]; - - switch(attribute.getType()) { - case TN3270::Attribute::String: - return PyUnicode_FromString(attribute.toString().c_str()); - - case TN3270::Attribute::Boolean: - return PyBool_FromLong(attribute.getBoolean()); - - case TN3270::Attribute::Uchar: - throw std::system_error(ENOTSUP, std::system_category()); - - case TN3270::Attribute::Int16: - throw std::system_error(ENOTSUP, std::system_category()); - - case TN3270::Attribute::Uint16: - throw std::system_error(ENOTSUP, std::system_category()); - - case TN3270::Attribute::Int32: - return PyLong_FromLong(attribute.getInt32()); - - case TN3270::Attribute::Int32x: - throw std::system_error(ENOTSUP, std::system_category()); - - case TN3270::Attribute::Uint32: - return PyLong_FromLong(attribute.getUint32()); - - case TN3270::Attribute::Int64: - throw std::system_error(ENOTSUP, std::system_category()); - - case TN3270::Attribute::Uint64: - throw std::system_error(ENOTSUP, std::system_category()); - - default: - throw runtime_error("Unexpected atttribute type"); - } - - return PyLong_FromLong(0); - - }); - -} - -int py3270_session_setter(PyObject *self, PyObject *value, void *name) { - - return 0; -} - diff --git a/src/terminal/get.cc b/src/terminal/get.cc deleted file mode 100644 index d9616ac..0000000 --- a/src/terminal/get.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* - * "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 get.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 - - using std::string; - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - - PyObject * py3270_session_get(PyObject *self, PyObject *args) { - - return py3270_session_call(self, [args](TN3270::Host &host){ - - string text; - - switch(PyTuple_Size(args)) { - case 0: // Get the entire screen - text = host.toString(); - break; - - case 2: // Address and length. - { - int baddr, length; - - if (!PyArg_ParseTuple(args, "ii", &baddr, &length)) - return (PyObject *) NULL; - - text = host.toString(baddr, length); - } - break; - - case 3: // Row, col and length - { - unsigned int row, col; - int length; - - if (!PyArg_ParseTuple(args, "IIi", &row, &col, &length)) - return (PyObject *) NULL; - - text = host.toString(row, col, length); - } - break; - - default: - throw std::system_error(EINVAL, std::system_category()); - - } - - return PyUnicode_FromString(text.c_str()); - - }); - - } - - PyObject * py3270_session_str(PyObject *self) { - - return py3270_session_call(self, [](TN3270::Host &host){ - - return PyUnicode_FromString(host.toString().c_str()); - - }); - - } - diff --git a/src/terminal/init.cc b/src/terminal/init.cc deleted file mode 100644 index f22a19f..0000000 --- a/src/terminal/init.cc +++ /dev/null @@ -1,211 +0,0 @@ -/* - * "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 py3270.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) - * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: - * - * - * - * - */ - - #include - #include - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - -static void cleanup(pySession * session) { - - if(session->host) { - delete session->host; - session->host = nullptr; - } - -} - -void py3270_session_type_init(PyTypeObject *type) { - - // Load lib3270's attributes - { - auto attributes = TN3270::getAttributes(); - size_t szData = sizeof(struct PyGetSetDef) * (attributes.size()+1); - - type->tp_getset = (struct PyGetSetDef *) malloc(szData); - memset(type->tp_getset,0,szData); - - size_t ix = 0; - for(auto attribute : attributes) { - -// debug("Creating attribute %s",attribute->name); - - type->tp_getset[ix].name = (char *) attribute->name; - type->tp_getset[ix].doc = (char *) (attribute->description ? attribute->description : attribute->summary); - type->tp_getset[ix].get = py3270_session_getter; - type->tp_getset[ix].set = py3270_session_setter; - type->tp_getset[ix].closure = (void *) attribute->name; - ix++; - } - - - } - -} - - -int py3270_session_init(PyObject *self, PyObject *args, PyObject *kwds) { - - pySession * session = (pySession *) self; - debug("%s session=%p host=%p",__FUNCTION__,session,session->host); - - try { - - cleanup(session); - - const char *id = ""; - - if (!PyArg_ParseTuple(args, "s", &id)) - id = ""; - - session->host = new TN3270::Host(id); - - return 0; - - } catch(const std::exception &e) { - - PyErr_SetString(PyExc_RuntimeError, e.what()); - - } catch(...) { - - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module"); - - } - - return -1; - -} - -void py3270_session_finalize(PyObject *self) { - - debug("%s",__FUNCTION__); - cleanup((pySession *) self); - -} - -PyObject * py3270_session_alloc(PyTypeObject *type, PyObject *args, PyObject *kwds) { - - debug("%s",__FUNCTION__); - return type->tp_alloc(type,0); - -} - -void py3270_session_dealloc(PyObject * self) { - - debug("%s",__FUNCTION__); - - cleanup((pySession *) 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/terminal/network.cc b/src/terminal/network.cc deleted file mode 100644 index 45b1ba1..0000000 --- a/src/terminal/network.cc +++ /dev/null @@ -1,166 +0,0 @@ -/* - * "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 misc.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) - * - * Implementa métodos básicos inicio/final do objeto python - * - * Referências: - * - * - * - * - */ - - #include - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - - PyObject * py3270_session_connect(PyObject *self, PyObject *args) { - - return py3270_session_call(self, [args](TN3270::Host &host){ - - const char * url = ""; - - if(!PyArg_ParseTuple(args, "s", &url)) { - throw runtime_error("connect requires a host URL"); - } - - host.connect(url); - - return 0; - - }); - - } - - PyObject * py3270_session_disconnect(PyObject *self, PyObject *args) { - - return py3270_session_call(self, [args](TN3270::Host &host){ - - host.disconnect(); - - return 0; - - }); - - } - - -/* - PyObject * terminal_connect(PyObject *self, PyObject *args) { - - int rc = -1; - int wait = 60; - const char * host = ""; - - if (!PyArg_ParseTuple(args, "s|i", &host, &wait)) { - PyErr_SetString(terminalError, "connect requires a host URL"); - return NULL; - } - - try { - - rc = ((pw3270_TerminalObject *) self)->session->connect(host,wait); - - } catch(std::exception &e) { - - PyErr_SetString(terminalError, e.what()); - return NULL; - } - - return PyLong_FromLong(rc); - - } - - PyObject * terminal_disconnect(PyObject *self, PyObject *args) { - - int rc = -1; - - try { - - rc = ((pw3270_TerminalObject *) self)->session->disconnect(); - - } catch(std::exception &e) { - - PyErr_SetString(terminalError, e.what()); - return NULL; - } - - 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/terminal/set.cc b/src/terminal/set.cc deleted file mode 100644 index aa45e43..0000000 --- a/src/terminal/set.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* - * "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 - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - - PyObject * py3270_session_set(PyObject *self, PyObject *args) { - - return py3270_session_call(self, [args](TN3270::Host &host){ - - switch(PyTuple_Size(args)) { - case 1: // Only text. - { - const char *text; - - if(!PyArg_ParseTuple(args, "s", &text)) - return (PyObject *) NULL; - - host.push(text,-1); - - } - break; - - case 2: // Address and text. - { - int baddr; - const char *text; - - if(!PyArg_ParseTuple(args, "is", &baddr, &text)) - return (PyObject *) NULL; - - host.push(baddr, text); - } - break; - - case 3: // Row, col and text - { - unsigned int row, col; - const char *text; - - if (!PyArg_ParseTuple(args, "IIs", &row, &col, &text)) - return (PyObject *) NULL; - - host.push(row,col,text); - - } - break; - - default: - throw std::system_error(EINVAL, std::system_category()); - - } - - return PyLong_FromLong(0); - - }); - - } - - -/* - 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); - - } - -*/ diff --git a/testprograms/sample.py b/testprograms/sample.py index 7b1ca04..e6fca32 100644 --- a/testprograms/sample.py +++ b/testprograms/sample.py @@ -1,7 +1,7 @@ #!/usr/bin/python #-*- coding: utf-8 -import inspect +#import inspect import tn3270 print("Using TN3270 Version " + tn3270.version()) @@ -16,25 +16,25 @@ print(session.width) print(session.connected) print(session.url) -session.connect('') +#session.connect('') print(session.connected) -#print('----------------------') -#print(dir(session)) -#print('----------------------') +print('----------------------') +print(dir(session)) +print('----------------------') #print(session.get(14,22,38)) -print("-----------------------------------------------------------------------") -print(session) -print("-----------------------------------------------------------------------") +#print("-----------------------------------------------------------------------") +#print(session) +#print("-----------------------------------------------------------------------") -session.set("value") +#session.set("value") -print("-----------------------------------------------------------------------") -print(session) -print("-----------------------------------------------------------------------") +#print("-----------------------------------------------------------------------") +#print(session) +#print("-----------------------------------------------------------------------") del session input("Press enter to exit") -- libgit2 0.21.2