~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/SessionManager.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     QNX Software Systems - Initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.debug.internal.core;
12
 
 
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;
22
 
 
23
 
/**
24
 
 * Default implementation of the session manager. Terminates the session when the last target is terminated;
25
 
 */
26
 
public class SessionManager implements IDebugEventSetListener {
27
 
 
28
 
        public SessionManager() {
29
 
                DebugPlugin.getDefault().addDebugEventListener( this );
30
 
        }
31
 
 
32
 
        /*
33
 
         * (non-Javadoc)
34
 
         * 
35
 
         * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
36
 
         */
37
 
        public Object getAdapter( Class adapter ) {
38
 
                if ( SessionManager.class.equals( adapter ) )
39
 
                        return this;
40
 
                return null;
41
 
        }
42
 
 
43
 
        public void dispose() {
44
 
                DebugPlugin.getDefault().removeDebugEventListener( this );
45
 
        }
46
 
 
47
 
        /*
48
 
         * (non-Javadoc)
49
 
         * 
50
 
         * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
51
 
         */
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() );
59
 
                                }
60
 
                        }
61
 
                }
62
 
        }
63
 
 
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() )
69
 
                                terminate = false;
70
 
                }
71
 
                if ( terminate ) {
72
 
                        try {
73
 
                                session.terminate();
74
 
                        }
75
 
                        catch( CDIException e ) {
76
 
                                CDebugCorePlugin.log( e );
77
 
                        }
78
 
                }
79
 
        }
80
 
}