001package jmri.jmrix.bidib;
002
003import java.io.IOException;
004import java.util.Set;
005import org.bidib.jbidibc.core.BidibInterface;
006import org.bidib.jbidibc.core.MessageListener;
007import org.bidib.jbidibc.core.NodeListener;
008import org.bidib.jbidibc.core.node.listener.TransferListener;
009import org.bidib.jbidibc.messages.ConnectionListener;
010import org.bidib.jbidibc.messages.helpers.Context;
011import org.bidib.jbidibc.messages.helpers.DefaultContext;
012
013/**
014 * Abstract base for classes representing a BiDiB communications port
015 * <p>
016 *
017 * @author Bob Jacobsen Copyright (C) 2001, 2008
018 * @author Eckart Meyer Copyright (C) 2023
019 */
020public abstract class BiDiBNetworkPortController extends jmri.jmrix.AbstractNetworkPortController implements BiDiBPortController {
021
022    protected BidibInterface bidib = null;
023    protected Context context = new DefaultContext();
024
025    public BiDiBNetworkPortController() {
026        super(new BiDiBSystemConnectionMemo());
027    }
028
029    @Override
030    public abstract void connect(String host, int port) throws IOException;
031    
032    /**
033     * {@inheritDoc}
034     */
035    @Override
036    public BiDiBSystemConnectionMemo getSystemConnectionMemo() {
037        return (BiDiBSystemConnectionMemo) super.getSystemConnectionMemo();
038    }
039
040    // Implementation of the BiDiBPortController interface
041
042    /**
043     * Get the physical port name used with jbidibc
044     * 
045     * @return physical port name
046     */
047    @Override
048    public String getRealPortName() {
049        return getCurrentPortName(); //default implemention
050    }
051    
052    /**
053     * Register all Listeners to the specific BiDiB Object.
054     * We need this here since the BidibInterface does not
055     * provide this method.
056     * 
057     * @param connectionListener add to this
058     * @param nodeListeners listeners to add
059     * @param messageListeners listeners to add
060     * @param transferListeners  listeners to add
061     */    
062    @Override
063    public abstract void registerAllListeners(ConnectionListener connectionListener, Set<NodeListener> nodeListeners,
064        Set<MessageListener> messageListeners, Set<TransferListener> transferListeners);
065    
066    /**
067     * Get the Bidib adapter context
068     * 
069     * @return Context
070     */
071    @Override
072    public Context getContext() {
073        return context;
074    }
075}
076
077
078