Commit 2a69db4a4ef3c79b5ec7732a0a4dbea845ccbc4e
1 parent
87b76c6f
Exists in
master
and in
3 other branches
Addint method to wait for screen content.
Showing
5 changed files
with
160 additions
and
39 deletions
Show diff stats
lib3270.cbp
@@ -176,6 +176,9 @@ | @@ -176,6 +176,9 @@ | ||
176 | <Unit filename="src/core/version.c"> | 176 | <Unit filename="src/core/version.c"> |
177 | <Option compilerVar="CC" /> | 177 | <Option compilerVar="CC" /> |
178 | </Unit> | 178 | </Unit> |
179 | + <Unit filename="src/core/wait.c"> | ||
180 | + <Option compilerVar="CC" /> | ||
181 | + </Unit> | ||
179 | <Unit filename="src/core/windows/connect.c"> | 182 | <Unit filename="src/core/windows/connect.c"> |
180 | <Option compilerVar="CC" /> | 183 | <Option compilerVar="CC" /> |
181 | </Unit> | 184 | </Unit> |
src/core/iocalls.c
@@ -473,40 +473,6 @@ LIB3270_EXPORT int lib3270_wait(H3270 *hSession, int seconds) | @@ -473,40 +473,6 @@ LIB3270_EXPORT int lib3270_wait(H3270 *hSession, int seconds) | ||
473 | return 0; | 473 | return 0; |
474 | } | 474 | } |
475 | 475 | ||
476 | -LIB3270_EXPORT int lib3270_wait_for_update(H3270 *hSession, int seconds) | ||
477 | -{ | ||
478 | - return errno = ENOTSUP; | ||
479 | -} | ||
480 | - | ||
481 | -LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) | ||
482 | -{ | ||
483 | - time_t end = time(0)+seconds; | ||
484 | - | ||
485 | - FAIL_IF_NOT_ONLINE(hSession); | ||
486 | - | ||
487 | - event_dispatcher(hSession,0); | ||
488 | - | ||
489 | - // Keyboard is locked by operator error, fails! | ||
490 | - if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) | ||
491 | - return -1; | ||
492 | - | ||
493 | - do | ||
494 | - { | ||
495 | - if(!lib3270_lock_status(hSession)) | ||
496 | - return 0; | ||
497 | - | ||
498 | - if(!lib3270_connected(hSession)) | ||
499 | - return ENOTCONN; | ||
500 | - | ||
501 | - event_dispatcher(hSession,1); | ||
502 | - | ||
503 | - } | ||
504 | - while(time(0) < end); | ||
505 | - | ||
506 | - return ETIMEDOUT; | ||
507 | -} | ||
508 | - | ||
509 | - | ||
510 | LIB3270_EXPORT void lib3270_ring_bell(H3270 *session) | 476 | LIB3270_EXPORT void lib3270_ring_bell(H3270 *session) |
511 | { | 477 | { |
512 | CHECK_SESSION_HANDLE(session); | 478 | CHECK_SESSION_HANDLE(session); |
@@ -0,0 +1,109 @@ | @@ -0,0 +1,109 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | +#include <lib3270-internals.h> | ||
31 | +#include <lib3270/log.h> | ||
32 | +#include <lib3270/trace.h> | ||
33 | +#include "kybdc.h" | ||
34 | + | ||
35 | +/*---[ Implement ]------------------------------------------------------------------------------------------*/ | ||
36 | + | ||
37 | +LIB3270_EXPORT int lib3270_wait_for_update(H3270 *hSession, int seconds) | ||
38 | +{ | ||
39 | + return errno = ENOTSUP; | ||
40 | +} | ||
41 | + | ||
42 | +LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) | ||
43 | +{ | ||
44 | + time_t end = time(0)+seconds; | ||
45 | + | ||
46 | + FAIL_IF_NOT_ONLINE(hSession); | ||
47 | + | ||
48 | + lib3270_main_iterate(hSession,0); | ||
49 | + | ||
50 | + // Keyboard is locked by operator error, fails! | ||
51 | + if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) | ||
52 | + return errno = EPERM; | ||
53 | + | ||
54 | + do | ||
55 | + { | ||
56 | + if(!lib3270_lock_status(hSession)) | ||
57 | + return 0; | ||
58 | + | ||
59 | + if(!lib3270_connected(hSession)) | ||
60 | + return errno = ENOTCONN; | ||
61 | + | ||
62 | + lib3270_main_iterate(hSession,1); | ||
63 | + | ||
64 | + } | ||
65 | + while(time(0) < end); | ||
66 | + | ||
67 | + return errno = ETIMEDOUT; | ||
68 | +} | ||
69 | + | ||
70 | +int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *key, int seconds) | ||
71 | +{ | ||
72 | + time_t end = time(0)+seconds; | ||
73 | + | ||
74 | + FAIL_IF_NOT_ONLINE(hSession); | ||
75 | + | ||
76 | + lib3270_main_iterate(hSession,0); | ||
77 | + | ||
78 | + if(baddr < 0) | ||
79 | + baddr = lib3270_get_cursor_address(hSession); | ||
80 | + | ||
81 | + do | ||
82 | + { | ||
83 | + // Keyboard is locked by operator error, fails! | ||
84 | + if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) | ||
85 | + return errno = EPERM; | ||
86 | + | ||
87 | + if(!lib3270_connected(hSession)) | ||
88 | + return errno = ENOTCONN; | ||
89 | + | ||
90 | + if(lib3270_cmp_text_at_address(hSession, baddr, key, 0) == 0) | ||
91 | + return 0; | ||
92 | + | ||
93 | + lib3270_main_iterate(hSession,1); | ||
94 | + | ||
95 | + } | ||
96 | + while(time(0) < end); | ||
97 | + | ||
98 | + return errno = ETIMEDOUT; | ||
99 | + | ||
100 | +} | ||
101 | + | ||
102 | +int lib3270_wait_for_string_at(H3270 *hSession, unsigned int row, unsigned int col, const char *key, int seconds) | ||
103 | +{ | ||
104 | + int baddr = lib3270_translate_to_address(hSession,row,col); | ||
105 | + if(baddr < 0) | ||
106 | + return errno; | ||
107 | + | ||
108 | + return lib3270_wait_for_string_at_address(hSession,baddr,key,seconds); | ||
109 | +} |
src/include/lib3270.h
@@ -1137,6 +1137,7 @@ | @@ -1137,6 +1137,7 @@ | ||
1137 | */ | 1137 | */ |
1138 | LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf); | 1138 | LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf); |
1139 | 1139 | ||
1140 | + LIB3270_EXPORT int lib3270_cmp_text_at_address(H3270 *h, int baddr, const char *text, char lf); | ||
1140 | 1141 | ||
1141 | /** | 1142 | /** |
1142 | * @brief Get contents of the field at position. | 1143 | * @brief Get contents of the field at position. |
@@ -1479,6 +1480,43 @@ | @@ -1479,6 +1480,43 @@ | ||
1479 | LIB3270_EXPORT void lib3270_set_session_id(H3270 *hSession, char id); | 1480 | LIB3270_EXPORT void lib3270_set_session_id(H3270 *hSession, char id); |
1480 | LIB3270_EXPORT char lib3270_get_session_id(H3270 *hSession); | 1481 | LIB3270_EXPORT char lib3270_get_session_id(H3270 *hSession); |
1481 | 1482 | ||
1483 | + /** | ||
1484 | + * @brief Wait for string at position. | ||
1485 | + * | ||
1486 | + * @param hSession TN3270 Session. | ||
1487 | + * @param row Row inside the screen. | ||
1488 | + * @param col Col inside the screen. | ||
1489 | + * @param key The string to wait for. | ||
1490 | + * @param seconds Maximum wait time. | ||
1491 | + * | ||
1492 | + * @return 0 if the string was found, error code if not (sets errno). | ||
1493 | + * | ||
1494 | + * @retval ENOTCONN Not connected to host. | ||
1495 | + * @retval EOVERFLOW Invalid position. | ||
1496 | + * @retval ETIMEDOUT Timeout. | ||
1497 | + * @retval EPERM The keyboard is locked. | ||
1498 | + * | ||
1499 | + */ | ||
1500 | + LIB3270_EXPORT int lib3270_wait_for_string_at(H3270 *hSession, unsigned int row, unsigned int col, const char *key, int seconds); | ||
1501 | + | ||
1502 | + /** | ||
1503 | + * @brief Wait for string at addrress. | ||
1504 | + * | ||
1505 | + * @param hSession TN3270 Session. | ||
1506 | + * @param baddr Start position (-1 to current cursor position). | ||
1507 | + * @param key The string to wait for. | ||
1508 | + * @param seconds Maximum wait time. | ||
1509 | + * | ||
1510 | + * @return 0 if the string was found, error code if not (sets errno). | ||
1511 | + * | ||
1512 | + * @retval ENOTCONN Not connected to host. | ||
1513 | + * @retval EOVERFLOW Invalid position. | ||
1514 | + * @retval ETIMEDOUT Timeout. | ||
1515 | + * @retval EPERM The keyboard is locked. | ||
1516 | + * | ||
1517 | + */ | ||
1518 | + LIB3270_EXPORT int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *key, int seconds); | ||
1519 | + | ||
1482 | #ifdef __cplusplus | 1520 | #ifdef __cplusplus |
1483 | } | 1521 | } |
1484 | #endif | 1522 | #endif |
src/selection/selection.c
@@ -347,14 +347,19 @@ LIB3270_EXPORT char * lib3270_get_string_at(H3270 *h, unsigned int row, unsigned | @@ -347,14 +347,19 @@ LIB3270_EXPORT char * lib3270_get_string_at(H3270 *h, unsigned int row, unsigned | ||
347 | 347 | ||
348 | LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf) | 348 | LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf) |
349 | { | 349 | { |
350 | - int rc; | ||
351 | - size_t sz = strlen(text); | ||
352 | - char * contents; | ||
353 | - | ||
354 | int baddr = lib3270_translate_to_address(h,row,col); | 350 | int baddr = lib3270_translate_to_address(h,row,col); |
355 | if(baddr < 0) | 351 | if(baddr < 0) |
356 | return -1; | 352 | return -1; |
357 | 353 | ||
354 | + return lib3270_cmp_text_at_address(h,baddr,text,lf); | ||
355 | +} | ||
356 | + | ||
357 | + LIB3270_EXPORT int lib3270_cmp_text_at_address(H3270 *h, int baddr, const char *text, char lf) | ||
358 | + { | ||
359 | + int rc; | ||
360 | + size_t sz = strlen(text); | ||
361 | + char * contents; | ||
362 | + | ||
358 | contents = lib3270_get_string_at_address(h,baddr,sz,lf); | 363 | contents = lib3270_get_string_at_address(h,baddr,sz,lf); |
359 | if(!contents) | 364 | if(!contents) |
360 | return -1; | 365 | return -1; |
@@ -364,7 +369,7 @@ LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int | @@ -364,7 +369,7 @@ LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int | ||
364 | lib3270_free(contents); | 369 | lib3270_free(contents); |
365 | 370 | ||
366 | return rc; | 371 | return rc; |
367 | -} | 372 | + } |
368 | 373 | ||
369 | 374 | ||
370 | /** | 375 | /** |