diff --git a/src/classlib/session.cc b/src/classlib/session.cc index ada6ecc..a12d9ee 100644 --- a/src/classlib/session.cc +++ b/src/classlib/session.cc @@ -199,15 +199,22 @@ { time_t end = time(0)+timeout; + iterate(false); while(time(0) < end) { - if(!is_connected()) - return ENOTCONN; + trace("Aguardar %d segundos",(int) (end - time(0))); - if(!cmp_text_at(row,col,key)) + int rc = wait_for_ready(end - time(0)); + if(rc) { + return rc; + } + + if(!cmp_text_at(row,col,key)) { return 0; + } + + iterate(true); - iterate(); } return ETIMEDOUT; diff --git a/src/java/getset.cc b/src/java/getset.cc index a16e676..81e6e1e 100644 --- a/src/java/getset.cc +++ b/src/java/getset.cc @@ -118,6 +118,29 @@ JNIEXPORT jint JNICALL Java_pw3270_terminal_cmp_1string_1at(JNIEnv *env, jobject } +JNIEXPORT jint JNICALL Java_pw3270_terminal_wait_1for_1string_1at(JNIEnv *env, jobject obj, jint row, jint col, jstring j_str, jint timeout) { + + const char * str = env->GetStringUTFChars(j_str, 0); + jint rc = -1; + + try { + + rc = java::getHandle(env,obj)->wait_for_string_at((int) row, (int) col, str, timeout); + + } catch(std::exception &e) { + + env->ReleaseStringUTFChars( j_str, str); + env->ThrowNew(env->FindClass("java/lang/Exception"), e.what()); + return -1; + + } + + env->ReleaseStringUTFChars( j_str, str); + return rc; + + +} + JNIEXPORT jint JNICALL Java_pw3270_terminal_input_1string(JNIEnv *env, jobject obj, jstring j_str) { const char * str = env->GetStringUTFChars(j_str, 0); diff --git a/src/java/terminal.java b/src/java/terminal.java index 49ce97c..e6356fc 100644 --- a/src/java/terminal.java +++ b/src/java/terminal.java @@ -53,6 +53,19 @@ public class terminal public native int wait_for_ready(int seconds); /** + * Wait for text at defined position + * + * @param row Row for text to compare. + * @param col Column for text to compare. + * @param text String to compare. + * @param seconds Maximum time (in seconds) to wait for. + * + * @return 0 for success, error code if not. + * + */ + public native int wait_for_string_at(int row, int col, String text, int seconds); + + /** * Get the current lib3270 version. * * @return String with the current lib3270 version. -- libgit2 0.21.2