debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/TRKLaunchDelegate.java
changeset 772 c3301e21f173
parent 728 a39d0ba41f81
child 1260 f3b387a17eb7
equal deleted inserted replaced
770:cb7e68ca1ef4 772:c3301e21f173
    20 
    20 
    21 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
    21 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
    22 import org.eclipse.cdt.core.model.ICProject;
    22 import org.eclipse.cdt.core.model.ICProject;
    23 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
    23 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
    24 import org.eclipse.cdt.debug.core.ICDebugConfiguration;
    24 import org.eclipse.cdt.debug.core.ICDebugConfiguration;
       
    25 import org.eclipse.cdt.debug.core.cdi.CDIException;
    25 import org.eclipse.cdt.debug.core.cdi.ICDISession;
    26 import org.eclipse.cdt.debug.core.cdi.ICDISession;
    26 import org.eclipse.cdt.ui.CUIPlugin;
    27 import org.eclipse.cdt.ui.CUIPlugin;
    27 import org.eclipse.core.runtime.*;
    28 import org.eclipse.core.runtime.CoreException;
    28 import org.eclipse.debug.core.*;
    29 import org.eclipse.core.runtime.IPath;
       
    30 import org.eclipse.core.runtime.IProgressMonitor;
       
    31 import org.eclipse.core.runtime.IStatus;
       
    32 import org.eclipse.core.runtime.NullProgressMonitor;
       
    33 import org.eclipse.core.runtime.Path;
       
    34 import org.eclipse.core.runtime.Status;
       
    35 import org.eclipse.core.runtime.SubProgressMonitor;
       
    36 import org.eclipse.debug.core.DebugException;
       
    37 import org.eclipse.debug.core.ILaunch;
       
    38 import org.eclipse.debug.core.ILaunchConfiguration;
       
    39 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
       
    40 import org.eclipse.debug.core.ILaunchManager;
    29 import org.eclipse.jface.dialogs.MessageDialog;
    41 import org.eclipse.jface.dialogs.MessageDialog;
    30 import org.eclipse.swt.widgets.Display;
    42 import org.eclipse.swt.widgets.Display;
    31 
    43 
    32 import com.freescale.cdt.debug.cw.CWException;
    44 import com.freescale.cdt.debug.cw.CWException;
    33 import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper;
    45 import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper;
       
    46 import com.freescale.cdt.debug.cw.core.cdi.ISessionListener;
    34 import com.freescale.cdt.debug.cw.core.cdi.Session;
    47 import com.freescale.cdt.debug.cw.core.cdi.Session;
    35 import com.freescale.cdt.debug.cw.core.cdi.model.Target;
    48 import com.freescale.cdt.debug.cw.core.cdi.model.Target;
    36 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
    49 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
    37 import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder;
    50 import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder;
    38 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
    51 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
    39 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
    52 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
    40 import com.nokia.carbide.remoteconnections.interfaces.IConnection;
    53 import com.nokia.carbide.remoteconnections.interfaces.IConnection;
       
    54 import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
       
    55 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus;
       
    56 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener;
       
    57 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus;
    41 import com.nokia.cdt.debug.cw.symbian.SettingsData;
    58 import com.nokia.cdt.debug.cw.symbian.SettingsData;
    42 import com.nokia.cdt.debug.cw.symbian.SymbianPlugin;
    59 import com.nokia.cdt.debug.cw.symbian.SymbianPlugin;
    43 import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog;
    60 import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog;
    44 
    61 
    45 import cwdbg.PreferenceConstants;
    62 import cwdbg.PreferenceConstants;
    48 
    65 
    49 	private static final String DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION = "DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION"; //$NON-NLS-1$
    66 	private static final String DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION = "DONT_ASK_ABOUT_PARTIAL_UPGRADE_OPTION"; //$NON-NLS-1$
    50 	private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K
    67 	private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K
    51 	
    68 	
    52 	protected Session cwDebugSession;
    69 	protected Session cwDebugSession;
    53 	
    70 	private IConnection connection;
       
    71 	private IConnectionStatusChangedListener connectionStatusChangedListener;
    54 	
    72 	
    55 	public void launch(
    73 	public void launch(
    56 			ILaunchConfiguration 	config, 
    74 			ILaunchConfiguration 	config, 
    57 			String 					mode, 
    75 			String 					mode, 
    58 			ILaunch 				launch, 
    76 			ILaunch 				launch, 
    75 		
    93 		
    76         if (!RemoteConnectionsTRKHelper.configUsesConnectionAttribute(config)) {
    94         if (!RemoteConnectionsTRKHelper.configUsesConnectionAttribute(config)) {
    77         	config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy());
    95         	config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy());
    78         }
    96         }
    79         
    97         
    80         final IConnection connection = RemoteConnectionsTRKHelper.ensureConnectionFromConfig(config);
    98         connection = RemoteConnectionsTRKHelper.ensureConnectionFromConfig(config);
    81 		if (connection == null) {
    99 		if (connection == null) {
    82 			IStatus status = new Status(Status.ERROR, LaunchPlugin.PLUGIN_ID, 
   100 			IStatus status = new Status(Status.ERROR, LaunchPlugin.PLUGIN_ID, 
    83 				LaunchMessages.getString("TRKLaunchDelegate.NoConnectionErrorMsg")); //$NON-NLS-1$
   101 				LaunchMessages.getString("TRKLaunchDelegate.NoConnectionErrorMsg")); //$NON-NLS-1$
    84 			throw new DebugException(status);
   102 			throw new DebugException(status);
    85 		}
   103 		}
   127                         
   145                         
   128             // set the default source locator if required
   146             // set the default source locator if required
   129             setDefaultSourceLocator(launch, config);
   147             setDefaultSourceLocator(launch, config);
   130 
   148 
   131             if (mode.equals(ILaunchManager.DEBUG_MODE)) {
   149             if (mode.equals(ILaunchManager.DEBUG_MODE)) {
   132                 // debug mode
   150         		hookConnectionStatus();
       
   151                // debug mode
   133                 ICDebugConfiguration debugConfig = getDebugConfig(config);
   152                 ICDebugConfiguration debugConfig = getDebugConfig(config);
   134                 ICDISession dsession = null;
   153                 ICDISession dsession = null;
   135                 String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
   154                 String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
   136                         ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
   155                         ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
   137                 if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
   156                 if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
   172 							session.debuggingStopped(null);
   191 							session.debuggingStopped(null);
   173 							this.abort(e.getLocalizedMessage(), null, 0);
   192 							this.abort(e.getLocalizedMessage(), null, 0);
   174 						}
   193 						}
   175 					}
   194 					}
   176                 }
   195                 }
       
   196                 hookSessionEnded();
   177             }
   197             }
   178             else if (mode.equals(ILaunchManager.RUN_MODE)) {
   198             else if (mode.equals(ILaunchManager.RUN_MODE)) {
   179                 // Run the program.
   199                 // Run the program.
   180             	// Connect to DE, download and launch the program, close debug session.
   200             	// Connect to DE, download and launch the program, close debug session.
   181                 ICDebugConfiguration debugConfig = getDebugConfig(config);
   201                 ICDebugConfiguration debugConfig = getDebugConfig(config);
   222 					}
   242 					}
   223 				});
   243 				});
   224             }
   244             }
   225         } catch (CWException e) {
   245         } catch (CWException e) {
   226        		connection.useConnection(false);
   246        		connection.useConnection(false);
       
   247        		unhookConnectionStatus();
   227         	if (! monitor.isCanceled()) // don't throw on user cancellation
   248         	if (! monitor.isCanceled()) // don't throw on user cancellation
   228         		e.printStackTrace();
   249         		e.printStackTrace();
   229 		} catch (CoreException e) {
   250 		} catch (CoreException e) {
   230 			connection.useConnection(false);
   251 			connection.useConnection(false);
       
   252 			unhookConnectionStatus();
   231         	if (! monitor.isCanceled()) // don't throw on user cancellation
   253         	if (! monitor.isCanceled()) // don't throw on user cancellation
   232         		throw e;
   254         		throw e;
   233 		} finally {
   255 		} finally {
   234             monitor.done();
   256             monitor.done();
   235             removeBeingLaunched(config);
   257             removeBeingLaunched(config);
   236         }
   258         }
   237 	} // end of synchronized.
   259 	} // end of synchronized.
       
   260 	}
       
   261 
       
   262 	protected void hookSessionEnded() {
       
   263 		if (cwDebugSession != null) {
       
   264 			cwDebugSession.addListener(new ISessionListener() {
       
   265 				public void sessionEnded() {
       
   266 					connection.useConnection(false);
       
   267 					unhookConnectionStatus();
       
   268 				}
       
   269 			});
       
   270 		}
       
   271 	}
       
   272 
       
   273 	protected void hookConnectionStatus() {
       
   274 		if (connection instanceof IConnection2) {
       
   275 			connectionStatusChangedListener = new IConnectionStatusChangedListener() {
       
   276 				public void statusChanged(IConnectionStatus status) {
       
   277 					if (status.getEConnectionStatus().equals(EConnectionStatus.IN_USE_DISCONNECTED)) {
       
   278 						try {
       
   279 							cwDebugSession.getLaunch().terminate();
       
   280 						} catch (Exception e) {
       
   281 							LaunchPlugin.log(e);
       
   282 						}
       
   283 					}
       
   284 				}
       
   285 			};
       
   286 			((IConnection2) connection).addStatusChangedListener(connectionStatusChangedListener);
       
   287 		}
       
   288 	}
       
   289 
       
   290 	protected void unhookConnectionStatus() {
       
   291 		if (connection instanceof IConnection2 && connectionStatusChangedListener != null) {
       
   292 			((IConnection2) connection).removeStatusChangedListener(connectionStatusChangedListener);
       
   293 		}
   238 	}
   294 	}
   239 
   295 
   240 	@Override
   296 	@Override
   241 	public boolean buildForLaunch(final ILaunchConfiguration configuration,
   297 	public boolean buildForLaunch(final ILaunchConfiguration configuration,
   242 			String mode, IProgressMonitor monitor) throws CoreException {
   298 			String mode, IProgressMonitor monitor) throws CoreException {