1
/*******************************************************************************
2
* Copyright (c) 2000, 2005 QNX Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.debug.internal.core;
13
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
14
import org.eclipse.cdt.debug.core.cdi.CDIException;
15
import org.eclipse.cdt.debug.core.cdi.ICDISession;
16
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
17
import org.eclipse.debug.core.DebugEvent;
18
import org.eclipse.debug.core.DebugPlugin;
19
import org.eclipse.debug.core.IDebugEventSetListener;
20
import org.eclipse.debug.core.ILaunch;
21
import org.eclipse.debug.core.model.IDebugTarget;
24
* Default implementation of the session manager. Terminates the session when the last target is terminated;
26
public class SessionManager implements IDebugEventSetListener {
28
public SessionManager() {
29
DebugPlugin.getDefault().addDebugEventListener( this );
35
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
37
public Object getAdapter( Class adapter ) {
38
if ( SessionManager.class.equals( adapter ) )
43
public void dispose() {
44
DebugPlugin.getDefault().removeDebugEventListener( this );
50
* @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
52
public void handleDebugEvents( DebugEvent[] events ) {
53
for( int i = 0; i < events.length; i++ ) {
54
DebugEvent event = events[i];
55
if ( event.getKind() == DebugEvent.TERMINATE ) {
56
Object element = event.getSource();
57
if ( element instanceof IDebugTarget && ((IDebugTarget)element).getAdapter( ICDITarget.class ) != null ) {
58
handleTerminateEvent( ((IDebugTarget)element).getLaunch(), ((ICDITarget)((IDebugTarget)element).getAdapter( ICDITarget.class )).getSession() );
64
private void handleTerminateEvent( ILaunch launch, ICDISession session ) {
65
IDebugTarget[] targets = launch.getDebugTargets();
66
boolean terminate = true;
67
for( int i = 0; i < targets.length; ++i ) {
68
if ( targets[i].getAdapter( ICDITarget.class ) != null && session.equals( ((ICDITarget)targets[i].getAdapter( ICDITarget.class )).getSession() ) && !targets[i].isTerminated() && !targets[i].isDisconnected() )
75
catch( CDIException e ) {
76
CDebugCorePlugin.log( e );