001package edu.wpi.first.wpilibj.networktables2.server;
002
003/**
004 * Represents the state of a connection to the server
005 * 
006 * @author Mitchell
007 *
008 */
009public class ServerConnectionState {
010        /**
011         * represents that the server has received the connection from the client but has not yet received the client hello
012         */
013        public static final ServerConnectionState GOT_CONNECTION_FROM_CLIENT = new ServerConnectionState("GOT_CONNECTION_FROM_CLIENT");
014        /**
015         * represents that the client is in a connected non-error state
016         */
017        public static final ServerConnectionState CONNECTED_TO_CLIENT = new ServerConnectionState("CONNECTED_TO_CLIENT");
018        /**
019         * represents that the client has disconnected from the server
020         */
021        public static final ServerConnectionState CLIENT_DISCONNECTED = new ServerConnectionState("CLIENT_DISCONNECTED");
022        
023        /**
024         * Represents that the client is in an error state
025         * 
026         * @author Mitchell
027         *
028         */
029        public static class Error extends ServerConnectionState{
030                private final Exception e;
031                /**
032                 * Create a new error state
033                 * @param e
034                 */
035                public Error(final Exception e){
036                        super("SERVER_ERROR");
037                        this.e = e;
038                }
039                public String toString(){
040                        return "SERVER_ERROR: "+e.getClass()+": "+e.getMessage();
041                }
042                /**
043                 * @return the exception that caused the client connection to enter an error state
044                 */
045                public Exception getException(){
046                        return e;
047                }
048        }
049        
050        private String name;
051        protected ServerConnectionState(String name){
052                this.name = name;
053        }
054        public String toString(){
055                return name;
056        }
057}