author | Ed Swartz <ed.swartz@nokia.com> |
Tue, 16 Feb 2010 09:29:07 -0600 | |
changeset 961 | 8c95e3acb374 |
parent 924 | 657e34ac671f |
child 962 | 239e8d35ac54 |
permissions | -rw-r--r-- |
748 | 1 |
/** |
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
package com.nokia.carbide.trk.support.status; |
|
19 |
||
20 |
import java.util.ArrayList; |
|
21 |
import java.util.List; |
|
22 |
||
924
657e34ac671f
Fix deadlock when the Select Connection dialog is up, user plugs in a device, and the Remote Connections view is shown
Ed Swartz <ed.swartz@nokia.com>
parents:
848
diff
changeset
|
23 |
import org.eclipse.swt.widgets.Display; |
657e34ac671f
Fix deadlock when the Select Connection dialog is up, user plugs in a device, and the Remote Connections view is shown
Ed Swartz <ed.swartz@nokia.com>
parents:
848
diff
changeset
|
24 |
import org.eclipse.swt.widgets.Shell; |
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
25 |
import org.eclipse.ui.PartInitException; |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
26 |
|
748 | 27 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
28 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
|
29 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
30 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
|
31 |
import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection.ConnectionStatus; |
|
32 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
|
33 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
|
34 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
35 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; |
|
36 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
37 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
748 | 38 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; |
749 | 39 |
import com.nokia.carbide.trk.support.Messages; |
748 | 40 |
import com.nokia.carbide.trk.support.connection.USBConnectionType; |
41 |
import com.nokia.carbide.trk.support.service.TRKConnectedService; |
|
42 |
import com.nokia.carbide.trk.support.service.TracingConnectedService; |
|
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
43 |
import com.nokia.cpp.internal.api.utils.ui.RunRunnableWhenWorkbenchVisibleJob; |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
44 |
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
748 | 45 |
|
46 |
/** |
|
47 |
* A singleton object that manages the device status of dynamic connections |
|
48 |
* based on the status of the TRK and Tracing services. |
|
49 |
*/ |
|
50 |
public class ConnectionStatusReconciler { |
|
51 |
||
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
52 |
private static final String CONNECTIONS_VIEW_ID = |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
53 |
"com.nokia.carbide.remoteconnections.view.ConnectionsView"; //$NON-NLS-1$ |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
54 |
|
748 | 55 |
private class ConnectionListener implements IConnectionListener { |
56 |
||
57 |
public void connectionAdded(IConnection connection) { |
|
58 |
addConnection(connection); |
|
59 |
} |
|
60 |
||
61 |
public void connectionRemoved(IConnection connection) { |
|
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
62 |
if (connection.equals(userSetCurrentConnection)) |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
63 |
userSetCurrentConnection = null; |
748 | 64 |
removeConnection(connection); |
65 |
} |
|
66 |
||
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
67 |
public void currentConnectionSet(IConnection connection) { |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
68 |
if (connection != null && !connection.equals(reconcilerSetCurrentConnection)) |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
69 |
userSetCurrentConnection = connection; |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
70 |
} |
748 | 71 |
|
72 |
} |
|
73 |
||
74 |
private class ServiceStatusListener implements IStatusChangedListener { |
|
75 |
||
76 |
public void statusChanged(IStatus status) { |
|
77 |
handleServiceStatusChange(status); |
|
78 |
} |
|
79 |
||
80 |
} |
|
81 |
||
82 |
private static ConnectionStatusReconciler instance; |
|
83 |
private IConnectionsManager manager; |
|
84 |
private IConnectionListener connectionListener; |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
85 |
private List<IConnection> handledConnections; |
748 | 86 |
private ServiceStatusListener serviceStatusListener; |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
87 |
private IConnection reconcilerSetCurrentConnection; |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
88 |
private IConnection userSetCurrentConnection; |
748 | 89 |
|
90 |
private ConnectionStatusReconciler() { |
|
91 |
connectionListener = new ConnectionListener(); |
|
92 |
manager = RemoteConnectionsActivator.getConnectionsManager(); |
|
93 |
manager.addConnectionListener(connectionListener); |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
94 |
handledConnections = new ArrayList<IConnection>(); |
748 | 95 |
serviceStatusListener = new ServiceStatusListener(); |
96 |
} |
|
97 |
||
98 |
public static ConnectionStatusReconciler getInstance() { |
|
99 |
if (instance == null) |
|
100 |
instance = new ConnectionStatusReconciler(); |
|
101 |
||
102 |
return instance; |
|
103 |
} |
|
104 |
||
105 |
public void dispose() { |
|
106 |
manager.removeConnectionListener(connectionListener); |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
107 |
for (IConnection connection : new ArrayList<IConnection>(handledConnections)) { |
748 | 108 |
removeConnection(connection); |
109 |
} |
|
110 |
} |
|
111 |
||
752
a0609ea7401a
add sys trk checking for usb only and use with reconciler
dadubrow
parents:
750
diff
changeset
|
112 |
private boolean isDynamic(IConnection connection) { |
a0609ea7401a
add sys trk checking for usb only and use with reconciler
dadubrow
parents:
750
diff
changeset
|
113 |
return connection instanceof IConnection2 && ((IConnection2) connection).isDynamic(); |
748 | 114 |
} |
115 |
||
116 |
private boolean isSysTRK(TRKConnectedService service) { |
|
117 |
String value = service.getProperties().get(TRKConnectedService.PROP_SYS_TRK); |
|
752
a0609ea7401a
add sys trk checking for usb only and use with reconciler
dadubrow
parents:
750
diff
changeset
|
118 |
return Boolean.parseBoolean(value); |
748 | 119 |
} |
120 |
||
121 |
private void addConnection(IConnection connection) { |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
122 |
handledConnections.add(connection); |
748 | 123 |
for (IConnectedService service : manager.getConnectedServices(connection)) { |
124 |
if (service instanceof TRKConnectedService || |
|
125 |
service instanceof TracingConnectedService) { |
|
126 |
service.addStatusChangedListener(serviceStatusListener); |
|
127 |
} |
|
128 |
} |
|
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
129 |
showConnectionsView(); |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
130 |
} |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
131 |
|
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
132 |
private void showConnectionsView() { |
924
657e34ac671f
Fix deadlock when the Select Connection dialog is up, user plugs in a device, and the Remote Connections view is shown
Ed Swartz <ed.swartz@nokia.com>
parents:
848
diff
changeset
|
133 |
// avoid deadlock if this called as a result of a launch sequence issuing a "select connection" dialog |
961
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
134 |
final Shell shell = WorkbenchUtils.getActiveShell(); |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
135 |
final boolean isVisible[] = { true }; |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
136 |
Display.getDefault().syncExec(new Runnable() { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
137 |
public void run() { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
138 |
isVisible[0] = shell != null && shell.isVisible(); |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
139 |
} |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
140 |
}); |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
141 |
|
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
142 |
Runnable runnable = new Runnable() { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
143 |
public void run() { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
144 |
try { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
145 |
WorkbenchUtils.getView(CONNECTIONS_VIEW_ID); |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
146 |
} catch (PartInitException e) { |
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
147 |
} |
961
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
148 |
} |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
149 |
}; |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
150 |
|
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
151 |
if (shell == null || !isVisible[0]) { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
152 |
RunRunnableWhenWorkbenchVisibleJob.start(runnable); |
924
657e34ac671f
Fix deadlock when the Select Connection dialog is up, user plugs in a device, and the Remote Connections view is shown
Ed Swartz <ed.swartz@nokia.com>
parents:
848
diff
changeset
|
153 |
} else { |
961
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
154 |
Display.getDefault().asyncExec(runnable); |
924
657e34ac671f
Fix deadlock when the Select Connection dialog is up, user plugs in a device, and the Remote Connections view is shown
Ed Swartz <ed.swartz@nokia.com>
parents:
848
diff
changeset
|
155 |
} |
748 | 156 |
} |
157 |
||
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
158 |
private void reconcileAsCurrent(IConnection connection) { |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
159 |
if (canBeSetToCurrent(connection)) { |
770 | 160 |
if (isReady(connection)) { // set as current |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
161 |
reconcilerSetCurrentConnection = connection; |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
162 |
manager.setCurrentConnection(connection); |
770 | 163 |
} else if (isNotReady(connection) && connection.equals(manager.getCurrentConnection())) { |
164 |
// unset current or set something else current |
|
165 |
if (isDynamic(connection) && userSetCurrentConnection != null) { |
|
166 |
manager.setCurrentConnection(userSetCurrentConnection); |
|
167 |
} |
|
168 |
else { |
|
169 |
// look for some other existing connection that is ready |
|
170 |
for (IConnection c : manager.getConnections()) { |
|
171 |
if (canBeSetToCurrent(c) && isReady(c)) { |
|
172 |
reconcilerSetCurrentConnection = connection; |
|
173 |
manager.setCurrentConnection(connection); |
|
174 |
return; |
|
175 |
} |
|
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
176 |
} |
770 | 177 |
// set to no current connection |
178 |
manager.setCurrentConnection(null); |
|
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
179 |
} |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
180 |
} |
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
181 |
} |
758
c3cf3704d340
Make setting default part of reconciler responsibility
dadubrow
parents:
752
diff
changeset
|
182 |
} |
c3cf3704d340
Make setting default part of reconciler responsibility
dadubrow
parents:
752
diff
changeset
|
183 |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
184 |
private boolean isReady(IConnection connection) { |
770 | 185 |
return equalsConnectionStatus(connection, EConnectionStatus.READY); |
186 |
} |
|
187 |
||
188 |
private boolean isNotReady(IConnection connection) { |
|
189 |
return equalsConnectionStatus(connection, EConnectionStatus.NOT_READY); |
|
190 |
} |
|
191 |
||
192 |
private boolean equalsConnectionStatus(IConnection connection, EConnectionStatus status) { |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
193 |
if (connection instanceof IConnection2) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
194 |
IConnectionStatus connectionStatus = ((IConnection2) connection).getStatus(); |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
195 |
if (connectionStatus != null) |
770 | 196 |
return connectionStatus.getEConnectionStatus().equals(status); |
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
197 |
} |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
198 |
return false; |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
199 |
} |
770 | 200 |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
201 |
private boolean canBeSetToCurrent(IConnection connection) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
202 |
// USB connections for now |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
203 |
return USBConnectionType.ID.equals(connection.getConnectionType().getIdentifier()); |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
204 |
} |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
205 |
|
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
206 |
private void reconcileStatus(IConnection connection) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
207 |
if (!isDynamic(connection)) // don't set status for user generated connections |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
208 |
return; |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
209 |
|
748 | 210 |
boolean isSysTRK = false; |
211 |
EStatus trkStatus = EStatus.UNKNOWN; |
|
212 |
EStatus traceStatus = EStatus.UNKNOWN; |
|
213 |
for (IConnectedService service : manager.getConnectedServices(connection)) { |
|
214 |
if (service instanceof TRKConnectedService) { |
|
215 |
isSysTRK = isSysTRK((TRKConnectedService) service); |
|
216 |
trkStatus = service.getStatus().getEStatus(); |
|
217 |
} |
|
218 |
if (service instanceof TracingConnectedService) { |
|
219 |
traceStatus = service.getStatus().getEStatus(); |
|
220 |
} |
|
221 |
} |
|
222 |
setConnectionStatus((IConnection2) connection, isSysTRK, trkStatus, traceStatus); |
|
223 |
} |
|
224 |
||
225 |
private void setConnectionStatus(IConnection2 connection, boolean isSysTRK, EStatus trkStatus, EStatus traceStatus) { |
|
226 |
// use trk status |
|
227 |
EConnectionStatus connectionStatus = service2ConnectionStatus(trkStatus); |
|
228 |
// if sys trk, tracing also used |
|
229 |
if (isSysTRK && connectionStatus.equals(EConnectionStatus.READY)) { |
|
230 |
connectionStatus = service2ConnectionStatus(traceStatus); |
|
231 |
} |
|
232 |
||
233 |
String shortDesc = getShortDescriptionForStatus(connectionStatus); |
|
749 | 234 |
StringBuilder longDesc = new StringBuilder(Messages.getString("ConnectionStatusReconciler_TRKServicePrefix")); //$NON-NLS-1$ |
748 | 235 |
longDesc.append(getServiceStatusString(trkStatus)); |
236 |
if (isSysTRK) { |
|
749 | 237 |
longDesc.append(Messages.getString("ConnectionStatusReconciler_TracingServicePrefix")); //$NON-NLS-1$ |
748 | 238 |
longDesc.append(getServiceStatusString(traceStatus)); |
239 |
} |
|
240 |
||
241 |
connection.setStatus(new ConnectionStatus(connectionStatus, shortDesc, longDesc.toString())); |
|
242 |
} |
|
243 |
||
244 |
private String getShortDescriptionForStatus(EConnectionStatus connectionStatus) { |
|
245 |
switch (connectionStatus) { |
|
246 |
case READY: |
|
749 | 247 |
return Messages.getString("ConnectionStatusReconciler_ReadyLabel"); //$NON-NLS-1$ |
748 | 248 |
case NOT_READY: |
749 | 249 |
return Messages.getString("ConnectionStatusReconciler_NotReadyLabel"); //$NON-NLS-1$ |
748 | 250 |
case IN_USE: |
749 | 251 |
return Messages.getString("ConnectionStatusReconciler_InUseLabel"); //$NON-NLS-1$ |
748 | 252 |
case IN_USE_DISCONNECTED: |
749 | 253 |
return Messages.getString("ConnectionStatusReconciler_DisconnectedLabel"); //$NON-NLS-1$ |
748 | 254 |
} |
749 | 255 |
return ""; //$NON-NLS-1$ |
748 | 256 |
} |
257 |
||
258 |
private String getServiceStatusString(EStatus status) { |
|
259 |
switch (status) { |
|
260 |
case UP: |
|
749 | 261 |
return Messages.getString("ConnectionStatusReconciler_availableLabel"); //$NON-NLS-1$ |
748 | 262 |
case DOWN: |
749 | 263 |
return Messages.getString("ConnectionStatusReconciler_unavailableLabel"); //$NON-NLS-1$ |
748 | 264 |
case IN_USE: |
749 | 265 |
return Messages.getString("ConnectionStatusReconciler_inUseLabel_lower"); //$NON-NLS-1$ |
748 | 266 |
} |
749 | 267 |
return ""; //$NON-NLS-1$ |
748 | 268 |
} |
269 |
||
270 |
private EConnectionStatus service2ConnectionStatus(EStatus serviceStatus) { |
|
271 |
switch (serviceStatus) { |
|
272 |
case UP: |
|
273 |
return EConnectionStatus.READY; |
|
274 |
case DOWN: |
|
275 |
return EConnectionStatus.NOT_READY; |
|
276 |
case IN_USE: |
|
277 |
return EConnectionStatus.IN_USE; |
|
278 |
} |
|
279 |
return EConnectionStatus.NONE; |
|
280 |
} |
|
281 |
||
282 |
private void removeConnection(IConnection connection) { |
|
283 |
handledConnections.remove(connection); |
|
284 |
} |
|
285 |
||
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
286 |
private IConnection findConnection(IConnectedService cs) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
287 |
for (IConnection connection : handledConnections) { |
748 | 288 |
for (IConnectedService connectedService : manager.getConnectedServices(connection)) { |
289 |
if (cs.equals(connectedService)) |
|
290 |
return connection; |
|
291 |
} |
|
292 |
} |
|
293 |
return null; |
|
294 |
} |
|
295 |
||
296 |
public void handleServiceStatusChange(IStatus status) { |
|
297 |
IConnectedService service = status.getConnectedService(); |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
298 |
IConnection connection = findConnection(service); |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
299 |
if (connection instanceof IConnection2) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
300 |
reconcileStatus((IConnection2) connection); |
748 | 301 |
} |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
302 |
if (connection != null) |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
303 |
reconcileAsCurrent(connection); |
748 | 304 |
} |
305 |
||
306 |
} |