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 java.util.ArrayList;
14
import org.eclipse.cdt.debug.core.CDIDebugModel;
15
import org.eclipse.cdt.debug.core.cdi.CDIException;
16
import org.eclipse.cdt.debug.core.cdi.model.ICDISignal;
17
import org.eclipse.cdt.debug.core.model.ICSignal;
18
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
19
import org.eclipse.cdt.debug.internal.core.model.CSignal;
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.debug.core.DebugEvent;
24
import org.eclipse.debug.core.DebugException;
27
* Manages the collection of signals on a debug target.
29
public class CSignalManager implements IAdaptable {
32
* The debug target associated with this manager.
34
private CDebugTarget fDebugTarget;
37
* The list of signals.
39
private ICSignal[] fSignals = null;
44
private boolean fIsDisposed = false;
47
* Constructor for CSignalManager.
49
public CSignalManager( CDebugTarget target ) {
50
fDebugTarget = target;
54
* @see org.eclipse.cdt.debug.core.ICSignalManager#getSignals()
56
public ICSignal[] getSignals() throws DebugException {
57
if ( !isDisposed() && fSignals == null ) {
59
ICDISignal[] cdiSignals = getDebugTarget().getCDITarget().getSignals();
60
ArrayList list = new ArrayList( cdiSignals.length );
61
for( int i = 0; i < cdiSignals.length; ++i ) {
62
list.add( new CSignal( getDebugTarget(), cdiSignals[i] ) );
64
fSignals = (ICSignal[])list.toArray( new ICSignal[list.size()] );
66
catch( CDIException e ) {
67
throwDebugException( e.getMessage(), DebugException.TARGET_REQUEST_FAILED, e );
70
return (fSignals != null) ? fSignals : new ICSignal[0];
74
* @see org.eclipse.cdt.debug.internal.core.CUpdateManager#dispose()
76
public void dispose() {
77
if ( fSignals != null )
78
for( int i = 0; i < fSignals.length; ++i ) {
79
((CSignal)fSignals[i]).dispose();
86
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
88
public Object getAdapter( Class adapter ) {
89
if ( adapter.equals( CSignalManager.class ) ) {
92
if ( adapter.equals( CDebugTarget.class ) ) {
93
return getDebugTarget();
98
public void signalChanged( ICDISignal cdiSignal ) {
99
CSignal signal = find( cdiSignal );
100
if ( signal != null ) {
101
signal.fireChangeEvent( DebugEvent.STATE );
105
private CSignal find( ICDISignal cdiSignal ) {
107
ICSignal[] signals = getSignals();
108
for( int i = 0; i < signals.length; ++i )
109
if ( signals[i].getName().equals( cdiSignal.getName() ) )
110
return (CSignal)signals[i];
112
catch( DebugException e ) {
117
protected boolean isDisposed() {
122
* Throws a debug exception with the given message, error code, and underlying exception.
124
protected void throwDebugException( String message, int code, Throwable exception ) throws DebugException {
125
throw new DebugException( new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), code, message, exception ) );
128
protected CDebugTarget getDebugTarget() {