001package jmri.jmrix.loconet.pr2;
002
003import jmri.GlobalProgrammerManager;
004import jmri.InstanceManager;
005import jmri.PowerManager;
006import jmri.ThrottleManager;
007import jmri.jmrix.loconet.LnPr2ThrottleManager;
008import jmri.jmrix.loconet.LnPowerManager;
009import jmri.jmrix.loconet.LnTrafficController;
010import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
011import jmri.jmrix.loconet.SlotManager;
012
013/**
014 * Lightweight class to denote that a PR2 is active
015 *
016 * @author Bob Jacobsen Copyright (C) 2010
017 */
018public class PR2SystemConnectionMemo extends LocoNetSystemConnectionMemo {
019
020    public PR2SystemConnectionMemo(LnTrafficController lt,
021            SlotManager sm) {
022        super(lt, sm);
023    }
024
025    public PR2SystemConnectionMemo() {
026        super();
027    }
028
029    /**
030     * Configure the subset of LocoNet managers valid for the PR2.
031     */
032    @Override
033    public void configureManagers() {
034        jmri.InstanceManager.store(getPowerPr2Manager(), jmri.PowerManager.class);
035
036        jmri.InstanceManager.setThrottleManager(getPr2ThrottleManager());
037
038        if (getProgrammerManager().isAddressedModePossible()) {
039            InstanceManager.store(getProgrammerManager(), jmri.AddressedProgrammerManager.class);
040        }
041        if (getProgrammerManager().isGlobalProgrammerAvailable()) {
042            InstanceManager.store(getProgrammerManager(), GlobalProgrammerManager.class);
043        }
044
045        register();
046    }
047
048    public LnPr2PowerManager getPowerPr2Manager() {
049        if (getDisabled()) {
050            return null;
051        }
052        return (LnPr2PowerManager) classObjectMap.computeIfAbsent(PowerManager.class, (Class<?> c) -> new LnPr2PowerManager(this));
053    }
054
055    public LnPr2ThrottleManager getPr2ThrottleManager() {
056        if (getDisabled()) {
057            return null;
058        }
059        return (LnPr2ThrottleManager) classObjectMap.computeIfAbsent(ThrottleManager.class, (Class<?> c) -> new LnPr2ThrottleManager(this));
060    }
061
062    @Override
063    public void dispose() {
064        InstanceManager.deregister(this, PR2SystemConnectionMemo.class);
065
066        LnPr2PowerManager powerPr2Manager = (LnPr2PowerManager) get(PowerManager.class);
067        if (powerPr2Manager != null) {
068            powerPr2Manager.dispose();
069            InstanceManager.deregister(powerPr2Manager, LnPowerManager.class);
070            deregister(powerPr2Manager,PowerManager.class);
071        }
072
073        super.dispose();
074    }
075
076}