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 /** 011 * Called when an outgoing message is sent to the CAN Network. 012 * @param m the CanMessage being sent. 013 */ 014 void message(CanMessage m); 015 016 /** 017 * Called when an incoming CanFrame is received from the CAN Network. 018 * @param m the CanReply being received. 019 */ 020 void reply(CanReply m); 021 022 /** 023 * Add a Traffic Controller Listener. 024 * Adding here, rather than in a class construction header 025 * avoids Leaking Constructor errors. 026 * @param tcToAdd The system memo CAN Traffic Controller 027 */ 028 default void addTc(TrafficController tcToAdd) { 029 if (tcToAdd != null) { 030 tcToAdd.addCanListener(this); 031 } 032 } 033 034 /** 035 * Add a Traffic Controller Listener. 036 * Adding here, rather than in a class construction header 037 * avoids Leaking Constructor errors. 038 * @param memoToAdd The CAN system Connection. 039 */ 040 default void addTc(CanSystemConnectionMemo memoToAdd) { 041 if (memoToAdd != null) { 042 addTc(memoToAdd.getTrafficController()); 043 } 044 } 045 046 /** 047 * Remove a Traffic Controller Listener. 048 * @param tcToRemove The system memo CAN Traffic Controller. 049 */ 050 default void removeTc(TrafficController tcToRemove) { 051 if (tcToRemove != null) { 052 tcToRemove.removeCanListener(this); 053 } 054 } 055 056 /** 057 * Remove a Traffic Controller Listener. 058 * @param memoToRemove The CAN system Connection. 059 */ 060 default void removeTc(CanSystemConnectionMemo memoToRemove) { 061 if (memoToRemove != null) { 062 removeTc(memoToRemove.getTrafficController()); 063 } 064 } 065}