Package jmri.jmrix.bidib.netbidib
Class NetBiDiBAdapter
java.lang.Object
jmri.jmrix.AbstractPortController
jmri.jmrix.AbstractNetworkPortController
jmri.jmrix.bidib.BiDiBNetworkPortController
jmri.jmrix.bidib.netbidib.NetBiDiBAdapter
- All Implemented Interfaces:
BiDiBPortController,NetworkPortAdapter,PortAdapter
Implements BiDiBPortController for the netBiDiB system network
connection.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intstatic final String(package private) static final String(package private) static final String(package private) longFields inherited from class jmri.jmrix.bidib.BiDiBNetworkPortController
bidib, contextFields inherited from class jmri.jmrix.AbstractNetworkPortController
connTimeout, m_HostName, m_port, socketConnFields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidSet the server's host name and port using mdns autoconfiguration.protected voidAbstract class for controllers to close the connection.voidConfigure all of the other jmrix widgets needed to work with this adapter.voidconnect()This methods is called from network connection config.voidConnects to the end device using a hostname/ip address and portvoidGet and set the ZeroConf/mDNS advertisement name.Get the device list of all found devices and return them as a map of strings suitable for display and indexed by the unique id.Get the InputStream from the port.booleanGet whether or not this adapter is configured to use autoconfiguration via MDNS.Get a unique id for ourself.Get the outputStream to the port.Get the ZeroConf/mDNS service type.Get and set the BiDiB Unique ID.booleanGet the connection ready status from the traffic controllerbooleanCheck if the connection is detached i.e. it is opened, paired but the logon has been rejected.booleanisOpened()Check of the connection is opened.voidregisterAllListeners(org.bidib.jbidibc.messages.ConnectionListener connectionListener, Set<org.bidib.jbidibc.core.NodeListener> nodeListeners, Set<org.bidib.jbidibc.core.MessageListener> messageListeners, Set<org.bidib.jbidibc.core.node.listener.TransferListener> transferListeners) Register all Listeners to the specific BiDiB Object.voidvoidselectDeviceListItem(int i) Set hostname, port and unique id from the device list entry selected by a given index.voidsetAdvertisementName(String AdName) voidsetLogon(boolean logon) Set or remove the detached state.voidsetMdnsConfigure(boolean autoconfig) Set whether or not this adapter should be configured automatically via MDNS.voidsetPaired(boolean paired, ActionListener l) Set new pairing state.voidsetUniqueId(Long uniqueId) Methods inherited from class jmri.jmrix.bidib.BiDiBNetworkPortController
getContext, getRealPortName, getSystemConnectionMemoMethods inherited from class jmri.jmrix.AbstractNetworkPortController
getConnectionTimeout, getCurrentPortName, getHostAddress, getHostName, getPort, reconnectFromLoop, resetupConnection, setConnectionTimeout, setHostAddress, setHostName, setPort, setPort, setServiceTypeMethods inherited from class jmri.jmrix.AbstractPortController
configureOption1, configureOption2, configureOption3, configureOption4, dispose, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, purgeStream, reconnect, recover, safeSleep, setClosed, setDisabled, setManufacturer, setOpened, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName, statusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.jmrix.NetworkPortAdapter
statusMethods inherited from interface jmri.jmrix.PortAdapter
configureOption1, configureOption2, configureOption3, configureOption4, dispose, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, recover, setDisabled, setManufacturer, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
Field Details
-
NET_BIDIB_DEFAULT_PAIRING_STORE_FILE
- See Also:
-
OPTION_DEVICE_LIST
- See Also:
-
OPTION_UNIQUE_ID
- See Also:
-
BIDIB_JMRI_PID
- See Also:
-
timeout
long timeout
-
-
Constructor Details
-
NetBiDiBAdapter
public NetBiDiBAdapter()
-
-
Method Details
-
deviceListAddFromPairingStore
-
connect
Description copied from interface:NetworkPortAdapterConnects to the end device using a hostname/ip address and port- Specified by:
connectin interfaceNetworkPortAdapter- Specified by:
connectin classBiDiBNetworkPortController- Parameters:
host- hostname / ip address.port- network port.- Throws:
IOException- on connection error.
-
connect
This methods is called from network connection config. It creates the BiDiB object from jbidibc and opens it. The connectPort method of the traffic controller is called for generic initialisation.- Specified by:
connectin interfacePortAdapter- Overrides:
connectin classAbstractNetworkPortController
-
configure
Configure all of the other jmrix widgets needed to work with this adapter. -
closeConnection
Abstract class for controllers to close the connection. Called prior to any re-connection attempts.- Overrides:
closeConnectionin classAbstractNetworkPortController
-
registerAllListeners
public void registerAllListeners(org.bidib.jbidibc.messages.ConnectionListener connectionListener, Set<org.bidib.jbidibc.core.NodeListener> nodeListeners, Set<org.bidib.jbidibc.core.MessageListener> messageListeners, Set<org.bidib.jbidibc.core.node.listener.TransferListener> transferListeners) Register all Listeners to the specific BiDiB Object. We need this here since the BidibInterface does not provide this method.- Specified by:
registerAllListenersin interfaceBiDiBPortController- Specified by:
registerAllListenersin classBiDiBNetworkPortController- Parameters:
connectionListener- add to thisnodeListeners- listeners to addmessageListeners- listeners to addtransferListeners- listeners to add
-
getNetBidibUniqueId
Get a unique id for ourself. The product id part is fixed and registered with bidib.org. The serial number is a hash from the MAC address. This is a variation of org.bidib.wizard.core.model.settings.NetBidibSettings.getNetBidibUniqueId(). Instead of just using the network interface from InetAddress.getLocalHost() - which can result to the loopback-interface, which does not have a hardware address - we loop through the list of interfaces until we find an interface which is up and not a loopback. It would be even better, if we check for virtual interfaces (those could be present if VMs run on the machine) and then exclude them. But there is no generic method to find those interfaces. So we just return an UID derived from the first found non-loopback interface or the default UID if there is no such interface.- Returns:
- Unique ID as long
-
getInputStream
Description copied from class:AbstractNetworkPortControllerGet the InputStream from the port.- Specified by:
getInputStreamin interfacePortAdapter- Overrides:
getInputStreamin classAbstractNetworkPortController- Returns:
- the InputStream from the port
-
getOutputStream
Description copied from class:AbstractNetworkPortControllerGet the outputStream to the port.- Specified by:
getOutputStreamin interfacePortAdapter- Overrides:
getOutputStreamin classAbstractNetworkPortController- Returns:
- the outputStream to the port
-
setMdnsConfigure
Set whether or not this adapter should be configured automatically via MDNS.- Specified by:
setMdnsConfigurein interfaceNetworkPortAdapter- Overrides:
setMdnsConfigurein classAbstractNetworkPortController- Parameters:
autoconfig- boolean value.
-
getMdnsConfigure
Get whether or not this adapter is configured to use autoconfiguration via MDNS.- Specified by:
getMdnsConfigurein interfaceNetworkPortAdapter- Overrides:
getMdnsConfigurein classAbstractNetworkPortController- Returns:
- true if configured using MDNS.
-
autoConfigure
Set the server's host name and port using mdns autoconfiguration.- Specified by:
autoConfigurein interfaceNetworkPortAdapter- Overrides:
autoConfigurein classAbstractNetworkPortController
-
getAdvertisementName
Get and set the ZeroConf/mDNS advertisement name.This value is the unique id in BiDiB.
- Specified by:
getAdvertisementNamein interfaceNetworkPortAdapter- Overrides:
getAdvertisementNamein classAbstractNetworkPortController- Returns:
- advertisement name.
-
setAdvertisementName
- Specified by:
setAdvertisementNamein interfaceNetworkPortAdapter- Overrides:
setAdvertisementNamein classAbstractNetworkPortController
-
getServiceType
Get the ZeroConf/mDNS service type.This value is fixed in BiDiB, so return the default value.
- Specified by:
getServiceTypein interfaceNetworkPortAdapter- Overrides:
getServiceTypein classAbstractNetworkPortController- Returns:
- service type.
-
getDeviceListEntries
Get the device list of all found devices and return them as a map of strings suitable for display and indexed by the unique id. This is used by the connection config.- Returns:
- map of strings containing device info.
-
selectDeviceListItem
Set hostname, port and unique id from the device list entry selected by a given index.- Parameters:
i- selected index into device list
-
getUniqueId
Get and set the BiDiB Unique ID.If we haven't set the unique ID of the connection before, try to find it from the root node of the connection. This will work only if the connection is open and not detached.
- Returns:
- unique Id as Long
-
setUniqueId
-
isConnectionReady
Get the connection ready status from the traffic controller- Returns:
- true if the connection is opened and ready to use (paired and logged in)
-
setPaired
Set new pairing state. If the pairing should be removed, close the connection, set pairing state in the device list and update the pairing store. If pairing should be initiated, a connection is temporary opened and a pariring dialog is displayed which informs the user to confirm the pairing on the remote device. If the process has completed, the temporary connection is closed. Pairing and unpairing is an asynchroneous process, so an action listener may be provided which is called when the process has completed.- Parameters:
paired- - true if the pairing should be initiated, false if pairing should be removedl- - and event listener, called when pairing or unpairing has finished.
-
isOpened
Check of the connection is opened. This does not mean that it is paired or logged on.- Returns:
- true if opened
-
isDetached
Check if the connection is detached i.e. it is opened, paired but the logon has been rejected.- Returns:
- true if detached
-
setLogon
Set or remove the detached state.- Parameters:
logon- - true for logon (attach), false for logoff (detach)
-
addConnectionChangedListener
-
removeConnectionChangedListener
-