1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.support.model;
17
18 import org.fourthline.cling.model.ServiceReference;
19
20
21
22
23
24
25
26 public class ConnectionInfo {
27
28 public enum Status {
29 OK,
30 ContentFormatMismatch,
31 InsufficientBandwidth,
32 UnreliableChannel,
33 Unknown
34 }
35
36 public enum Direction {
37 Output,
38 Input;
39
40 public Direction getOpposite() {
41 return this.equals(Output) ? Input : Output;
42 }
43
44 }
45
46 final protected int connectionID;
47
48 final protected int rcsID;
49 final protected int avTransportID;
50
51 final protected ProtocolInfo protocolInfo;
52
53 final protected ServiceReference peerConnectionManager;
54 final protected int peerConnectionID;
55
56 final protected Direction direction;
57 protected Status connectionStatus = Status.Unknown;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public ConnectionInfo() {
81 this(0, 0, 0, null, null, -1, Direction.Input, Status.Unknown);
82 }
83
84
85 public ConnectionInfo(int connectionID,
86 int rcsID, int avTransportID,
87 ProtocolInfo protocolInfo,
88 ServiceReference peerConnectionManager, int peerConnectionID,
89 Direction direction, Status connectionStatus) {
90 this.connectionID = connectionID;
91 this.rcsID = rcsID;
92 this.avTransportID = avTransportID;
93 this.protocolInfo = protocolInfo;
94 this.peerConnectionManager = peerConnectionManager;
95 this.peerConnectionID = peerConnectionID;
96 this.direction = direction;
97 this.connectionStatus = connectionStatus;
98 }
99
100 public int getConnectionID() {
101 return connectionID;
102 }
103
104 public int getRcsID() {
105 return rcsID;
106 }
107
108 public int getAvTransportID() {
109 return avTransportID;
110 }
111
112 public ProtocolInfo getProtocolInfo() {
113 return protocolInfo;
114 }
115
116 public ServiceReference getPeerConnectionManager() {
117 return peerConnectionManager;
118 }
119
120 public int getPeerConnectionID() {
121 return peerConnectionID;
122 }
123
124 public Direction getDirection() {
125 return direction;
126 }
127
128 synchronized public Status getConnectionStatus() {
129 return connectionStatus;
130 }
131
132 synchronized public void setConnectionStatus(Status connectionStatus) {
133 this.connectionStatus = connectionStatus;
134 }
135
136 @Override
137 public boolean equals(Object o) {
138 if (this == o) return true;
139 if (o == null || getClass() != o.getClass()) return false;
140
141 ConnectionInfo that = (ConnectionInfo) o;
142
143 if (avTransportID != that.avTransportID) return false;
144 if (connectionID != that.connectionID) return false;
145 if (peerConnectionID != that.peerConnectionID) return false;
146 if (rcsID != that.rcsID) return false;
147 if (connectionStatus != that.connectionStatus) return false;
148 if (direction != that.direction) return false;
149 if (peerConnectionManager != null ? !peerConnectionManager.equals(that.peerConnectionManager) : that.peerConnectionManager != null)
150 return false;
151 if (protocolInfo != null ? !protocolInfo.equals(that.protocolInfo) : that.protocolInfo != null) return false;
152
153 return true;
154 }
155
156 @Override
157 public int hashCode() {
158 int result = connectionID;
159 result = 31 * result + rcsID;
160 result = 31 * result + avTransportID;
161 result = 31 * result + (protocolInfo != null ? protocolInfo.hashCode() : 0);
162 result = 31 * result + (peerConnectionManager != null ? peerConnectionManager.hashCode() : 0);
163 result = 31 * result + peerConnectionID;
164 result = 31 * result + direction.hashCode();
165 result = 31 * result + connectionStatus.hashCode();
166 return result;
167 }
168
169 @Override
170 public String toString() {
171 return "(" + getClass().getSimpleName() + ") ID: " + getConnectionID() + ", Status: " + getConnectionStatus();
172 }
173 }