Commit d3c899e3765fc832d9e33aab99525dcfbb5436d0

Authored by perry.werneck@gmail.com
1 parent d3ab3fb9

Testando envio de mensagems jni<->android

android/jni/main.cpp
@@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
28 28
29 #include "globals.h" 29 #include "globals.h"
30 #include <lib3270/session.h> 30 #include <lib3270/session.h>
  31 + #include <lib3270/popup.h>
31 32
32 /*--[ Defines ]--------------------------------------------------------------------------------------*/ 33 /*--[ Defines ]--------------------------------------------------------------------------------------*/
33 34
@@ -57,25 +58,47 @@ static void post_message(H3270 *session, int msgid, int arg1 = 0, int arg2 = 0) @@ -57,25 +58,47 @@ static void post_message(H3270 *session, int msgid, int arg1 = 0, int arg2 = 0)
57 JNIEnv * env = ((INFO *) session->widget)->env; 58 JNIEnv * env = ((INFO *) session->widget)->env;
58 jobject obj = ((INFO *) session->widget)->obj; 59 jobject obj = ((INFO *) session->widget)->obj;
59 jclass cls = env->GetObjectClass(obj); 60 jclass cls = env->GetObjectClass(obj);
60 - jmethodID mid = env->GetMethodID(cls, "post_message", "(III)V");; 61 + jmethodID mid = env->GetMethodID(cls, "postMessage", "(III)V");;
61 env->CallVoidMethod(obj,mid,(jint) msgid, (jint) arg1, (jint) arg2); 62 env->CallVoidMethod(obj,mid,(jint) msgid, (jint) arg1, (jint) arg2);
62 } 63 }
63 } 64 }
64 65
65 static void update_status(H3270 *session, LIB3270_MESSAGE id) 66 static void update_status(H3270 *session, LIB3270_MESSAGE id)
66 { 67 {
67 - post_message(session,0,id); 68 + post_message(session,1,id);
68 } 69 }
69 70
70 static void changed(H3270 *session, int offset, int len) 71 static void changed(H3270 *session, int offset, int len)
71 { 72 {
72 - post_message(session,1,offset,len); 73 + post_message(session,2,offset,len);
  74 +}
  75 +
  76 +static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args)
  77 +{
  78 + if(session->widget)
  79 + {
  80 + JNIEnv * env = ((INFO *) session->widget)->env;
  81 + jobject obj = ((INFO *) session->widget)->obj;
  82 + jclass cls = env->GetObjectClass(obj);
  83 + jmethodID mid = env->GetMethodID(cls, "postPopup", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
  84 + char * descr;
  85 +
  86 + descr = lib3270_vsprintf(fmt, args);
  87 +
  88 + env->CallVoidMethod(obj,mid, (jint) type,
  89 + env->NewStringUTF(title),
  90 + env->NewStringUTF(msg),
  91 + env->NewStringUTF(descr) );
  92 + lib3270_free(descr);
  93 + }
73 } 94 }
74 95
75 JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj) 96 JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_init(JNIEnv *env, jclass obj)
76 { 97 {
77 H3270 * session = lib3270_session_new(""); 98 H3270 * session = lib3270_session_new("");
78 99
  100 + lib3270_set_popup_handler(popuphandler);
  101 +
79 session->changed = changed; 102 session->changed = changed;
80 session->update_status = update_status; 103 session->update_status = update_status;
81 104
android/res/values/strings.xml 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 +
  4 + <string name="hello">Hello World, PW3270Activity!</string>
  5 + <string name="app_name">PW3270</string>
  6 + <string-array name="program_msg">
  7 + <item>LIB3270_MESSAGE_NONE</item>
  8 + <item>LIB3270_MESSAGE_SYSWAIT</item>
  9 + <item>LIB3270_MESSAGE_TWAIT</item>
  10 + <item>LIB3270_MESSAGE_CONNECTED</item>
  11 + <item>LIB3270_MESSAGE_DISCONNECTED</item>
  12 + <item>LIB3270_MESSAGE_AWAITING_FIRST</item>
  13 + <item>LIB3270_MESSAGE_MINUS</item>
  14 + <item>LIB3270_MESSAGE_PROTECTED</item>
  15 + <item>LIB3270_MESSAGE_NUMERIC</item>
  16 + <item>LIB3270_MESSAGE_OVERFLOW</item>
  17 + <item>LIB3270_MESSAGE_INHIBIT</item>
  18 + <item>LIB3270_MESSAGE_KYBDLOCK</item>
  19 + <item>LIB3270_MESSAGE_X</item>
  20 + <item>LIB3270_MESSAGE_RESOLVING</item>
  21 + <item>LIB3270_MESSAGE_CONNECTING</item>
  22 + </string-array>
  23 +
  24 +
  25 +</resources>
0 \ No newline at end of file 26 \ No newline at end of file
android/src/br/com/bb/pw3270/PW3270Activity.java
@@ -6,6 +6,7 @@ import android.widget.TextView; @@ -6,6 +6,7 @@ import android.widget.TextView;
6 import android.widget.Button; 6 import android.widget.Button;
7 import android.widget.EditText; 7 import android.widget.EditText;
8 import android.view.View; 8 import android.view.View;
  9 +import android.content.res.*;
9 10
10 public class PW3270Activity extends Activity implements View.OnClickListener 11 public class PW3270Activity extends Activity implements View.OnClickListener
11 { 12 {
@@ -20,24 +21,34 @@ public class PW3270Activity extends Activity implements View.OnClickListener @@ -20,24 +21,34 @@ public class PW3270Activity extends Activity implements View.OnClickListener
20 21
21 } 22 }
22 23
23 - protected void update_message(int id) 24 + protected void updateProgramMessage(int id)
24 { 25 {
25 - this.view.setText("ID=" + id); 26 + this.view.setText(message[id]);
  27 + }
  28 +
  29 + public void popupMessage(int type, String title, String text, String info)
  30 + {
  31 + this.view.setText(title + "\n" + text + "\n" + info);
26 } 32 }
27 33
28 34
29 }; 35 };
30 36
31 - terminal host;  
32 - EditText uri; 37 + private terminal host;
  38 + private EditText uri;
  39 + private Resources res;
  40 + private String[] message;
