author | stechong |
Wed, 20 Oct 2010 11:19:31 -0500 | |
changeset 2165 | 2a7b5eccb0bc |
parent 2032 | a503dd2537d9 |
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; |
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
28 |
import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection.ConnectionStatus; |
748 | 29 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
30 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
31 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
32 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
748 | 33 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
34 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
|
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; |
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
41 |
import com.nokia.cpp.internal.api.utils.ui.RunRunnableWhenWorkbenchVisibleJob; |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
42 |
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
748 | 43 |
|
44 |
/** |
|
45 |
* A singleton object that manages the device status of dynamic connections |
|
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
46 |
* based on the status of the debugging services. |
748 | 47 |
*/ |
48 |
public class ConnectionStatusReconciler { |
|
49 |
||
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
50 |
private static final String CONNECTIONS_VIEW_ID = |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
51 |
"com.nokia.carbide.remoteconnections.view.ConnectionsView"; //$NON-NLS-1$ |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
52 |
|
748 | 53 |
private class ConnectionListener implements IConnectionListener { |
54 |
||
55 |
public void connectionAdded(IConnection connection) { |
|
56 |
addConnection(connection); |
|
57 |
} |
|
58 |
||
59 |
public void connectionRemoved(IConnection connection) { |
|
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
60 |
if (connection.equals(userSetCurrentConnection)) |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
61 |
userSetCurrentConnection = null; |
748 | 62 |
removeConnection(connection); |
63 |
} |
|
64 |
||
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
65 |
public void currentConnectionSet(IConnection connection) { |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
66 |
if (connection != null && !connection.equals(reconcilerSetCurrentConnection)) |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
67 |
userSetCurrentConnection = connection; |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
68 |
} |
748 | 69 |
|
70 |
} |
|
71 |
||
72 |
private class ServiceStatusListener implements IStatusChangedListener { |
|
73 |
||
74 |
public void statusChanged(IStatus status) { |
|
75 |
handleServiceStatusChange(status); |
|
76 |
} |
|
77 |
||
78 |
} |
|
79 |
||
80 |
private static ConnectionStatusReconciler instance; |
|
81 |
private IConnectionsManager manager; |
|
82 |
private IConnectionListener connectionListener; |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
83 |
private List<IConnection> handledConnections; |
748 | 84 |
private ServiceStatusListener serviceStatusListener; |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
85 |
private IConnection reconcilerSetCurrentConnection; |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
86 |
private IConnection userSetCurrentConnection; |
748 | 87 |
|
88 |
private ConnectionStatusReconciler() { |
|
89 |
connectionListener = new ConnectionListener(); |
|
90 |
manager = RemoteConnectionsActivator.getConnectionsManager(); |
|
91 |
manager.addConnectionListener(connectionListener); |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
92 |
handledConnections = new ArrayList<IConnection>(); |
748 | 93 |
serviceStatusListener = new ServiceStatusListener(); |
94 |
} |
|
95 |
||
96 |
public static ConnectionStatusReconciler getInstance() { |
|
97 |
if (instance == null) |
|
98 |
instance = new ConnectionStatusReconciler(); |
|
99 |
||
100 |
return instance; |
|
101 |
} |
|
102 |
||
103 |
public void dispose() { |
|
104 |
manager.removeConnectionListener(connectionListener); |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
105 |
for (IConnection connection : new ArrayList<IConnection>(handledConnections)) { |
748 | 106 |
removeConnection(connection); |
107 |
} |
|
108 |
} |
|
109 |
||
752
a0609ea7401a
add sys trk checking for usb only and use with reconciler
dadubrow
parents:
750
diff
changeset
|
110 |
private boolean isDynamic(IConnection connection) { |
a0609ea7401a
add sys trk checking for usb only and use with reconciler
dadubrow
parents:
750
diff
changeset
|
111 |
return connection instanceof IConnection2 && ((IConnection2) connection).isDynamic(); |
748 | 112 |
} |
113 |
||
1968
3482df86a51d
Remove TRK service and replace with TCF TRK service. Remove wildcard service check used as an interim when TCF TRK and TRK were both options.
Ed Swartz <ed.swartz@nokia.com>
parents:
1851
diff
changeset
|
114 |
/* C3TCF |
748 | 115 |
private boolean isSysTRK(TRKConnectedService service) { |
116 |
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
|
117 |
return Boolean.parseBoolean(value); |
748 | 118 |
} |
1968
3482df86a51d
Remove TRK service and replace with TCF TRK service. Remove wildcard service check used as an interim when TCF TRK and TRK were both options.
Ed Swartz <ed.swartz@nokia.com>
parents:
1851
diff
changeset
|
119 |
*/ |
748 | 120 |
private void addConnection(IConnection connection) { |
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
121 |
handledConnections.add(connection); |
748 | 122 |
for (IConnectedService service : manager.getConnectedServices(connection)) { |
1968
3482df86a51d
Remove TRK service and replace with TCF TRK service. Remove wildcard service check used as an interim when TCF TRK and TRK were both options.
Ed Swartz <ed.swartz@nokia.com>
parents:
1851
diff
changeset
|
123 |
if (/* C3TCF service instanceof TRKConnectedService ||*/ isTCFTRKService(service)) { |
748 | 124 |
service.addStatusChangedListener(serviceStatusListener); |
125 |
} |
|
126 |
} |
|
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
127 |
showConnectionsView(); |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
128 |
} |
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
129 |
|
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
130 |
private void showConnectionsView() { |
962
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
131 |
// avoid deadlock with RunRunnableWhenWorkbenchVisibleJob |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
132 |
// 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
|
133 |
final Shell shell = WorkbenchUtils.getActiveShell(); |
962
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
134 |
final boolean isVisible[] = { false }; |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
135 |
|
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
136 |
if (shell != null) { |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
137 |
Display.getDefault().syncExec(new Runnable() { |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
138 |
public void run() { |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
139 |
isVisible[0] = shell.isVisible(); |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
140 |
} |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
141 |
}); |
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
142 |
} |
961
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
143 |
|
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
144 |
Runnable runnable = new Runnable() { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
145 |
public void run() { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
146 |
try { |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
147 |
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
|
148 |
} catch (PartInitException e) { |
848
679300bad088
Show connections view when new connection is added
dadubrow
parents:
770
diff
changeset
|
149 |
} |
961
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 |
}; |
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
152 |
|
962
239e8d35ac54
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
961
diff
changeset
|
153 |
if (!isVisible[0]) { |
961
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
154 |
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
|
155 |
} else { |
961
8c95e3acb374
Fix bug 10725 -- jam more UI code into syncExec
Ed Swartz <ed.swartz@nokia.com>
parents:
924
diff
changeset
|
156 |
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
|
157 |
} |
748 | 158 |
} |
159 |
||
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
160 |
private void reconcileAsCurrent(IConnection connection) { |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
161 |
if (canBeSetToCurrent(connection)) { |
770 | 162 |
if (isReady(connection)) { // set as current |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
163 |
reconcilerSetCurrentConnection = connection; |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
164 |
manager.setCurrentConnection(connection); |
770 | 165 |
} else if (isNotReady(connection) && connection.equals(manager.getCurrentConnection())) { |
166 |
// unset current or set something else current |
|
167 |
if (isDynamic(connection) && userSetCurrentConnection != null) { |
|
168 |
manager.setCurrentConnection(userSetCurrentConnection); |
|
169 |
} |
|
170 |
else { |
|
171 |
// look for some other existing connection that is ready |
|
172 |
for (IConnection c : manager.getConnections()) { |
|
173 |
if (canBeSetToCurrent(c) && isReady(c)) { |
|
174 |
reconcilerSetCurrentConnection = connection; |
|
175 |
manager.setCurrentConnection(connection); |
|
176 |
return; |
|
177 |
} |
|
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
178 |
} |
770 | 179 |
// set to no current connection |
180 |
manager.setCurrentConnection(null); |
|
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
181 |
} |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
182 |
} |
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
183 |
} |
758
c3cf3704d340
Make setting default part of reconciler responsibility
dadubrow
parents:
752
diff
changeset
|
184 |
} |
c3cf3704d340
Make setting default part of reconciler responsibility
dadubrow
parents:
752
diff
changeset
|
185 |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
186 |
private boolean isReady(IConnection connection) { |
770 | 187 |
return equalsConnectionStatus(connection, EConnectionStatus.READY); |
188 |
} |
|
189 |
||
190 |
private boolean isNotReady(IConnection connection) { |
|
191 |
return equalsConnectionStatus(connection, EConnectionStatus.NOT_READY); |
|
192 |
} |
|
193 |
||
194 |
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
|
195 |
if (connection instanceof IConnection2) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
196 |
IConnectionStatus connectionStatus = ((IConnection2) connection).getStatus(); |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
197 |
if (connectionStatus != null) |
770 | 198 |
return connectionStatus.getEConnectionStatus().equals(status); |
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
199 |
} |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
200 |
return false; |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
201 |
} |
770 | 202 |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
203 |
private boolean canBeSetToCurrent(IConnection connection) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
204 |
// USB connections for now |
1559
cc9cfb62406b
Remove temporary USB (TCF) connection and move TCF-related services into Carbide EDC
Ed Swartz <ed.swartz@nokia.com>
parents:
1416
diff
changeset
|
205 |
return USBConnectionType.ID.equals(connection.getConnectionType().getIdentifier()); |
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
206 |
} |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
207 |
|
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
208 |
private void reconcileStatus(IConnection connection) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
209 |
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
|
210 |
return; |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
211 |
|
748 | 212 |
boolean isSysTRK = false; |
213 |
EStatus trkStatus = EStatus.UNKNOWN; |
|
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
214 |
EStatus tcfTRKStatus = EStatus.UNKNOWN; |
748 | 215 |
for (IConnectedService service : manager.getConnectedServices(connection)) { |
1968
3482df86a51d
Remove TRK service and replace with TCF TRK service. Remove wildcard service check used as an interim when TCF TRK and TRK were both options.
Ed Swartz <ed.swartz@nokia.com>
parents:
1851
diff
changeset
|
216 |
/* C3TCF |
748 | 217 |
if (service instanceof TRKConnectedService) { |
218 |
isSysTRK = isSysTRK((TRKConnectedService) service); |
|
219 |
trkStatus = service.getStatus().getEStatus(); |
|
220 |
} |
|
1968
3482df86a51d
Remove TRK service and replace with TCF TRK service. Remove wildcard service check used as an interim when TCF TRK and TRK were both options.
Ed Swartz <ed.swartz@nokia.com>
parents:
1851
diff
changeset
|
221 |
*/ |
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
222 |
if (isTCFTRKService(service)) { //$NON-NLS-1$ |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
223 |
tcfTRKStatus = service.getStatus().getEStatus(); |
748 | 224 |
} |
225 |
} |
|
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
226 |
setConnectionStatus((IConnection2) connection, isSysTRK, trkStatus, tcfTRKStatus); |
748 | 227 |
} |
228 |
||
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
229 |
private boolean isTCFTRKService(IConnectedService service) { |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
230 |
return service.getService().getIdentifier().equals("com.nokia.carbide.cpp.edc.TCFTRKService"); |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
231 |
} |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
232 |
|
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
233 |
private void setConnectionStatus(IConnection2 connection, boolean isSysTRK, EStatus trkStatus, EStatus tcfTRKStatus) { |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
234 |
EStatus serviceStatus = tcfTRKStatus; |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
235 |
EConnectionStatus connectionStatus = service2ConnectionStatus(serviceStatus); |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
236 |
if (!connectionStatus.equals(EConnectionStatus.READY)) { |
2032 | 237 |
serviceStatus = tcfTRKStatus; // C3TCF !!!!!!!!!!!!! |
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
238 |
connectionStatus = service2ConnectionStatus(serviceStatus); |
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
239 |
} |
748 | 240 |
|
241 |
String shortDesc = getShortDescriptionForStatus(connectionStatus); |
|
749 | 242 |
StringBuilder longDesc = new StringBuilder(Messages.getString("ConnectionStatusReconciler_TRKServicePrefix")); //$NON-NLS-1$ |
1851
1abb98459179
Bug 11791 - add tcf trk to connection status reconcilation
dadubrow
parents:
1559
diff
changeset
|
243 |
longDesc.append(getServiceStatusString(serviceStatus)); |
748 | 244 |
|
245 |
connection.setStatus(new ConnectionStatus(connectionStatus, shortDesc, longDesc.toString())); |
|
246 |
} |
|
247 |
||
248 |
private String getShortDescriptionForStatus(EConnectionStatus connectionStatus) { |
|
249 |
switch (connectionStatus) { |
|
250 |
case READY: |
|
749 | 251 |
return Messages.getString("ConnectionStatusReconciler_ReadyLabel"); //$NON-NLS-1$ |
748 | 252 |
case NOT_READY: |
749 | 253 |
return Messages.getString("ConnectionStatusReconciler_NotReadyLabel"); //$NON-NLS-1$ |
748 | 254 |
case IN_USE: |
749 | 255 |
return Messages.getString("ConnectionStatusReconciler_InUseLabel"); //$NON-NLS-1$ |
748 | 256 |
case IN_USE_DISCONNECTED: |
749 | 257 |
return Messages.getString("ConnectionStatusReconciler_DisconnectedLabel"); //$NON-NLS-1$ |
748 | 258 |
} |
749 | 259 |
return ""; //$NON-NLS-1$ |
748 | 260 |
} |
261 |
||
262 |
private String getServiceStatusString(EStatus status) { |
|
263 |
switch (status) { |
|
264 |
case UP: |
|
749 | 265 |
return Messages.getString("ConnectionStatusReconciler_availableLabel"); //$NON-NLS-1$ |
748 | 266 |
case DOWN: |
749 | 267 |
return Messages.getString("ConnectionStatusReconciler_unavailableLabel"); //$NON-NLS-1$ |
748 | 268 |
case IN_USE: |
749 | 269 |
return Messages.getString("ConnectionStatusReconciler_inUseLabel_lower"); //$NON-NLS-1$ |
748 | 270 |
} |
749 | 271 |
return ""; //$NON-NLS-1$ |
748 | 272 |
} |
273 |
||
274 |
private EConnectionStatus service2ConnectionStatus(EStatus serviceStatus) { |
|
275 |
switch (serviceStatus) { |
|
276 |
case UP: |
|
277 |
return EConnectionStatus.READY; |
|
278 |
case DOWN: |
|
279 |
return EConnectionStatus.NOT_READY; |
|
280 |
case IN_USE: |
|
281 |
return EConnectionStatus.IN_USE; |
|
282 |
} |
|
283 |
return EConnectionStatus.NONE; |
|
284 |
} |
|
285 |
||
286 |
private void removeConnection(IConnection connection) { |
|
287 |
handledConnections.remove(connection); |
|
288 |
} |
|
289 |
||
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
290 |
private IConnection findConnection(IConnectedService cs) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
291 |
for (IConnection connection : handledConnections) { |
748 | 292 |
for (IConnectedService connectedService : manager.getConnectedServices(connection)) { |
293 |
if (cs.equals(connectedService)) |
|
294 |
return connection; |
|
295 |
} |
|
296 |
} |
|
297 |
return null; |
|
298 |
} |
|
299 |
||
300 |
public void handleServiceStatusChange(IStatus status) { |
|
301 |
IConnectedService service = status.getConnectedService(); |
|
763
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
302 |
IConnection connection = findConnection(service); |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
303 |
if (connection instanceof IConnection2) { |
751f5182b866
Refactor API and related from default connection to current + update heuristics
dadubrow
parents:
758
diff
changeset
|
304 |
reconcileStatus((IConnection2) connection); |
748 | 305 |
} |
764
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
306 |
if (connection != null) |
603d6ca035e8
updated set and reset current depending on ready state
dadubrow
parents:
763
diff
changeset
|
307 |
reconcileAsCurrent(connection); |
748 | 308 |
} |
309 |
||
310 |
} |