Class NetBiDiBAdapter

    • Method Detail

      • connect

        public void connect​(java.lang.String host,
                            int port)
                     throws java.io.IOException
        Description copied from interface: NetworkPortAdapter
        Connects to the end device using a hostname/ip address and port
        Specified by:
        connect in interface NetworkPortAdapter
        Specified by:
        connect in class BiDiBNetworkPortController
        Parameters:
        host - hostname / ip address.
        port - network port.
        Throws:
        java.io.IOException - on connection error.
      • connect

        public void 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:
        connect in interface PortAdapter
        Overrides:
        connect in class AbstractNetworkPortController
      • configure

        public void configure()
        Configure all of the other jmrix widgets needed to work with this adapter.
      • registerAllListeners

        public void registerAllListeners​(org.bidib.jbidibc.messages.ConnectionListener connectionListener,
                                         java.util.Set<org.bidib.jbidibc.core.NodeListener> nodeListeners,
                                         java.util.Set<org.bidib.jbidibc.core.MessageListener> messageListeners,
                                         java.util.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:
        registerAllListeners in interface BiDiBPortController
        Specified by:
        registerAllListeners in class BiDiBNetworkPortController
        Parameters:
        connectionListener - add to this
        nodeListeners - listeners to add
        messageListeners - listeners to add
        transferListeners - listeners to add
      • getNetBidibUniqueId

        public java.lang.Long 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
      • getDeviceListEntries

        public java.util.Map<java.lang.Long,​java.lang.String> 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

        public void selectDeviceListItem​(int i)
        Set hostname, port and unique id from the device list entry selected by a given index.
        Parameters:
        i - selected index into device list
      • getUniqueId

        public java.lang.Long 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

        public void setUniqueId​(java.lang.Long uniqueId)
      • isConnectionReady

        public boolean 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

        public void setPaired​(boolean paired,
                              java.awt.event.ActionListener l)
        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 removed
        l - - and event listener, called when pairing or unpairing has finished.
      • isOpened

        public boolean isOpened()
        Check of the connection is opened. This does not mean that it is paired or logged on.
        Returns:
        true if opened
      • isDetached

        public boolean isDetached()
        Check if the connection is detached i.e. it is opened, paired but the logon has been rejected.
        Returns:
        true if detached
      • setLogon

        public void setLogon​(boolean logon)
        Set or remove the detached state.
        Parameters:
        logon - - true for logon (attach), false for logoff (detach)