001package jmri.jmrix.dcc4pc;
002
003import javax.annotation.Nonnull;
004import jmri.AddressedProgrammer;
005import jmri.AddressedProgrammerManager;
006import jmri.GlobalProgrammerManager;
007import jmri.Programmer;
008import jmri.managers.DefaultProgrammerManager;
009
010/**
011 * DCC4PC Programmer acts as a proxy for ops mode programming. Extend
012 * DefaultProgrammerManager to provide ops mode programmers on XpressNet
013 *
014 * @see jmri.managers.DefaultProgrammerManager
015 * @author Kevin Dickerson Copyright (C) 2012
016 *
017 */
018public class Dcc4PcProgrammerManager extends DefaultProgrammerManager {
019
020    private final GlobalProgrammerManager manager;
021
022    public <T extends AddressedProgrammerManager & GlobalProgrammerManager> Dcc4PcProgrammerManager(@Nonnull T manager) {
023        super(manager.getGlobalProgrammer());
024        this.manager = manager;
025    }
026
027    @Override
028    public Programmer getGlobalProgrammer() {
029        return manager.getGlobalProgrammer();
030    }
031
032    @Override
033    public String getUserName() {
034        return manager.getUserName();
035    }
036
037    /**
038     * XpressNet command station does provide Ops Mode We should make this
039     * return false based on what command station we're using but for now, we'll
040     * return true
041     */
042    @Override
043    public boolean isAddressedModePossible() {
044        if (manager instanceof AddressedProgrammerManager) {
045            return ((AddressedProgrammerManager) manager).isAddressedModePossible();
046        }
047        return false;
048    }
049
050    @Override
051    public boolean isGlobalProgrammerAvailable() {
052        return manager.isGlobalProgrammerAvailable();
053    }
054
055    @Override
056    public AddressedProgrammer getAddressedProgrammer(boolean pLongAddress, int pAddress) {
057        if (manager instanceof AddressedProgrammerManager) {
058            return new Dcc4PcOpsModeProgrammer(pLongAddress, pAddress, (AddressedProgrammerManager) manager);
059        }
060        return null;
061    }
062
063    @Override
064    public AddressedProgrammer reserveAddressedProgrammer(boolean pLongAddress, int pAddress) {
065        if (manager instanceof AddressedProgrammerManager) {
066            return ((AddressedProgrammerManager) manager).reserveAddressedProgrammer(pLongAddress, pAddress);
067        }
068        return null;
069    }
070
071    @Override
072    public void releaseAddressedProgrammer(AddressedProgrammer p) {
073        if (manager instanceof AddressedProgrammerManager) {
074            ((AddressedProgrammerManager) manager).releaseAddressedProgrammer(p);
075        }
076    }
077
078    @Override
079    public Programmer reserveGlobalProgrammer() {
080        return manager.reserveGlobalProgrammer();
081    }
082
083    @Override
084    public void releaseGlobalProgrammer(Programmer p) {
085        manager.releaseGlobalProgrammer(p);
086    }
087}