Mercurial > hg > RemoteEditor > Eclipse
changeset 210:6c194d94fc43
Merge with 12259860a143ecefd64205fa2b8ef5533990d9d2
author | dimolto |
---|---|
date | Sun, 19 Dec 2010 14:25:36 +0900 |
parents | a853f36c238c (diff) 12259860a143 (current diff) |
children | 399682d17382 |
files | |
diffstat | 1 files changed, 104 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/src/remoteeditor/editors/REPEditor.java Sat Dec 18 18:23:28 2010 +0900 +++ b/src/remoteeditor/editors/REPEditor.java Sun Dec 19 14:25:36 2010 +0900 @@ -30,16 +30,12 @@ private boolean hasInputLock = true; private boolean master; private boolean syncEnable = true; + private REPCommand quit = null; public REPEditor(REPText repText, boolean master){ this.repText = repText; this.master = master; repText.addTextListener(this); - if(master){ - userCommand.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,name +"-file")); - }else{ - userCommand.add(new REPCommand(REP.SMCMD_JOIN, 0, 0, 0, 0, name)); - } } public void textDeleted(REPTextEvent event) { @@ -134,78 +130,21 @@ } } - public void handle(REPCommand command) { - Logger.print(command); - if(command == null) return; - switch(command.cmd){ - case REPCMD_DELETE: - if(command.eid != eid){ - String del = repText.delete(command.lineno); - command.setString(del); - } - forward(command); - break; - case REPCMD_INSERT: - if(command.eid != eid){ - repText.insert(command.lineno, command.string); - } - forward(command); - break; - case REPCMD_NOP: - case REPCMD_INSERT_ACK: - case REPCMD_DELETE_ACK: - forward(command); - break; - case SMCMD_PUT_ACK: - sid = command.sid; - eid = command.eid; - name += "(eid="+eid+",sid="+sid+")"; - inputLock = false; - break; - case SMCMD_JOIN_ACK : - sid = command.sid; - eid = command.eid; - name += "(eid="+eid+",sid="+sid+")"; - inputLock = false; - break; - case SMCMD_START_MERGE : - // lock user input during merge (optional) - inputLock = hasInputLock; - repText.startMerge(this); - command.cmd = REP.SMCMD_START_MERGE_ACK; - send(command); - break; - case SMCMD_END_MERGE : - inputLock = false; - repText.endMerge(); - break; - case SMCMD_SYNC: - // start contents sync with newly joined editor - command.cmd = REP.SMCMD_SYNC_ACK; - forward(command); - //if (cmd.eid==eid) { - if (master && syncEnable ) { - syncCounter = 1; - timeout = 1; - } - break; - } - } + private void userInput() { - Logger.print(); REPCommand command = userCommand.poll(); if(command != null){ switch(command.cmd){ case REPCMD_DELETE_USER: - send(command); + sendCommand(command); break; case REPCMD_INSERT_USER: - send(command); + sendCommand(command); break; case SMCMD_PUT: case SMCMD_JOIN: - send(command); + sendCommand(command); break; } }else{ @@ -215,12 +154,107 @@ } } - private void forward(REPCommand command) { + private void handle(REPCommand cmd) { + if (cmd==null) return; + switch(cmd.cmd) { + case REPCMD_INSERT : + if (cmd.eid!=eid) { + repText.insert(cmd.lineno, cmd.string); + } + forwardCommand(cmd); + break; + case REPCMD_DELETE : + if (cmd.eid!=eid) { + String del=""; + if(cmd.lineno<repText.size()) { + del = repText.delete(cmd.lineno); + } + cmd.setString(del); + } + forwardCommand(cmd); + break; + case REPCMD_NOP : + case REPCMD_MERGE_MARK : + case REPCMD_INSERT_ACK : + case REPCMD_DELETE_ACK : + forwardCommand(cmd); + break; + case REPCMD_CLOSE : + case REPCMD_CLOSE_2 : + assert(false); + break; + + case SMCMD_JOIN_ACK : + sid = cmd.sid; + eid = cmd.eid; + setName(name+eid); + name += "(sid="+sid+")"; + inputLock = false; + break; + case SMCMD_PUT_ACK : + sid = cmd.sid; + eid = cmd.eid; + setName(name+eid); + name += "(sid="+sid+")"; + inputLock = false; + break; + case SMCMD_QUIT : + if (cmd.eid!=eid) + quit = cmd; + else // eid=-1 means do not forward but send it. + quit = new REPCommand(REP.SMCMD_QUIT_2, + sid, -1, seq, 0, ""); + timeout=1; + if (quit.eid==-1) + sendCommand(quit); + else + forwardCommand(quit); + quit=null; + //close connection user + + break; + case SMCMD_START_MERGE : + // lock user input during merge (optional) + inputLock = hasInputLock; + cmd.cmd = REP.SMCMD_START_MERGE_ACK; + sendCommand(cmd); + break; + case SMCMD_END_MERGE : + inputLock = false; + break; + // master editor changes QUIT_2 to QUIT_2_ACK + // Session manager should do this + case SMCMD_QUIT_2 : + if (cmd.eid!=eid) { + forwardCommand(cmd); + } else { + cmd.cmd = REP.SMCMD_QUIT_2_ACK; + sendCommand(cmd); + } + running = false; + break; + case SMCMD_SYNC: + // start contents sync with newly joined editor + cmd.cmd = REP.SMCMD_SYNC_ACK; + forwardCommand(cmd); + //if (cmd.eid==eid) { + if (master && syncEnable ) { + syncCounter = 1; + timeout = 1; + } + break; + default: + assert(false); + break; + } + } + + private void forwardCommand(REPCommand command) { REPCommand cmd = new REPCommand(command); channel.write(cmd); } - private void send(REPCommand command) { + private void sendCommand(REPCommand command) { REPCommand cmd = new REPCommand(command); cmd.setSEQID(seq++); cmd.setEID(eid); @@ -237,8 +271,8 @@ int i = syncCounter - 1; REPCommand del = new REPCommand(REP.REPCMD_DELETE_USER, sid, eid, 0, i, repText.get(i)); REPCommand ins = new REPCommand(REP.REPCMD_INSERT_USER, sid, eid, 0, i, repText.get(i)); - send(del); - send(ins); + sendCommand(del); + sendCommand(ins); syncCounter++; } }