org.ka2ddo.yaac.io
Class PortConnector

java.lang.Object
  extended by org.ka2ddo.ax25.Connector
      extended by org.ka2ddo.yaac.io.PortConnector
Direct Known Subclasses:
AbstractGpsConnector, ExternalMessageSourceConnector, GpsdConnector, SerialWeatherConnector, TransmittingPortConnector, WxnowTxtConnector

public abstract class PortConnector
extends Connector

This class defines the generic API for an object that connects a bidirectional real-time data stream to this application.

To support the dynamically plugin-built support for multiple port types, each non-abstract PortConnector subclass must define the following public static final fields:


Nested Class Summary
 
Nested classes/interfaces inherited from class org.ka2ddo.ax25.Connector
Connector.PortStats
 
Field Summary
 PortConfig.Cfg currentCfg
          The port type-specific configuration associated with this PortConnector.
 PortConfig portConfig
          The port configuration associated with this PortConnector.
 
Fields inherited from class org.ka2ddo.ax25.Connector
CAP_FULL_DUPLEX, CAP_GPS_DATA, CAP_HF, CAP_IGATE, CAP_OPENTRAC, CAP_RCV_PACKET_DATA, CAP_RF, CAP_WAYPOINT_SENDER, CAP_WEATHER, CAP_XMT_PACKET_DATA, stats
 
Constructor Summary
PortConnector()
           
 
Method Summary
static void addFrameListener(FrameListener l)
          Add an object that wants to be informed of incoming raw AX.25 frames.
 void addPortEventListener(PortEventListener l)
          Register a listener for port transmission and/or reception events.
abstract  void configure(PortConfig cfg)
          Update the configuration of the connector to match the updated setup.
static PortConnector createPort(PortConfig cfg)
          Instantiate a PortConnector object of the type specified in the configuration object.
static void fireConsumeFrame(AX25Frame frame, long rcptTimeInMsecSinceEpoch)
          Send an AX.25 frame to all the listeners expecting to process raw frames,
protected  AX25Frame fireConsumeFrame(byte[] buf, int offset, int length, long rcptTimeInMsecSinceEpoch)
          Extract an AX.25 frame from a byte array and send it to all the listeners expecting to process raw frames,
 void fireFailed()
          Report to interested listeners that the port has failed for some reason.
 void fireReceiving(boolean isReceiving)
          Report to interested listeners that the port has started or stopped receiving.
protected  void fireTransmitting(boolean isTransmitting)
          Report to interested listeners that the port has started or stopped transmitting.
static java.lang.Class<? extends PortConnector> getPortConnectorClass(java.lang.String portTypeName)
          Get the class corresponding to a particular port type name.
static java.util.Collection<java.lang.Class<? extends PortConnector>> portConnectorClasses()
          Get all the concrete subclasses of PortConnector currently registered in YAAC for which instances can be created and configured.
static java.util.Set<java.lang.String> portTypeNames()
          Get all the registered PortConnector names that should be displayed in the port configuration dialog as a port type.
static void registerPortConnectorType(java.lang.String typeName, java.lang.Class<? extends PortConnector> pcClazz)
          Add a new subclass of PortConnector to the supported map of PortConnector types.
static void removeFrameListener(FrameListener l)
          Remove an object that used to be informed about incoming raw AX.25 frames.
 void removePortEventListener(PortEventListener l)
          Unregister a listener so it no longer is informed of transmission and reception events.
 void setPortConfig(PortConfig portConfig)
          Store the configuration associated with this PortConnector.
 
Methods inherited from class org.ka2ddo.ax25.Connector
close, finalize, getCallsign, getCapabilities, getStats, hasCapability, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

portConfig

public PortConfig portConfig
The port configuration associated with this PortConnector.


currentCfg

public PortConfig.Cfg currentCfg
The port type-specific configuration associated with this PortConnector.

Constructor Detail

PortConnector

public PortConnector()
Method Detail

registerPortConnectorType

public static void registerPortConnectorType(java.lang.String typeName,
                                             java.lang.Class<? extends PortConnector> pcClazz)
Add a new subclass of PortConnector to the supported map of PortConnector types.

