15 * |
15 * |
16 */ |
16 */ |
17 package com.nokia.cdt.internal.debug.launch; |
17 package com.nokia.cdt.internal.debug.launch; |
18 |
18 |
19 import java.io.File; |
19 import java.io.File; |
|
20 import java.util.ArrayList; |
|
21 import java.util.List; |
20 |
22 |
21 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; |
23 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; |
22 import org.eclipse.cdt.core.model.ICProject; |
24 import org.eclipse.cdt.core.model.ICProject; |
23 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
25 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
24 import org.eclipse.cdt.debug.core.ICDebugConfiguration; |
26 import org.eclipse.cdt.debug.core.ICDebugConfiguration; |
25 import org.eclipse.cdt.debug.core.cdi.CDIException; |
|
26 import org.eclipse.cdt.debug.core.cdi.ICDISession; |
27 import org.eclipse.cdt.debug.core.cdi.ICDISession; |
27 import org.eclipse.cdt.ui.CUIPlugin; |
28 import org.eclipse.cdt.ui.CUIPlugin; |
28 import org.eclipse.core.runtime.CoreException; |
29 import org.eclipse.core.runtime.CoreException; |
|
30 import org.eclipse.core.runtime.IConfigurationElement; |
29 import org.eclipse.core.runtime.IPath; |
31 import org.eclipse.core.runtime.IPath; |
30 import org.eclipse.core.runtime.IProgressMonitor; |
32 import org.eclipse.core.runtime.IProgressMonitor; |
31 import org.eclipse.core.runtime.IStatus; |
33 import org.eclipse.core.runtime.IStatus; |
32 import org.eclipse.core.runtime.NullProgressMonitor; |
34 import org.eclipse.core.runtime.NullProgressMonitor; |
33 import org.eclipse.core.runtime.Path; |
35 import org.eclipse.core.runtime.Path; |
|
36 import org.eclipse.core.runtime.Platform; |
34 import org.eclipse.core.runtime.Status; |
37 import org.eclipse.core.runtime.Status; |
35 import org.eclipse.core.runtime.SubProgressMonitor; |
38 import org.eclipse.core.runtime.SubProgressMonitor; |
36 import org.eclipse.debug.core.DebugException; |
39 import org.eclipse.debug.core.DebugException; |
37 import org.eclipse.debug.core.ILaunch; |
40 import org.eclipse.debug.core.ILaunch; |
38 import org.eclipse.debug.core.ILaunchConfiguration; |
41 import org.eclipse.debug.core.ILaunchConfiguration; |
53 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
56 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
54 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
57 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
55 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
58 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
56 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener; |
59 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener; |
57 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; |
60 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; |
|
61 import com.nokia.cdt.debug.common.internal.api.ILaunchDelegateConnectionExtension; |
58 import com.nokia.cdt.debug.cw.symbian.SettingsData; |
62 import com.nokia.cdt.debug.cw.symbian.SettingsData; |
59 import com.nokia.cdt.debug.cw.symbian.SymbianPlugin; |
63 import com.nokia.cdt.debug.cw.symbian.SymbianPlugin; |
60 import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog; |
64 import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog; |
61 |
65 |
62 import cwdbg.PreferenceConstants; |
66 import cwdbg.PreferenceConstants; |
65 |
69 |
66 private static final String DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION = "DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION"; //$NON-NLS-1$ |
70 private static final String DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION = "DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION"; //$NON-NLS-1$ |
67 private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K |
71 private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K |
68 |
72 |
69 protected Session cwDebugSession; |
73 protected Session cwDebugSession; |
70 private IConnection connection; |
74 protected IConnection connection; |
71 private IConnectionStatusChangedListener connectionStatusChangedListener; |
75 private IConnectionStatusChangedListener connectionStatusChangedListener; |
|
76 private List<ILaunchDelegateConnectionExtension> connectionExtensions; |
72 |
77 |
73 public void launch( |
78 public void launch( |
74 ILaunchConfiguration config, |
79 ILaunchConfiguration config, |
75 String mode, |
80 final String mode, |
76 ILaunch launch, |
81 final ILaunch launch, |
77 IProgressMonitor monitor) throws CoreException |
82 IProgressMonitor monitor) throws CoreException |
78 { |
83 { |
79 // See comment at definition of the "mutex" for why this "synchronized". |
84 // See comment at definition of the "mutex" for why this "synchronized". |
80 synchronized(Session.sessionStartStopMutex()) { |
85 synchronized(Session.sessionStartStopMutex()) { |
81 |
86 |
231 display = Display.getDefault(); |
238 display = Display.getDefault(); |
232 } |
239 } |
233 |
240 |
234 display.syncExec(new Runnable() { |
241 display.syncExec(new Runnable() { |
235 public void run() { |
242 public void run() { |
236 connection.useConnection(false); |
243 shutdownConnection(launch); |
237 MessageDialog.openInformation( |
244 MessageDialog.openInformation( |
238 CUIPlugin.getActiveWorkbenchShell(), |
245 CUIPlugin.getActiveWorkbenchShell(), |
239 LaunchMessages.getString("CarbideCPPLaunchDelegate.DebuggerName"), //$NON-NLS-1$ |
246 LaunchMessages.getString("CarbideCPPLaunchDelegate.DebuggerName"), //$NON-NLS-1$ |
240 LaunchMessages.getString("TRKLaunchDelegate.runSucceed") + //$NON-NLS-1$ |
247 LaunchMessages.getString("TRKLaunchDelegate.runSucceed") + //$NON-NLS-1$ |
241 "\n\t\"" + exeLaunched + "\""); //$NON-NLS-1$ //$NON-NLS-2$ |
248 "\n\t\"" + exeLaunched + "\""); //$NON-NLS-1$ //$NON-NLS-2$ |
242 } |
249 } |
243 }); |
250 }); |
244 } |
251 } |
|
252 |
|
253 invokeConnectionSpecificPostLaunch(launch, new SubProgressMonitor(monitor, 5)); |
245 } catch (CWException e) { |
254 } catch (CWException e) { |
246 connection.useConnection(false); |
255 shutdownConnection(launch); |
247 unhookConnectionStatus(); |
256 unhookConnectionStatus(); |
248 if (! monitor.isCanceled()) // don't throw on user cancellation |
257 if (! monitor.isCanceled()) // don't throw on user cancellation |
249 e.printStackTrace(); |
258 e.printStackTrace(); |
250 } catch (CoreException e) { |
259 } catch (CoreException e) { |
251 connection.useConnection(false); |
260 shutdownConnection(launch); |
252 unhookConnectionStatus(); |
261 unhookConnectionStatus(); |
253 if (! monitor.isCanceled()) // don't throw on user cancellation |
262 if (! monitor.isCanceled()) // don't throw on user cancellation |
254 throw e; |
263 throw e; |
255 } finally { |
264 } finally { |
256 monitor.done(); |
265 monitor.done(); |
257 removeBeingLaunched(config); |
266 removeBeingLaunched(config); |
258 } |
267 } |
259 } // end of synchronized. |
268 } // end of synchronized. |
260 } |
269 } |
261 |
270 |
262 protected void hookSessionEnded() { |
271 protected void shutdownConnection(ILaunch launch) { |
|
272 try { |
|
273 invokeConnectionSpecificShutdown(launch, new NullProgressMonitor()); |
|
274 } catch (CoreException e) { |
|
275 LaunchPlugin.log(e); |
|
276 } finally { |
|
277 connection.useConnection(false); |
|
278 } |
|
279 } |
|
280 |
|
281 /** Create the extensions every session, in case they hold state. */ |
|
282 protected List<ILaunchDelegateConnectionExtension> getLaunchDelegateConnectionExtensions() { |
|
283 if (connectionExtensions == null) { |
|
284 connectionExtensions = new ArrayList<ILaunchDelegateConnectionExtension>(); |
|
285 IConfigurationElement[] elements = |
|
286 Platform.getExtensionRegistry().getConfigurationElementsFor(ILaunchDelegateConnectionExtension.ID); |
|
287 for (IConfigurationElement element : elements) { |
|
288 try { |
|
289 connectionExtensions.add((ILaunchDelegateConnectionExtension) element.createExecutableExtension("class")); |
|
290 } catch (CoreException e) { |
|
291 LaunchPlugin.log(e); |
|
292 } |
|
293 } |
|
294 } |
|
295 return connectionExtensions; |
|
296 } |
|
297 |
|
298 protected void invokeConnectionSpecificSetup(ILaunch launch, |
|
299 IProgressMonitor monitor) throws CoreException { |
|
300 List<ILaunchDelegateConnectionExtension> extensions = getLaunchDelegateConnectionExtensions(); |
|
301 monitor.beginTask("", extensions.size()); |
|
302 for (ILaunchDelegateConnectionExtension extension : extensions) { |
|
303 extension.initializeConnection(launch, connection, new SubProgressMonitor(monitor, 1)); |
|
304 } |
|
305 monitor.done(); |
|
306 } |
|
307 |
|
308 protected void invokeConnectionSpecificPostLaunch(ILaunch launch, |
|
309 IProgressMonitor monitor) throws CoreException { |
|
310 List<ILaunchDelegateConnectionExtension> extensions = getLaunchDelegateConnectionExtensions(); |
|
311 monitor.beginTask("", extensions.size()); |
|
312 for (ILaunchDelegateConnectionExtension extension : extensions) { |
|
313 extension.launchStarted(launch, connection, new SubProgressMonitor(monitor, 1)); |
|
314 } |
|
315 monitor.done(); |
|
316 } |
|
317 |
|
318 |
|
319 protected void invokeConnectionSpecificShutdown( |
|
320 ILaunch launch, IProgressMonitor monitor) throws CoreException { |
|
321 List<ILaunchDelegateConnectionExtension> extensions = getLaunchDelegateConnectionExtensions(); |
|
322 monitor.beginTask("", extensions.size()); |
|
323 for (ILaunchDelegateConnectionExtension extension : extensions) { |
|
324 extension.terminateConnection(launch, connection, new SubProgressMonitor(monitor, 1)); |
|
325 } |
|
326 monitor.done(); |
|
327 } |
|
328 |
|
329 protected void hookSessionEnded(final ILaunch launch) { |
263 if (cwDebugSession != null) { |
330 if (cwDebugSession != null) { |
264 cwDebugSession.addListener(new ISessionListener() { |
331 cwDebugSession.addListener(new ISessionListener() { |
265 public void sessionEnded() { |
332 public void sessionEnded() { |
266 connection.useConnection(false); |
333 try { |
267 unhookConnectionStatus(); |
334 invokeConnectionSpecificShutdown(launch, new NullProgressMonitor()); |
|
335 } catch (CoreException e) { |
|
336 LaunchPlugin.log(e); |
|
337 } finally { |
|
338 connection.useConnection(false); |
|
339 unhookConnectionStatus(); |
|
340 } |
268 } |
341 } |
269 }); |
342 }); |
270 } |
343 } |
271 } |
344 } |
272 |
345 |