001package jmri.managers;
002
003import javax.annotation.CheckForNull;
004import javax.annotation.Nonnull;
005import jmri.Manager;
006
007import jmri.Sensor;
008import jmri.SensorManager;
009
010/**
011 * Implementation of a SensorManager that can serve as a proxy for multiple
012 * system-specific implementations.
013 *
014 * @author Bob Jacobsen Copyright (C) 2003, 2010
015 */
016public class ProxySensorManager extends AbstractProvidingProxyManager<Sensor>
017        implements SensorManager {
018
019    public ProxySensorManager() {
020        super();
021    }
022
023    @Override
024    protected AbstractManager<Sensor> makeInternalManager() {
025        return jmri.InstanceManager.getDefault(jmri.jmrix.internal.InternalSystemConnectionMemo.class).getSensorManager();
026    }
027
028    /**
029     * Locate via user name, then system name if needed.
030     *
031     * @return Null if nothing by that name exists
032     */
033    @Override
034    @CheckForNull
035    public Sensor getSensor(@Nonnull String name) {
036        return super.getNamedBean(name);
037    }
038
039    /** {@inheritDoc} */
040    @Override
041    @Nonnull
042    protected Sensor makeBean(Manager<Sensor> manager, String systemName, String userName) throws IllegalArgumentException {
043        return ((SensorManager) manager).newSensor(systemName, userName);
044    }
045
046    @Override
047    @Nonnull
048    public Sensor provideSensor(@Nonnull String sName) throws IllegalArgumentException {
049        return super.provideNamedBean(sName);
050    }
051
052    /** {@inheritDoc} */
053    @Override
054    @Nonnull
055    public Sensor provide(@Nonnull String name) throws IllegalArgumentException { return provideSensor(name); }
056
057    /** {@inheritDoc} */
058    @Override
059    @Nonnull
060    public Sensor newSensor(@Nonnull String systemName, String userName) throws IllegalArgumentException {
061        return newNamedBean(systemName, userName);
062    }
063
064    /**
065     * Triggers #updateAll on all SensorManagers.
066     */
067    @Override
068    public void updateAll() {
069        getManagerList().forEach(m -> ((SensorManager) m).updateAll());
070    }
071
072    @Override
073    public boolean allowMultipleAdditions(@Nonnull String systemName) {
074        return ((SensorManager) getManagerOrDefault(systemName)).allowMultipleAdditions(systemName);
075    }
076
077    @Override
078    public long getDefaultSensorDebounceGoingActive() {
079        return ((SensorManager) getDefaultManager()).getDefaultSensorDebounceGoingActive();
080    }
081
082    @Override
083    public long getDefaultSensorDebounceGoingInActive() {
084        return ((SensorManager) getDefaultManager()).getDefaultSensorDebounceGoingInActive();
085    }
086
087    @Override
088    public void setDefaultSensorDebounceGoingActive(long timer) {
089        getManagerList().forEach(m -> ((SensorManager) m).setDefaultSensorDebounceGoingActive(timer));
090    }
091
092    @Override
093    public void setDefaultSensorDebounceGoingInActive(long timer) {
094        getManagerList().forEach(m -> ((SensorManager) m).setDefaultSensorDebounceGoingInActive(timer));
095    }
096
097    @Override
098    public int getXMLOrder() {
099        return jmri.Manager.SENSORS;
100    }
101
102    @Override
103    @Nonnull
104    public String getBeanTypeHandled(boolean plural) {
105        return Bundle.getMessage(plural ? "BeanNameSensors" : "BeanNameSensor");
106    }
107
108    /**
109     * {@inheritDoc}
110     */
111    @Override
112    public Class<Sensor> getNamedBeanClass() {
113        return Sensor.class;
114    }
115
116    /**
117     * Do the sensor objects provided by this manager support configuring
118     * an internal pull up or pull down resistor?
119     *
120     * @return true if pull up/pull down configuration is supported,
121     * default to false to satisfy the SensorManager interface
122     */
123    @Override
124    public boolean isPullResistanceConfigurable(){
125       return false;
126    }
127
128    /**
129     * Do the sensor objects provided by the manager for this system name
130     * support configuring an internal pull up or pull down resistor?
131     * @param systemName to select correct manager
132     * @return true if pull up/pull down configuration is supported
133     */
134    public boolean isPullResistanceConfigurable(String systemName){
135        return ((SensorManager) getManagerOrDefault(systemName)).isPullResistanceConfigurable();
136    }
137
138    // private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ProxySensorManager.class);
139}