001package jmri.jmrix.mqtt;
002
003import java.util.Comparator;
004import java.util.ResourceBundle;
005
006import jmri.*;
007import jmri.jmrix.ConfiguringSystemConnectionMemo;
008import jmri.jmrix.DefaultSystemConnectionMemo;
009import jmri.util.NamedBeanComparator;
010
011/**
012 *
013 * @author Lionel Jeanson
014 */
015public class MqttSystemConnectionMemo extends DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo {
016
017    private MqttAdapter mqttAdapter;
018
019    public MqttSystemConnectionMemo() {
020        super("M", "MQTT");
021        InstanceManager.store(this, MqttSystemConnectionMemo.class);
022    }
023
024    @Override
025    public void configureManagers() {
026//        setPowerManager(new jmri.jmrix.jmriclient.JMRIClientPowerManager(this));
027//        jmri.InstanceManager.store(getPowerManager(), jmri.PowerManager.class);
028
029        jmri.InstanceManager.setTurnoutManager(getTurnoutManager());
030        jmri.InstanceManager.setSensorManager(getSensorManager());
031        jmri.InstanceManager.setLightManager(getLightManager());
032
033//        jmri.InstanceManager.setReporterManager(getReporterManager());
034
035        register();
036    }
037
038    @Override
039    protected ResourceBundle getActionModelResourceBundle() {
040        return null;
041    }
042
043    @Override
044    public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type) {
045        return new NamedBeanComparator<>();
046    }
047
048    public MqttTurnoutManager getTurnoutManager() {
049        if (getDisabled()) {
050            return null;
051        }
052        return (MqttTurnoutManager) classObjectMap.computeIfAbsent(TurnoutManager.class,(Class c) -> {
053                    MqttTurnoutManager t = new MqttTurnoutManager(this);
054                    t.setSendTopicPrefix(getMqttAdapter().getOptionState("10.3"));
055                    t.setRcvTopicPrefix(getMqttAdapter().getOptionState("10.5"));
056                    return t;
057                });
058                
059    }
060
061    public MqttSensorManager getSensorManager() {
062        if (getDisabled()) {
063            return null;
064        }
065        return (MqttSensorManager) classObjectMap.computeIfAbsent(SensorManager.class,(Class c) -> {
066                    MqttSensorManager t = new MqttSensorManager(this);
067                    t.setSendTopicPrefix(getMqttAdapter().getOptionState("11.3"));
068                    t.setRcvTopicPrefix(getMqttAdapter().getOptionState("11.5"));
069                    return t;
070                });
071    }
072
073    public MqttLightManager getLightManager() {
074        if (getDisabled()) {
075            return null;
076        }
077        return (MqttLightManager) classObjectMap.computeIfAbsent(LightManager.class,(Class c) -> {
078                    MqttLightManager t = new MqttLightManager(this);
079                    t.setSendTopicPrefix(getMqttAdapter().getOptionState("12.3"));
080                    t.setRcvTopicPrefix(getMqttAdapter().getOptionState("12.5"));
081                    return t;
082                });
083    }
084
085    void setMqttAdapter(MqttAdapter ma) {
086        mqttAdapter = ma;
087    }
088
089    public MqttAdapter getMqttAdapter() {
090        return mqttAdapter;
091    }
092}