Commit 8223b6f76b61a2d193a7a38da5de924c53b3752d
1 parent
2b74680a
Exists in
master
and in
5 other branches
Implementando temporização pelas funções do java
Showing
8 changed files
with
198 additions
and
47 deletions
Show diff stats
android/Makefile
@@ -82,5 +82,5 @@ sigs.txt: bin/classes/$(CLASSPATH)/lib3270.class | @@ -82,5 +82,5 @@ sigs.txt: bin/classes/$(CLASSPATH)/lib3270.class | ||
82 | 82 | ||
83 | jni/lib3270jni.h: bin/classes/$(CLASSPATH)/lib3270.class | 83 | jni/lib3270jni.h: bin/classes/$(CLASSPATH)/lib3270.class |
84 | @echo " GEN `basename $@`" | 84 | @echo " GEN `basename $@`" |
85 | - @$(JAVAH) -o $@ -classpath bin/classes $(subst /,.,$(CLASSPATH)).lib3270 | 85 | + @$(JAVAH) -o $@ -classpath $(ANDROIDSDK)/platforms/android-15/android.jar:bin/classes $(subst /,.,$(CLASSPATH)).lib3270 |
86 | 86 |
android/jni/main.cpp
@@ -30,6 +30,16 @@ | @@ -30,6 +30,16 @@ | ||
30 | #include <lib3270/popup.h> | 30 | #include <lib3270/popup.h> |
31 | #include <lib3270/internals.h> | 31 | #include <lib3270/internals.h> |
32 | 32 | ||
33 | +/*--[ Structs ]--------------------------------------------------------------------------------------*/ | ||
34 | + | ||
35 | + typedef struct _timer | ||
36 | + { | ||
37 | + size_t sz; | ||
38 | + bool enabled; | ||
39 | + H3270 * session; | ||
40 | + void (*proc)(H3270 *session); | ||
41 | + } TIMER; | ||
42 | + | ||
33 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ | 43 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
34 | 44 | ||
35 | const char *java_class_name = "br/com/bb/pw3270/lib3270"; | 45 | const char *java_class_name = "br/com/bb/pw3270/lib3270"; |
@@ -116,6 +126,73 @@ static int write_buffer(H3270 *session, unsigned const char *buf, int len) | @@ -116,6 +126,73 @@ static int write_buffer(H3270 *session, unsigned const char *buf, int len) | ||
116 | return rc; | 126 | return rc; |
117 | } | 127 | } |
118 | 128 | ||
129 | +static void * add_timeout(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)) | ||
130 | +{ | ||
131 | + if(session->widget) | ||
132 | + { | ||
133 | + JNIEnv * env = ((INFO *) session->widget)->env; | ||
134 | + jobject obj = ((INFO *) session->widget)->obj; | ||
135 | + jclass cls = env->GetObjectClass(obj); | ||
136 | + jmethodID mid = env->GetMethodID(cls, "newTimer", "(JI)V"); | ||
137 | + TIMER * timer = (TIMER *) lib3270_malloc(sizeof(TIMER)); | ||
138 | + | ||
139 | + timer->sz = sizeof(timer); | ||
140 | + timer->enabled = true; | ||
141 | + timer->session = session; | ||
142 | + timer->proc = proc; | ||
143 | + | ||
144 | + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Timer ID %08lx created",(unsigned long) timer); | ||
145 | + | ||
146 | + env->CallVoidMethod(obj,mid, (jlong) timer, (jint) interval_ms); | ||
147 | + | ||
148 | + } | ||
149 | + else | ||
150 | + { | ||
151 | + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Can set timer, no jni env for active session"); | ||
152 | + } | ||
153 | + | ||
154 | + | ||
155 | +} | ||
156 | + | ||
157 | +static void remove_timeout(void *timer) | ||
158 | +{ | ||
159 | + if(timer == NULL || ((TIMER *) timer)->sz != sizeof(TIMER)) | ||
160 | + { | ||
161 | + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Invalid timer ID %08lx",(unsigned long) timer); | ||
162 | + return; | ||
163 | + } | ||
164 | + | ||
165 | + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Removing timeout %d",(int) timer); | ||
166 | + ((TIMER *) timer)->enabled = false; | ||
167 | + | ||
168 | +} | ||
169 | + | ||
170 | +JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_timerFinish(JNIEnv *env, jobject obj, jlong id) | ||
171 | +{ | ||
172 | + TIMER *timer = (TIMER *) id; | ||
173 | + | ||
174 | + if(timer == NULL) | ||
175 | + { | ||
176 | + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Unexpected call to %s: No timer ID",__FUNCTION__); | ||
177 | + return; | ||
178 | + } | ||
179 | + | ||
180 | + if(timer->sz != sizeof(TIMER)) | ||
181 | + { | ||
182 | + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, | ||
183 | + "Invalid timer ID %08lx in %s (sz=%d, expected=%d)",(unsigned long) timer, | ||
184 | + __FUNCTION__,timer->sz,sizeof(timer)); | ||
185 | + return; | ||
186 | + } | ||
187 | + | ||
188 | + if(timer->enabled) | ||
189 | + timer->proc(timer->session); | ||
190 | + | ||
191 | + lib3270_free(timer); | ||
192 | +} | ||
193 | + | ||
194 | + | ||
195 | + | ||
119 | JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj) | 196 | JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj) |
120 | { | 197 | { |
121 | H3270 * session = lib3270_session_new(""); | 198 | H3270 * session = lib3270_session_new(""); |
@@ -123,6 +200,7 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass ob | @@ -123,6 +200,7 @@ JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass ob | ||
123 | __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Initializing session %p",session); | 200 | __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "Initializing session %p",session); |
124 | 201 | ||
125 | lib3270_set_popup_handler(popuphandler); | 202 | lib3270_set_popup_handler(popuphandler); |
203 | + lib3270_register_time_handlers(add_timeout,remove_timeout); | ||
126 | 204 | ||
127 | session->write = write_buffer; | 205 | session->write = write_buffer; |
128 | session->changed = changed; | 206 | session->changed = changed; |
android/lib3270NDK.cbp
@@ -36,6 +36,7 @@ | @@ -36,6 +36,7 @@ | ||
36 | <Unit filename="../src/include/lib3270/actions.h" /> | 36 | <Unit filename="../src/include/lib3270/actions.h" /> |
37 | <Unit filename="../src/include/lib3270/html.h" /> | 37 | <Unit filename="../src/include/lib3270/html.h" /> |
38 | <Unit filename="../src/include/lib3270/internals.h" /> | 38 | <Unit filename="../src/include/lib3270/internals.h" /> |
39 | + <Unit filename="../src/include/lib3270/session.h" /> | ||
39 | <Unit filename="../src/lib3270/html.c"> | 40 | <Unit filename="../src/lib3270/html.c"> |
40 | <Option compilerVar="CC" /> | 41 | <Option compilerVar="CC" /> |
41 | </Unit> | 42 | </Unit> |
@@ -57,6 +58,7 @@ | @@ -57,6 +58,7 @@ | ||
57 | <Unit filename="jni/lib3270jni.h" /> | 58 | <Unit filename="jni/lib3270jni.h" /> |
58 | <Unit filename="jni/main.cpp" /> | 59 | <Unit filename="jni/main.cpp" /> |
59 | <Unit filename="jni/misc.cpp" /> | 60 | <Unit filename="jni/misc.cpp" /> |
61 | + <Unit filename="src/br/com/bb/pw3270/PW3270Activity.java" /> | ||
60 | <Unit filename="src/br/com/bb/pw3270/lib3270.java" /> | 62 | <Unit filename="src/br/com/bb/pw3270/lib3270.java" /> |
61 | <Extensions> | 63 | <Extensions> |
62 | <code_completion /> | 64 | <code_completion /> |
android/src/br/com/bb/pw3270/lib3270.java
@@ -3,27 +3,29 @@ package br.com.bb.pw3270; | @@ -3,27 +3,29 @@ package br.com.bb.pw3270; | ||
3 | import java.lang.Thread; | 3 | import java.lang.Thread; |
4 | import android.os.Handler; | 4 | import android.os.Handler; |
5 | import android.os.Message; | 5 | import android.os.Message; |
6 | +import android.os.CountDownTimer; | ||
6 | import android.util.Log; | 7 | import android.util.Log; |
7 | import javax.net.SocketFactory; | 8 | import javax.net.SocketFactory; |
8 | import java.net.Socket; | 9 | import java.net.Socket; |
9 | import javax.net.ssl.SSLSocketFactory; | 10 | import javax.net.ssl.SSLSocketFactory; |
10 | import java.io.DataInputStream; | 11 | import java.io.DataInputStream; |
11 | import java.io.DataOutputStream; | 12 | import java.io.DataOutputStream; |
13 | +import java.util.Vector; | ||
12 | 14 | ||
13 | public class lib3270 | 15 | public class lib3270 |
14 | { | 16 | { |
15 | private NetworkThread mainloop; | 17 | private NetworkThread mainloop; |
16 | private static final String TAG = "lib3270"; | 18 | private static final String TAG = "lib3270"; |
17 | 19 | ||
18 | - private boolean changed; | ||
19 | - private boolean connected = false; | 20 | + private boolean changed; |
21 | + private boolean connected = false; | ||
20 | 22 | ||
21 | - DataOutputStream outData = null; | ||
22 | - DataInputStream inData = null; | 23 | + DataOutputStream outData = null; |
24 | + DataInputStream inData = null; | ||
23 | 25 | ||
24 | - private String hostname = "3270.df.bb"; | ||
25 | - private int port = 8023; | ||
26 | - private boolean ssl = false; | 26 | + private String hostname = "3270.df.bb"; |
27 | + private int port = 8023; | ||
28 | + private boolean ssl = false; | ||
27 | 29 | ||
28 | static | 30 | static |
29 | { | 31 | { |
@@ -40,6 +42,34 @@ public class lib3270 | @@ -40,6 +42,34 @@ public class lib3270 | ||
40 | mainloop = null; | 42 | mainloop = null; |
41 | } | 43 | } |
42 | 44 | ||
45 | + private class timer extends CountDownTimer | ||
46 | + { | ||
47 | + private long id; | ||
48 | + private lib3270 terminal; | ||
49 | + | ||
50 | + timer(lib3270 session, long timer_id, int msec) | ||
51 | + { | ||
52 | + super(msec,msec); | ||
53 | + | ||
54 | + terminal = session; | ||
55 | + id = timer_id; | ||
56 | + | ||
57 | + Log.d(TAG,"Timer " + id + " set to " + msec + " ms"); | ||
58 | + | ||
59 | + this.start(); | ||
60 | + } | ||
61 | + | ||
62 | + public void onTick(long millisUntilFinished) | ||
63 | + { | ||
64 | + } | ||
65 | + | ||
66 | + public void onFinish() | ||
67 | + { | ||
68 | + Log.d(TAG,"Timer " + id + " finished"); | ||
69 | + terminal.timerFinish(id); | ||
70 | + } | ||
71 | + | ||
72 | + } | ||
43 | private class popupMessageInfo | 73 | private class popupMessageInfo |
44 | { | 74 | { |
45 | public String title; | 75 | public String title; |
@@ -372,6 +402,14 @@ public class lib3270 | @@ -372,6 +402,14 @@ public class lib3270 | ||
372 | public native boolean isConnected(); | 402 | public native boolean isConnected(); |
373 | public native boolean isTerminalReady(); | 403 | public native boolean isTerminalReady(); |
374 | 404 | ||
405 | + // Timers | ||
406 | + protected void newTimer(long id, int msec) | ||
407 | + { | ||
408 | + new timer(this,id,msec); | ||
409 | + } | ||
410 | + | ||
411 | + private native void timerFinish(long id); | ||
412 | + | ||
375 | // Keyboard actions | 413 | // Keyboard actions |
376 | public native void sendEnter(); | 414 | public native void sendEnter(); |
377 | public native void sendPFkey(int id); | 415 | public native void sendPFkey(int id); |
src/include/lib3270.h
@@ -590,6 +590,15 @@ | @@ -590,6 +590,15 @@ | ||
590 | int LIB3270_EXPORT lib3270_register_handlers(const struct lib3270_callbacks *cbk); | 590 | int LIB3270_EXPORT lib3270_register_handlers(const struct lib3270_callbacks *cbk); |
591 | 591 | ||
592 | /** | 592 | /** |
593 | + * Register time handlers. | ||
594 | + * | ||
595 | + * @param add Callback for adding a timeout | ||
596 | + * @param rm Callback for removing a timeout | ||
597 | + * | ||
598 | + */ | ||
599 | + void LIB3270_EXPORT lib3270_register_time_handlers(void * (*add)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)), void (*rm)(void *timer)); | ||
600 | + | ||
601 | + /** | ||
593 | * Get program message. | 602 | * Get program message. |
594 | * | 603 | * |
595 | * @see LIB3270_MESSAGE | 604 | * @see LIB3270_MESSAGE |
src/include/lib3270/session.h
@@ -241,7 +241,7 @@ | @@ -241,7 +241,7 @@ | ||
241 | unsigned char hisopts[LIB3270_TELNET_N_OPTS]; | 241 | unsigned char hisopts[LIB3270_TELNET_N_OPTS]; |
242 | 242 | ||
243 | // kybd.c | 243 | // kybd.c |
244 | - unsigned int kybdlock; | 244 | + unsigned int kybdlock; /**< keyboard lock state */ |
245 | unsigned char aid; /**< current attention ID */ | 245 | unsigned char aid; /**< current attention ID */ |
246 | void * unlock_id; | 246 | void * unlock_id; |
247 | time_t unlock_delay_time; | 247 | time_t unlock_delay_time; |
src/lib3270/iocalls.c
@@ -614,6 +614,16 @@ void remove_input_calls(H3270 *session) | @@ -614,6 +614,16 @@ void remove_input_calls(H3270 *session) | ||
614 | } | 614 | } |
615 | } | 615 | } |
616 | 616 | ||
617 | +LIB3270_EXPORT void lib3270_register_time_handlers(void * (*add)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)), void (*rm)(void *timer)) | ||
618 | +{ | ||
619 | + if(add) | ||
620 | + add_timeout = add; | ||
621 | + | ||
622 | + if(rm) | ||
623 | + remove_timeout = rm; | ||
624 | + | ||
625 | +} | ||
626 | + | ||
617 | LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk) | 627 | LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk) |
618 | { | 628 | { |
619 | if(!cbk) | 629 | if(!cbk) |
@@ -622,11 +632,7 @@ LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk | @@ -622,11 +632,7 @@ LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk | ||
622 | if(cbk->sz != sizeof(struct lib3270_callbacks)) | 632 | if(cbk->sz != sizeof(struct lib3270_callbacks)) |
623 | return EINVAL; | 633 | return EINVAL; |
624 | 634 | ||
625 | - if(cbk->AddTimeOut) | ||
626 | - add_timeout = cbk->AddTimeOut; | ||
627 | - | ||
628 | - if(cbk->RemoveTimeOut) | ||
629 | - remove_timeout = cbk->RemoveTimeOut; | 635 | + lib3270_register_time_handlers(cbk->AddTimeOut,cbk->RemoveTimeOut); |
630 | 636 | ||
631 | if(cbk->AddInput) | 637 | if(cbk->AddInput) |
632 | add_input = cbk->AddInput; | 638 | add_input = cbk->AddInput; |
src/lib3270/kybdc.h
@@ -19,39 +19,57 @@ | @@ -19,39 +19,57 @@ | ||
19 | 19 | ||
20 | #ifndef KYBDC_H_INCLUDED | 20 | #ifndef KYBDC_H_INCLUDED |
21 | 21 | ||
22 | -#define KYBDC_H_INCLUDED | ||
23 | - | ||
24 | -/* keyboard lock states */ | ||
25 | -// LIB3270_INTERNAL unsigned int kybdlock; | ||
26 | -#define KL_OERR_MASK 0x000f | ||
27 | -#define KL_OERR_PROTECTED 1 | ||
28 | -#define KL_OERR_NUMERIC 2 | ||
29 | -#define KL_OERR_OVERFLOW 3 | ||
30 | -#define KL_OERR_DBCS 4 | ||
31 | -#define KL_NOT_CONNECTED 0x0010 | ||
32 | -#define KL_AWAITING_FIRST 0x0020 | ||
33 | -#define KL_OIA_TWAIT 0x0040 | ||
34 | -#define KL_OIA_LOCKED 0x0080 | ||
35 | -#define KL_DEFERRED_UNLOCK 0x0100 | ||
36 | -#define KL_ENTER_INHIBIT 0x0200 | ||
37 | -#define KL_SCROLLED 0x0400 | ||
38 | -#define KL_OIA_MINUS 0x0800 | ||
39 | - | ||
40 | - | ||
41 | -/* other functions */ | ||
42 | -LIB3270_INTERNAL void add_xk(KeySym key, KeySym assoc); | ||
43 | -LIB3270_INTERNAL void clear_xks(void); | ||
44 | -LIB3270_INTERNAL void do_reset(H3270 *session, Boolean explicit); | ||
45 | -LIB3270_INTERNAL void hex_input(char *s); | ||
46 | -LIB3270_INTERNAL void kybdlock_clr(H3270 *session, unsigned int bits, const char *cause); | ||
47 | -LIB3270_INTERNAL void kybd_inhibit(H3270 *session, Boolean inhibit); | ||
48 | -LIB3270_INTERNAL void kybd_init(void); | ||
49 | -LIB3270_INTERNAL int kybd_prime(void); | ||
50 | -LIB3270_INTERNAL void kybd_scroll_lock(Boolean lock); | ||
51 | -LIB3270_INTERNAL Boolean run_ta(void); | ||
52 | -LIB3270_INTERNAL int state_from_keymap(char keymap[32]); | ||
53 | -LIB3270_INTERNAL void kybd_connect(H3270 *session, int connected, void *dunno); | ||
54 | -LIB3270_INTERNAL void kybd_in3270(H3270 *session, int in3270 unused, void *dunno); | 22 | + #define KYBDC_H_INCLUDED |
23 | + | ||
24 | + /* keyboard lock states */ | ||
25 | + typedef enum lib3270_kl_state | ||
26 | + { | ||
27 | + LIB3270_KL_OERR_MASK = 0x000f, | ||
28 | + LIB3270_KL_OERR_PROTECTED = 0x0001, | ||
29 | + LIB3270_KL_OERR_NUMERIC = 0x0002, | ||
30 | + LIB3270_KL_OERR_OVERFLOW = 0x0003, | ||
31 | + LIB3270_KL_OERR_DBCS = 0x0004, | ||
32 | + LIB3270_KL_NOT_CONNECTED = 0x0010, | ||
33 | + LIB3270_KL_AWAITING_FIRST = 0x0020, | ||
34 | + LIB3270_KL_OIA_TWAIT = 0x0040, | ||
35 | + LIB3270_KL_OIA_LOCKED = 0x0080, | ||
36 | + LIB3270_KL_DEFERRED_UNLOCK = 0x0100, | ||
37 | + LIB3270_KL_ENTER_INHIBIT = 0x0200, | ||
38 | + LIB3270_KL_SCROLLED = 0x0400, | ||
39 | + LIB3270_KL_OIA_MINUS = 0x0800 | ||
40 | + | ||
41 | + } LIB3270_KL_STATE; | ||
42 | + | ||
43 | + #define KL_OERR_MASK LIB3270_KL_OERR_MASK | ||
44 | + #define KL_OERR_PROTECTED LIB3270_KL_OERR_PROTECTED | ||
45 | + #define KL_OERR_NUMERIC LIB3270_KL_OERR_NUMERIC | ||
46 | + #define KL_OERR_OVERFLOW LIB3270_KL_OERR_OVERFLOW | ||
47 | + #define KL_OERR_DBCS LIB3270_KL_OERR_DBCS | ||
48 | + #define KL_NOT_CONNECTED LIB3270_KL_NOT_CONNECTED | ||
49 | + #define KL_AWAITING_FIRST LIB3270_KL_AWAITING_FIRST | ||
50 | + #define KL_OIA_TWAIT LIB3270_KL_OIA_TWAIT | ||
51 | + #define KL_OIA_LOCKED LIB3270_KL_OIA_LOCKED | ||
52 | + #define KL_DEFERRED_UNLOCK LIB3270_KL_DEFERRED_UNLOCK | ||
53 | + #define KL_ENTER_INHIBIT LIB3270_KL_ENTER_INHIBIT | ||
54 | + #define KL_SCROLLED LIB3270_KL_SCROLLED | ||
55 | + #define KL_OIA_MINUS LIB3270_KL_OIA_MINUS | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + /* other functions */ | ||
60 | + LIB3270_INTERNAL void add_xk(KeySym key, KeySym assoc); | ||
61 | + LIB3270_INTERNAL void clear_xks(void); | ||
62 | + LIB3270_INTERNAL void do_reset(H3270 *session, Boolean explicit); | ||
63 | + LIB3270_INTERNAL void hex_input(char *s); | ||
64 | + LIB3270_INTERNAL void kybdlock_clr(H3270 *session, unsigned int bits, const char *cause); | ||
65 | + LIB3270_INTERNAL void kybd_inhibit(H3270 *session, Boolean inhibit); | ||
66 | + LIB3270_INTERNAL void kybd_init(void); | ||
67 | + LIB3270_INTERNAL int kybd_prime(void); | ||
68 | + LIB3270_INTERNAL void kybd_scroll_lock(Boolean lock); | ||
69 | + LIB3270_INTERNAL Boolean run_ta(void); | ||
70 | + LIB3270_INTERNAL int state_from_keymap(char keymap[32]); | ||
71 | + LIB3270_INTERNAL void kybd_connect(H3270 *session, int connected, void *dunno); | ||
72 | + LIB3270_INTERNAL void kybd_in3270(H3270 *session, int in3270 unused, void *dunno); | ||
55 | 73 | ||
56 | 74 | ||
57 | #endif /* KYBDC_H_INCLUDED */ | 75 | #endif /* KYBDC_H_INCLUDED */ |