Commit b6f8c26c427d1acadfbb2dd889777065a183c5df
1 parent
090ddd31
Exists in
master
Implementing "waitforstring" method.
Showing
5 changed files
with
46 additions
and
85 deletions
Show diff stats
src/action/methods.cc
... | ... | @@ -97,31 +97,9 @@ DLL_PRIVATE PyObject * py3270_action_wait(PyObject *self, PyObject *args) { |
97 | 97 | |
98 | 98 | return py3270_action_call(self, [args, self](TN3270::Action &action) { |
99 | 99 | |
100 | - switch(PyTuple_Size(args)) { | |
101 | - case 0: | |
102 | - action.wait(); | |
103 | - break; | |
100 | + py3270_wait( * ((pyAction *) self)->session->host, args); | |
104 | 101 | |
105 | - case 1: | |
106 | - { | |
107 | - unsigned int seconds; | |
108 | - | |
109 | - if (!PyArg_ParseTuple(args, "I", &seconds)) | |
110 | - return (PyObject *) NULL; | |
111 | - | |
112 | - action.wait(seconds); | |
113 | - | |
114 | - } | |
115 | - break; | |
116 | - | |
117 | - default: | |
118 | - throw std::system_error(EINVAL, std::system_category()); | |
119 | - | |
120 | - } | |
121 | - | |
122 | - debug("%s: ob_refcnt@%p=%ld",__FUNCTION__,self,self->ob_refcnt); | |
123 | 102 | Py_INCREF(self); |
124 | - | |
125 | 103 | return self; |
126 | 104 | |
127 | 105 | }); | ... | ... |
src/action/new.cc
... | ... | @@ -43,8 +43,8 @@ DLL_PRIVATE PyObject * py3270_action_new_from_session(PyObject *session, void *a |
43 | 43 | |
44 | 44 | pyAction * pObj = (pyAction *) _PyObject_New(&py3270_action_type); |
45 | 45 | |
46 | - pObj->session = session; | |
47 | - pObj->action = ((pySession *) session)->host->getAction((const LIB3270_ACTION *) action); | |
46 | + pObj->session = (pySession *) session; | |
47 | + pObj->action = pObj->session->host->getAction((const LIB3270_ACTION *) action); | |
48 | 48 | |
49 | 49 | debug("%s: ob_refcnt@%p=%ld",__FUNCTION__,pObj,((PyObject *) pObj)->ob_refcnt); |
50 | 50 | ... | ... |
src/include/py3270.h
... | ... | @@ -90,6 +90,8 @@ |
90 | 90 | |
91 | 91 | DLL_PRIVATE PyObject * py3270_action_call(PyObject *self, std::function<PyObject * (TN3270::Action &action)> worker) noexcept; |
92 | 92 | |
93 | + DLL_PRIVATE void py3270_wait(Host &host, PyObject *args); | |
94 | + | |
93 | 95 | extern "C" { |
94 | 96 | |
95 | 97 | #else |
... | ... | @@ -106,7 +108,7 @@ |
106 | 108 | |
107 | 109 | typedef struct { |
108 | 110 | PyObject_HEAD |
109 | - PyObject * session; | |
111 | + pySession * session; | |
110 | 112 | Action * action; |
111 | 113 | } pyAction; |
112 | 114 | ... | ... |
src/session/wait.cc
... | ... | @@ -36,84 +36,68 @@ |
36 | 36 | |
37 | 37 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
38 | 38 | |
39 | - PyObject * py3270_session_wait(PyObject *self, PyObject *args) { | |
40 | - | |
41 | - return py3270_session_call(self, [args](TN3270::Host &host){ | |
42 | - | |
43 | - switch(PyTuple_Size(args)) { | |
44 | - case 0: // No time defined, use the default one. | |
45 | - host.waitForReady(); | |
46 | - break; | |
39 | + void py3270_wait(TN3270::Host &host, PyObject *args) { | |
47 | 40 | |
48 | - case 1: // Has argument, wait for it. | |
49 | - { | |
50 | - unsigned int seconds; | |
41 | + switch(PyTuple_Size(args)) { | |
42 | + case 0: // No time defined, use the default one. | |
43 | + host.waitForReady(); | |
44 | + break; | |
51 | 45 | |
52 | - if(!PyArg_ParseTuple(args, "I", &seconds)) | |
53 | - return (PyObject *) NULL; | |
46 | + case 1: // Only one argument, its the time. | |
47 | + { | |
48 | + unsigned int seconds; | |
54 | 49 | |
55 | - host.waitForReady(seconds); | |
56 | - } | |
57 | - break; | |
58 | - | |
59 | - default: | |
60 | - throw std::system_error(EINVAL, std::system_category()); | |
50 | + if(!PyArg_ParseTuple(args, "I", &seconds)) | |
51 | + throw std::system_error(EINVAL, std::system_category()); | |
61 | 52 | |
53 | + host.waitForReady(seconds); | |
62 | 54 | } |
55 | + break; | |
63 | 56 | |
64 | - return PyLong_FromLong(0); | |
57 | + case 2: // 2 arguments, it's the address and content. | |
58 | + { | |
59 | + int baddr; | |
60 | + const char *text; | |
65 | 61 | |
66 | - }); | |
62 | + if(!PyArg_ParseTuple(args, "is", &baddr, &text)) | |
63 | + throw std::system_error(EINVAL, std::system_category()); | |
67 | 64 | |
68 | - } | |
69 | - | |
70 | - | |
71 | -/* | |
72 | - PyObject * terminal_set_string_at(PyObject *self, PyObject *args) { | |
65 | + host.wait(baddr,text); | |
66 | + } | |
67 | + break; | |
73 | 68 | |
74 | - int row, col, rc; | |
75 | - const char *text; | |
69 | + case 3: // 3 arguments, it's the row, col, and content. | |
70 | + { | |
71 | + unsigned int row, col; | |
72 | + const char *text; | |
76 | 73 | |
77 | - if (!PyArg_ParseTuple(args, "iis", &row, &col, &text)) { | |
78 | - PyErr_SetString(terminalError, strerror(EINVAL)); | |
79 | - return NULL; | |
80 | - } | |
74 | + if (!PyArg_ParseTuple(args, "IIs", &row, &col, &text)) | |
75 | + throw std::system_error(EINVAL, std::system_category()); | |
81 | 76 | |
82 | - try { | |
77 | + host.wait(row,col,text); | |
83 | 78 | |
84 | - rc = ((pw3270_TerminalObject *) self)->session->set_string_at(row,col,text); | |
79 | + } | |
80 | + break; | |
85 | 81 | |
86 | - } catch(std::exception &e) { | |
82 | + default: | |
83 | + throw std::system_error(EINVAL, std::system_category()); | |
87 | 84 | |
88 | - PyErr_SetString(terminalError, e.what()); | |
89 | - return NULL; | |
90 | 85 | } |
91 | 86 | |
92 | - return PyLong_FromLong(rc); | |
93 | 87 | |
94 | 88 | } |
95 | 89 | |
96 | - PyObject * terminal_set_cursor_at(PyObject *self, PyObject *args) { | |
97 | 90 | |
98 | - int row, col, rc; | |
99 | - | |
100 | - if (!PyArg_ParseTuple(args, "ii", &row, &col)) { | |
101 | - PyErr_SetString(terminalError, strerror(EINVAL)); | |
102 | - return NULL; | |
103 | - } | |
104 | - | |
105 | - try { | |
91 | + PyObject * py3270_session_wait(PyObject *self, PyObject *args) { | |
106 | 92 | |
107 | - rc = ((pw3270_TerminalObject *) self)->session->set_cursor_position(row,col); | |
93 | + return py3270_session_call(self, [self, args](TN3270::Host &host){ | |
108 | 94 | |
109 | - } catch(std::exception &e) { | |
95 | + py3270_wait(host, args); | |
110 | 96 | |
111 | - PyErr_SetString(terminalError, e.what()); | |
112 | - return NULL; | |
113 | - } | |
97 | + Py_INCREF(self); | |
98 | + return self; | |
114 | 99 | |
115 | - return PyLong_FromLong(rc); | |
100 | + }); | |
116 | 101 | |
117 | 102 | } |
118 | 103 | |
119 | -*/ | ... | ... |
testprograms/sample.py
... | ... | @@ -23,8 +23,6 @@ if session.reconnect.activatable: |
23 | 23 | print("Reconnecting...") |
24 | 24 | session.reconnect().wait(10) |
25 | 25 | |
26 | -#session.connect('') | |
27 | - | |
28 | 26 | print(session.connected) |
29 | 27 | |
30 | 28 | #print('----------------------') |
... | ... | @@ -37,10 +35,9 @@ print("-----------------------------------------------------------------------") |
37 | 35 | print(session) |
38 | 36 | print("-----------------------------------------------------------------------") |
39 | 37 | |
40 | -session.enter().wait(2) | |
41 | - | |
38 | +session.enter().wait(14,2,"Senha") | |
42 | 39 | |
43 | -#session.set("value") | |
40 | +session.set("value") | |
44 | 41 | |
45 | 42 | print("-----------------------------------------------------------------------") |
46 | 43 | print(session) | ... | ... |