View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.model;
17  
18  import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
19  
20  /**
21   * @author Christian Bauer
22   */
23  public class Connection {
24  
25      static public class StatusInfo {
26  
27          private Status status;
28          private long uptimeSeconds;
29          private Error lastError;
30  
31          public StatusInfo(Status status, UnsignedIntegerFourBytes uptime, Error lastError) {
32              this(status, uptime.getValue(), lastError);
33          }
34  
35          public StatusInfo(Status status, long uptimeSeconds, Error lastError) {
36              this.status = status;
37              this.uptimeSeconds = uptimeSeconds;
38              this.lastError = lastError;
39          }
40  
41          public Status getStatus() {
42              return status;
43          }
44  
45          public long getUptimeSeconds() {
46              return uptimeSeconds;
47          }
48  
49          public UnsignedIntegerFourBytes getUptime() {
50              return new UnsignedIntegerFourBytes(getUptimeSeconds());
51          }
52  
53          public Error getLastError() {
54              return lastError;
55          }
56  
57          @Override
58          public boolean equals(Object o) {
59              if (this == o) return true;
60              if (o == null || getClass() != o.getClass()) return false;
61  
62              StatusInfo that = (StatusInfo) o;
63  
64              if (uptimeSeconds != that.uptimeSeconds) return false;
65              if (lastError != that.lastError) return false;
66              if (status != that.status) return false;
67  
68              return true;
69          }
70  
71          @Override
72          public int hashCode() {
73              int result = status.hashCode();
74              result = 31 * result + (int) (uptimeSeconds ^ (uptimeSeconds >>> 32));
75              result = 31 * result + lastError.hashCode();
76              return result;
77          }
78  
79          @Override
80          public String toString() {
81              return "(" + getClass().getSimpleName() + ") " + getStatus();
82          }
83      }
84  
85      public enum Type {
86          /**
87           * Valid connection types cannot be identified.
88           */
89          Unconfigured,
90  
91          /**
92           * The Internet Gateway is an IP router between the LAN and the WAN connection.
93           */
94          IP_Routed,
95  
96          /**
97           * The Internet Gateway is an Ethernet bridge between the LAN and the WAN connection.
98           */
99          IP_Bridged
100     }
101 
102     public enum Status {
103         /**
104          * This value indicates that other variables in the service table are
105          * uninitialized or in an invalid state.
106          */
107         Unconfigured,
108 
109         /**
110          * The WANConnectionDevice is in the process of initiating a connection
111          * for the first time after the connection became disconnected.
112          */
113         Connecting,
114 
115         /**
116          * At least one client has successfully
117          * initiated an Internet connection using this instance.
118          */
119         Connected,
120 
121         /**
122          * The connection is active (packets are allowed to flow
123          * through), but will transition to Disconnecting state after a certain period.
124          */
125         PendingDisconnect,
126 
127         /**
128          * The WANConnectionDevice is in the process of terminating a connection.
129          * On successful termination, ConnectionStatus transitions to Disconnected.
130          */
131         Disconnecting,
132 
133         /**
134          * No ISP connection is active (or being activated) from this connection
135          * instance. No packets are transiting the gateway.
136          */
137         Disconnected
138     }
139 
140     public enum Error {
141         ERROR_NONE,
142         ERROR_COMMAND_ABORTED,
143         ERROR_NOT_ENABLED_FOR_INTERNET,
144         ERROR_USER_DISCONNECT,
145         ERROR_ISP_DISCONNECT,
146         ERROR_IDLE_DISCONNECT,
147         ERROR_FORCED_DISCONNECT,
148         ERROR_NO_CARRIER,
149         ERROR_IP_CONFIGURATION,
150         ERROR_UNKNOWN
151     }
152 }