package net.northking.cctp.upperComputer.deviceManager.thread;

import net.northking.cctp.upperComputer.driver.proxy.WebDriverAgentApiProxy;
import net.northking.cctp.upperComputer.entity.PhoneEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Device8100WatchThread extends Thread{

    private Logger logger = LoggerFactory.getLogger(Device8100WatchThread.class);

    private PhoneEntity phoneEntity;

    private WebDriverAgentApiProxy api8100Proxy;

    public Device8100WatchThread(PhoneEntity phoneEntity){
        this.phoneEntity = phoneEntity;
    }

    @Override
    public void run() {
        api8100Proxy = new WebDriverAgentApiProxy(phoneEntity.getUdid(),phoneEntity.getPort8100());
        while (!isInterrupted()) {
            try {
                api8100Proxy.startListen();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        logger.warn("设备【{}】代理端口8100监听退出............",phoneEntity.getUdid());
    }

    public void exit8100Process(){
        if (null != this.api8100Proxy) {
            interrupt();
            this.api8100Proxy.stop8100Proxy();
        } else {
            logger.info("当前设备的8100代理对象是null");
        }
    }
}
