Commit 45611798f7352fb86b48b42fbf799b208daa032e
1 parent
09e47663
Exists in
master
Adding "set" methods.
Showing
5 changed files
with
70 additions
and
205 deletions
Show diff stats
src/include/py3270.h
| ... | ... | @@ -117,6 +117,7 @@ |
| 117 | 117 | DLL_PRIVATE PyObject * py3270_session_disconnect(PyObject *self, PyObject *args); |
| 118 | 118 | |
| 119 | 119 | DLL_PRIVATE PyObject * py3270_session_get(PyObject *self, PyObject *args); |
| 120 | + DLL_PRIVATE PyObject * py3270_session_set(PyObject *self, PyObject *args); | |
| 120 | 121 | DLL_PRIVATE PyObject * py3270_session_str(PyObject *self); |
| 121 | 122 | |
| 122 | 123 | /* | ... | ... |
src/module/init.c
src/terminal/get.cc
| ... | ... | @@ -83,7 +83,7 @@ |
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - DLL_PRIVATE PyObject * py3270_session_str(PyObject *self) { | |
| 86 | + PyObject * py3270_session_str(PyObject *self) { | |
| 87 | 87 | |
| 88 | 88 | return py3270_session_call(self, [](TN3270::Host &host){ |
| 89 | 89 | |
| ... | ... | @@ -93,205 +93,3 @@ |
| 93 | 93 | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - | |
| 97 | - /* | |
| 98 | -DLL_PRIVATE PyObject * py3270_session_getattr(PyObject *self, char *attr_name) { | |
| 99 | - | |
| 100 | - PyObject * rc = NULL; | |
| 101 | - | |
| 102 | - printf("\n\n*************%s(%s)\n\n",__FUNCTION__,attr_name); | |
| 103 | - | |
| 104 | - try { | |
| 105 | - | |
| 106 | - TN3270::Property * property = ((pySession * ) self)->host->getProperty(attr_name); | |
| 107 | - | |
| 108 | - try { | |
| 109 | - | |
| 110 | - switch(property->getType()) { | |
| 111 | - case TN3270::Property::String: | |
| 112 | - rc = PyUnicode_FromString(property->toString().c_str()); | |
| 113 | - break; | |
| 114 | - | |
| 115 | - case TN3270::Property::Boolean: | |
| 116 | - rc = PyBool_FromLong(property->toBool()); | |
| 117 | - break; | |
| 118 | - | |
| 119 | - case TN3270::Property::Uchar: | |
| 120 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 121 | - break; | |
| 122 | - | |
| 123 | - case TN3270::Property::Int16: | |
| 124 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 125 | - break; | |
| 126 | - | |
| 127 | - case TN3270::Property::Uint16: | |
| 128 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 129 | - break; | |
| 130 | - | |
| 131 | - case TN3270::Property::Int32: | |
| 132 | - rc = PyLong_FromLong(property->toInt32()); | |
| 133 | - break; | |
| 134 | - | |
| 135 | - case TN3270::Property::Int32x: | |
| 136 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 137 | - break; | |
| 138 | - | |
| 139 | - case TN3270::Property::Uint32: | |
| 140 | - rc = PyLong_FromLong(property->toUint32()); | |
| 141 | - break; | |
| 142 | - | |
| 143 | - case TN3270::Property::Int64: | |
| 144 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 145 | - break; | |
| 146 | - | |
| 147 | - case TN3270::Property::Uint64: | |
| 148 | - throw std::system_error(ENOTSUP, std::system_category()); | |
| 149 | - break; | |
| 150 | - | |
| 151 | - default: | |
| 152 | - throw runtime_error("Unexpected property type"); | |
| 153 | - } | |
| 154 | - | |
| 155 | - } catch(...) { | |
| 156 | - | |
| 157 | - delete property; | |
| 158 | - throw; | |
| 159 | - | |
| 160 | - } | |
| 161 | - | |
| 162 | - delete property; | |
| 163 | - | |
| 164 | - } catch(const exception &e) { | |
| 165 | - | |
| 166 | - PyErr_SetString(PyExc_RuntimeError, e.what()); | |
| 167 | - | |
| 168 | - } catch( ... ) { | |
| 169 | - | |
| 170 | - PyErr_SetString(PyExc_RuntimeError, "Unexpected error in core module"); | |
| 171 | - | |
| 172 | - } | |
| 173 | - | |
| 174 | - return rc; | |
| 175 | - | |
| 176 | -} | |
| 177 | -*/ | |
| 178 | - | |
| 179 | - | |
| 180 | -/* | |
| 181 | -PyObject * terminal_get_version(PyObject *self, PyObject *args) { | |
| 182 | - | |
| 183 | - return PyString_FromString( ((pw3270_TerminalObject *) self)->session->get_version().c_str() ); | |
| 184 | - | |
| 185 | -} | |
| 186 | - | |
| 187 | -PyObject * terminal_get_revision(PyObject *self, PyObject *args) { | |
| 188 | - | |
| 189 | - return PyString_FromString( ((pw3270_TerminalObject *) self)->session->get_revision().c_str() ); | |
| 190 | - | |
| 191 | -} | |
| 192 | - | |
| 193 | -PyObject * terminal_is_connected(PyObject *self, PyObject *args) { | |
| 194 | - | |
| 195 | - return PyBool_FromLong( ((pw3270_TerminalObject *) self)->session->is_connected() ); | |
| 196 | - | |
| 197 | -} | |
| 198 | - | |
| 199 | -PyObject * terminal_is_ready(PyObject *self, PyObject *args) { | |
| 200 | - | |
| 201 | - return PyBool_FromLong( ((pw3270_TerminalObject *) self)->session->is_ready() ); | |
| 202 | - | |
| 203 | -} | |
| 204 | - | |
| 205 | -PyObject * terminal_is_protected_at(PyObject *self, PyObject *args) { | |
| 206 | - | |
| 207 | - int rc, row, col; | |
| 208 | - | |
| 209 | - if (!PyArg_ParseTuple(args, "ii", &row, &col)) { | |
| 210 | - PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 211 | - return NULL; | |
| 212 | - } | |
| 213 | - | |
| 214 | - try { | |
| 215 | - | |
| 216 | - rc = ((pw3270_TerminalObject *) self)->session->get_is_protected_at(row,col); | |
| 217 | - | |
| 218 | - } catch(std::exception &e) { | |
| 219 | - | |
| 220 | - PyErr_SetString(terminalError, e.what()); | |
| 221 | - return NULL; | |
| 222 | - } | |
| 223 | - | |
| 224 | - return PyBool_FromLong( rc ); | |
| 225 | - | |
| 226 | -} | |
| 227 | - | |
| 228 | - | |
| 229 | -PyObject * terminal_cmp_string_at(PyObject *self, PyObject *args) { | |
| 230 | - | |
| 231 | - int row, col, rc; | |
| 232 | - const char *text; | |
| 233 | - | |
| 234 | - if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) { | |
| 235 | - PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 236 | - return NULL; | |
| 237 | - } | |
| 238 | - | |
| 239 | - try { | |
| 240 | - | |
| 241 | - rc = ((pw3270_TerminalObject *) self)->session->cmp_string_at(row,col,text); | |
| 242 | - | |
| 243 | - } catch(std::exception &e) { | |
| 244 | - | |
| 245 | - PyErr_SetString(terminalError, e.what()); | |
| 246 | - return NULL; | |
| 247 | - } | |
| 248 | - | |
| 249 | - return PyLong_FromLong(rc); | |
| 250 | - | |
| 251 | -} | |
| 252 | - | |
| 253 | -PyObject * terminal_get_string_at(PyObject *self, PyObject *args) { | |
| 254 | - | |
| 255 | - int row, col, sz; | |
| 256 | - string rc; | |
| 257 | - | |
| 258 | - if (!PyArg_ParseTuple(args, "iii", &row, &col, &sz)) { | |
| 259 | - PyErr_SetString(terminalError, strerror(EINVAL)); | |
| 260 | - return NULL; | |
| 261 | - } | |
| 262 | - | |
| 263 | - try { | |
| 264 | - | |
| 265 | - rc = ((pw3270_TerminalObject *) self)->session->get_string_at(row,col,sz); | |
| 266 | - | |
| 267 | - } catch(std::exception &e) { | |
| 268 | - | |
| 269 | - PyErr_SetString(terminalError, e.what()); | |
| 270 | - return NULL; | |
| 271 | - } | |
| 272 | - | |
| 273 | - return PyString_FromString(rc.c_str()); | |
| 274 | - | |
| 275 | -} | |
| 276 | - | |
| 277 | -PyObject * terminal_get_contents(PyObject *self) { | |
| 278 | - | |
| 279 | - string rc; | |
| 280 | - | |
| 281 | - try { | |
| 282 | - | |
| 283 | - rc = ((pw3270_TerminalObject *) self)->session->get_string(); | |
| 284 | - | |
| 285 | - } catch(std::exception &e) { | |
| 286 | - | |
| 287 | - PyErr_SetString(terminalError, e.what()); | |
| 288 | - return NULL; | |
| 289 | - } | |
| 290 | - | |
| 291 | - return PyString_FromString(rc.c_str()); | |
| 292 | - | |
| 293 | - | |
| 294 | - | |
| 295 | -} | |
| 296 | - | |
| 297 | -*/ | ... | ... |
src/terminal/set.cc
| ... | ... | @@ -36,6 +36,59 @@ |
| 36 | 36 | |
| 37 | 37 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 38 | 38 | |
| 39 | + PyObject * py3270_session_set(PyObject *self, PyObject *args) { | |
| 40 | + | |
| 41 | + return py3270_session_call(self, [args](TN3270::Host &host){ | |
| 42 | + | |
| 43 | + switch(PyTuple_Size(args)) { | |
| 44 | + case 1: // Only text. | |
| 45 | + { | |
| 46 | + const char *text; | |
| 47 | + | |
| 48 | + if(!PyArg_ParseTuple(args, "s", &text)) | |
| 49 | + return (PyObject *) NULL; | |
| 50 | + | |
| 51 | + host.push(text,-1); | |
| 52 | + | |
| 53 | + } | |
| 54 | + break; | |
| 55 | + | |
| 56 | + case 2: // Address and text. | |
| 57 | + { | |
| 58 | + int baddr; | |
| 59 | + const char *text; | |
| 60 | + | |
| 61 | + if(!PyArg_ParseTuple(args, "is", &baddr, &text)) | |
| 62 | + return (PyObject *) NULL; | |
| 63 | + | |
| 64 | + host.push(baddr, text); | |
| 65 | + } | |
| 66 | + break; | |
| 67 | + | |
| 68 | + case 3: // Row, col and text | |
| 69 | + { | |
| 70 | + unsigned int row, col; | |
| 71 | + const char *text; | |
| 72 | + | |
| 73 | + if (!PyArg_ParseTuple(args, "IIs", &row, &col, &text)) | |
| 74 | + return (PyObject *) NULL; | |
| 75 | + | |
| 76 | + host.push(row,col,text); | |
| 77 | + | |
| 78 | + } | |
| 79 | + break; | |
| 80 | + | |
| 81 | + default: | |
| 82 | + throw std::system_error(EINVAL, std::system_category()); | |
| 83 | + | |
| 84 | + } | |
| 85 | + | |
| 86 | + return PyLong_FromLong(0); | |
| 87 | + | |
| 88 | + }); | |
| 89 | + | |
| 90 | + } | |
| 91 | + | |
| 39 | 92 | |
| 40 | 93 | /* |
| 41 | 94 | PyObject * terminal_set_string_at(PyObject *self, PyObject *args) { | ... | ... |
testprograms/sample.py
| ... | ... | @@ -26,9 +26,15 @@ print(session.connected) |
| 26 | 26 | |
| 27 | 27 | #print(session.get(14,22,38)) |
| 28 | 28 | |
| 29 | -#print "-----------------------------------------------------------------------" | |
| 29 | +print("-----------------------------------------------------------------------") | |
| 30 | 30 | print(session) |
| 31 | -#print "-----------------------------------------------------------------------" | |
| 31 | +print("-----------------------------------------------------------------------") | |
| 32 | + | |
| 33 | +session.set("value") | |
| 34 | + | |
| 35 | +print("-----------------------------------------------------------------------") | |
| 36 | +print(session) | |
| 37 | +print("-----------------------------------------------------------------------") | |
| 32 | 38 | |
| 33 | 39 | del session |
| 34 | 40 | input("Press enter to exit") | ... | ... |