package net.northking.cctp.upperComputer.driver.ios;


import net.northking.cctp.upperComputer.driver.usbmuxd.AppleDevice;
import net.northking.cctp.upperComputer.driver.usbmuxd.UsbMuxd;
import net.northking.cctp.upperComputer.driver.usbmuxd.UsbMuxdConnectFailedException;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class LocalUsbmuxdDeviceSocketStream implements DeviceSocketStream {
    private final UsbMuxd usbMuxd;
    private final AppleDevice appleDevice;
    private final int port;

    private final UsbMuxd.ConnectOperator connectOperator;

    public LocalUsbmuxdDeviceSocketStream(UsbMuxd usbMuxd, AppleDevice appleDevice, int port) throws IOException, UsbMuxdConnectFailedException {
        this.usbMuxd = usbMuxd;
        this.appleDevice = appleDevice;
        this.port = port;
        this.connectOperator = usbMuxd.connectDeviceLocalPort(appleDevice, port);
    }

    @Override
    public InputStream getInputStream() {
        return connectOperator.inputStream;
    }

    @Override
    public OutputStream getOutputStream() {
        return connectOperator.outputStream;
    }


    @Override
    public void close() throws Exception {
        connectOperator.close();
    }

    public AppleDevice getAppleDevice() {
        return appleDevice;
    }

    public int getPort() {
        return port;
    }

    public UsbMuxd.ConnectOperator getConnectOperator() {
        return connectOperator;
    }
}
