From a046e5a6cb6d43a3ec76834f58f89c5e635dc712 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 31 Aug 2012 17:33:43 +0000 Subject: [PATCH] Android - Implementando string de logon para passar automaticamente pela tela inicial --- android/jni/main.cpp | 29 ++++++++++++++++++++++++----- android/jni/text.cpp | 8 +++++--- android/src/br/com/bb/pw3270/lib3270.java | 19 ++++--------------- src/include/lib3270.h | 13 ++++++++++++- src/include/lib3270/log.h | 3 ++- src/lib3270/ctlr.c | 8 +------- src/lib3270/ctlrc.h | 4 +++- src/lib3270/kybd.c | 17 +++++++++-------- src/lib3270/screen.c | 6 +++++- 9 files changed, 65 insertions(+), 42 deletions(-) diff --git a/android/jni/main.cpp b/android/jni/main.cpp index d18990b..8b7f126 100644 --- a/android/jni/main.cpp +++ b/android/jni/main.cpp @@ -77,10 +77,20 @@ static void changed(H3270 *session, int offset, int len) trace("%s: offset=%d len=%d",__FUNCTION__,offset,len); { - char *text = lib3270_get_as_html(session,(LIB3270_HTML_OPTION) (LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM)); - + char *text = lib3270_get_text(PW3270_SESSION,0,-1); if(text) + { + char *strtok_r(char *str, const char *delim, char **saveptr); + char *save; + +/* + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Contents:\n"); + for(char *ptr = strtok_r(text,"\n",&save);ptr;ptr = strtok_r(NULL,"\n",&save)) + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s\n",ptr); +*/ + lib3270_free(text); + } } pw3270_jni_post_message(2,offset,len); @@ -258,16 +268,25 @@ static void ctlr_done(H3270 *session) static void autostart(H3270 *session) { - // pw3270_jni_post_message(10); - { char *text = lib3270_get_text(PW3270_SESSION,0,-1); if(text) { - __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Contents:\n%s\n",text); + char *strtok_r(char *str, const char *delim, char **saveptr); + char *save; + +/* + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Contents:\n"); + for(char *ptr = strtok_r(text,"\n",&save);ptr;ptr = strtok_r(NULL,"\n",&save)) + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s\n",ptr); +*/ + lib3270_free(text); } } + + pw3270_jni_post_message(10); + } jint JNI_OnLoad(JavaVM *vm, void *reserved) diff --git a/android/jni/text.cpp b/android/jni/text.cpp index 65d4ef7..a406940 100644 --- a/android/jni/text.cpp +++ b/android/jni/text.cpp @@ -139,16 +139,18 @@ JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setTextAt(JNIEnv *env, jobj PW3270_JNI_END } -JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_input(JNIEnv *env, jobject obj, jstring str, jint pasting) +JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_runStartupString(JNIEnv *env, jobject obj, jstring str) { int rc = -1; PW3270_JNI_BEGIN if(lib3270_connected(PW3270_SESSION)) - rc = lib3270_emulate_input(PW3270_SESSION, env->GetStringUTFChars(str, 0), -1, (int) pasting); + { + lib3270_set_cursor_address(PW3270_SESSION,lib3270_get_next_unprotected(PW3270_SESSION,0)); + lib3270_emulate_input(PW3270_SESSION, env->GetStringUTFChars(str, 0), -1, 0); + } PW3270_JNI_END - return rc; } diff --git a/android/src/br/com/bb/pw3270/lib3270.java b/android/src/br/com/bb/pw3270/lib3270.java index 1f464d7..4b97ead 100644 --- a/android/src/br/com/bb/pw3270/lib3270.java +++ b/android/src/br/com/bb/pw3270/lib3270.java @@ -140,22 +140,11 @@ public abstract class lib3270 break; case 10: // Run autostart - Log.v(TAG, "AAA---------------------------------------------------------------"); - Log.v(TAG, "In3270="+(in3270() ? "Yes" : "No")); - /* String str = settings.getString("logonstring",""); Log.v(TAG, "Logon string is \"" + str + "\""); if( str != "") - { - int sz = input(str,0); - Log.v(TAG, "Input exits with "+sz); - } - */ - - Log.v(TAG, "Contents:\n" + getText() + "\n"); - - Log.v(TAG, "AAA---------------------------------------------------------------"); + runStartupString(str); break; } @@ -176,7 +165,7 @@ public abstract class lib3270 this.screenState = -1; for(int f = 0; f < toggle.length; f++) - setToggle(toggle[f],settings.getBoolean(toggle[f],true)); + setToggle(toggle[f],settings.getBoolean(toggle[f],false)); } @@ -632,7 +621,7 @@ public abstract class lib3270 public native void setTextAt(int offset, byte[] str, int len); - public native int input(String text, int pasting); - public native boolean in3270(); + + public native void runStartupString(String text); } diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 4065273..1b977fd 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -441,7 +441,7 @@ * @param len Size of the string (or -1 to null terminated strings) * @param pasting Non zero for pasting (See comments). * - * @return The number of unprocessed characters. + * @return The number of unprocessed characters or -1 if failed */ LIB3270_EXPORT int lib3270_emulate_input(H3270 *session, const char *s, int len, int pasting); @@ -769,6 +769,17 @@ LIB3270_EXPORT char * lib3270_get_field_at(H3270 *h, int baddr); /** + * Find the next unprotected field. + * + * @param hSession Session handle. + * @param baddr0 Search start addr. + * + * @return address following the unprotected attribute byte, or 0 if no nonzero-width unprotected field can be found. + * + */ + LIB3270_EXPORT int lib3270_get_next_unprotected(H3270 *hSession, int baddr0); + + /** * Find the buffer address of the field attribute for a given buffer address. * * @param h Session handle. diff --git a/src/include/lib3270/log.h b/src/include/lib3270/log.h index 0666b51..9a838da 100644 --- a/src/include/lib3270/log.h +++ b/src/include/lib3270/log.h @@ -45,7 +45,8 @@ #define lib3270_write_rc(s,m,r,f,...) __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, f "\n", __VA_ARGS__ ) #define lib3270_write_va_log(s,m,f,a) __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, f "\n", a) - #define trace( fmt, ... ) __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); + // #define trace( fmt, ... ) __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); + #define trace(x, ...) // __VA_ARGS__ #else diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 678abd8..752cbab 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -240,7 +240,6 @@ static void set_formatted(H3270 *hSession, int state) hSession->update_formatted(hSession,hSession->formatted); } */ - trace("Screen is now %s",hSession->formatted ? "formatted" : "unformatted"); } /** @@ -366,12 +365,7 @@ unsigned char get_field_attribute(H3270 *hSession, int baddr) return hSession->ea_buf[find_field_attribute(hSession,baddr)].fa; } -/* - * Find the next unprotected field. Returns the address following the - * unprotected attribute byte, or 0 if no nonzero-width unprotected field - * can be found. - */ -int next_unprotected(H3270 *hSession, int baddr0) +LIB3270_EXPORT int lib3270_get_next_unprotected(H3270 *hSession, int baddr0) { register int baddr, nbaddr; diff --git a/src/lib3270/ctlrc.h b/src/lib3270/ctlrc.h index 6f8fac1..eddd59c 100644 --- a/src/lib3270/ctlrc.h +++ b/src/lib3270/ctlrc.h @@ -61,7 +61,9 @@ LIB3270_INTERNAL enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int b LIB3270_INTERNAL void ctlr_write_sscp_lu(H3270 *session, unsigned char buf[], int buflen); LIB3270_INTERNAL void mdt_clear(H3270 *hSession, int baddr); LIB3270_INTERNAL void mdt_set(H3270 *hSession, int baddr); -LIB3270_INTERNAL int next_unprotected(H3270 *session, int baddr0); + +#define next_unprotected(session, baddr0) lib3270_get_next_unprotected(session, baddr0) + LIB3270_INTERNAL enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen); LIB3270_INTERNAL void ps_process(H3270 *hSession); diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index abcb250..dab3c92 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -86,7 +86,9 @@ struct ta; #include "api.h" -/*#define KYBDLOCK_TRACE 1*/ +#ifdef DEBUG + #define KYBDLOCK_TRACE +#endif // DEBUG /* Statics */ // static enum { NONE, COMPOSE, FIRST } composing = NONE; @@ -372,12 +374,9 @@ static void kybdlock_set(H3270 *hSession, unsigned int bits) n = hSession->kybdlock | bits; if (n != hSession->kybdlock) { -/* #if defined(KYBDLOCK_TRACE) - lib3270_trace_event(hSession," %s: kybdlock |= 0x%04x, 0x%04x -> 0x%04x\n", - cause, bits, kybdlock, n); + lib3270_trace_event(hSession," %s: kybdlock |= 0x%04x, 0x%04x -> 0x%04x\n", "set", bits, hSession->kybdlock, n); #endif -*/ if ((hSession->kybdlock ^ bits) & KL_DEFERRED_UNLOCK) { /* Turned on deferred unlock. */ @@ -396,10 +395,12 @@ void lib3270_kybdlock_clear(H3270 *hSession, LIB3270_KL_STATE bits) { unsigned int n = hSession->kybdlock & ~( (unsigned int) bits); + trace("%s: kybdlock=%d",__FUNCTION__,n); + if (n != hSession->kybdlock) { #if defined(KYBDLOCK_TRACE) - lib3270_trace_event(hSession," %s: kybdlock &= ~0x%04x, 0x%04x -> 0x%04x\n", __FUNCTION__, bits, kybdlock, n); + lib3270_trace_event(hSession," %s: kybdlock &= ~0x%04x, 0x%04x -> 0x%04x\n", "clear", bits, hSession->kybdlock, n); #endif if ((hSession->kybdlock ^ n) & KL_DEFERRED_UNLOCK) { @@ -2502,7 +2503,7 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, const char *s, int len len = mb_to_unicode(s, len, w_ibuf, w_ibuf_len, NULL); if (len < 0) { - return 0; /* failed */ + return -1; /* failed */ } ws = w_ibuf; #else /*][*/ @@ -2523,7 +2524,7 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, const char *s, int len if (hSession->kybdlock) { lib3270_trace_event(hSession," keyboard locked, string dropped\n"); - return 0; + return -1; } if (pasting && IN_3270) diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index cdb3714..7ef6e9c 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -372,10 +372,14 @@ void screen_update(H3270 *session, int bstart, int bend) session->changed(session,first,len); } - if(session->starting && session->formatted && lib3270_in_3270(session)) + if(session->starting && session->formatted && !session->kybdlock && lib3270_in_3270(session)) { session->starting = 0; + +// cursor_move(session,next_unprotected(session,0)); +// lib3270_emulate_input(session,"\\n",-1,0); session->autostart(session); + #ifdef DEBUG { char *text = lib3270_get_text(session,0,-1); -- libgit2 0.21.2