Changeset 19

Show
Ignore:
Timestamp:
07/03/07 19:26:57 (5 years ago)
Author:
ciro
Message:

invoked internal opcode constants in all java client code.
added a counter to the CommunicationController?, so after a certain amount of send messages without any received respond, the client assumes a connection error occured and forces to disconnect.
fixed a bug in the FormParser? (the "type='options' was actually ignored, whoops)

Location:
mymrc/trunk/Java-client/src/org/myMRC
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • mymrc/trunk/Java-client/src/org/myMRC/control/Controller.java

    r15 r19  
    179179     */ 
    180180    public void processInternalEvent(int opcode, String data) { 
    181         AlertScreen alert = null; 
     181        AlertScreen alert = new AlertScreen(null, opcode, display.getCurrent()); 
     182         
    182183        switch (opcode) { 
    183             case 900: 
     184            case Opcode.IOP_START: 
    184185                if (!communicator.isAlive()) { 
    185186                    this.handle(Opcode.IOP_PARSEFORM, Content.CONT_START); 
     
    189190                break; 
    190191                 
    191             case 990: 
     192            case Opcode.IOP_CONNECT: 
    192193                // connect 
    193194                /* 
    194                  * FIXME: without using a Thread here, the connection opening 
    195                  *        blocks and nothing happens - with a Thread it somehow 
    196                  *        magically works.. 
    197                  */ 
    198                 /* 
    199                 try { 
    200                     System.out.println("trying to connect to " + config.getServerString()); 
    201                     communicator.open("socket://" + config.getServerString()); 
    202                 } catch (IOException ioe) { 
    203                     ioe.printStackTrace(); 
    204                 } 
     195                 * We have to use a separate thread to start the 
     196                 * CommunicationController. 
    205197                 */ 
    206198                if (!communicator.isAlive()) { 
     
    213205                break; 
    214206                 
    215             case Opcode.IOP_DISCONNECT: /* 991 */ 
     207            case Opcode.IOP_DISCONNECT_CONF: 
     208                // disconnect confirmation 
     209                //alert.setTitle("Disconnect?"); 
     210                alert.setString("Do you really want to disconnect?"); 
     211                display.setCurrent(alert); 
     212                break; 
     213                 
     214            case Opcode.IOP_DISCONNECT_FORCED: 
     215                alert.setString("Network communication error: " + data); 
     216                display.setCurrent(alert); 
     217                break; 
     218                 
     219            case Opcode.IOP_DISCONNECT: 
    216220                // disconnect 
    217221                System.out.println("handling IOP_DISCONNECT"); 
     
    220224                break; 
    221225                 
    222             case 901: 
     226            case Opcode.IOP_ABOUT_DIALOG: 
    223227                // about 
    224228                System.out.println("processing internal event \"About\""); 
     
    226230                break; 
    227231                 
    228             case 920: 
     232            case Opcode.IOP_SETTINGS: 
    229233                // settings 
    230234                this.handle(Opcode.IOP_PARSEFORM, Content.CONT_SETTINGS); 
    231235                break; 
    232236                 
    233             case 921: 
     237            case Opcode.IOP_SETTINGS_SAVE: 
    234238                // save settings 
    235239                config.writeSettings(form); 
     
    238242                } catch (IOException ioe) { 
    239243                    ioe.printStackTrace(); 
    240                     alert = new AlertScreen("Saving settings failed!", 921, null); 
     244                    //alert.setTitle("Saving settings failed!"); 
    241245                    alert.setTimeout(alert.FOREVER); 
    242246                    alert.setString("Error while saving settings:\n" + ioe.getMessage()); 
    243247                    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                             */ 
     248                    break; 
    249249                } 
    250                 alert = new AlertScreen("Settings saved", 921, null); 
     250                //alert.setTitle("Settings saved"); 
    251251                alert.setString("Your settings have been saved successfully"); 
    252252                display.setCurrent(alert); 
     
    254254                break; 
    255255                 
    256             case 998: // exit confirmation 
    257                 alert = new AlertScreen("Exit?", 998, display.getCurrent()); 
     256            case Opcode.IOP_INT_EXIT_CONF: // exit confirmation 
     257                //alert.setTitle("Exit?"); 
    258258                alert.setString("Do you really want to quit?"); 
    259259                display.setCurrent(alert); 
    260260                break; 
    261261                 
    262             case 999: 
     262            case Opcode.IOP_INT_EXIT: 
    263263                // exit (the real one) 
    264264                if (communicator.isAlive()) { 
     
    294294            alert.setString("Unable to connect to remote server:\n" + e.getMessage()); 
    295295            display.setCurrent(alert); 
    296             return; /* hum.. */ 
     296            return; 
    297297        } 
    298298        CommunicationController.getInstance().send(Opcode.OP_HELLO, null); 
  • mymrc/trunk/Java-client/src/org/myMRC/events/Content.java

    r15 r19  
    2626            "   <string label=\"hallo :)\"/>" + 
    2727            "   <string label=\"Not Connected\"/>" + 
    28             "   <command label=\"Connect\" opcode=\"0990\"/>" + 
    29             "   <command label=\"Settings\" opcode=\"0920\"/>" + 
    30             "   <command label=\"About\" opcode=\"0901\"/>" + 
    31             "   <command label=\"Exit\" opcode=\"0998\"/>" + 
    32             "   <command type=\"back\" label=\"Exit\" opcode=\"0998\"/>" + 
     28            "   <command label=\"Connect\" opcode=\"0" + Opcode.IOP_CONNECT + "\"/>" + 
     29            "   <command label=\"Settings\" opcode=\"0" + Opcode.IOP_SETTINGS + "\"/>" + 
     30            "   <command label=\"About\" opcode=\"0" + Opcode.IOP_ABOUT_DIALOG + "\"/>" + 
     31            "   <command label=\"Exit\" opcode=\"0" + Opcode.IOP_INT_EXIT_CONF + "\"/>" + 
     32            "   <command type=\"back\" label=\"Exit\" opcode=\"0" + Opcode.IOP_INT_EXIT_CONF + "\"/>" + 
    3333            "</form>"; 
    3434     
     
    3838            "   <string label=\"hallo :)\"/>" + 
    3939            "   <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\"/>" + 
     40            "   <command label=\"Connect\" opcode=\"0" + Opcode.IOP_CONNECT + "\"/>" + 
     41            "   <command label=\"Settings\" opcode=\"0" + Opcode.IOP_SETTINGS + "\"/>" + 
     42            "   <command label=\"About\" opcode=\"0" + Opcode.IOP_ABOUT_DIALOG + "\"/>" + 
     43            "   <command label=\"Exit\" opcode=\"0" + Opcode.IOP_INT_EXIT_CONF + "\"/>" + 
     44            "   <command type=\"back\" label=\"Exit\" opcode=\"0" + Opcode.IOP_INT_EXIT_CONF + "\"/>" + 
    4545            "</form>"; 
    4646             
     
    4949            //"   <image file=\"mymrc.png\"/>" + 
    5050            "   <string label=\"hallo :)\"/>" + 
     51            "   <string label=\"OH OH! this is deprecated, it shouldn't be displayed\"/>" + 
    5152            "   <command label=\"Continue\" opcode=\"0000\"/>" + 
    5253            "   <command label=\"Disconnect\" opcode=\"0991\"/>" + 
     
    6162            "   <textfield setting=\"serverHost\" label=\"Server Host\" size=\"20\"/>" + 
    6263            "   <textfield setting=\"serverPort\" label=\"Server Port\" type=\"number\" size=\"5\"/>" + 
    63             "   <command type=\"back\" label=\"Cancel\" opcode=\"0900\"/>" + 
    64             "   <command label=\"Save\" opcode=\"0921\"/>" + 
     64            "   <command type=\"back\" label=\"Cancel\" opcode=\"0" + Opcode.IOP_START + "\"/>" + 
     65            "   <command label=\"Save\" opcode=\"0" + Opcode.IOP_SETTINGS_SAVE + "\"/>" + 
    6566            "</form>"; 
    6667     
     
    6970            "   <string label=\"myMRC 0.1\"/>" + 
    7071            "   <string label=\"(c) 2007 Sven Gregori and Damien Lefevre\"/>" + 
    71             "   <command type=\"back\" label=\"OK\" opcode=\"0900\"/>" + 
     72            "   <command type=\"back\" label=\"Ok\" opcode=\"0" + Opcode.IOP_START + "\"/>" + 
    7273            "</form>"; 
    7374} 
  • mymrc/trunk/Java-client/src/org/myMRC/events/Opcode.java

    r15 r19  
    3333     * client internal opcode group 09xx 
    3434     */ 
    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    public static final int   IOP_START             =   900; 
     36    public static final int   IOP_ABOUT_DIALOG      =   901; 
     37    public static final String OP_PARSELIST         = "0910"; 
     38    public static final int   IOP_PARSELIST         =   910; 
     39    public static final String OP_PARSRFORM         = "0911"; 
     40    public static final int   IOP_PARSEFORM         =   911; 
     41    public static final int   IOP_SETTINGS          =   920; 
     42    public static final int   IOP_SETTINGS_SAVE     =   921; 
     43    public static final int   IOP_CONNECT           =   990; 
     44    public static final int   IOP_DISCONNECT_CONF   =   991; 
     45    public static final int   IOP_DISCONNECT_FORCED =   992; 
     46    public static final int   IOP_DISCONNECT        =   993; 
     47    public static final int   IOP_INT_EXIT_CONF     =   998; 
     48    public static final int   IOP_INT_EXIT          =   999; 
    4049} 
  • mymrc/trunk/Java-client/src/org/myMRC/net/CommunicationController.java

    r15 r19  
    105105             
    106106        } catch (ConnectionNotFoundException cnfe) { 
    107             /*  
    108              * Event.execute() for EV_(RE)CONNECT will display an error in that 
    109              * case, so no special handling necessary here. 
    110              * 
    111              *          FUCK THAT! 
    112              *          FIXME! 
    113              */ 
    114107            isAlive = false; 
    115108            throw new IOException(cnfe.getMessage()); // FIXME: this is just a temporary hack 
     
    198191            requestTable.put(replyId, requester); 
    199192        } 
     193         
    200194         
    201195        /* 
     
    249243         
    250244        try { 
     245            if (counter > MAX_UNRESPONDED_SENDS) { 
     246                throw new IOException("Maximum unresponded sends exceeded"); 
     247            } 
     248             
    251249            /* finally! we can send it ;) */ 
    252250            System.out.println("send: '" + sendBuf + "'"); 
    253251            ostream.write(sendBuf.toString().getBytes()); 
    254252            ostream.flush(); 
     253            counter++; 
    255254             
    256255        } catch (IOException ioe) { 
    257256            //ioe.printStackTrace(); 
    258             Controller.getInstance().processInternalEvent(Opcode.IOP_DISCONNECT, null); 
     257            Controller.getInstance().processInternalEvent( 
     258                    Opcode.IOP_DISCONNECT_FORCED, ioe.getMessage()); 
    259259        } 
    260260    } 
  • mymrc/trunk/Java-client/src/org/myMRC/parser/FormParser.java

    r10 r19  
    4141        if (parser.getEventType() == XmlPullParser.START_TAG) { 
    4242            if (parser.getName().equalsIgnoreCase("form")) { 
    43                 String label = parser.getAttributeValue(null, "label"); 
    44                 form.setTitle(label); 
     43                String title = parser.getAttributeValue(null, "title"); 
     44                form.setTitle(title); 
    4545 
    4646                while (!(parser.next() == XmlPullParser.END_TAG && 
     
    5050                    createFormItem(); 
    5151                } 
    52                  
    53             } else if (parser.getName().equalsIgnoreCase("command")) { 
    54                 String label = parser.getAttributeValue(null, "label"); 
    55                 String eventId = parser.getAttributeValue(null, "event"); 
    56                 form.addEventCommand(eventId, label); 
    57                  
     52                                 
    5853            } else { 
    5954                /* 
     
    163158                if (cmdType != null) { 
    164159                    if (cmdType.equalsIgnoreCase("options")) { 
    165                          
     160                        form.addEventCommand(opcode, cmdLabel); 
    166161                    } 
    167162                    else if (cmdType.equalsIgnoreCase("back")) { 
  • mymrc/trunk/Java-client/src/org/myMRC/screen/FormScreen.java

    r10 r19  
    121121        if (command == backCommand) { 
    122122            controller.processOutput(backOpcode, null); 
    123              
     123 
    124124        } else { 
    125125            for (int i = 0; i < commands.size(); i++) { 
     
    146146                            controller.processOutput(Opcode.OP_FORMVAL, value); 
    147147                        } 
    148                     }  
     148                    } 
     149                     
    149150                } else if (command == cmd.getCommand()) { 
    150151                    String opcodeIdx = cmd.getOpcode();