diff --git a/py3270.cbp b/py3270.cbp
index 087777e..f16bfed 100644
--- a/py3270.cbp
+++ b/py3270.cbp
@@ -60,6 +60,7 @@
+
diff --git a/src/include/py3270.h b/src/include/py3270.h
index 963d8f4..ea493a6 100644
--- a/src/include/py3270.h
+++ b/src/include/py3270.h
@@ -116,6 +116,8 @@
DLL_PRIVATE PyTypeObject py3270_session_type;
DLL_PRIVATE PyTypeObject py3270_action_type;
+ DLL_PRIVATE const PyGetSetDef py3270_session_attributes[];
+
DLL_PRIVATE PyObject * py3270_get_module_version(PyObject *self, PyObject *args);
DLL_PRIVATE PyObject * py3270_get_module_revision(PyObject *self, PyObject *args);
@@ -133,12 +135,17 @@
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_get_timeout(PyObject *self, void *dunno);
+ DLL_PRIVATE int py3270_session_set_timeout(PyObject *self, PyObject *value, void *dunno);
+
DLL_PRIVATE PyObject * py3270_session_connect(PyObject *self, PyObject *args);
DLL_PRIVATE PyObject * py3270_session_get(PyObject *self, PyObject *args);
DLL_PRIVATE PyObject * py3270_session_set(PyObject *self, PyObject *args);
DLL_PRIVATE PyObject * py3270_session_str(PyObject *self);
DLL_PRIVATE PyObject * py3270_session_wait(PyObject *self, PyObject *args);
+ DLL_PRIVATE PyObject * py3270_session_find(PyObject *self, PyObject *args);
+ DLL_PRIVATE PyObject * py3270_session_count(PyObject *self, PyObject *args);
// Action object
DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *action);
diff --git a/src/session/attributes.cc b/src/session/attributes.cc
index 7f5c06b..50011fe 100644
--- a/src/session/attributes.cc
+++ b/src/session/attributes.cc
@@ -87,6 +87,39 @@ PyObject * py3270_session_getter(PyObject *self, void *name) {
int py3270_session_setter(PyObject *self, PyObject *value, void *name) {
+ try {
+
+ auto attribute = ((pySession * ) self)->host->getAttribute((const char *) name);
+
+ if(PyLong_Check(value)) {
+
+ // Is a long, use PyLong_AsUnsignedLong
+ attribute = (int) PyLong_AsUnsignedLong(value);
+
+ } else if(PyBool_Check(value)) {
+
+ // Is a boolean, use PyLong_AsUnsignedLong != 0
+ attribute = (bool) (PyLong_AsUnsignedLong(value) != 0);
+
+ } else if(PyUnicode_Check(value)) {
+
+ // Is a unicode string
+ attribute = (const char *) PyUnicode_AsUTF8AndSize(value,NULL);
+
+ }
+
+ } catch(const exception &e) {
+
+ PyErr_SetString(PyExc_RuntimeError, e.what());
+ return -1;
+
+ } catch( ... ) {
+
+ PyErr_SetString(PyExc_RuntimeError, "Unexpected error setting timeout");
+ return -1;
+
+ }
+
return 0;
}
diff --git a/src/session/get.cc b/src/session/get.cc
index d9616ac..28738c4 100644
--- a/src/session/get.cc
+++ b/src/session/get.cc
@@ -93,3 +93,12 @@
}
+ PyObject * py3270_session_get_timeout(PyObject *self, void *dunno) {
+
+ return py3270_session_call(self, [](TN3270::Host &host){
+
+ return PyLong_FromLong(host.getTimeout());
+
+ });
+
+ }
diff --git a/src/session/init.cc b/src/session/init.cc
index c3341cf..7794635 100644
--- a/src/session/init.cc
+++ b/src/session/init.cc
@@ -63,14 +63,25 @@ void py3270_session_type_init(PyTypeObject *type) {
auto actions = TN3270::getActions();
size_t ix = 0;
+ // Compute block size
size_t szData = sizeof(struct PyGetSetDef) * (attributes.size() + actions.size() + 1);
+ for(size_t i = 0; py3270_session_attributes[i].name; i++) {
+ szData += sizeof(struct PyGetSetDef);
+ }
+
+ // Allocate and clean
type->tp_getset = (struct PyGetSetDef *) malloc(szData);
memset(type->tp_getset,0,szData);
- for(auto attribute : attributes) {
+ // Copy internal attributes
+ for(size_t i = 0; py3270_session_attributes[i].name; i++) {
+ type->tp_getset[ix] = py3270_session_attributes[i];
+ ix++;
+ }
-// debug("Creating attribute %s",attribute->name);
+ // Copy lib3270's attributes
+ for(auto attribute : attributes) {
py3270_session_attribute_init(&type->tp_getset[ix], (const LIB3270_PROPERTY *) attribute);
diff --git a/src/session/misc.cc b/src/session/misc.cc
new file mode 100644
index 0000000..6e8f5bc
--- /dev/null
+++ b/src/session/misc.cc
@@ -0,0 +1,67 @@
+/*
+ * "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_find(PyObject *self, PyObject *args) {
+
+ return py3270_session_call(self, [self, args](TN3270::Host &host){
+
+ const char *text;
+
+ if(!PyArg_ParseTuple(args, "s", &text))
+ throw std::system_error(EINVAL, std::system_category());
+
+ return PyLong_FromLong(host.find(text));
+
+ });
+
+ }
+
+ PyObject * py3270_session_count(PyObject *self, PyObject *args) {
+
+ return py3270_session_call(self, [self, args](TN3270::Host &host){
+
+ const char *text;
+
+ if(!PyArg_ParseTuple(args, "s", &text))
+ throw std::system_error(EINVAL, std::system_category());
+
+ return PyLong_FromLong(host.count(text));
+
+ });
+
+ }
diff --git a/src/session/set.cc b/src/session/set.cc
index aa45e43..284146c 100644
--- a/src/session/set.cc
+++ b/src/session/set.cc
@@ -89,53 +89,35 @@
}
-
-/*
- 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;
- }
+ int py3270_session_set_timeout(PyObject *self, PyObject *value, void *dunno) {
try {
- rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text);
-
- } catch(std::exception &e) {
+ auto host = ((pySession * ) self)->host;
- PyErr_SetString(terminalError, e.what());
- return NULL;
- }
+ if(PyLong_Check(value)) {
- return PyLong_FromLong(rc);
+ host->setTimeout( (time_t) PyLong_AsUnsignedLong(value));
- }
+ } else {
- PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args) {
+ throw std::system_error(EINVAL, std::system_category());
- int row, col, rc;
+ }
- if (!PyArg_ParseTuple(args, "ii", &row, &col)) {
- PyErr_SetString(terminalError, strerror(EINVAL));
- return NULL;
- }
+ } catch(const exception &e) {
- try {
+ PyErr_SetString(PyExc_RuntimeError, e.what());
+ return -1;
- rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col);
+ } catch( ... ) {
- } catch(std::exception &e) {
+ PyErr_SetString(PyExc_RuntimeError, "Unexpected error setting timeout");
+ return -1;
- PyErr_SetString(terminalError, e.what());
- return NULL;
}
- return PyLong_FromLong(rc);
+ return 0;
}
-*/
diff --git a/src/session/type.c b/src/session/type.c
index 548235b..3c92bfa 100644
--- a/src/session/type.c
+++ b/src/session/type.c
@@ -66,10 +66,39 @@ static PyMethodDef py3270_session_methods[] = {
},
{
+ "find",
+ (PyCFunction) py3270_session_find,
+ METH_VARARGS,
+ ""
+ },
+
+ {
+ "count",
+ (PyCFunction) py3270_session_count,
+ METH_VARARGS,
+ ""
+ },
+
+ {
NULL
}
};
+
+const struct PyGetSetDef py3270_session_attributes[] = {
+
+ {
+ .name = "timeout",
+ .doc = "Timeout (in seconds) for host access",
+ .get = py3270_session_get_timeout,
+ .set = py3270_session_set_timeout
+ },
+
+ {
+ .name = NULL
+ }
+};
+
// https://docs.python.org/3/c-api/typeobj.html
PyTypeObject py3270_session_type = {
diff --git a/src/session/wait.cc b/src/session/wait.cc
index b534486..420d2e0 100644
--- a/src/session/wait.cc
+++ b/src/session/wait.cc
@@ -87,7 +87,6 @@
}
-
PyObject * py3270_session_wait(PyObject *self, PyObject *args) {
return py3270_session_call(self, [self, args](TN3270::Host &host){
@@ -100,4 +99,3 @@
});
}
-
diff --git a/testprograms/sample.py b/testprograms/sample.py
index f6cbd82..9eb41ba 100644
--- a/testprograms/sample.py
+++ b/testprograms/sample.py
@@ -7,25 +7,32 @@ import tn3270
print("Using TN3270 Version " + tn3270.version())
print(tn3270.revision())
-session = tn3270.Session(":a")
+session = tn3270.Session("")
+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)
+print(session.url)
+session.url = "http://www.google.com"
+print(session.url)
-print(session.reconnect)
+#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.connected)
+#print(session.find('sisbb'))
+#print(session.count('sisbb'))
#print('----------------------')
#print(dir(session))
@@ -33,17 +40,17 @@ print(session.connected)
#print(session.get(14,22,38))
-print("-----------------------------------------------------------------------")
-print(session)
-print("-----------------------------------------------------------------------")
+#print("-----------------------------------------------------------------------")
+#print(session)
+#print("-----------------------------------------------------------------------")
-session.enter().wait(14,2,"Senha")
+#session.enter().wait(14,2,"Senha")
-session.set("value")
+#session.set("value")
-print("-----------------------------------------------------------------------")
-print(session)
-print("-----------------------------------------------------------------------")
+#print("-----------------------------------------------------------------------")
+#print(session)
+#print("-----------------------------------------------------------------------")
input("Press enter to exit")
--
libgit2 0.21.2