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

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

/**
 * Adb shell会话<br>
 * 一切准备已经完成，内部提供有效的InputStream和OutputStream，自行实现相关处理逻辑<br>
 * 将此类交给Adb进行初始化。
 */
public abstract class AdbShellSession {
    private InputStream mInputStream;
    private OutputStream mOutputStream;

    private AdbTransport transport;

    private boolean ready = false;

    public void init(InputStream inputStream, OutputStream outputStream,AdbTransport transport) {
        if (ready) throw new IllegalStateException("会话已经初始化");
        mInputStream = inputStream;
        mOutputStream = outputStream;
        this.transport = transport;
        ready = true;
    }

    public InputStream getInputStream() {
        if (!ready) throw new IllegalStateException("会话尚未初始化");
        return mInputStream;
    }

    public OutputStream getOutputStream() {
        if (!ready) throw new IllegalStateException("会话尚未初始化");
        return mOutputStream;
    }

    /**
     * 是否已经准备好，可以使用
     *
     * @return 准备好
     */
    public boolean isReady() {
        return ready;
    }

    public void close() throws IOException {
        transport.close();
    }

}
