001/*
002 *  @author Gregory J. Bedlek Copyright (C) 2018, 2019
003 */
004package jmri.jmrit.ctc;
005
006import jmri.Sensor;
007
008public class Fleeting {
009    private final NBHSensor _mFleetingToggleInternalSensor;
010    private final boolean _mDefaultFleetingEnabled;
011
012    /**
013     * Class to manage the Fleeting sensor (if defined).  Provides reasonable
014     * return values if none defined.
015     *
016     * @param fleetingToggleInternalSensor  The defined internal fleeting sensor name (ex: "IS:FLEETING")
017     * @param defaultFleetingEnabled        The users choice as to whether fleeting is initially enabled or not.
018     */
019    public Fleeting (NBHSensor fleetingToggleInternalSensor, boolean defaultFleetingEnabled) {
020        _mFleetingToggleInternalSensor = fleetingToggleInternalSensor;
021        _mDefaultFleetingEnabled = defaultFleetingEnabled;
022        _mFleetingToggleInternalSensor.setKnownState(_mDefaultFleetingEnabled ? Sensor.ACTIVE : Sensor.INACTIVE);
023    }
024
025
026    /**
027     * Stub routine for completeness, we can be consistent in higher level code with this defined (even if it does nothing).
028     */
029    public void removeAllListeners() {}   // None done.
030
031    /**
032     * Routine you can call to find out if fleeting is enabled.  Provides reasonable defaults if things don't exist.
033     * @return True if fleeting is enabled, else false.
034     */
035    public boolean isFleetingEnabled() {
036        if (_mFleetingToggleInternalSensor.valid()) return _mFleetingToggleInternalSensor.getKnownState() == Sensor.ACTIVE;
037        return _mDefaultFleetingEnabled;
038    }
039}