001package jmri.jmrit.logixng.tools.debugger;
002
003import java.beans.PropertyChangeListener;
004import java.beans.PropertyChangeSupport;
005
006import javax.annotation.OverridingMethodsMustInvokeSuper;
007
008import jmri.beans.PropertyChangeProvider;
009import jmri.jmrit.logixng.ConditionalNG;
010
011/**
012 * LogixNG Debugger
013 * <P>
014 * This class is _not_ thread safe. It must be called on the thread that is
015 * used for the conditionalNG that the debugger is activated for.
016 * 
017 * @author Daniel Bergqvist Copyright 2020
018 */
019public class Debugger implements PropertyChangeProvider {
020    
021    public static final String STEP_BEFORE = "StepBefore";
022    public static final String STEP_AFTER = "StepAfter";
023    
024    private ConditionalNG _debugConditionalNG = null;
025    private boolean _break = false;
026    
027    private final PropertyChangeSupport _pcs = new PropertyChangeSupport(this);
028    
029    
030    
031    /*
032    Breakpoint before/after - Always stop
033    Step over - 
034    Step into - 
035    */
036    
037    public void activateDebugger(ConditionalNG conditionalNG) {
038        if (_debugConditionalNG != null) {
039            throw new IllegalStateException("Debugger is already active");
040        }
041        _debugConditionalNG = conditionalNG;
042    }
043    
044    public void deActivateDebugger() {
045        _debugConditionalNG = null;
046    }
047    
048    public boolean isDebuggerActive() {
049        return _debugConditionalNG != null;
050    }
051    
052    public ConditionalNG getDebugConditionalNG() {
053        return _debugConditionalNG;
054    }
055    
056    public void setBreak(boolean value) {
057        _break = value;
058    }
059    
060    public boolean getBreak() {
061        return _break;
062    }
063    
064    @OverridingMethodsMustInvokeSuper
065    protected void firePropertyChange(String p, Object old, Object n) {
066        _pcs.firePropertyChange(p, old, n);
067    }
068
069    @Override
070    public void addPropertyChangeListener(PropertyChangeListener listener) {
071        _pcs.addPropertyChangeListener(listener);
072    }
073
074    @Override
075    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
076        _pcs.addPropertyChangeListener(propertyName, listener);
077    }
078
079    @Override
080    public PropertyChangeListener[] getPropertyChangeListeners() {
081        return _pcs.getPropertyChangeListeners();
082    }
083
084    @Override
085    public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
086        return _pcs.getPropertyChangeListeners(propertyName);
087    }
088
089    @Override
090    public void removePropertyChangeListener(PropertyChangeListener listener) {
091        _pcs.removePropertyChangeListener(listener);
092    }
093
094    @Override
095    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
096        _pcs.removePropertyChangeListener(propertyName, listener);
097    }
098    
099}