Mercurial > hg > Applications > AliceVNC
changeset 31:556e27a53219
refactor and bug fix
author | sugi |
---|---|
date | Sat, 08 Nov 2014 23:11:45 +0900 |
parents | d8c6a4c7f16e |
children | 7d65ad341cc9 |
files | src/main/java/jp/ac/u_ryukyu/alicevnc/AliceVNC.java src/main/java/jp/ac/u_ryukyu/alicevnc/CheckCurrentInfo.java src/main/java/jp/ac/u_ryukyu/alicevnc/CheckMyName.java src/main/java/jp/ac/u_ryukyu/alicevnc/CreateWindow.java src/main/java/jp/ac/u_ryukyu/alicevnc/NegotiateVNCServer.java src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveChangeRequest.java src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveServerInitMessage.java src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveUpdateRectangle.java src/main/java/jp/ac/u_ryukyu/alicevnc/RenderAndControllerHolder.java |
diffstat | 9 files changed, 96 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/AliceVNC.java Sat Nov 08 21:00:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/AliceVNC.java Sat Nov 08 23:11:45 2014 +0900 @@ -13,9 +13,7 @@ public void run() { ods.put("AliceVNCConfig", conf); new CheckMyName(); - new ReceiveChangeRequest(); - new SendChangeRequest(); - new NegotiateVNCServer(); + } }
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckCurrentInfo.java Sat Nov 08 21:00:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckCurrentInfo.java Sat Nov 08 23:11:45 2014 +0900 @@ -41,9 +41,6 @@ address = mes.route.get(last); mes.route.remove(last); ods.put(address, "changeRequest", mes); - - // update current server info - //ods.update("currentServer", order); } else { // not allow to change int last = order.route.size() - 1;
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckMyName.java Sat Nov 08 21:00:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckMyName.java Sat Nov 08 23:11:45 2014 +0900 @@ -14,13 +14,15 @@ @Override public void run() { - boolean vncRight = false; if ("node0".equals(info.asString())) { - vncRight = true; + new CreateWindow("local"); + new NegotiateVNCServer(); } else { - + new CreateWindow("parent"); } - ods.put("vncRight", vncRight); + + new ReceiveChangeRequest(); + new SendChangeRequest(); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/CreateWindow.java Sat Nov 08 23:11:45 2014 +0900 @@ -0,0 +1,67 @@ +package jp.ac.u_ryukyu.alicevnc; + +import com.glavsoft.drawing.Renderer; +import com.glavsoft.rfb.IRepaintController; +import com.glavsoft.rfb.encoding.PixelFormat; +import com.glavsoft.rfb.encoding.decoder.AliceVNCMessage; +import com.glavsoft.rfb.protocol.Protocol; +import com.glavsoft.rfb.protocol.ProtocolSettings; +import com.glavsoft.viewer.Viewer; +import com.glavsoft.viewer.cli.Parser; +import com.glavsoft.viewer.swing.ParametersHandler; +import com.glavsoft.viewer.swing.SwingViewerWindow; +import com.glavsoft.viewer.swing.SwingViewerWindowFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class CreateWindow extends CodeSegment { + + private Receiver info = ids.create(CommandType.PEEK); + + public CreateWindow(String key){ + info.setKey(key, "initMessage"); + } + + public void run() { + PixelFormat pixelFormat = null; + int width = 0; + int height = 0; + String name = "defalut"; + + Parser parser = new Parser(); + ParametersHandler.completeParserOptions(parser); + if (parser.isSet(ParametersHandler.ARG_HELP)) { + System.exit(0); + } + Viewer viewer = new Viewer(parser); + SwingViewerWindowFactory viewerWindowFactory = new SwingViewerWindowFactory(true, false, viewer); + ProtocolSettings settings = ProtocolSettings.getDefaultSettings(); + + Protocol context = new Protocol(null, null, null, settings); + context.setMessageQueue(new MyMessageQueue()); + + AliceVNCMessage message = info.asClass(AliceVNCMessage.class); + pixelFormat = message.getPixelFormat(); + width = message.width; + height = message.height; + name = message.name; + ods.update("initMessage", message); + + context.setPixelFormat(pixelFormat); + context.setFbWidth(width); + context.setFbHeight(height); + context.setRemoteDesktopName(name); + + SwingViewerWindow viewerWindow = viewerWindowFactory.createViewerWindow(context, settings, viewer.getUiSettings(), null, null); + settings.setViewOnly(true); + IRepaintController repaintController = viewerWindow.getSurface(); + Renderer renderer = repaintController.createRenderer(null, width, height, context.getPixelFormat()); + RenderAndControllerHolder holder = new RenderAndControllerHolder(renderer, repaintController); + ods.put("holder", holder); + + new ReceiveUpdateRectangle(); + } + +}
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/NegotiateVNCServer.java Sat Nov 08 21:00:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/NegotiateVNCServer.java Sat Nov 08 23:11:45 2014 +0900 @@ -13,44 +13,29 @@ public class NegotiateVNCServer extends CodeSegment { private Receiver info = ids.create(CommandType.PEEK); private Receiver info1 = ids.create(CommandType.PEEK); - private Receiver info2 = ids.create(CommandType.TAKE); - public NegotiateVNCServer(){ info.setKey("host"); info1.setKey("AliceVNCConfig"); - info2.setKey("vncRight"); } @Override public void run() { - AliceVNCConfig conf = info1.asClass(AliceVNCConfig.class); String hostname = info.asString(); - boolean vncRight = info2.asClass(boolean.class); - if (vncRight) { - // root node connect to vnc Server first time. - String[] args = {"localhost"}; - // negotiate VNCServer by Viewer - Viewer.main(args); + // root node connect to vnc Server first time. + String[] args = {"localhost"}; + // negotiate VNCServer by Viewer + Viewer.main(args); - // currentServer Info - ChangeRequestMessage currentServerInfo = new ChangeRequestMessage(MessageType.CurrentVNCInfo); - currentServerInfo.name = hostname; - currentServerInfo.allowChange = conf.getAllowChange(); - ArrayList<String> list = new ArrayList<String>(); - currentServerInfo.route = list; - ods.put("changeRequest", currentServerInfo); - new ReceiveServerInitMessage(); - } else { - new ReceiveServerInitMessage("parent"); - if (conf.getProxyFlag()){ - new SendChangeRequest(); - - } - } - + // currentServer Info + ChangeRequestMessage currentServerInfo = new ChangeRequestMessage(MessageType.CurrentVNCInfo); + currentServerInfo.name = hostname; + currentServerInfo.allowChange = conf.getAllowChange(); + ArrayList<String> list = new ArrayList<String>(); + currentServerInfo.route = list; + ods.put("changeRequest", currentServerInfo); }
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveChangeRequest.java Sat Nov 08 21:00:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveChangeRequest.java Sat Nov 08 23:11:45 2014 +0900 @@ -2,8 +2,6 @@ import java.util.List; -import com.glavsoft.viewer.Viewer; - import jp.ac.u_ryukyu.alicevnc.ChangeRequestMessage.MessageType; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType;
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveServerInitMessage.java Sat Nov 08 21:00:49 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -package jp.ac.u_ryukyu.alicevnc; - -import com.glavsoft.drawing.Renderer; -import com.glavsoft.rfb.IRepaintController; -import com.glavsoft.rfb.encoding.PixelFormat; -import com.glavsoft.rfb.encoding.decoder.AliceVNCMessage; -import com.glavsoft.rfb.protocol.Protocol; -import com.glavsoft.rfb.protocol.ProtocolSettings; -import com.glavsoft.viewer.Viewer; -import com.glavsoft.viewer.cli.Parser; -import com.glavsoft.viewer.swing.ParametersHandler; -import com.glavsoft.viewer.swing.SwingViewerWindow; -import com.glavsoft.viewer.swing.SwingViewerWindowFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class ReceiveServerInitMessage extends CodeSegment { - - private Receiver info = ids.create(CommandType.PEEK); - - public ReceiveServerInitMessage(){ - info.setKey("ServerInitMessage"); - } - - public ReceiveServerInitMessage(String key){ - info.setKey(key, "AliceVNCInitMessage"); - } - - public void run() { - PixelFormat pixelFormat = null; - int width = 0; - int height = 0; - String name = "defalut"; - - Parser parser = new Parser(); - ParametersHandler.completeParserOptions(parser); - if (parser.isSet(ParametersHandler.ARG_HELP)) { - System.exit(0); - } - Viewer viewer = new Viewer(parser); - SwingViewerWindowFactory viewerWindowFactory = new SwingViewerWindowFactory(true, false, viewer); - ProtocolSettings settings = ProtocolSettings.getDefaultSettings(); - - Protocol context = new Protocol(null, null, null, settings); - context.setMessageQueue(new MyMessageQueue()); - - AliceVNCMessage message = info.asClass(AliceVNCMessage.class); - pixelFormat = message.getPixelFormat(); - width = message.width; - height = message.height; - name = message.name; - ods.update("AliceVNCInitMessage", message); - - context.setPixelFormat(pixelFormat); - context.setFbWidth(width); - context.setFbHeight(height); - context.setRemoteDesktopName(name); - - SwingViewerWindow viewerWindow = viewerWindowFactory.createViewerWindow(context, settings, viewer.getUiSettings(), null, null); - settings.setViewOnly(true); - IRepaintController repaintController = viewerWindow.getSurface(); - Renderer renderer = repaintController.createRenderer(null, width, height, context.getPixelFormat()); - RenderAndControllerHolder holder = new RenderAndControllerHolder(renderer, repaintController); - ods.put("Holder", holder); - - new ReceiveUpdateRectangle(); - } - -}
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveUpdateRectangle.java Sat Nov 08 21:00:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveUpdateRectangle.java Sat Nov 08 23:11:45 2014 +0900 @@ -21,7 +21,7 @@ private Receiver info3 = ids.create(CommandType.PEEK); public ReceiveUpdateRectangle(){ - info.setKey("Holder"); + info.setKey("holder"); info1.setKey("aliceVNCMessage"); info2.setKey("pixelByteArray"); info3.setKey("_CLIST"); @@ -33,17 +33,17 @@ @SuppressWarnings("unchecked") ArrayList<String> clist = info3.asClass(ArrayList.class); for (String node : clist){ - if (!info1.from.equals(node)) { + if (!info1.from.equals(node)) { // not need send data comes from - // Data Segment from other node is already serialized + // Data Segment from other node is already serialized ods.put(node, "aliceVNCMessage", info1.getReceiveData()); //ods.setCompressFlag(true); ods.put(node, "pixelByteArray", info2.getReceiveData()); ods.setCompressFlag(false); } - + } - + try { RenderAndControllerHolder holder = info.asClass(RenderAndControllerHolder.class); AliceVNCMessage message = info1.asClass(AliceVNCMessage.class); @@ -54,24 +54,23 @@ message.x, message.y, message.width, message.height); rect.encodingType = message.getEncodingType(); byte[] buf = info2.asClass(byte[].class); - + // this method name is wrong. decoder.decode(holder.getRenderer(), rect, buf, 0); holder.getRepaintController().repaintBitmap(rect); - - } else if (message.getEncodingType() == EncodingType.DESKTOP_SIZE) { + } else if (message.getEncodingType() == EncodingType.DESKTOP_SIZE) { holder.setRenderer( - holder.getRepaintController().createRenderer(null, message.width, + holder.getRepaintController().createRenderer(null, message.width, message.height, message.getPixelFormat()) ); - + } else if (message.getEncodingType() == EncodingType.RICH_CURSOR) { byte[] buf = info2.asClass(byte[].class); RichCursorDecoder.getInstance().decode(holder.getRenderer(), message, buf); holder.getRepaintController().repaintCursor(); + } - this.recycle(); } catch (TransportException e) {
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/RenderAndControllerHolder.java Sat Nov 08 21:00:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/RenderAndControllerHolder.java Sat Nov 08 23:11:45 2014 +0900 @@ -7,7 +7,7 @@ private Renderer renderer; private IRepaintController repaintController; - + public RenderAndControllerHolder(Renderer renderer, IRepaintController repaintController) { this.repaintController = repaintController;