changeset 176:fa6cfb85444e

on going ...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 22 Jun 2014 15:08:45 +0900
parents e1aa06b0d2ff
children 8019a393875a
files src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java
diffstat 7 files changed, 66 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Sun Jun 22 11:35:01 2014 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Sun Jun 22 15:08:45 2014 +0900
@@ -151,7 +151,7 @@
                 logger.severe("Close session: " + e.getMessage());
 				if(!rfb.isRoot() && !(rfb.getTerminationType())) {
 					System.out.println("task stop");
-					TreeVncProtocol echo = rfb.getEcho();
+					TreeVncProtocol echo = new TreeVncProtocol(rfb.getConnectionParam().getHostName(), rfb.getConnectionParam().getPort());
 					int counter = 3;
 					while(counter-- > 0) {
 						try {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java	Sun Jun 22 11:35:01 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java	Sun Jun 22 15:08:45 2014 +0900
@@ -13,7 +13,6 @@
 	private int portNumber = ConnectionParams.DEFAULT_VNC_ROOT;
 	private MyRfbProto rfb;
     private String myHostName;
-    public TreeVncCommandChannelListener acceptThread;
 	
 	public CreateConnectionParam(MyRfbProto rfb) {
 		this.rfb = rfb;
@@ -33,22 +32,15 @@
 	 * @param v
 	 */
 	public void createConnectionParam(ViewerInterface v) {
+        rfb.setConnectionParam(this);
 		TreeVncProtocol echo = new TreeVncProtocol(hostName,portNumber);
-		rfb.setEcho(echo);
 		try {
             echo.whereToConnect(myHostName,rfb.getAcceptPort());
         } catch (IOException e) {
-            // cannot send where to connect
+            System.out.println("cannot connect to root "+e.getMessage());
         }
 	}
 	
-	public void runTreeVncCommandListener() {
-		rfb.selectPort(ConnectionParams.DEFAULT_VNC_ROOT);
-		acceptThread = new TreeVncCommandChannelListener(rfb, rfb.getAcceptPort());
-		Thread accThread = new Thread(acceptThread, "tree-vnc-command-listener");
-		accThread.start();
-	}
-
 	public synchronized void setHostName(String _hostName, int port, String _myHostName) {
 	    hostName = _hostName;
 	    portNumber = port;
@@ -63,13 +55,19 @@
 	        hostName = hostAndPort.substring(0,i);
 	    } else  
 	        hostName = hostAndPort;
+	    // who sets myHostName?
 	}
 
 	public String getMyHostName() {
 	    return myHostName;
 	}
 
-    public  TreeVncCommandChannelListener getAcceptThread() {
-        return acceptThread;
+    public int getPort() {
+        return portNumber;
     }
+
+    public String getHostName() {
+        return hostName;
+    }
+
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Sun Jun 22 11:35:01 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Sun Jun 22 15:08:45 2014 +0900
@@ -13,7 +13,6 @@
 import java.util.zip.Deflater;
 import java.util.zip.Inflater;
 
-import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
 import jp.ac.u_ryukyu.treevnc.server.RequestScreenThread;
 import jp.ac.u_ryukyu.treevnc.server.TreeManagement;
 import jp.ac.u_ryukyu.treevnc.server.TreeRootFinderListener;
@@ -42,7 +41,6 @@
 	protected boolean readyReconnect = false;
 	private boolean cuiVersion;
 	private long counter = 0; // packet serial number
-    TreeVncProtocol treeProtocol;
     public ServerSocket servSock;
     private boolean permitChangeScreen = true;
     private static final int INFLATE_BUFSIZE = 1024 * 100;
@@ -54,8 +52,9 @@
     private boolean leader;
     private TreeManagement treeManager;
     private TreeVncCommandChannelListener acceptThread;
-    private boolean firstTime;
+    private boolean firstTime = false;
     private TreeRootFinderListener getCast;
+    private CreateConnectionParam cp;
 
 
 	public MyRfbProto() {
@@ -301,12 +300,6 @@
 		b[7] = (byte) (w & 0xff);
 		b[8] = (byte) ((h >> 8) & 0xff);
 		b[9] = (byte) (h & 0xff);
-
-//		os.write(b);
-	}
-	
-	public void setEcho(TreeVncProtocol _echo) {
-		treeProtocol = _echo;
 	}
 	
 	public void setViewer(ViewerInterface v) {
@@ -316,10 +309,6 @@
 	public ViewerInterface getViewer() {
 		return viewer;
 	}
-	
-	public TreeVncProtocol getEcho() {
-		return treeProtocol;
-	}
 
 	public void setTerminationType(boolean setType) {
 		/*nop*/
@@ -638,24 +627,27 @@
     /**
      * start accepting children
      * run rootFinderListener if necessary
-     * @param vncProxyService TODO
      */
-    public void createConnectionAndStart(ViewerInterface vncProxyService) {
+    public void createConnectionAndStart(ViewerInterface v) {
     	selectPort(ConnectionParams.DEFAULT_VNC_ROOT);
     	if (treeManager!=null) {
     	    treeManager.getList().getFirst().setPort(getAcceptPort());
     	}
-    	acceptThread = new TreeVncCommandChannelListener(this, getAcceptPort());
-    	Thread thread = new Thread(acceptThread, "TreeVNC-accept");
-    	thread.start();
-    	if(firstTime) {
-    		getCast = new TreeRootFinderListener(vncProxyService);
-    		thread = new Thread(getCast, "tree-root-find-listener");
+        startTreeVncCommandListener();
+    	if(isRoot() && firstTime) {
+    		getCast = new TreeRootFinderListener(v);
+    		Thread thread = new Thread(getCast, "tree-root-find-listener");
     		thread.start();
     		firstTime = false;
     	}
     }
 
+    public void startTreeVncCommandListener() {
+        acceptThread = new TreeVncCommandChannelListener(this, getAcceptPort());
+    	Thread thread = new Thread(acceptThread, "TreeVNC-accept");
+    	thread.start();
+    }
+
     public void initRoot(ViewerInterface vncProxyService, String hostName) {
     	treeManager = new TreeManagement(hostName, ConnectionParams.DEFAULT_VNC_ROOT,this);
         vncProxyService.initRootViewer(hostName);
@@ -666,5 +658,13 @@
         return acceptThread;
     }
 
+    public void setConnectionParam(CreateConnectionParam createConnectionParam) {
+        cp =  createConnectionParam;
+    }
+
+    public CreateConnectionParam getConnectionParam() {
+        return cp;
+    }
+
 	
 }
--- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java	Sun Jun 22 11:35:01 2014 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java	Sun Jun 22 15:08:45 2014 +0900
@@ -214,7 +214,7 @@
 		CuiViewer viewer = new CuiViewer();
 		MyRfbProtoClient rfb = new MyRfbProtoClient();
 		CreateConnectionParam cp = new CreateConnectionParam(rfb);
-		cp.runTreeVncCommandListener();
+		rfb.createConnectionAndStart(this);
 		try {
             cp.findTreeVncRoot();
         } catch (InterruptedException e) {
@@ -231,7 +231,7 @@
 		MyRfbProtoClient rfb = new MyRfbProtoClient();
 		CreateConnectionParam cp = new CreateConnectionParam(rfb);
 		cp.setHostName(hostName);
-		cp.runTreeVncCommandListener();
+		rfb.createConnectionAndStart(this);
 		cp.createConnectionParam(viewer);
 		rfb.setViewer(viewer);
 		rfb.setCuiVersion(true);
@@ -260,10 +260,6 @@
 	}
 
     @Override
-    public void createRootSelectionPanel() {
-    }
-
-    @Override
     public void connectToParenet(int port, String hostname) throws IOException {
         setTeminationType(false);
         closeApp();
@@ -296,4 +292,9 @@
         
     }
 
+    @Override
+    public void setNoConnection(boolean noConnection) {
+        
+    }
+
 }
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java	Sun Jun 22 11:35:01 2014 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java	Sun Jun 22 15:08:45 2014 +0900
@@ -25,22 +25,19 @@
 	        vps.setNoConnection(noConnection);
 	        vps.proxyStart(args,width,height);
 	        if (!permitChangeScreen ) vps.getRfb().setPermitChangeScreen(false);
+	        vps.getRfb().getAcceptThread().waitForShutdown();
+	        return;
 	    }
 	    ViewerInterface v;
 	    if (viewer) {
 	        v = cui ? new CuiViewer() : new Viewer();
 	        if (treeProxy) {
+	            v.setNoConnection(noConnection);
 	            v.proxyStart(args,width,height);
-	        }
-	        if(hostName!=null) {
-	            v.startTreeViewer(hostName,true);
 	        } else {
-	            v.startTreeViewer();
+	            v.startTreeViewer(hostName,cui);
 	        }
 	    }
-	    if (vps!=null && vps.getRfb().getAcceptThread()!=null) {
-	        vps.getRfb().getAcceptThread().waitForShutdown();
-	    }
 	}
 
 	private void modeSelect(String[] args) {
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Sun Jun 22 11:35:01 2014 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Sun Jun 22 15:08:45 2014 +0900
@@ -41,6 +41,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.Socket;
+import java.net.UnknownHostException;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
 import java.util.logging.*;
@@ -49,8 +50,6 @@
 import jp.ac.u_ryukyu.treevnc.MyRfbProto;
 import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient;
 import jp.ac.u_ryukyu.treevnc.server.MyRfbProtoProxy;
-import jp.ac.u_ryukyu.treevnc.server.TreeManagement;
-import jp.ac.u_ryukyu.treevnc.server.VncProxyService;
 
 @SuppressWarnings("serial")
 public class Viewer extends JApplet implements Runnable, WindowListener , ViewerInterface{
@@ -288,41 +287,29 @@
 	}
 	
 	/**
-	 * starter for TreeVNC
-	 */
-	public void startTreeViewer() {
-		MyRfbProtoClient rfb = new MyRfbProtoClient();
-		CreateConnectionParam cp = new CreateConnectionParam(rfb);
-		cp.runTreeVncCommandListener();
-		try {
-            cp.findTreeVncRoot();
-        } catch (InterruptedException e) {
-            System.out.println("cannot find TreeVNC Root "+e.getMessage());
-            return;
-        }
-		isTreeVNC = true;
-		myRfb =  rfb;
-        settings.setViewOnly(true); // too avoid unnecessary upward traffic
-        cp.createConnectionParam(this);
-        rfb.setViewer(this);
-        cp.getAcceptThread().waitForShutdown();
- 	}
-	
-	/**
-	 * start view with specific TreeVNC root
+	 * start TreeVNC viewer
 	 */
 	public void startTreeViewer(String hostName,boolean cui) {
 		MyRfbProtoClient rfb = new MyRfbProtoClient();
 		rfb.setCuiVersion(cui);
 		CreateConnectionParam cp = new CreateConnectionParam(rfb);
-		cp.setHostName(hostName);
-		cp.runTreeVncCommandListener();
+		if (hostName!=null) {
+		    cp.setHostName(hostName);
+		} else {
+		    try {
+		        cp.findTreeVncRoot();
+		    } catch (InterruptedException e) {
+		        System.out.println("cannot find TreeVNC Root "+e.getMessage());
+		        return;
+		    }
+		}
+		rfb.createConnectionAndStart(this);
 		cp.createConnectionParam(this);
 		isTreeVNC = true;
 		rfb.setViewer(this);
 		myRfb =  rfb;
         settings.setViewOnly(true); // too avoid unnecessary upward traffic
-        cp.getAcceptThread().waitForShutdown();
+        rfb.getAcceptThread().waitForShutdown();
 	}
 	
 
@@ -361,12 +348,8 @@
 	}
 
     @Override
-    public void createRootSelectionPanel() {
-    }
-
-    @Override
-    public void changeVNCServer(String newHostName, int i, int j, short id) {
-        
+    public void changeVNCServer(String newHostName, int i, int j, short id) throws UnknownHostException, IOException, InterruptedException {
+        myRfb.changeVNCServer(this, newHostName, i, j, id);
     }
 
     @Override
@@ -379,12 +362,6 @@
     }
 
     @Override
-    public void inhelitClients(ViewerInterface vncProxyService, String hostName) {
-        // TODO Auto-generated method stub
-        
-    }
-    
-    @Override
     public void initRootViewer(String hostName) {
         isApplet = false;
         setIsTreeVNC(true);
@@ -398,7 +375,8 @@
      * @param vs
      * @param hostName
      */
-    public void inhelitClients(VncProxyService vs, String hostName) {
+    @Override
+    public void inhelitClients(ViewerInterface vs, String hostName) {
         myRfb.setReadyReconnect(false);
         setConnectionParam(hostName,vncport);
         isApplet = true;
@@ -423,6 +401,7 @@
             System.exit(0);
         }
         myRfb = new MyRfbProtoProxy();
+        myRfb.setViewer(this);
         myRfb.initRoot(this, "localhost");
     }
 }
--- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java	Sun Jun 22 11:35:01 2014 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java	Sun Jun 22 15:08:45 2014 +0900
@@ -2,6 +2,7 @@
 
 import java.io.IOException;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import jp.ac.u_ryukyu.treevnc.MyRfbProto;
 
@@ -27,13 +28,9 @@
 
     public void startTreeViewer(String hostName, boolean b);
 
-    public void startTreeViewer();
-
-	public void createRootSelectionPanel();
-
     public void connectToParenet(int port, String hostname) throws IOException;
 
-    public void changeVNCServer(String newHostName, int i, int j, short id);
+    public void changeVNCServer(String newHostName, int i, int j, short id) throws UnknownHostException, IOException, InterruptedException;
 
     public void initRoot(String hostName, MyRfbProto myRfb);
 
@@ -43,4 +40,6 @@
 
     public void proxyStart(String[] args, int width, int height);
 
+    public void setNoConnection(boolean noConnection);
+
 }