diff --git a/py3270.cbp b/py3270.cbp
index a58e063..087777e 100644
--- a/py3270.cbp
+++ b/py3270.cbp
@@ -43,6 +43,7 @@
+
@@ -65,6 +66,7 @@
+
diff --git a/src/action/init.cc b/src/action/init.cc
index 1cd311b..8f47441 100644
--- a/src/action/init.cc
+++ b/src/action/init.cc
@@ -45,33 +45,4 @@ void py3270_action_type_init(PyTypeObject *type) {
}
-static void cleanup(pyAction * self) {
-
- if(self->action) {
- delete self->action;
- self->action = nullptr;
- }
-
-}
-
-void py3270_action_dealloc(PyObject * self) {
- debug("%s",__FUNCTION__);
- cleanup((pyAction *) self);
-}
-
-void py3270_action_finalize(PyObject *self) {
- debug("%s",__FUNCTION__);
- cleanup((pyAction *) self);
-}
-
-PyObject * py3270_action_activatable(PyObject *self, PyObject *args) {
-
- return py3270_action_call(self, [](TN3270::Action &action) {
-
- return PyBool_FromLong(action.activatable());
-
- });
-
-
-}
diff --git a/src/action/methods.cc b/src/action/methods.cc
new file mode 100644
index 0000000..c784d10
--- /dev/null
+++ b/src/action/methods.cc
@@ -0,0 +1,132 @@
+/*
+ * "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
+ #include
+
+/*---[ Implement ]----------------------------------------------------------------------------------*/
+
+PyObject * py3270_action_call(PyObject *self, PyObject *args, PyObject *kwargs) {
+
+ return py3270_action_activate(self,args);
+
+}
+
+PyObject * py3270_action_describe(PyObject *self, PyObject *obj, PyObject *type) {
+
+ return py3270_action_call(self, [](TN3270::Action &action) {
+
+ return (PyObject *) PyUnicode_FromString(action.getDescription());
+
+ });
+
+}
+
+PyObject * py3270_action_activate(PyObject *self, PyObject *args) {
+
+ return py3270_action_call(self, [args, self](TN3270::Action &action) {
+
+ if(PyTuple_Size(args) == 1) {
+
+ unsigned int seconds;
+
+ if (!PyArg_ParseTuple(args, "I", &seconds))
+ return (PyObject *) NULL;
+
+ action.activate();
+ action.wait(seconds);
+
+ } else {
+
+ action.activate();
+
+ }
+
+ Py_INCREF(self);
+ return self;
+
+ });
+
+}
+
+PyObject * py3270_action_get_activatable(PyObject *self, void *dunno) {
+
+ return py3270_action_call(self, [](TN3270::Action &action) {
+
+ return PyBool_FromLong(action.activatable());
+
+ });
+
+}
+
+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;
+
+ 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 6eaa940..8eb1ff2 100644
--- a/src/action/new.cc
+++ b/src/action/new.cc
@@ -29,8 +29,8 @@
*
* Referências:
*
- *
- *
+ *
+ *
*
*/
@@ -41,10 +41,29 @@
DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action) {
- pyAction * object = (pyAction *) _PyObject_New(&py3270_action_type);
+ pyAction * pObj = (pyAction *) _PyObject_New(&py3270_action_type);
+
+ pObj->session = session;
+ pObj->action = ((pySession *) session)->host->getAction((const LIB3270_ACTION *) action);
+
+ debug("%s: ob_refcnt@%p=%ld",__FUNCTION__,pObj,((PyObject *) pObj)->ob_refcnt);
- object->action = ((pySession *) session)->host->getAction((const LIB3270_ACTION *) action);
+ Py_INCREF(pObj->session);
- return (PyObject *) object;
+ return (PyObject *) pObj;
}
+
+void py3270_action_dealloc(PyObject * self) {
+
+ pyAction * pObj = (pyAction *) self;
+
+ debug("%s: %p",__FUNCTION__,self);
+
+ Py_DECREF(pObj->session);
+
+ delete pObj->action;
+ pObj->action = nullptr;
+
+}
+
diff --git a/src/action/tools.cc b/src/action/tools.cc
index b962941..aa54a4f 100644
--- a/src/action/tools.cc
+++ b/src/action/tools.cc
@@ -42,8 +42,7 @@ PyObject * py3270_action_call(PyObject *self, std::functionaction;
- return worker(*action);
+ return worker(* (((pyAction * ) self)->action));
} catch(const exception &e) {
@@ -51,7 +50,7 @@ PyObject * py3270_action_call(PyObject *self, std::functionname);
+// debug("Creating attribute %s",attribute->name);
py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) attribute);
@@ -84,7 +84,7 @@ void py3270_session_type_init(PyTypeObject *type) {
for(auto action : actions) {
- debug("Creating action %s",action->name);
+// debug("Creating action %s",action->name);
py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) action);
diff --git a/src/session/network.cc b/src/session/network.cc
index 45b1ba1..35ae310 100644
--- a/src/session/network.cc
+++ b/src/session/network.cc
@@ -56,19 +56,6 @@
}
- 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) {
diff --git a/src/session/type.c b/src/session/type.c
index d916dba..548235b 100644
--- a/src/session/type.c
+++ b/src/session/type.c
@@ -45,9 +45,9 @@ static PyMethodDef py3270_session_methods[] = {
},
{
- "disconnect",
- (PyCFunction) py3270_session_disconnect,
- METH_NOARGS,
+ "wait",
+ (PyCFunction) py3270_session_wait,
+ METH_VARARGS,
""
},
diff --git a/src/session/wait.cc b/src/session/wait.cc
new file mode 100644
index 0000000..9cb2b71
--- /dev/null
+++ b/src/session/wait.cc
@@ -0,0 +1,119 @@
+/*
+ * "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_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;
+
+ case 1: // Has argument, wait for it.
+ {
+ unsigned int seconds;
+
+ if(!PyArg_ParseTuple(args, "I", &seconds))
+ return (PyObject *) NULL;
+
+ host.waitForReady(seconds);
+ }
+ 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 f394373..e4aa4ac 100644
--- a/testprograms/sample.py
+++ b/testprograms/sample.py
@@ -11,10 +11,17 @@ session = tn3270.Session("")
print("Using tn3270 version " + session.version + " revision " + session.revision)
-print(session.cstate)
-print(session.width)
-print(session.connected)
-print(session.url)
+#print(session.cstate)
+#print(session.width)
+#print(session.connected)
+#print(session.url)
+
+#
+# Can reconnect? If yes do it!
+#
+if session.reconnect.activatable:
+ print("Reconnecting...")
+ session.reconnect().wait(10)
#session.connect('')
@@ -24,27 +31,21 @@ print(session.connected)
#print(dir(session))
#print('----------------------')
-test = session.reconnect
-print('----------------------')
-print(dir(test))
-print('----------------------')
-
-print(test.activatable())
+#print(session.get(14,22,38))
+print("-----------------------------------------------------------------------")
+print(session)
+print("-----------------------------------------------------------------------")
-#print(session.get(14,22,38))
+session.enter().wait(2)
-#print("-----------------------------------------------------------------------")
-#print(session)
-#print("-----------------------------------------------------------------------")
#session.set("value")
-#print("-----------------------------------------------------------------------")
-#print(session)
-#print("-----------------------------------------------------------------------")
+print("-----------------------------------------------------------------------")
+print(session)
+print("-----------------------------------------------------------------------")
-del session
input("Press enter to exit")
--
libgit2 0.21.2