001package jmri.jmrix.can;
002
003/**
004 * Defines the interface for listening to CAN messages
005 *
006 * @author Andrew Crosland Copyright (C) 2008
007 */
008public interface CanListener extends jmri.jmrix.AbstractMRListener {
009
010    public void message(CanMessage m);
011
012    public void reply(CanReply m);
013    
014    /**
015     * Add a Traffic Controller Listener.
016     * Adding here, rather than in a class construction header
017     * avoids Leaking Constructor errors.
018     * @param tcToAdd The system memo CAN Traffic Controller
019     */
020    public default void addTc(TrafficController tcToAdd) {
021        if (tcToAdd != null) {
022            tcToAdd.addCanListener(this);
023        }
024    }
025    
026    /**
027     * Add a Traffic Controller Listener.
028     * Adding here, rather than in a class construction header
029     * avoids Leaking Constructor errors.
030     * @param memoToAdd The CAN system Connection
031     */
032    public default void addTc(CanSystemConnectionMemo memoToAdd) {
033        if (memoToAdd != null) {
034            addTc(memoToAdd.getTrafficController());
035        }
036    }
037    
038    /**
039     * Remove a Traffic Controller Listener.
040     * @param tcToRemove The system memo CAN Traffic Controller
041     */
042    public default void removeTc(TrafficController tcToRemove) {
043        if (tcToRemove != null) {
044            tcToRemove.removeCanListener(this);
045        }
046    }
047    
048    /**
049     * Remove a Traffic Controller Listener.
050     * @param memoToRemove The CAN system Connection
051     */
052    public default void removeTc(CanSystemConnectionMemo memoToRemove) {
053        if (memoToRemove != null) {
054            removeTc(memoToRemove.getTrafficController());
055        }
056    }
057}