Commit d3ab3fb98019d136335466f6b5c9d4d6ad45fd2f
1 parent
8a40574b
Exists in
master
and in
5 other branches
Implementando objeto lib3270 para android
Showing
5 changed files
with
163 additions
and
43 deletions
Show diff stats
android/jni/main.cpp
@@ -38,23 +38,58 @@ | @@ -38,23 +38,58 @@ | ||
38 | 38 | ||
39 | } INFO; | 39 | } INFO; |
40 | 40 | ||
41 | + #define session_request(env, obj) INFO jni_data = { env, obj }; \ | ||
42 | + H3270 * session = lib3270_get_default_session_handle(); \ | ||
43 | + session->widget = &jni_data; | ||
44 | + | ||
45 | + #define session_release() session->widget = 0; | ||
46 | + | ||
47 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | ||
48 | + | ||
49 | + const char *java_class_name = "br/com/bb/pw3270/lib3270"; | ||
50 | + | ||
41 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 51 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
42 | 52 | ||
53 | +static void post_message(H3270 *session, int msgid, int arg1 = 0, int arg2 = 0) | ||
54 | +{ | ||
55 | + if(session->widget) | ||
56 | + { | ||
57 | + JNIEnv * env = ((INFO *) session->widget)->env; | ||
58 | + jobject obj = ((INFO *) session->widget)->obj; | ||
59 | + jclass cls = env->GetObjectClass(obj); | ||
60 | + jmethodID mid = env->GetMethodID(cls, "post_message", "(III)V");; | ||
61 | + env->CallVoidMethod(obj,mid,(jint) msgid, (jint) arg1, (jint) arg2); | ||
62 | + } | ||
63 | +} | ||
64 | + | ||
65 | +static void update_status(H3270 *session, LIB3270_MESSAGE id) | ||
66 | +{ | ||
67 | + post_message(session,0,id); | ||
68 | +} | ||
69 | + | ||
70 | +static void changed(H3270 *session, int offset, int len) | ||
71 | +{ | ||
72 | + post_message(session,1,offset,len); | ||
73 | +} | ||
74 | + | ||
43 | JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj) | 75 | JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj) |
44 | { | 76 | { |
45 | H3270 * session = lib3270_session_new(""); | 77 | H3270 * session = lib3270_session_new(""); |
46 | 78 | ||
79 | + session->changed = changed; | ||
80 | + session->update_status = update_status; | ||
81 | + | ||
47 | return 0; | 82 | return 0; |
48 | } | 83 | } |
49 | 84 | ||
50 | JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_processEvents(JNIEnv *env, jobject obj) | 85 | JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_processEvents(JNIEnv *env, jobject obj) |
51 | { | 86 | { |
52 | - INFO data = { env, obj }; | ||
53 | - H3270 * session = lib3270_get_default_session_handle(); | 87 | + session_request(env,obj); |
54 | 88 | ||
55 | - session->widget = &data; | ||
56 | lib3270_main_iterate(session,1); | 89 | lib3270_main_iterate(session,1); |
57 | - session->widget = 0; | 90 | + |
91 | + session_release(); | ||
92 | + | ||
58 | return 0; | 93 | return 0; |
59 | } | 94 | } |
60 | 95 | ||
@@ -70,7 +105,9 @@ JNIEXPORT jboolean JNICALL Java_br_com_bb_pw3270_lib3270_isTerminalReady(JNIEnv | @@ -70,7 +105,9 @@ JNIEXPORT jboolean JNICALL Java_br_com_bb_pw3270_lib3270_isTerminalReady(JNIEnv | ||
70 | 105 | ||
71 | JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setHost(JNIEnv *env, jobject obj, jstring hostname) | 106 | JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setHost(JNIEnv *env, jobject obj, jstring hostname) |
72 | { | 107 | { |
73 | - lib3270_set_host(lib3270_get_default_session_handle(),env->GetStringUTFChars(hostname, 0)); | 108 | + session_request(env,obj); |
109 | + lib3270_set_host(session,env->GetStringUTFChars(hostname, 0)); | ||
110 | + session_release(); | ||
74 | } | 111 | } |
75 | 112 | ||
76 | JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHost(JNIEnv *env, jobject obj) | 113 | JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHost(JNIEnv *env, jobject obj) |
@@ -78,3 +115,10 @@ JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHost(JNIEnv *env, job | @@ -78,3 +115,10 @@ JNIEXPORT jstring JNICALL Java_br_com_bb_pw3270_lib3270_getHost(JNIEnv *env, job | ||
78 | return env->NewStringUTF(lib3270_get_host(lib3270_get_default_session_handle())); | 115 | return env->NewStringUTF(lib3270_get_host(lib3270_get_default_session_handle())); |
79 | } | 116 | } |
80 | 117 | ||
118 | +JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_do_1connect(JNIEnv *env, jobject obj) | ||
119 | +{ | ||
120 | + session_request(env,obj); | ||
121 | + update_status(session,(LIB3270_MESSAGE) 10); | ||
122 | + session_release(); | ||
123 | + return -1; | ||
124 | +} |
android/res/layout/main.xml
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | android:layout_height="wrap_content" > | 9 | android:layout_height="wrap_content" > |
10 | 10 | ||
11 | <EditText | 11 | <EditText |
12 | - android:id="@+id/editText1" | 12 | + android:id="@+id/hostname" |
13 | android:layout_width="match_parent" | 13 | android:layout_width="match_parent" |
14 | android:layout_height="match_parent" | 14 | android:layout_height="match_parent" |
15 | android:layout_weight="1" | 15 | android:layout_weight="1" |
android/src/br/com/bb/pw3270/PW3270Activity.java
@@ -4,10 +4,32 @@ import android.app.Activity; | @@ -4,10 +4,32 @@ import android.app.Activity; | ||
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | import android.widget.TextView; | 5 | import android.widget.TextView; |
6 | import android.widget.Button; | 6 | import android.widget.Button; |
7 | +import android.widget.EditText; | ||
8 | +import android.view.View; | ||
7 | 9 | ||
8 | -public class PW3270Activity extends Activity { | 10 | +public class PW3270Activity extends Activity implements View.OnClickListener |
11 | +{ | ||
9 | 12 | ||
10 | - lib3270 host; | 13 | + private class terminal extends lib3270 |
14 | + { | ||
15 | + TextView view; | ||
16 | + | ||
17 | + terminal(TextView view) | ||
18 | + { | ||
19 | + this.view = view; | ||
20 | + | ||
21 | + } | ||
22 | + | ||
23 | + protected void update_message(int id) | ||
24 | + { | ||
25 | + this.view.setText("ID=" + id); | ||
26 | + } | ||
27 | + | ||
28 | + | ||
29 | + }; | ||
30 | + | ||
31 | + terminal host; | ||
32 | + EditText uri; | ||
11 | 33 | ||
12 | /** Called when the activity is first created. */ | 34 | /** Called when the activity is first created. */ |
13 | @Override | 35 | @Override |
@@ -15,13 +37,21 @@ public class PW3270Activity extends Activity { | @@ -15,13 +37,21 @@ public class PW3270Activity extends Activity { | ||
15 | super.onCreate(savedInstanceState); | 37 | super.onCreate(savedInstanceState); |
16 | setContentView(R.layout.main); | 38 | setContentView(R.layout.main); |
17 | 39 | ||
18 | - TextView text = (TextView) findViewById(R.id.text); | ||
19 | - Button btn = (Button) findViewById(R.id.connect); | 40 | + uri = (EditText) findViewById(R.id.hostname); |
20 | 41 | ||
21 | - | 42 | + // Set button |
43 | + Button btn = (Button) findViewById(R.id.connect); | ||
44 | + btn.setOnClickListener((View.OnClickListener) this); | ||
22 | 45 | ||
23 | - host = new lib3270(); | 46 | + host = new terminal((TextView) findViewById(R.id.text)); |
24 | 47 | ||
25 | - text.setText(host.getVersion()); | ||
26 | } | 48 | } |
49 | + | ||
50 | + public void onClick(View v) | ||
51 | + { | ||
52 | + // Perform action on click | ||
53 | + host.setHost(uri.getText().toString()); | ||
54 | + host.connect(); | ||
55 | + } | ||
56 | + | ||
27 | } | 57 | } |
28 | \ No newline at end of file | 58 | \ No newline at end of file |
android/src/br/com/bb/pw3270/lib3270.java
1 | package br.com.bb.pw3270; | 1 | package br.com.bb.pw3270; |
2 | 2 | ||
3 | import java.lang.Thread; | 3 | import java.lang.Thread; |
4 | +// import java.util.Observer; | ||
5 | +// import java.util.Observable; | ||
6 | +import android.os.Handler; | ||
7 | +import android.os.Message; | ||
4 | 8 | ||
5 | -public class lib3270 extends Thread | 9 | +public class lib3270 |
6 | { | 10 | { |
7 | - | 11 | + NetworkThread terminal; |
12 | + | ||
8 | static | 13 | static |
9 | { | 14 | { |
10 | System.loadLibrary("3270"); | 15 | System.loadLibrary("3270"); |
11 | init(); | 16 | init(); |
12 | } | 17 | } |
13 | 18 | ||
14 | - /** | ||
15 | - * @param args | ||
16 | - */ | ||
17 | - public static void main(String[] args) | 19 | + lib3270() |
18 | { | 20 | { |
19 | - // TODO Auto-generated method stub | ||
20 | - | 21 | + terminal = new NetworkThread(handler); |
21 | } | 22 | } |
22 | - | ||
23 | - /** | ||
24 | - * Connect to host, keep event loop running until disconnected. | ||
25 | - */ | ||
26 | - public void run() | 23 | + |
24 | + // Main Thread | ||
25 | + private class NetworkThread extends Thread | ||
27 | { | 26 | { |
28 | - do_connect(); | ||
29 | - while(isConnected()) | ||
30 | - processEvents(); | 27 | + Handler mHandler; |
28 | + | ||
29 | + NetworkThread(Handler h) | ||
30 | + { | ||
31 | + mHandler = h; | ||
32 | + } | ||
33 | + | ||
34 | + public void run() | ||
35 | + { | ||
36 | + postMessage(0,99,0); | ||
37 | +/* | ||
38 | + do_connect(); | ||
39 | + while(isConnected()) | ||
40 | + processEvents(); | ||
41 | +*/ | ||
42 | + } | ||
43 | + | ||
44 | + public void postMessage(int what, int arg1, int arg2) | ||
45 | + { | ||
46 | + Message msg = mHandler.obtainMessage(); | ||
47 | + msg.what = what; | ||
48 | + msg.arg1 = arg1; | ||
49 | + msg.arg2 = arg2; | ||
50 | + mHandler.sendMessage(msg); | ||
51 | + } | ||
52 | + | ||
31 | } | 53 | } |
54 | + | ||
55 | + // Define the Handler that receives messages from the thread and update the progress | ||
56 | + final Handler handler = new Handler() | ||
57 | + { | ||
58 | + public void handleMessage(Message msg) | ||
59 | + { | ||
60 | + switch(msg.what) | ||
61 | + { | ||
62 | + case 0: | ||
63 | + update_message(msg.arg1); | ||
64 | + break; | ||
65 | + | ||
66 | + } | ||
67 | + } | ||
68 | + }; | ||
69 | + | ||
70 | + /*---[ Signal methods ]--------------------------------------------------*/ | ||
71 | + | ||
72 | + protected void update_message(int id) | ||
73 | + { | ||
74 | + } | ||
75 | + | ||
76 | + | ||
77 | + /*---[ External methods ]------------------------------------------------*/ | ||
32 | 78 | ||
79 | + public int connect() | ||
80 | + { | ||
81 | + terminal.start(); | ||
82 | + return 0; | ||
83 | + } | ||
84 | + | ||
85 | + /*---[ Native calls ]----------------------------------------------------*/ | ||
33 | static private native int init(); | 86 | static private native int init(); |
34 | - | 87 | + |
35 | private native int processEvents(); | 88 | private native int processEvents(); |
36 | private native int do_connect(); | 89 | private native int do_connect(); |
37 | 90 | ||
@@ -46,15 +99,6 @@ public class lib3270 extends Thread | @@ -46,15 +99,6 @@ public class lib3270 extends Thread | ||
46 | public native String getHost(); | 99 | public native String getHost(); |
47 | public native boolean isConnected(); | 100 | public native boolean isConnected(); |
48 | public native boolean isTerminalReady(); | 101 | public native boolean isTerminalReady(); |
49 | - | ||
50 | - public void connect(String hostname) | ||
51 | - { | ||
52 | - setHost(hostname); | ||
53 | - start(); | ||
54 | - } | ||
55 | - | ||
56 | - | ||
57 | - | ||
58 | - | ||
59 | 102 | ||
103 | + | ||
60 | } | 104 | } |
pw3270.cbp
@@ -41,13 +41,15 @@ | @@ -41,13 +41,15 @@ | ||
41 | <Add option="`pkg-config gtk+-3.0 lib3270 --libs`" /> | 41 | <Add option="`pkg-config gtk+-3.0 lib3270 --libs`" /> |
42 | </Linker> | 42 | </Linker> |
43 | <Unit filename="Makefile.in" /> | 43 | <Unit filename="Makefile.in" /> |
44 | + <Unit filename="android/jni/globals.h" /> | ||
45 | + <Unit filename="android/jni/main.cpp" /> | ||
46 | + <Unit filename="android/jni/misc.cpp" /> | ||
47 | + <Unit filename="android/src/br/com/bb/pw3270/PW3270Activity.java" /> | ||
48 | + <Unit filename="android/src/br/com/bb/pw3270/lib3270.java" /> | ||
44 | <Unit filename="autogen.sh" /> | 49 | <Unit filename="autogen.sh" /> |
45 | <Unit filename="colors.conf" /> | 50 | <Unit filename="colors.conf" /> |
46 | <Unit filename="configure.ac" /> | 51 | <Unit filename="configure.ac" /> |
47 | <Unit filename="pw3270.spec.in" /> | 52 | <Unit filename="pw3270.spec.in" /> |
48 | - <Unit filename="src/android/jni/main.cpp" /> | ||
49 | - <Unit filename="src/android/jni/misc.cpp" /> | ||
50 | - <Unit filename="src/android/src/br/com/bb/pw3270/lib3270.java" /> | ||
51 | <Unit filename="src/include/lib3270.h" /> | 53 | <Unit filename="src/include/lib3270.h" /> |
52 | <Unit filename="src/include/lib3270/action_table.h" /> | 54 | <Unit filename="src/include/lib3270/action_table.h" /> |
53 | <Unit filename="src/include/lib3270/actions.h" /> | 55 | <Unit filename="src/include/lib3270/actions.h" /> |