jmri.jmrix.lenz
Class XNetTrafficController

java.lang.Object
  extended by jmri.jmrix.AbstractMRTrafficController
      extended by jmri.jmrix.lenz.XNetTrafficController
All Implemented Interfaces:
XNetInterface
Direct Known Subclasses:
XNetPacketizer, XNetTrafficRouter

public abstract class XNetTrafficController
extends AbstractMRTrafficController
implements XNetInterface

Abstract base class for implementations of XNetInterface.

This provides just the basic interface, plus the "" static method for locating the local implementation.

Author:
Bob Jacobsen Copyright (C) 2002, Paul Bender Copyright (C) 2004,2005

Nested Class Summary
 
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
 
Field Summary
protected  Hashtable mListenerMasks
           
protected static XNetTrafficController self
           
 
Fields inherited from class jmri.jmrix.AbstractMRTrafficController
allowUnexpectedReply, cmdListeners, controller, IDLESTATE, istream, mCurrentMode, mCurrentState, mLastSender, mWaitBeforePoll, NORMALMODE, NOTIFIEDSTATE, OKSENDMSGSTATE, ostream, PROGRAMINGMODE, replyInDispatch, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, xmtRunnable
 
Fields inherited from interface jmri.jmrix.lenz.XNetInterface
ALL, COMMINFO, CONSIST, CS_INFO, FEEDBACK, INTERFACE, PROGRAMMING, THROTTLE
 
Method Summary
 void addXNetListener(int mask, XNetListener l)
          Request notification of things happening on the XNet.
protected  boolean endOfMessage(AbstractMRReply msg)
           
protected  AbstractMRMessage enterNormalMode()
          enterNormalMode() returns the value of getExitProgModeMsg();
protected  AbstractMRMessage enterProgMode()
          enterProgMode(); has to be available, even though it doesn't do anything on lenz
 void forwardMessage(AbstractMRListener reply, AbstractMRMessage m)
          Forward a preformatted XNetMessage to a specific listener interface.
 void forwardReply(AbstractMRListener client, AbstractMRReply m)
          Forward a preformatted XNetMessage to the registered XNetListeners.
 LenzCommandStation getCommandStation()
          Get access to communicating command station object
static XNetTrafficController instance()
          static function returning the TrafficController instance to use.
protected  void loadChars(AbstractMRReply msg, DataInputStream istream)
          Get characters from the input source, and file a message.
protected  AbstractMRReply newReply()
           
protected  AbstractMRMessage pollMessage()
          Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TC should just sleep.
protected  AbstractMRListener pollReplyHandler()
           
protected  boolean programmerIdle()
          enterNormalMode() returns the value of getExitProgModeMsg();
 void removeXNetListener(int mask, XNetListener l)
           
abstract  void sendXNetMessage(XNetMessage m, XNetListener reply)
          Forward a preformatted XNetMessage to the actual interface.
protected  void setInstance()
          static function setting this object as the TrafficController instance to use.
abstract  boolean status()
           
 
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, connectPort, disconnectPort, enterProgModeDelayTime, finalize, forwardToPort, getPortName, handleOneIncomingReply, handleTimeout, hasTimeouts, lengthOfByteStream, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, readByteProtected, receiveLoop, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, waitForStartOfReply
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mListenerMasks

protected Hashtable mListenerMasks

self

protected static XNetTrafficController self
Method Detail

instance

public static XNetTrafficController instance()
static function returning the TrafficController instance to use.

Returns:
The registered TrafficController instance for general use, if need be creating one.

setInstance

protected void setInstance()
static function setting this object as the TrafficController instance to use.

Specified by:
setInstance in class AbstractMRTrafficController

status

public abstract boolean status()
Specified by:
status in interface XNetInterface
Overrides:
status in class AbstractMRTrafficController

sendXNetMessage

public abstract void sendXNetMessage(XNetMessage m,
                                     XNetListener reply)
Forward a preformatted XNetMessage to the actual interface.

Specified by:
sendXNetMessage in interface XNetInterface
Parameters:
m - Message to send; will be updated with CRC

forwardMessage

public void forwardMessage(AbstractMRListener reply,
                           AbstractMRMessage m)
Forward a preformatted XNetMessage to a specific listener interface.

Specified by:
forwardMessage in class AbstractMRTrafficController
Parameters:
m - Message to send;

forwardReply

public void forwardReply(AbstractMRListener client,
                         AbstractMRReply m)
Forward a preformatted XNetMessage to the registered XNetListeners. NOTE: this drops the packet if the checksum is bad.

Specified by:
forwardReply in class AbstractMRTrafficController
Parameters:
m - Message to send # @param client is the client getting the message

pollMessage

protected AbstractMRMessage pollMessage()
Description copied from class: AbstractMRTrafficController
Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TC should just sleep.

Specified by:
pollMessage in class AbstractMRTrafficController

pollReplyHandler

protected AbstractMRListener pollReplyHandler()
Specified by:
pollReplyHandler in class AbstractMRTrafficController

addXNetListener

public void addXNetListener(int mask,
                            XNetListener l)
Description copied from interface: XNetInterface
Request notification of things happening on the XNet.

The same listener can register multiple times with different masks. (Multiple registrations with a single mask value are equivalent to a single registration) Mask values are defined as class constants. Note that these are bit masks, and should be OR'd, not added, if multiple values are desired.

The event notification contains the received message as source, not this object, so that we can notify of an incoming message to multiple places and then move on.

Specified by:
addXNetListener in interface XNetInterface
Parameters:
mask - The OR of the key values of messages to be reported (to reduce traffic, provide for listeners interested in different things)
l - Object to be notified of new messages as they arrive.

removeXNetListener

public void removeXNetListener(int mask,
                               XNetListener l)
Specified by:
removeXNetListener in interface XNetInterface

enterProgMode

protected AbstractMRMessage enterProgMode()
enterProgMode(); has to be available, even though it doesn't do anything on lenz

Specified by:
enterProgMode in class AbstractMRTrafficController

enterNormalMode

protected AbstractMRMessage enterNormalMode()
enterNormalMode() returns the value of getExitProgModeMsg();

Specified by:
enterNormalMode in class AbstractMRTrafficController

programmerIdle

protected boolean programmerIdle()
enterNormalMode() returns the value of getExitProgModeMsg();

Overrides:
programmerIdle in class AbstractMRTrafficController

endOfMessage

protected boolean endOfMessage(AbstractMRReply msg)
Specified by:
endOfMessage in class AbstractMRTrafficController

newReply

protected AbstractMRReply newReply()
Specified by:
newReply in class AbstractMRTrafficController

loadChars

protected void loadChars(AbstractMRReply msg,
                         DataInputStream istream)
                  throws IOException
Get characters from the input source, and file a message.

Returns only when the message is complete.

Only used in the Receive thread.

Overrides:
loadChars in class AbstractMRTrafficController
Parameters:
msg - message to fill
istream - character source.
Throws:
IOException - when presented by the input source.

getCommandStation

public LenzCommandStation getCommandStation()
Get access to communicating command station object

Returns:
associated Command Station object


Copyright © 1997 - 2008 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: SourceForge_Logo