- Timestamp:
- 07/03/07 05:18:10 (5 years ago)
- Location:
- mymrc/trunk/Java-client/src/org/myMRC
- Files:
-
- 6 modified
-
control/Controller.java (modified) (8 diffs)
-
events/Content.java (modified) (1 diff)
-
events/Opcode.java (modified) (2 diffs)
-
net/CommunicationController.java (modified) (8 diffs)
-
net/Receiver.java (modified) (1 diff)
-
settings/Configuration.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mymrc/trunk/Java-client/src/org/myMRC/control/Controller.java
r10 r15 107 107 } 108 108 109 public void setScreen(Displayable screen) { 110 display.setCurrent(screen); 111 } 109 112 110 113 /** … … 152 155 */ 153 156 public void processOutput(String opcode, String data) { 154 if (opcode.charAt(0) == '0' && opcode.charAt(1) == '9') { 155 processInternalEvent(Util.atoi(opcode), data); 157 int iopcode = Util.atoi(opcode); 158 if (iopcode >= 900 && iopcode <= 999) { 159 processInternalEvent(iopcode, data); 160 161 } else if (!communicator.isAlive()) { 162 /* 163 * connection to server lost, we should display that and 164 * go back to the default screen instead of trying to send data. 165 */ 166 this.handle(Opcode.IOP_PARSEFORM, Content.CONT_START_DISCONNECTED); 167 156 168 } else { 157 169 communicator.send(opcode, data); … … 166 178 * @param data event's data 167 179 */ 168 private void processInternalEvent(int opcode, String data) { 180 public void processInternalEvent(int opcode, String data) { 181 AlertScreen alert = null; 169 182 switch (opcode) { 170 183 case 900: … … 192 205 */ 193 206 if (!communicator.isAlive()) { 194 ConnectionStarter comstarter = new ConnectionStarter( );207 ConnectionStarter comstarter = new ConnectionStarter(this.display); 195 208 comstarter.start(); 196 209 } else { … … 200 213 break; 201 214 202 case 991:215 case Opcode.IOP_DISCONNECT: /* 991 */ 203 216 // disconnect 217 System.out.println("handling IOP_DISCONNECT"); 204 218 communicator.destroy(); 205 this.handle(Opcode.IOP_PARSEFORM, Content.CONT_START );219 this.handle(Opcode.IOP_PARSEFORM, Content.CONT_START_DISCONNECTED); 206 220 break; 207 221 … … 221 235 config.writeSettings(form); 222 236 try { 223 confcon.getInstance().save();237 confcon.getInstance().save(); 224 238 } catch (IOException ioe) { 225 239 ioe.printStackTrace(); 226 } 227 this.processInternalEvent(900, null); 240 alert = new AlertScreen("Saving settings failed!", 921, null); 241 alert.setTimeout(alert.FOREVER); 242 alert.setString("Error while saving settings:\n" + ioe.getMessage()); 243 display.setCurrent(alert); 244 break; /* uhm.. I don't get it, I really NEED a break here.. 245 * well, at least in a test case where I manually 246 * threw an IOException .. should be checked when 247 * we have some real exception case 248 */ 249 } 250 alert = new AlertScreen("Settings saved", 921, null); 251 alert.setString("Your settings have been saved successfully"); 252 display.setCurrent(alert); 253 //this.processInternalEvent(900, null); 254 break; 255 256 case 998: // exit confirmation 257 alert = new AlertScreen("Exit?", 998, display.getCurrent()); 258 alert.setString("Do you really want to quit?"); 259 display.setCurrent(alert); 228 260 break; 229 261 230 262 case 999: 231 // exit 263 // exit (the real one) 232 264 if (communicator.isAlive()) { 233 //this.processOutput(Opcode.OP_EXIT, null);234 265 communicator.destroy(); // FIXME does it work? 235 266 } … … 239 270 } 240 271 } 272 273 241 274 242 275 … … 246 279 */ 247 280 class ConnectionStarter extends Thread { 281 private Display display; 282 283 public ConnectionStarter(Display mainDisplay) { 284 this.display = mainDisplay; 285 } 286 248 287 public void run() { 288 /* hum, emulator doesn't react here sometimes anymore */ 249 289 try { 250 290 CommunicationController.getInstance().open( 251 291 "socket://" + Configuration.getInstance().getServerString()); 252 292 } catch (Exception e) { 253 e.printStackTrace(); 293 AlertScreen alert = new AlertScreen("Connection failed!", 990, display.getCurrent()); 294 alert.setString("Unable to connect to remote server:\n" + e.getMessage()); 295 display.setCurrent(alert); 296 return; /* hum.. */ 254 297 } 255 298 CommunicationController.getInstance().send(Opcode.OP_HELLO, null); -
mymrc/trunk/Java-client/src/org/myMRC/events/Content.java
r10 r15 23 23 public static final String CONT_START = 24 24 "<form label=\"myMRC 0.1\">" + 25 " <image file=\"mymrc.png\"/>" + 25 //" <image file=\"mymrc.png\"/>" + 26 " <string label=\"hallo :)\"/>" + 27 " <string label=\"Not Connected\"/>" + 26 28 " <command label=\"Connect\" opcode=\"0990\"/>" + 27 29 " <command label=\"Settings\" opcode=\"0920\"/>" + 28 30 " <command label=\"About\" opcode=\"0901\"/>" + 29 " <command label=\"Exit\" opcode=\"099 9\"/>" +30 " <command type=\"back\" label=\"Exit\" opcode=\"099 9\"/>" +31 " <command label=\"Exit\" opcode=\"0998\"/>" + 32 " <command type=\"back\" label=\"Exit\" opcode=\"0998\"/>" + 31 33 "</form>"; 32 34 35 public static final String CONT_START_DISCONNECTED = 36 "<form label=\"myMRC 0.1\">" + 37 //" <image file=\"mymrc.png\"/>" + 38 " <string label=\"hallo :)\"/>" + 39 " <string label=\"Connection lost!\"/>" + 40 " <command label=\"Connect\" opcode=\"0990\"/>" + 41 " <command label=\"Settings\" opcode=\"0920\"/>" + 42 " <command label=\"About\" opcode=\"0901\"/>" + 43 " <command label=\"Exit\" opcode=\"0998\"/>" + 44 " <command type=\"back\" label=\"Exit\" opcode=\"0998\"/>" + 45 "</form>"; 46 33 47 public static final String CONT_START_CONNECTED = 34 48 "<form label=\"myMRC 0.1\">" + 35 " <image file=\"mymrc.png\"/>" + 49 //" <image file=\"mymrc.png\"/>" + 50 " <string label=\"hallo :)\"/>" + 36 51 " <command label=\"Continue\" opcode=\"0000\"/>" + 37 52 " <command label=\"Disconnect\" opcode=\"0991\"/>" + 38 53 " <command label=\"Settings\" opcode=\"0920\"/>" + 39 54 " <command label=\"About\" opcode=\"0901\"/>" + 40 " <command label=\"Exit\" opcode=\"099 9\"/>" +41 " <command type=\"back\" label=\"Exit\" opcode=\"099 9\"/>" +55 " <command label=\"Exit\" opcode=\"0998\"/>" + 56 " <command type=\"back\" label=\"Exit\" opcode=\"0998\"/>" + 42 57 "</form>"; 43 58 -
mymrc/trunk/Java-client/src/org/myMRC/events/Opcode.java
r10 r15 20 20 public static final String OP_HELLO = "0000"; 21 21 public static final String OP_BACK = "0001"; 22 public static final int IOP_BACK = 1; 22 23 public static final String OP_NEXT = "0002"; 23 24 … … 28 29 public static final String OP_FORMKEY = "0401"; 29 30 public static final String OP_FORMVAL = "0402"; 30 31 public static final String OP_PARSELIST = "0910"; 32 public static final int IOP_PARSELIST = 910; 33 public static final String OP_PARSRFORM = "0911"; 34 public static final int IOP_PARSEFORM = 911; 31 32 /* 33 * client internal opcode group 09xx 34 */ 35 public static final String OP_PARSELIST = "0910"; 36 public static final int IOP_PARSELIST = 910; 37 public static final String OP_PARSRFORM = "0911"; 38 public static final int IOP_PARSEFORM = 911; 39 public static final int IOP_DISCONNECT = 991; 35 40 } -
mymrc/trunk/Java-client/src/org/myMRC/net/CommunicationController.java
r10 r15 12 12 import org.myMRC.Util; 13 13 import org.myMRC.control.Controller; 14 import org.myMRC.events.Opcode; 14 15 15 16 … … 51 52 private boolean isAlive = false; 52 53 private RequestTable requestTable; 53 //private EventHandler eventHandler;54 private int counter; 54 55 55 56 final int EVENTID_SIZE = 4; 56 57 final int DATABUF_SIZE = 16; 57 58 final int MAX_UNRESPONDED_SENDS = 5; 58 59 /** 59 60 * Returns the singleton instance of this class. … … 68 69 69 70 public static void destroy() { 71 System.out.println("seek and destroy \\o/"); 70 72 try { 71 73 instance.close(); … … 81 83 private CommunicationController() { 82 84 requestTable = new RequestTable(); 83 // eventHandler = new EventHandler();85 counter = 0; 84 86 } 85 87 … … 96 98 try { 97 99 socket = (SocketConnection) Connector.open(url); 100 socket.setSocketOption(SocketConnection.DELAY, 0); // disable Nagle 98 101 ostream = socket.openOutputStream(); 99 102 receiver = new Receiver(this, socket.openInputStream()); … … 105 108 * Event.execute() for EV_(RE)CONNECT will display an error in that 106 109 * case, so no special handling necessary here. 110 * 111 * FUCK THAT! 112 * FIXME! 107 113 */ 108 114 isAlive = false; 115 throw new IOException(cnfe.getMessage()); // FIXME: this is just a temporary hack 109 116 } catch (IOException ioe) { 110 117 ioe.printStackTrace(); … … 245 252 System.out.println("send: '" + sendBuf + "'"); 246 253 ostream.write(sendBuf.toString().getBytes()); 254 ostream.flush(); 255 247 256 } catch (IOException ioe) { 248 ioe.printStackTrace(); 257 //ioe.printStackTrace(); 258 Controller.getInstance().processInternalEvent(Opcode.IOP_DISCONNECT, null); 249 259 } 250 260 } … … 287 297 // eventHandler.handle(Event.getEvent(eventId), data); 288 298 } 299 300 counter = 0; 289 301 } 290 302 -
mymrc/trunk/Java-client/src/org/myMRC/net/Receiver.java
r10 r15 80 80 return null; 81 81 } 82 /* 83 *java.io.IOException: error 104 during TCP read 84 at com.sun.midp.io.j2me.socket.Protocol.nonBufferedRead(Protocol.java:299) 85 at com.sun.midp.io.BufferedConnectionAdapter.readBytes(BufferedConnectionAdapter.java:99) 86 at com.sun.midp.io.BaseInputStream.read(ConnectionBaseAdapter.java:582) 87 at org.myMRC.net.Receiver.read(Receiver.java:78) 88 at org.myMRC.net.Receiver.run(Receiver.java:47) 89 90 */ 82 91 83 92 -
mymrc/trunk/Java-client/src/org/myMRC/settings/Configuration.java
r10 r15 32 32 * default values 33 33 */ 34 final String DEFAULT_PATH = "/myMRC/"; 34 //final String DEFAULT_PATH = "/myMRC/"; 35 final String DEFAULT_PATH = "/E:/Others/"; 35 36 final String CONFIG_FILE = "myMRC.conf"; 36 37
