001package jmri.implementation;
002
003import java.util.Date;
004import javax.annotation.CheckForNull;
005import jmri.ClockControl;
006import jmri.InstanceManager;
007
008/**
009 * Class providing default logic of the ClockControl interface.
010 *
011 * Hardware systems that have fast clocks should "extend DefaultClockControl"
012 * and override the appropriate methods.
013 *
014 * This class provides default implementations of ClockControl methods that are
015 * not needed in the hardware implementation if one exists, or for those systems
016 * with no hardware fast clock.
017 *
018 * @author Dave Duchamp Copyright (C) 2007
019 */
020public class DefaultClockControl implements ClockControl {
021
022    public DefaultClockControl() {
023
024    }
025
026    /**
027     * Operational instance variables (not saved between runs)
028     */
029    /**
030     * Get Status of the Fast Clock.
031     * Potentially unused?
032     * {@inheritDoc}
033     */
034    @Override
035    public int getStatus() {
036        return 0;
037    }
038
039    /**
040     * Get name of hardware clock.
041     * <p>
042     * If there is no hardware clock, this method returns null.
043     * {@inheritDoc}
044     */
045    @Override
046    @CheckForNull
047    public String getHardwareClockName() {
048        return null;
049    }
050
051    /**
052     * Returns true if hardware clock accuracy can be corrected using the
053     * computer clock. 
054     * <p>
055     * Hardware implementations should override this and return
056     * true if they can correct their hardware clock.
057     * {@inheritDoc}
058     */
059    @Override
060    public boolean canCorrectHardwareClock() {
061        return false;
062    }
063
064    /**
065     * Returns true if hardware clock can be set to 12 or 24 hour display from
066     * JMRI software.
067     * <p>
068     * Default implementation is to return false.
069     * {@inheritDoc}
070     */
071    @Override
072    public boolean canSet12Or24HourClock() {
073        return false;
074    }
075
076    /**
077     * Default implementation returns false.
078     * <p>
079     * If an integer rate is required by the
080     * hardware, this method should be overridden.
081     * {@inheritDoc}
082     */
083    @Override
084    public boolean requiresIntegerRate() {
085        return false;
086    }
087
088    /**
089     * For the default implementation, setRate is ignored.
090     * {@inheritDoc}
091     */
092    @Override
093    public void setRate(double newRate) {
094    }
095
096    /**
097     * Default implementation returns the rate of the internal clock.
098     * {@inheritDoc}
099     */
100    @Override
101    public double getRate() {
102        return InstanceManager.getDefault(jmri.Timebase.class).getRate();
103    }
104
105    /**
106     * For the default implementation, set time is ignored.
107     * {@inheritDoc}
108     */
109    @Override
110    public void setTime(Date now) {
111    }
112
113    /**
114     * Default implementation returns InstanceM default jmri.Timebase getTime().
115     * ie. the time of the internal clock.
116     * {@inheritDoc}
117     */
118    @Override
119    public Date getTime() {
120        return InstanceManager.getDefault(jmri.Timebase.class).getTime();
121    }
122
123    /**
124     * Default implementation is to call SetTime to now.
125     * {@inheritDoc}
126     */
127    @Override
128    public void startHardwareClock(Date now) {
129        setTime(now);
130    }
131
132    /**
133     * Default implementation is to ignore.
134     * {@inheritDoc}
135     */
136    @Override
137    public void stopHardwareClock() {
138    }
139
140    /**
141     * Default implementation is to ignore this request.
142     * {@inheritDoc}
143     */
144    @Override
145    public void initializeHardwareClock(double rate, Date now, boolean getTime) {
146    }
147}