diff --git a/src/include/py3270.h b/src/include/py3270.h index b3287af..fbfbee5 100644 --- a/src/include/py3270.h +++ b/src/include/py3270.h @@ -117,6 +117,7 @@ DLL_PRIVATE PyObject * py3270_session_disconnect(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); /* diff --git a/src/module/init.c b/src/module/init.c index 757a468..ab557c6 100644 --- a/src/module/init.c +++ b/src/module/init.c @@ -88,6 +88,13 @@ static PyMethodDef py3270_session_methods[] = { }, { + "set", + (PyCFunction) py3270_session_set, + METH_VARARGS, + "" + }, + + { "get", (PyCFunction) py3270_session_get, METH_VARARGS, diff --git a/src/terminal/get.cc b/src/terminal/get.cc index e58ca5d..d9616ac 100644 --- a/src/terminal/get.cc +++ b/src/terminal/get.cc @@ -83,7 +83,7 @@ } - DLL_PRIVATE PyObject * py3270_session_str(PyObject *self) { + PyObject * py3270_session_str(PyObject *self) { return py3270_session_call(self, [](TN3270::Host &host){ @@ -93,205 +93,3 @@ } - - /* -DLL_PRIVATE PyObject * py3270_session_getattr(PyObject *self, char *attr_name) { - - PyObject * rc = NULL; - - printf("\n\n*************%s(%s)\n\n",__FUNCTION__,attr_name); - - try { - - TN3270::Property * property = ((pySession * ) self)->host->getProperty(attr_name); - - try { - - switch(property->getType()) { - case TN3270::Property::String: - rc = PyUnicode_FromString(property->toString().c_str()); - break; - - case TN3270::Property::Boolean: - rc = PyBool_FromLong(property->toBool()); - break; - - case TN3270::Property::Uchar: - throw std::system_error(ENOTSUP, std::system_category()); - break; - - case TN3270::Property::Int16: - throw std::system_error(ENOTSUP, std::system_category()); - break; - - case TN3270::Property::Uint16: - throw std::system_error(ENOTSUP, std::system_category()); - break; - - case TN3270::Property::Int32: - rc = PyLong_FromLong(property->toInt32()); - break; - - case TN3270::Property::Int32x: - throw std::system_error(ENOTSUP, std::system_category()); - break; - - case TN3270::Property::Uint32: - rc = PyLong_FromLong(property->toUint32()); - break; - - case TN3270::Property::Int64: - throw std::system_error(ENOTSUP, std::system_category()); - break; - - case TN3270::Property::Uint64: - throw std::system_error(ENOTSUP, std::system_category()); - break; - - default: - throw runtime_error("Unexpected property type"); - } - - } catch(...) { - - delete property; - throw; - - } - - delete property; - - } catch(const exception &e) { - - PyErr_SetString(PyExc_RuntimeError, e.what()); - - } catch( ... ) { - - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module"); - - } - - return rc; - -} -*/ - - -/* -PyObject * terminal_get_version(PyObject *self, PyObject *args) { - - return PyString_FromString( ((pw3270_TerminalObject *) self)->session->get_version().c_str() ); - -} - -PyObject * terminal_get_revision(PyObject *self, PyObject *args) { - - return PyString_FromString( ((pw3270_TerminalObject *) self)->session->get_revision().c_str() ); - -} - -PyObject * terminal_is_connected(PyObject *self, PyObject *args) { - - return PyBool_FromLong( ((pw3270_TerminalObject *) self)->session->is_connected() ); - -} - -PyObject * terminal_is_ready(PyObject *self, PyObject *args) { - - return PyBool_FromLong( ((pw3270_TerminalObject *) self)->session->is_ready() ); - -} - -PyObject * terminal_is_protected_at(PyObject *self, PyObject *args) { - - int rc, row, col; - - if (!PyArg_ParseTuple(args, "ii", &row, &col)) { - PyErr_SetString(terminalError, strerror(EINVAL)); - return NULL; - } - - try { - - rc = ((pw3270_TerminalObject *) self)->session->get_is_protected_at(row,col); - - } catch(std::exception &e) { - - PyErr_SetString(terminalError, e.what()); - return NULL; - } - - return PyBool_FromLong( rc ); - -} - - -PyObject * terminal_cmp_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->cmp_string_at(row,col,text); - - } catch(std::exception &e) { - - PyErr_SetString(terminalError, e.what()); - return NULL; - } - - return PyLong_FromLong(rc); - -} - -PyObject * terminal_get_string_at(PyObject *self, PyObject *args) { - - int row, col, sz; - string rc; - - if (!PyArg_ParseTuple(args, "iii", &row, &col, &sz)) { - PyErr_SetString(terminalError, strerror(EINVAL)); - return NULL; - } - - try { - - rc = ((pw3270_TerminalObject *) self)->session->get_string_at(row,col,sz); - - } catch(std::exception &e) { - - PyErr_SetString(terminalError, e.what()); - return NULL; - } - - return PyString_FromString(rc.c_str()); - -} - -PyObject * terminal_get_contents(PyObject *self) { - - string rc; - - try { - - rc = ((pw3270_TerminalObject *) self)->session->get_string(); - - } catch(std::exception &e) { - - PyErr_SetString(terminalError, e.what()); - return NULL; - } - - return PyString_FromString(rc.c_str()); - - - -} - -*/ diff --git a/src/terminal/set.cc b/src/terminal/set.cc index 86b752c..aa45e43 100644 --- a/src/terminal/set.cc +++ b/src/terminal/set.cc @@ -36,6 +36,59 @@ /*---[ 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) { diff --git a/testprograms/sample.py b/testprograms/sample.py index 250b203..7b1ca04 100644 --- a/testprograms/sample.py +++ b/testprograms/sample.py @@ -26,9 +26,15 @@ print(session.connected) #print(session.get(14,22,38)) -#print "-----------------------------------------------------------------------" +print("-----------------------------------------------------------------------") print(session) -#print "-----------------------------------------------------------------------" +print("-----------------------------------------------------------------------") + +session.set("value") + +print("-----------------------------------------------------------------------") +print(session) +print("-----------------------------------------------------------------------") del session input("Press enter to exit") -- libgit2 0.21.2