Commit 0142ec202886e36ee36c154674510b7aaa89fba1
1 parent
c853e9b4
Exists in
master
and in
5 other branches
Incluindo método para esperar por uma string na API java.
Showing
3 changed files
with
47 additions
and
4 deletions
Show diff stats
src/classlib/session.cc
| @@ -199,15 +199,22 @@ | @@ -199,15 +199,22 @@ | ||
| 199 | { | 199 | { |
| 200 | time_t end = time(0)+timeout; | 200 | time_t end = time(0)+timeout; |
| 201 | 201 | ||
| 202 | + iterate(false); | ||
| 202 | while(time(0) < end) | 203 | while(time(0) < end) |
| 203 | { | 204 | { |
| 204 | - if(!is_connected()) | ||
| 205 | - return ENOTCONN; | 205 | + trace("Aguardar %d segundos",(int) (end - time(0))); |
| 206 | 206 | ||
| 207 | - if(!cmp_text_at(row,col,key)) | 207 | + int rc = wait_for_ready(end - time(0)); |
| 208 | + if(rc) { | ||
| 209 | + return rc; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + if(!cmp_text_at(row,col,key)) { | ||
| 208 | return 0; | 213 | return 0; |
| 214 | + } | ||
| 215 | + | ||
| 216 | + iterate(true); | ||
| 209 | 217 | ||
| 210 | - iterate(); | ||
| 211 | } | 218 | } |
| 212 | 219 | ||
| 213 | return ETIMEDOUT; | 220 | return ETIMEDOUT; |
src/java/getset.cc
| @@ -118,6 +118,29 @@ JNIEXPORT jint JNICALL Java_pw3270_terminal_cmp_1string_1at(JNIEnv *env, jobject | @@ -118,6 +118,29 @@ JNIEXPORT jint JNICALL Java_pw3270_terminal_cmp_1string_1at(JNIEnv *env, jobject | ||
| 118 | 118 | ||
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | +JNIEXPORT jint JNICALL Java_pw3270_terminal_wait_1for_1string_1at(JNIEnv *env, jobject obj, jint row, jint col, jstring j_str, jint timeout) { | ||
| 122 | + | ||
| 123 | + const char * str = env->GetStringUTFChars(j_str, 0); | ||
| 124 | + jint rc = -1; | ||
| 125 | + | ||
| 126 | + try { | ||
| 127 | + | ||
| 128 | + rc = java::getHandle(env,obj)->wait_for_string_at((int) row, (int) col, str, timeout); | ||
| 129 | + | ||
| 130 | + } catch(std::exception &e) { | ||
| 131 | + | ||
| 132 | + env->ReleaseStringUTFChars( j_str, str); | ||
| 133 | + env->ThrowNew(env->FindClass("java/lang/Exception"), e.what()); | ||
| 134 | + return -1; | ||
| 135 | + | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + env->ReleaseStringUTFChars( j_str, str); | ||
| 139 | + return rc; | ||
| 140 | + | ||
| 141 | + | ||
| 142 | +} | ||
| 143 | + | ||
| 121 | JNIEXPORT jint JNICALL Java_pw3270_terminal_input_1string(JNIEnv *env, jobject obj, jstring j_str) { | 144 | JNIEXPORT jint JNICALL Java_pw3270_terminal_input_1string(JNIEnv *env, jobject obj, jstring j_str) { |
| 122 | 145 | ||
| 123 | const char * str = env->GetStringUTFChars(j_str, 0); | 146 | const char * str = env->GetStringUTFChars(j_str, 0); |
src/java/terminal.java
| @@ -53,6 +53,19 @@ public class terminal | @@ -53,6 +53,19 @@ public class terminal | ||
| 53 | public native int wait_for_ready(int seconds); | 53 | public native int wait_for_ready(int seconds); |
| 54 | 54 | ||
| 55 | /** | 55 | /** |
| 56 | + * Wait for text at defined position | ||
| 57 | + * | ||
| 58 | + * @param row Row for text to compare. | ||
| 59 | + * @param col Column for text to compare. | ||
| 60 | + * @param text String to compare. | ||
| 61 | + * @param seconds Maximum time (in seconds) to wait for. | ||
| 62 | + * | ||
| 63 | + * @return 0 for success, error code if not. | ||
| 64 | + * | ||
| 65 | + */ | ||
| 66 | + public native int wait_for_string_at(int row, int col, String text, int seconds); | ||
| 67 | + | ||
| 68 | + /** | ||
| 56 | * Get the current lib3270 version. | 69 | * Get the current lib3270 version. |
| 57 | * | 70 | * |
| 58 | * @return String with the current lib3270 version. | 71 | * @return String with the current lib3270 version. |