Commit 24e5bd3f7ffdf7563102a3773ba0669f9e3be669
1 parent
a2ea3a57
Exists in
master
and in
5 other branches
Implementando versão android
Showing
4 changed files
with
115 additions
and
16 deletions
Show diff stats
android/jni/html.cpp
@@ -32,10 +32,17 @@ | @@ -32,10 +32,17 @@ | ||
32 | 32 | ||
33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
34 | 34 | ||
35 | +static jbyteArray retString(JNIEnv *env, const char *txt) | ||
36 | +{ | ||
37 | + size_t len = strlen(txt); | ||
38 | + jbyteArray ret = env->NewByteArray(len); | ||
39 | + env->SetByteArrayRegion(ret, 0, len, (jbyte*) txt); | ||
40 | + return ret; | ||
41 | +} | ||
35 | 42 | ||
36 | -JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHTML(JNIEnv *env, jobject obj) | 43 | +JNIEXPORT jbyteArray JNICALL Java_br_com_bb_pw3270_lib3270_getHTML(JNIEnv *env, jobject obj) |
37 | { | 44 | { |
38 | - jstring ret; | 45 | + jbyteArray ret; |
39 | 46 | ||
40 | session_request(env,obj); | 47 | session_request(env,obj); |
41 | 48 | ||
@@ -44,13 +51,57 @@ JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHTML(JNIEnv *env, job | @@ -44,13 +51,57 @@ JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHTML(JNIEnv *env, job | ||
44 | if(session) | 51 | if(session) |
45 | { | 52 | { |
46 | char *text = lib3270_get_as_html(session,(LIB3270_HTML_OPTION) (LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM)); | 53 | char *text = lib3270_get_as_html(session,(LIB3270_HTML_OPTION) (LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM)); |
47 | - trace("text=%p",text); | ||
48 | - ret = env->NewStringUTF(text); | ||
49 | - lib3270_free(text); | 54 | + |
55 | + if(text) | ||
56 | + { | ||
57 | + ret = retString(env,text); | ||
58 | + lib3270_free(text); | ||
59 | + } | ||
60 | + else | ||
61 | + { | ||
62 | + ret = retString(env, "<b>Empty session</b>"); | ||
63 | + } | ||
64 | + } | ||
65 | + else | ||
66 | + { | ||
67 | + ret = retString(env, "<b>Invalid Session ID</b>"); | ||
68 | + } | ||
69 | + | ||
70 | + trace("%s ends",__FUNCTION__); | ||
71 | + | ||
72 | + session_release(); | ||
73 | + | ||
74 | + return ret; | ||
75 | +} | ||
76 | + | ||
77 | + | ||
78 | +JNIEXPORT jbyteArray JNICALL Java_br_com_bb_pw3270_lib3270_getText(JNIEnv *env, jobject obj) | ||
79 | +{ | ||
80 | + jbyteArray ret; | ||
81 | + | ||
82 | + session_request(env,obj); | ||
83 | + | ||
84 | + trace("%s starts, session=%p",__FUNCTION__,session); | ||
85 | + | ||
86 | + if(session) | ||
87 | + { | ||
88 | + char *text = lib3270_get_text(session,0,-1); | ||
89 | + | ||
90 | + trace("%s will return \"%s\"",__FUNCTION__,text ? text : ""); | ||
91 | + | ||
92 | + if(text) | ||
93 | + { | ||
94 | + ret = retString(env,text); | ||
95 | + lib3270_free(text); | ||
96 | + } | ||
97 | + else | ||
98 | + { | ||
99 | + ret = retString(env, ""); | ||
100 | + } | ||
50 | } | 101 | } |
51 | else | 102 | else |
52 | { | 103 | { |
53 | - ret = env->NewStringUTF("<b>Invalid Session ID</b>"); | 104 | + ret = retString(env, "<b>Invalid Session ID</b>"); |
54 | } | 105 | } |
55 | 106 | ||
56 | trace("%s ends",__FUNCTION__); | 107 | trace("%s ends",__FUNCTION__); |
android/lib3270NDK.cbp
@@ -38,6 +38,9 @@ | @@ -38,6 +38,9 @@ | ||
38 | <Unit filename="../src/lib3270/html.c"> | 38 | <Unit filename="../src/lib3270/html.c"> |
39 | <Option compilerVar="CC" /> | 39 | <Option compilerVar="CC" /> |
40 | </Unit> | 40 | </Unit> |
41 | + <Unit filename="../src/lib3270/selection.c"> | ||
42 | + <Option compilerVar="CC" /> | ||
43 | + </Unit> | ||
41 | <Unit filename="../src/lib3270/telnet.c"> | 44 | <Unit filename="../src/lib3270/telnet.c"> |
42 | <Option compilerVar="CC" /> | 45 | <Option compilerVar="CC" /> |
43 | </Unit> | 46 | </Unit> |
android/src/br/com/bb/pw3270/PW3270Activity.java
@@ -16,7 +16,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener | @@ -16,7 +16,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener | ||
16 | { | 16 | { |
17 | private class terminal extends lib3270 | 17 | private class terminal extends lib3270 |
18 | { | 18 | { |
19 | -// private static final String TAG = "pw3270"; | 19 | + private static final String TAG = "pw3270"; |
20 | 20 | ||
21 | TextView msgbox; | 21 | TextView msgbox; |
22 | Activity Main; | 22 | Activity Main; |
@@ -46,14 +46,16 @@ public class PW3270Activity extends Activity implements View.OnClickListener | @@ -46,14 +46,16 @@ public class PW3270Activity extends Activity implements View.OnClickListener | ||
46 | d.show(); | 46 | d.show(); |
47 | } | 47 | } |
48 | 48 | ||
49 | - /* | ||
50 | - | ||
51 | protected void redraw() | 49 | protected void redraw() |
52 | { | 50 | { |
53 | - String text = getHTML(); | ||
54 | - Log.i(TAG,text); | 51 | + try |
52 | + { | ||
53 | + String text = new String(getText(),getEncoding()); | ||
54 | + | ||
55 | + msgbox | ||
56 | + Log.i(TAG,text); | ||
57 | + } catch(Exception e) { } | ||
55 | } | 58 | } |
56 | - */ | ||
57 | 59 | ||
58 | 60 | ||
59 | }; | 61 | }; |
android/src/br/com/bb/pw3270/lib3270.java
@@ -51,6 +51,28 @@ public class lib3270 | @@ -51,6 +51,28 @@ public class lib3270 | ||
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | + private class byteMessage | ||
55 | + { | ||
56 | + byte[] msg; | ||
57 | + int sz; | ||
58 | + | ||
59 | + byteMessage(byte[] contents, int len) | ||
60 | + { | ||
61 | + msg = contents; | ||
62 | + sz = len; | ||
63 | + } | ||
64 | + | ||
65 | + byte[] getMessage() | ||
66 | + { | ||
67 | + return msg; | ||
68 | + } | ||
69 | + | ||
70 | + int getLength() | ||
71 | + { | ||
72 | + return sz; | ||
73 | + } | ||
74 | + } | ||
75 | + | ||
54 | protected int send_data(byte[] data, int len) | 76 | protected int send_data(byte[] data, int len) |
55 | { | 77 | { |
56 | Log.i(TAG,"Bytes a enviar: " + len); | 78 | Log.i(TAG,"Bytes a enviar: " + len); |
@@ -72,7 +94,7 @@ public class lib3270 | @@ -72,7 +94,7 @@ public class lib3270 | ||
72 | Log.i(TAG,"Erro ao enviar dados: " + msg); | 94 | Log.i(TAG,"Erro ao enviar dados: " + msg); |
73 | 95 | ||
74 | postPopup(0,"Erro na comunicação","Não foi possível enviar dados",msg); | 96 | postPopup(0,"Erro na comunicação","Não foi possível enviar dados",msg); |
75 | - | 97 | + |
76 | } | 98 | } |
77 | return -1; | 99 | return -1; |
78 | } | 100 | } |
@@ -156,8 +178,15 @@ public class lib3270 | @@ -156,8 +178,15 @@ public class lib3270 | ||
156 | } | 178 | } |
157 | else if(sz > 0) | 179 | else if(sz > 0) |
158 | { | 180 | { |
159 | - Log.d(TAG,sz + " bytes recebidos"); | ||
160 | - procRecvdata(in,sz); | 181 | + Message msg = mHandler.obtainMessage(); |
182 | + msg.what = 6; | ||
183 | + msg.obj = new byteMessage(in,sz); | ||
184 | + | ||
185 | + mHandler.sendMessage(msg); | ||
186 | + | ||
187 | +// Log.d(TAG,sz + " bytes recebidos"); | ||
188 | +// procRecvdata(in,sz); | ||
189 | + | ||
161 | } | 190 | } |
162 | } | 191 | } |
163 | 192 | ||
@@ -237,6 +266,7 @@ public class lib3270 | @@ -237,6 +266,7 @@ public class lib3270 | ||
237 | case 4: // erase | 266 | case 4: // erase |
238 | changed = false; | 267 | changed = false; |
239 | erase(); | 268 | erase(); |
269 | + break; | ||
240 | 270 | ||
241 | case 5: // ctlr_done | 271 | case 5: // ctlr_done |
242 | Log.d(TAG,"ctlr_done"); | 272 | Log.d(TAG,"ctlr_done"); |
@@ -245,6 +275,12 @@ public class lib3270 | @@ -245,6 +275,12 @@ public class lib3270 | ||
245 | changed = false; | 275 | changed = false; |
246 | redraw(); | 276 | redraw(); |
247 | } | 277 | } |
278 | + break; | ||
279 | + | ||
280 | + case 6: // recv_data | ||
281 | + Log.d(TAG,((byteMessage) msg.obj).getLength() + " bytes recebidos"); | ||
282 | + procRecvdata(((byteMessage) msg.obj).getMessage(),((byteMessage) msg.obj).getLength()); | ||
283 | + break; | ||
248 | } | 284 | } |
249 | } | 285 | } |
250 | }; | 286 | }; |
@@ -293,6 +329,12 @@ public class lib3270 | @@ -293,6 +329,12 @@ public class lib3270 | ||
293 | return -1; | 329 | return -1; |
294 | } | 330 | } |
295 | 331 | ||
332 | + public int disconnect() | ||
333 | + { | ||
334 | + connected = false; | ||
335 | + return 0; | ||
336 | + } | ||
337 | + | ||
296 | /*---[ Native calls ]----------------------------------------------------*/ | 338 | /*---[ Native calls ]----------------------------------------------------*/ |
297 | static private native int init(); | 339 | static private native int init(); |
298 | 340 | ||
@@ -314,7 +356,8 @@ public class lib3270 | @@ -314,7 +356,8 @@ public class lib3270 | ||
314 | public native boolean isTerminalReady(); | 356 | public native boolean isTerminalReady(); |
315 | 357 | ||
316 | // Get/Set screen contents | 358 | // Get/Set screen contents |
317 | - public native String getHTML(); | 359 | + public native byte[] getHTML(); |
360 | + public native byte[] getText(); | ||
318 | 361 | ||
319 | 362 | ||
320 | } | 363 | } |