33 41
34 /** Called when the activity is first created. */ 42 /** Called when the activity is first created. */
35 @Override 43 @Override
36 - public void onCreate(Bundle savedInstanceState) { 44 + public void onCreate(Bundle savedInstanceState)
  45 + {
37 super.onCreate(savedInstanceState); 46 super.onCreate(savedInstanceState);
38 setContentView(R.layout.main); 47 setContentView(R.layout.main);
39 48
40 - uri = (EditText) findViewById(R.id.hostname); 49 + res = getResources();
  50 + message = res.getStringArray(R.array.program_msg);
  51 + uri = (EditText) findViewById(R.id.hostname);
41 52
42 // Set button 53 // Set button
43 Button btn = (Button) findViewById(R.id.connect); 54 Button btn = (Button) findViewById(R.id.connect);
@@ -50,7 +61,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener @@ -50,7 +61,7 @@ public class PW3270Activity extends Activity implements View.OnClickListener
50 public void onClick(View v) 61 public void onClick(View v)
51 { 62 {
52 // Perform action on click 63 // Perform action on click
53 - host.setHost(uri.getText().toString()); 64 + // host.setHost(uri.getText().toString());
54 host.connect(); 65 host.connect();
55 } 66 }
56 67
android/src/br/com/bb/pw3270/lib3270.java
@@ -8,8 +8,8 @@ import android.os.Message; @@ -8,8 +8,8 @@ import android.os.Message;
8 8
9 public class lib3270 9 public class lib3270
10 { 10 {
11 - NetworkThread terminal;  
12 - 11 + private NetworkThread mainloop;
  12 +
13 static 13 static
14 { 14 {
15 System.loadLibrary("3270"); 15 System.loadLibrary("3270");
@@ -18,29 +18,46 @@ public class lib3270 @@ -18,29 +18,46 @@ public class lib3270
18 18
19 lib3270() 19 lib3270()
20 { 20 {
21 - terminal = new NetworkThread(handler); 21 + mainloop = null;
  22 + }
  23 +
  24 + private class popupMessageInfo
  25 + {
  26 + public String title;
  27 + public String text;
  28 + public String info;
  29 +
  30 + popupMessageInfo(String title, String text, String info)
  31 + {
  32 + this.title = title;
  33 + this.text = text;
  34 + this.info = info;
  35 + }
22 } 36 }
23 37
24 // Main Thread 38 // Main Thread
25 - private class NetworkThread extends Thread 39 + private class NetworkThread extends Thread
26 { 40 {
27 Handler mHandler; 41 Handler mHandler;
28 -  
29 - NetworkThread(Handler h) 42 +
  43 + NetworkThread(Handler h)
30 { 44 {
31 mHandler = h; 45 mHandler = h;
32 } 46 }
33 - 47 +
34 public void run() 48 public void run()
35 { 49 {
36 - postMessage(0,99,0);  
37 -/* 50 + postMessage(0,1,0);
  51 + postPopup(0,"titulo","texto","info");
  52 +
  53 + /*
38 do_connect(); 54 do_connect();
39 while(isConnected()) 55 while(isConnected())
40 processEvents(); 56 processEvents();
41 -*/ 57 + */
  58 + postMessage(0,0,0);
42 } 59 }
43 - 60 +
44 public void postMessage(int what, int arg1, int arg2) 61 public void postMessage(int what, int arg1, int arg2)
45 { 62 {
46 Message msg = mHandler.obtainMessage(); 63 Message msg = mHandler.obtainMessage();
@@ -49,39 +66,77 @@ public class lib3270 @@ -49,39 +66,77 @@ public class lib3270
49 msg.arg2 = arg2; 66 msg.arg2 = arg2;
50 mHandler.sendMessage(msg); 67 mHandler.sendMessage(msg);
51 } 68 }
52 - 69 +
  70 + public void postPopup(int type, String title, String text, String info)
  71 + {
  72 + Message msg = mHandler.obtainMessage();
  73 +
  74 + msg.what = 3;
  75 + msg.arg1 = type;
  76 + msg.obj = new popupMessageInfo(title,text,info);
  77 + mHandler.sendMessage(msg);
  78 + }
  79 +
53 } 80 }
54 - 81 +
  82 + public void postMessage(int what, int arg1, int arg2)
  83 + {
  84 + mainloop.postMessage(what, arg1, arg2);
  85 + }
  86 +
55 // Define the Handler that receives messages from the thread and update the progress 87 // Define the Handler that receives messages from the thread and update the progress
56 - final Handler handler = new Handler() 88 + final Handler handler = new Handler()
57 { 89 {
58 public void handleMessage(Message msg) 90 public void handleMessage(Message msg)
59 { 91 {
60 switch(msg.what) 92 switch(msg.what)
61 { 93 {
62 - case 0:  
63 - update_message(msg.arg1); 94 + case 0: // Start/Stop service thread
  95 + if(msg.arg1 == 0)
  96 + {
  97 + mainloop = null;
  98 + }
  99 + break;
  100 +
  101 + case 1: // OIA message has changed
  102 + updateProgramMessage(msg.arg1);
  103 + break;
  104 +
  105 + case 2: // Screen changed
  106 + break;
  107 +
  108 + case 3: // Popup
  109 + popupMessageInfo popup = (popupMessageInfo) msg.obj;
  110 + popupMessage(msg.arg1, popup.title, popup.text, popup.info);
  111 +
64 break; 112 break;
65 -  
66 } 113 }
67 } 114 }
68 }; 115 };
69 - 116 +
70 /*---[ Signal methods ]--------------------------------------------------*/ 117 /*---[ Signal methods ]--------------------------------------------------*/
71 -  
72 - protected void update_message(int id) 118 +
  119 + protected void updateProgramMessage(int id)
  120 + {
  121 + }
  122 +
  123 + public void popupMessage(int type, String title, String text, String info)
73 { 124 {
74 } 125 }
75 -  
76 126
77 /*---[ External methods ]------------------------------------------------*/ 127 /*---[ External methods ]------------------------------------------------*/
78 128
79 public int connect() 129 public int connect()
80 { 130 {
81 - terminal.start();  
82 - return 0; 131 + if(mainloop == null)
  132 + {
  133 + mainloop = new NetworkThread(handler);
  134 + mainloop.start();
  135 + return 0;
  136 + }
  137 + return -1;
83 } 138 }
84 - 139 +
85 /*---[ Native calls ]----------------------------------------------------*/ 140 /*---[ Native calls ]----------------------------------------------------*/
86 static private native int init(); 141 static private native int init();
87 142
@@ -90,7 +145,6 @@ public class lib3270 @@ -90,7 +145,6 @@ public class lib3270
90 145
91 // Misc calls 146 // Misc calls
92 public native String getEncoding(); 147 public native String getEncoding();
93 -  
94 public native String getVersion(); 148 public native String getVersion();
95 public native String getRevision(); 149 public native String getRevision();
96 150
@@ -100,5 +154,5 @@ public class lib3270 @@ -100,5 +154,5 @@ public class lib3270
100 public native boolean isConnected(); 154 public native boolean isConnected();
101 public native boolean isTerminalReady(); 155 public native boolean isTerminalReady();
102 156
103 - 157 +
104 } 158 }