001package jmri.jmrix.dccpp;
002
003import jmri.GlobalProgrammerManager;
004import org.slf4j.Logger;
005import org.slf4j.LoggerFactory;
006
007/**
008 * This class performs initialization for DCC++. It
009 * adds the appropriate Managers via the Initialization Manager.
010 *
011 * @author Paul Bender Copyright (C) 2003-2010
012 * @author Giorgio Terdina Copyright (C) 2007
013 * @author Mark Underwood Copyright (C) 2015
014 * @author Harald Barth Copyright (C) 2019
015 *
016 * Based on XNetInitializationManager by Paul Bender and Giorgio Terdina
017 */
018public class DCCppInitializationManager {
019
020    protected DCCppSystemConnectionMemo systemMemo = null;
021
022    DCCppPredefinedMeters predefinedMeters;
023    
024    public DCCppInitializationManager(DCCppSystemConnectionMemo memo) {
025
026        systemMemo = memo;
027
028        log.debug("Starting DCC++ Initialization Process");
029
030        jmri.InstanceManager.setThrottleManager(systemMemo.getThrottleManager());
031        systemMemo.setProgrammerManager(new DCCppProgrammerManager(new DCCppProgrammer(systemMemo.getDCCppTrafficController()), systemMemo));
032        if (systemMemo.getProgrammerManager().isAddressedModePossible()) {
033            jmri.InstanceManager.store(systemMemo.getProgrammerManager(), jmri.AddressedProgrammerManager.class);
034        }
035        if (systemMemo.getProgrammerManager().isGlobalProgrammerAvailable()) {
036            jmri.InstanceManager.store(systemMemo.getProgrammerManager(), GlobalProgrammerManager.class);
037        }
038        systemMemo.setCommandStation(systemMemo.getDCCppTrafficController().getCommandStation());
039        jmri.InstanceManager.store(systemMemo.getCommandStation(), jmri.CommandStation.class);
040        systemMemo.setTurnoutManager(new jmri.jmrix.dccpp.DCCppTurnoutManager(systemMemo));
041        jmri.InstanceManager.setTurnoutManager(systemMemo.getTurnoutManager());
042        systemMemo.setLightManager(new jmri.jmrix.dccpp.DCCppLightManager(systemMemo));
043        jmri.InstanceManager.setLightManager(systemMemo.getLightManager());
044        systemMemo.setSensorManager(new jmri.jmrix.dccpp.DCCppSensorManager(systemMemo));
045        jmri.InstanceManager.setSensorManager(systemMemo.getSensorManager());
046        jmri.InstanceManager.store(systemMemo.getPowerManager(), jmri.PowerManager.class);
047        log.debug("PowerManager: {}", jmri.InstanceManager.getDefault(jmri.PowerManager.class));
048        systemMemo.setClockControl(new DCCppClockControl(systemMemo));
049        predefinedMeters = new DCCppPredefinedMeters(systemMemo);
050
051        systemMemo.register();
052
053        log.info("DCC++ Initialization Complete");
054    }
055
056    private final static Logger log = LoggerFactory.getLogger(DCCppInitializationManager.class);
057
058}