package meerkat.pollingstation;

import meerkat.protobuf.PollingStation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Laura on 3/20/2017.
 */
public class PollingStationToyRun {
    final static Logger logger = LoggerFactory.getLogger(PollingStation.class);

    private static PollingStationScanner.PollingStationServer scanner;
    private static final String CONTEXT_PATH = "/scan";
    private static final int PORT = 0;

    public static void main(String [] args) throws Exception {
        logger.debug("Setting up Scanner WebApp!");

//        scanner = new ReceiverScanHandler(PORT, SUB_ADDRESS);
//
//            try {
//            scanner.start();
//        } catch (Exception e) {
//                e.printStackTrace();
//                System.err.println("Could not start server: " + e.getMessage());
//        }

        scanner = new PollingStationWebScanner(0, CONTEXT_PATH);
        PollingStation.ConnectionServerData serverData = scanner.start(true);

        logger.info("Started polling station web scanner on {} (nonce: {})", serverData.getServerUrl(), Long.toUnsignedString(serverData.getNonce()));
        PollingStationMainController controller = new PollingStationMainController();
        controller.init(scanner);

        Thread.currentThread().setName("Meerkat PS-Controller Thread");
        controller.run();
    }
}
