001package jmri.jmrit.withrottle;
002
003import java.util.ArrayList;
004import jmri.Consist;
005import jmri.LocoAddress;
006import jmri.DccLocoAddress;
007import jmri.implementation.NmraConsistManager;
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011/**
012 * @author Brett Hoffman Copyright (C) 2010, 2011
013 * 
014 */
015public class WiFiConsistManager extends NmraConsistManager {
016
017    ArrayList<ControllerInterface> listeners = null;
018    boolean isValid = false;
019
020    public WiFiConsistManager() {
021        super(jmri.InstanceManager.getDefault(jmri.CommandStation.class));
022        log.debug("New WiFiConsistManager");
023        isValid = true;
024    }
025
026    /**
027     * Check to see if an address will try to broadcast (0) a programming
028     * message.
029     *
030     * @param addr The address to check
031     * @return true if address is no good, otherwise false
032     */
033    public boolean checkForBroadcastAddress(DccLocoAddress addr) {
034        if (addr.getNumber() < 1) {
035            log.warn("Trying to use broadcast address!");
036            return true;
037        }
038        return false;
039    }
040
041    @Override
042    public Consist addConsist(LocoAddress address) {
043        if (! (address instanceof DccLocoAddress)) { 
044            throw new IllegalArgumentException("address is not a DccLocoAddress object");
045        }
046        WiFiConsist consist;
047        consist = new WiFiConsist((DccLocoAddress) address);
048        consistTable.put(address, consist);
049        return consist;
050    }
051
052    /**
053     * Add a listener to handle: listener.sendPacketToDevice(message);
054     *
055     * @param listener the listener to add.
056     */
057    public void addControllerListener(ControllerInterface listener) {
058        if (listeners == null) {
059            listeners = new ArrayList<ControllerInterface>(1);
060        }
061        if (!listeners.contains(listener)) {
062            listeners.add(listener);
063        }
064    }
065
066    public void removeControllerListener(ControllerInterface listener) {
067        if (listeners == null) {
068            return;
069        }
070        if (listeners.contains(listener)) {
071            listeners.remove(listener);
072        }
073    }
074
075    private final static Logger log = LoggerFactory.getLogger(WiFiConsistManager.class);
076
077}