001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package org.anarres.qemu.exec; 006 007import java.io.File; 008import java.net.InetAddress; 009import javax.annotation.CheckForNull; 010import javax.annotation.Nonnegative; 011 012/** 013 * 014 * @author shevek 015 */ 016public abstract class VncDisplay { 017 018 public static class Socket extends VncDisplay { 019 020 private final InetAddress address; 021 private final int display; 022 023 public Socket(@CheckForNull InetAddress address, @Nonnegative int display) { 024 this.address = address; 025 this.display = display; 026 } 027 028 public Socket(@Nonnegative int display) { 029 this(null, display); 030 } 031 032 @Override 033 public String toString() { 034 StringBuilder buf = new StringBuilder(); 035 if (address != null) 036 buf.append(address.getHostAddress()); 037 else 038 buf.append("0.0.0.0"); 039 buf.append(':').append(display); 040 return buf.toString(); 041 } 042 } 043 044 public static class Unix extends VncDisplay { 045 046 private final File path; 047 048 public Unix(File path) { 049 this.path = path; 050 } 051 052 public Unix(String path) { 053 this(new File(path)); 054 } 055 056 @Override 057 public String toString() { 058 return "unix:" + path.getAbsolutePath(); 059 } 060 } 061 062 public static class None extends VncDisplay { 063 064 @Override 065 public String toString() { 066 return "none"; 067 } 068 } 069 070 public enum Share { 071 072 ALLOW_EXCLUSIVE("allow-exclusive"), 073 FORCE_SHARED("force-shared"), 074 IGNORE("ignore"); 075 private final String text; 076 077 private Share(String text) { 078 this.text = text; 079 } 080 081 @Override 082 public String toString() { 083 return text; 084 } 085 } 086 public boolean reverse; 087 public boolean tls; 088 public boolean password; 089 public File x509; 090 public File x509verify; 091 public boolean sasl; 092 public boolean acl; 093 public boolean lossy; 094 public boolean nonadaptive; 095 public Share share; 096 097 private void append(StringBuilder buf, String text, boolean b) { 098 if (b) 099 buf.append(",").append(text); 100 } 101 102 private void append(StringBuilder buf, String text, File f) { 103 if (f != null) 104 buf.append(",").append(text).append("=").append(f.getAbsolutePath()); 105 } 106 107 @Override 108 public String toString() { 109 StringBuilder buf = new StringBuilder(); 110 append(buf, "reverse", reverse); 111 append(buf, "tls", tls); 112 append(buf, "password", password); 113 append(buf, "x509", x509); 114 append(buf, "x509verify", x509verify); 115 append(buf, "sasl", sasl); 116 append(buf, "acl", acl); 117 append(buf, "lossy", lossy); 118 append(buf, "non-adaptive", nonadaptive); 119 if (share != null) 120 buf.append(",share=").append(share); 121 return buf.toString(); 122 } 123}