001package edu.wpi.first.wpilibj.networktables2.client; 002 003/** 004 * Represents a state that the client is in 005 * 006 * @author Mitchell 007 * 008 */ 009public class ClientConnectionState { 010 /** 011 * indicates that the client is disconnected from the server 012 */ 013 public static final ClientConnectionState DISCONNECTED_FROM_SERVER = new ClientConnectionState("DISCONNECTED_FROM_SERVER"); 014 /** 015 * indicates that the client is connected to the server but has not yet begun communication 016 */ 017 public static final ClientConnectionState CONNECTED_TO_SERVER = new ClientConnectionState("CONNECTED_TO_SERVER"); 018 /** 019 * represents that the client has sent the hello to the server and is waiting for a response 020 */ 021 public static final ClientConnectionState SENT_HELLO_TO_SERVER = new ClientConnectionState("SENT_HELLO_TO_SERVER"); 022 /** 023 * represents that the client is now in sync with the server 024 */ 025 public static final ClientConnectionState IN_SYNC_WITH_SERVER = new ClientConnectionState("IN_SYNC_WITH_SERVER"); 026 027 /** 028 * Represents that a client received a message from the server indicating that the client's protocol revision is not supported by the server 029 * @author Mitchell 030 * 031 */ 032 public static class ProtocolUnsuppotedByServer extends ClientConnectionState{ 033 private final char serverVersion; 034 /** 035 * Create a new protocol unsupported state 036 * @param serverVersion 037 */ 038 public ProtocolUnsuppotedByServer(final char serverVersion){ 039 super("PROTOCOL_UNSUPPORTED_BY_SERVER"); 040 this.serverVersion = serverVersion; 041 } 042 /** 043 * @return the protocol version that the server reported it supports 044 */ 045 public char getServerVersion(){ 046 return serverVersion; 047 } 048 public String toString(){ 049 return "PROTOCOL_UNSUPPORTED_BY_SERVER: Server Version: 0x"+Integer.toHexString(serverVersion); 050 } 051 } 052 /** 053 * Represents that the client is in an error state 054 * 055 * @author Mitchell 056 * 057 */ 058 public static class Error extends ClientConnectionState{ 059 private final Exception e; 060 /** 061 * Create a new error state 062 * @param e 063 */ 064 public Error(final Exception e){ 065 super("CLIENT_ERROR"); 066 this.e = e; 067 } 068 /** 069 * @return the exception that caused the client to enter an error state 070 */ 071 public Exception getException(){ 072 return e; 073 } 074 public String toString(){ 075 return "CLIENT_ERROR: "+e.getClass()+": "+e.getMessage(); 076 } 077 } 078 079 private String name; 080 protected ClientConnectionState(String name){ 081 this.name = name; 082 } 083 public String toString(){ 084 return name; 085 } 086}