Parameters:
typeName - String name of PortConnector subclass
pcClazz - the Class object for instantiating objects of this type

portTypeNames

public static java.util.Set<java.lang.String> portTypeNames()
Get all the registered PortConnector names that should be displayed in the port configuration dialog as a port type.

Returns:
Set of String names to be displayed as port driver types.

portConnectorClasses

public static java.util.Collection<java.lang.Class<? extends PortConnector>> portConnectorClasses()
Get all the concrete subclasses of PortConnector currently registered in YAAC for which instances can be created and configured.

Returns:
Collection of subclasses of PortConnector

getPortConnectorClass

public static java.lang.Class<? extends PortConnector> getPortConnectorClass(java.lang.String portTypeName)
Get the class corresponding to a particular port type name.

Parameters:
portTypeName - String name of port connector type
Returns:
Class providing that port connector type, or null if no match

addFrameListener

public static void addFrameListener(FrameListener l)
Add an object that wants to be informed of incoming raw AX.25 frames.

Parameters:
l - FrameListener to add

removeFrameListener

public static void removeFrameListener(FrameListener l)
Remove an object that used to be informed about incoming raw AX.25 frames.

Parameters:
l - FrameListener to unregister

addPortEventListener

public void addPortEventListener(PortEventListener l)
Register a listener for port transmission and/or reception events.

Parameters:
l - PortEventListener to register

removePortEventListener

public void removePortEventListener(PortEventListener l)
Unregister a listener so it no longer is informed of transmission and reception events.

Parameters:
l - PortEventListener to unregister

fireConsumeFrame

protected AX25Frame fireConsumeFrame(byte[] buf,
                                     int offset,
                                     int length,
                                     long rcptTimeInMsecSinceEpoch)
Extract an AX.25 frame from a byte array and send it to all the listeners expecting to process raw frames,

Parameters:
buf - byte array supposedly containing an AX.25 frame
offset - zero-based index into byte array where frame starts
length - number of consecutive bytes in buffer that make up the frame
rcptTimeInMsecSinceEpoch - time since Unix epoch when frame started arriving
Returns:
the AX25Frame created from the specified bytes, or null if a frame could not be decoded

fireConsumeFrame

public static void fireConsumeFrame(AX25Frame frame,
                                    long rcptTimeInMsecSinceEpoch)
Send an AX.25 frame to all the listeners expecting to process raw frames,

Parameters:
frame - AX25Frame to process
rcptTimeInMsecSinceEpoch - time since Unix epoch when frame started arriving

fireTransmitting

protected void fireTransmitting(boolean isTransmitting)
Report to interested listeners that the port has started or stopped transmitting.

Parameters:
isTransmitting - boolean true if transmission has started, false if stopped

fireReceiving

public void fireReceiving(boolean isReceiving)
Report to interested listeners that the port has started or stopped receiving.

Parameters:
isReceiving - boolean true if reception has started, false if stopped

fireFailed

public void fireFailed()
Report to interested listeners that the port has failed for some reason.


createPort

public static PortConnector createPort(PortConfig cfg)
                                throws java.net.UnknownServiceException,
                                       java.io.IOException
Instantiate a PortConnector object of the type specified in the configuration object.

Parameters:
cfg - PortConfig object identifying what type of port to create
Returns:
instantiated but not configured PortConnector subclass object
Throws:
java.io.IOException - if port could not be instantiated
java.net.UnknownServiceException - if port type not recognized

configure

public abstract void configure(PortConfig cfg)
                        throws java.io.IOException,
                               java.lang.IllegalArgumentException
Update the configuration of the connector to match the updated setup.

Parameters:
cfg - PortConfig defining new port settings
Throws:
java.io.IOException - if interface changes could not be applied
java.lang.IllegalArgumentException - if type information is invalid for changing the settings of this PortConnector

setPortConfig

public void setPortConfig(PortConfig portConfig)
Store the configuration associated with this PortConnector. The PortConfig is assumed to be of the correct type here, such that the current() method will return the appropriate type-specific configuration data.

Parameters:
portConfig - PortConfig matching the PortConnector subclass's type