Commit c54366961bdddaae67f46b7ce3bba9c143e3f751
1 parent
9b21070e
Exists in
master
and in
1 other branch
Adding method to wait for keyboard unlock.
Showing
11 changed files
with
81 additions
and
42 deletions
Show diff stats
client/src/core/session.cc
| ... | ... | @@ -73,11 +73,16 @@ |
| 73 | 73 | |
| 74 | 74 | void Session::input(const char *text, const char control_char) { |
| 75 | 75 | |
| 76 | - waitForReady(); | |
| 76 | + size_t sz; | |
| 77 | 77 | |
| 78 | 78 | for(const char * ptr = strchr(text,control_char); ptr; ptr = strchr(text,control_char)) { |
| 79 | 79 | |
| 80 | - push(text,(size_t) (ptr-text)); | |
| 80 | + // Wait for unlock, ignore errors. | |
| 81 | + sz = (size_t) (ptr-text); | |
| 82 | + if(sz) { | |
| 83 | + waitForUnlock(); | |
| 84 | + push(text,sz); | |
| 85 | + } | |
| 81 | 86 | |
| 82 | 87 | switch(*(++ptr)) { |
| 83 | 88 | case 'P': // Print |
| ... | ... | @@ -86,7 +91,7 @@ |
| 86 | 91 | |
| 87 | 92 | case 'E': // Enter |
| 88 | 93 | push(ENTER); |
| 89 | - waitForReady(); | |
| 94 | + waitForUnlock(); | |
| 90 | 95 | break; |
| 91 | 96 | |
| 92 | 97 | case 'F': // Erase EOF |
| ... | ... | @@ -95,122 +100,98 @@ |
| 95 | 100 | |
| 96 | 101 | case '1': // PF1 |
| 97 | 102 | push(PF_1); |
| 98 | - waitForReady(); | |
| 99 | 103 | break; |
| 100 | 104 | |
| 101 | 105 | case '2': // PF2 |
| 102 | 106 | push(PF_2); |
| 103 | - waitForReady(); | |
| 104 | 107 | break; |
| 105 | 108 | |
| 106 | 109 | case '3': // PF3 |
| 107 | 110 | push(PF_3); |
| 108 | - waitForReady(); | |
| 109 | 111 | break; |
| 110 | 112 | |
| 111 | 113 | case '4': // PF4 |
| 112 | 114 | push(PF_4); |
| 113 | - waitForReady(); | |
| 114 | 115 | break; |
| 115 | 116 | |
| 116 | 117 | case '5': // PF5 |
| 117 | 118 | push(PF_5); |
| 118 | - waitForReady(); | |
| 119 | 119 | break; |
| 120 | 120 | |
| 121 | 121 | case '6': // PF6 |
| 122 | 122 | push(PF_6); |
| 123 | - waitForReady(); | |
| 124 | 123 | break; |
| 125 | 124 | |
| 126 | 125 | case '7': // PF7 |
| 127 | 126 | push(PF_7); |
| 128 | - waitForReady(); | |
| 129 | 127 | break; |
| 130 | 128 | |
| 131 | 129 | case '8': // PF8 |
| 132 | 130 | push(PF_8); |
| 133 | - waitForReady(); | |
| 134 | 131 | break; |
| 135 | 132 | |
| 136 | 133 | case '9': // PF9 |
| 137 | 134 | push(PF_9); |
| 138 | - waitForReady(); | |
| 139 | 135 | break; |
| 140 | 136 | |
| 141 | 137 | case 'a': // PF10 |
| 142 | 138 | push(PF_10); |
| 143 | - waitForReady(); | |
| 144 | 139 | break; |
| 145 | 140 | |
| 146 | 141 | case 'b': // PF11 |
| 147 | 142 | push(PF_11); |
| 148 | - waitForReady(); | |
| 149 | 143 | break; |
| 150 | 144 | |
| 151 | 145 | case 'c': // PF12 |
| 152 | 146 | push(PF_12); |
| 153 | - waitForReady(); | |
| 154 | 147 | break; |
| 155 | 148 | |
| 156 | 149 | case 'd': // PF13 |
| 157 | 150 | push(PF_13); |
| 158 | - waitForReady(); | |
| 159 | 151 | break; |
| 160 | 152 | |
| 161 | 153 | case 'e': // PF14 |
| 162 | 154 | push(PF_14); |
| 163 | - waitForReady(); | |
| 164 | 155 | break; |
| 165 | 156 | |
| 166 | 157 | case 'f': // PF15 |
| 167 | 158 | push(PF_15); |
| 168 | - waitForReady(); | |
| 169 | 159 | break; |
| 170 | 160 | |
| 171 | 161 | case 'g': // PF16 |
| 172 | 162 | push(PF_16); |
| 173 | - waitForReady(); | |
| 174 | 163 | break; |
| 175 | 164 | |
| 176 | 165 | case 'h': // PF17 |
| 177 | 166 | push(PF_17); |
| 178 | - waitForReady(); | |
| 179 | 167 | break; |
| 180 | 168 | |
| 181 | 169 | case 'i': // PF18 |
| 182 | 170 | push(PF_18); |
| 183 | - waitForReady(); | |
| 184 | 171 | break; |
| 185 | 172 | |
| 186 | 173 | case 'j': // PF19 |
| 187 | 174 | push(PF_19); |
| 188 | - waitForReady(); | |
| 189 | 175 | break; |
| 190 | 176 | |
| 191 | 177 | case 'k': // PF20 |
| 192 | 178 | push(PF_20); |
| 193 | - waitForReady(); | |
| 194 | 179 | break; |
| 195 | 180 | |
| 196 | 181 | case 'l': // PF21 |
| 197 | 182 | push(PF_21); |
| 198 | - waitForReady(); | |
| 199 | 183 | break; |
| 200 | 184 | |
| 201 | 185 | case 'm': // PF22 |
| 202 | 186 | push(PF_22); |
| 203 | - waitForReady(); | |
| 204 | 187 | break; |
| 205 | 188 | |
| 206 | 189 | case 'n': // PF23 |
| 207 | 190 | push(PF_23); |
| 208 | - waitForReady(); | |
| 209 | 191 | break; |
| 210 | 192 | |
| 211 | 193 | case 'o': // PF24 |
| 212 | 194 | push(PF_24); |
| 213 | - waitForReady(); | |
| 214 | 195 | break; |
| 215 | 196 | |
| 216 | 197 | case '@': // Send '@' character |
| ... | ... | @@ -219,17 +200,14 @@ |
| 219 | 200 | |
| 220 | 201 | case 'x': // PA1 |
| 221 | 202 | push(PA_1); |
| 222 | - waitForReady(); | |
| 223 | 203 | break; |
| 224 | 204 | |
| 225 | 205 | case 'y': // PA2 |
| 226 | 206 | push(PA_2); |
| 227 | - waitForReady(); | |
| 228 | 207 | break; |
| 229 | 208 | |
| 230 | 209 | case 'z': // PA3 |
| 231 | 210 | push(PA_3); |
| 232 | - waitForReady(); | |
| 233 | 211 | break; |
| 234 | 212 | |
| 235 | 213 | case 'B': // PC_LEFTTAB = "@B" |
| ... | ... | @@ -343,8 +321,10 @@ |
| 343 | 321 | text = (ptr+1); |
| 344 | 322 | } |
| 345 | 323 | |
| 346 | - if(*text) { | |
| 347 | - push(text,strlen(text)); | |
| 324 | + sz = strlen(text); | |
| 325 | + if(sz) { | |
| 326 | + waitForUnlock(); | |
| 327 | + push(text,sz); | |
| 348 | 328 | } |
| 349 | 329 | |
| 350 | 330 | } | ... | ... |
client/src/host/actions.cc
client/src/session/local/actions.cc
| ... | ... | @@ -60,7 +60,7 @@ |
| 60 | 60 | chkResponse(lib3270_disconnect(hSession)); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - void Local::Session::wait(unsigned short seconds) const { | |
| 63 | + void Local::Session::wait(time_t seconds) const { | |
| 64 | 64 | |
| 65 | 65 | std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); |
| 66 | 66 | chkResponse(lib3270_wait(this->hSession, seconds)); |
| ... | ... | @@ -73,7 +73,13 @@ |
| 73 | 73 | chkResponse(lib3270_wait_for_ready(this->hSession, timeout)); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - void Local::Session::waitForChange(unsigned short seconds) const { | |
| 76 | + void Local::Session::waitForUnlock(time_t timeout) const { | |
| 77 | + | |
| 78 | + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); | |
| 79 | + chkResponse(lib3270_wait_for_unlock(this->hSession, timeout)); | |
| 80 | + } | |
| 81 | + | |
| 82 | + void Local::Session::waitForChange(time_t seconds) const { | |
| 77 | 83 | |
| 78 | 84 | std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); |
| 79 | 85 | chkResponse(lib3270_wait_for_update(this->hSession, seconds)); | ... | ... |
client/src/session/local/private.h
| ... | ... | @@ -100,9 +100,10 @@ |
| 100 | 100 | void push(const Action action) override; |
| 101 | 101 | void print(LIB3270_CONTENT_OPTION option = LIB3270_CONTENT_ALL) override; |
| 102 | 102 | |
| 103 | - void wait(unsigned short seconds) const override; | |
| 103 | + void wait(time_t seconds) const override; | |
| 104 | 104 | void waitForReady(time_t timeout) const override; |
| 105 | - void waitForChange(unsigned short seconds) const override; | |
| 105 | + void waitForChange(time_t timeout) const override; | |
| 106 | + void waitForUnlock(time_t seconds) const override; | |
| 106 | 107 | |
| 107 | 108 | // States |
| 108 | 109 | ProgramMessage getProgramMessage() const override; | ... | ... |
client/src/session/remote/actions.cc
| ... | ... | @@ -83,7 +83,7 @@ |
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - void IPC::Session::wait(unsigned short seconds) const { | |
| 86 | + void IPC::Session::wait(time_t seconds) const { | |
| 87 | 87 | |
| 88 | 88 | time_t end = time(nullptr) + seconds; |
| 89 | 89 | |
| ... | ... | @@ -128,7 +128,33 @@ |
| 128 | 128 | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - void IPC::Session::waitForChange(unsigned short seconds) const { | |
| 131 | + void IPC::Session::waitForUnlock(time_t timeout) const { | |
| 132 | + | |
| 133 | + int rc; | |
| 134 | + | |
| 135 | + time_t end = time(nullptr) + timeout; | |
| 136 | + | |
| 137 | + while(time(nullptr) < end) { | |
| 138 | + | |
| 139 | + debug("Running waitForUnlock request..."); | |
| 140 | + | |
| 141 | + Request(*this,"waitForUnlock") | |
| 142 | + .push((uint32_t) 1) | |
| 143 | + .call() | |
| 144 | + .pop(rc); | |
| 145 | + | |
| 146 | + debug("Wait for unlock returned ",rc); | |
| 147 | + | |
| 148 | + if(rc == 0) | |
| 149 | + return; | |
| 150 | + | |
| 151 | + } | |
| 152 | + | |
| 153 | + throw std::runtime_error("Keyboard is locked"); | |
| 154 | + | |
| 155 | + } | |
| 156 | + | |
| 157 | + void IPC::Session::waitForChange(time_t seconds) const { | |
| 132 | 158 | |
| 133 | 159 | int rc; |
| 134 | 160 | ... | ... |
client/src/session/remote/private.h
| ... | ... | @@ -98,9 +98,10 @@ |
| 98 | 98 | void push(const Action action) override; |
| 99 | 99 | void print(LIB3270_CONTENT_OPTION option = LIB3270_CONTENT_ALL) override; |
| 100 | 100 | |
| 101 | - void wait(unsigned short seconds) const override; | |
| 101 | + void wait(time_t seconds) const override; | |
| 102 | 102 | void waitForReady(time_t timeout) const override; |
| 103 | - void waitForChange(unsigned short seconds) const override; | |
| 103 | + void waitForChange(time_t timeout) const override; | |
| 104 | + void waitForUnlock(time_t seconds) const override; | |
| 104 | 105 | |
| 105 | 106 | // States |
| 106 | 107 | ProgramMessage getProgramMessage() const override; | ... | ... |
common/src/include/lib3270/ipc.h
| ... | ... | @@ -327,13 +327,16 @@ |
| 327 | 327 | virtual void disconnect() = 0; |
| 328 | 328 | |
| 329 | 329 | /// @brief Wait. |
| 330 | - virtual void wait(unsigned short seconds) const = 0; | |
| 330 | + virtual void wait(time_t seconds) const = 0; | |
| 331 | 331 | |
| 332 | 332 | /// @brief Wait until session state changes to "ready". |
| 333 | 333 | virtual void waitForReady(time_t timeout = DEFAULT_TIMEOUT) const = 0; |
| 334 | 334 | |
| 335 | 335 | /// @brief Wait for screen changes. |
| 336 | - virtual void waitForChange(unsigned short seconds) const = 0; | |
| 336 | + virtual void waitForChange(time_t seconds = DEFAULT_TIMEOUT) const = 0; | |
| 337 | + | |
| 338 | + /// @brief Wait for screen changes. | |
| 339 | + virtual void waitForUnlock(time_t seconds = DEFAULT_TIMEOUT) const = 0; | |
| 337 | 340 | |
| 338 | 341 | /// @brief Send PF. |
| 339 | 342 | virtual void pfkey(unsigned short value) = 0; |
| ... | ... | @@ -436,6 +439,7 @@ |
| 436 | 439 | Host & connect(const char *url = nullptr); |
| 437 | 440 | Host & disconnect(); |
| 438 | 441 | Host & waitForReady(time_t timeout = DEFAULT_TIMEOUT); |
| 442 | + Host & waitForUnlock(time_t timeout = DEFAULT_TIMEOUT); | |
| 439 | 443 | |
| 440 | 444 | /// @brief Execute action by name. |
| 441 | 445 | inline Host & action(const char *action_name) { | ... | ... |
server/src/core/linux/gobject.c
| ... | ... | @@ -155,6 +155,10 @@ void ipc3270_add_terminal_introspection(GString *introspection) { |
| 155 | 155 | " <arg type='u' name='seconds' direction='in' />" \ |
| 156 | 156 | " <arg type='i' name='result' direction='out' />" \ |
| 157 | 157 | " </method>" \ |
| 158 | + " <method name= 'waitForUnlock'>" \ | |
| 159 | + " <arg type='u' name='seconds' direction='in' />" \ | |
| 160 | + " <arg type='i' name='result' direction='out' />" \ | |
| 161 | + " </method>" \ | |
| 158 | 162 | " <method name= 'waitForUpdate'>" \ |
| 159 | 163 | " <arg type='u' name='seconds' direction='in' />" \ |
| 160 | 164 | " <arg type='i' name='result' direction='out' />" \ | ... | ... |
server/src/core/methods/methods.c
| ... | ... | @@ -49,6 +49,7 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req |
| 49 | 49 | { "wait", ipc3270_method_wait }, |
| 50 | 50 | { "waitforready", ipc3270_method_wait_for_ready }, |
| 51 | 51 | { "waitforupdate", ipc3270_method_wait_for_update }, |
| 52 | + { "waitforunlock", ipc3270_method_wait_for_unlock }, | |
| 52 | 53 | |
| 53 | 54 | { "getString", ipc3270_method_get_string }, |
| 54 | 55 | { "getStringAt", ipc3270_method_get_string }, | ... | ... |
server/src/core/methods/private.h
| ... | ... | @@ -50,6 +50,7 @@ |
| 50 | 50 | G_GNUC_INTERNAL int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response, GError **error); |
| 51 | 51 | G_GNUC_INTERNAL int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *response, GError **error); |
| 52 | 52 | G_GNUC_INTERNAL int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject *response, GError **error); |
| 53 | + G_GNUC_INTERNAL int ipc3270_method_wait_for_unlock(GObject *session, GVariant *request, GObject *response, GError **error); | |
| 53 | 54 | |
| 54 | 55 | G_GNUC_INTERNAL int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError **error); |
| 55 | 56 | ... | ... |
server/src/core/methods/wait.c
| ... | ... | @@ -55,3 +55,12 @@ int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject |
| 55 | 55 | return 0; |
| 56 | 56 | |
| 57 | 57 | } |
| 58 | + | |
| 59 | +int ipc3270_method_wait_for_unlock(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) { | |
| 60 | + | |
| 61 | + guint seconds = 1; | |
| 62 | + g_variant_get(request, "(u)", &seconds); | |
| 63 | + ipc3270_response_append_int32(response, lib3270_wait_for_unlock(ipc3270_get_session(session),seconds)); | |
| 64 | + return 0; | |
| 65 | + | |
| 66 | +} | ... | ... |