001package jmri.jmrix;
002
003import java.io.DataInputStream;
004import java.io.DataOutputStream;
005import jmri.SystemConnectionMemo;
006
007/**
008 * Provide an abstract implementation of a *StreamPortController for stream
009 * based ports.
010 * <p>
011 * Implementing classes need to implement status and configure from the
012 * portAdapter interface, along with any system specific requirements.
013 *
014 * @author Paul Bender Copyright (C) 2014
015 */
016public abstract class AbstractStreamPortController extends AbstractPortController {
017
018    protected String _name = null;
019    protected DataInputStream input = null;
020    protected DataOutputStream output = null;
021
022    public AbstractStreamPortController(SystemConnectionMemo connectionMemo, DataInputStream in, DataOutputStream out, String pname) {
023        super(connectionMemo);
024        _name = pname;
025        input = in;
026        output = out;
027    }
028
029    public AbstractStreamPortController(SystemConnectionMemo connectionMemo) {
030        super(connectionMemo);
031    }
032
033    // return the InputStream from the port
034    @Override
035    public DataInputStream getInputStream() {
036        return input;
037    }
038
039    // return the outputStream to the port
040    @Override
041    public DataOutputStream getOutputStream() {
042        return output;
043    }
044
045    @Override
046    public String getCurrentPortName() {
047        return _name;
048    }
049
050    @Override
051    public void recover() {
052        // no recovery possible here.
053    }
054
055    // connection shouldn't require any action.
056    @Override
057    public void connect() {
058    }
059
060    public void connect(AbstractPortController port) {
061        _name = port.getCurrentPortName();
062        input = port.getInputStream();
063        output = port.getOutputStream();
064    }
065
066    @Override
067    public void dispose() {
068        super.dispose();
069        input = null;
070        output = null;
071    }
072
073    // static private final Logger log = LoggerFactory.getLogger(AbstractStreamPortController.class);
074
075}