<commit_before>"use strict";

function app() {

    var APP_CONF_FILE = 'appstate.conf';
    var BOARD_CONF_FILE = 'boardstate.conf';
    var HTTP_PORT = 8000;
    var WS_PORT = 8001;

    var http = require('./http')();
    //var log = require('./log').create('App');
    var conf = require('./conf').create();
    var setupCtrlF = require('./fake_setup_controller');
    var boardCtrlF = require('./board_controller');
    //var netUtils = require('./network_utils')();

    var app_state;
    var setupCtrl;
    var boardCtrl;

    var start = function() {
        console.log('app.js Starting MakerNode...');

        http.listen(HTTP_PORT);

        conf.read(APP_CONF_FILE).then(function(o) {
            app_state = o;
            if (app_state.mode === 'setup') {
                launch_setup_ctrl();
            } else {
                launch_board_ctrl();
            }
        });
    };

    var stop = function() {
        if (app_state.mode === 'setup') {
            setupCtrl.stop();
            //netUtils.stop_access_point();
        } else {
            boardCtrl.stop();
            //netUtils.stop_supplicant();
        }
        conf.write(app_state);
    };

    var launch_setup_ctrl = function() {
        console.log('app.js launch setup control');
        //netUtils.start_access_point();
        setupCtrl = setupCtrlF(app_state.setup_state);
        setupCtrl.on_setup_finished(function(setup_state) {
        console.log('app.js instantiated setup control');
            app_state.mode = 'control';
            app_state.setup_state = setup_state;
            conf.write();
            setupCtrl.stop();
            //netUtils.stop_access_point();
            launch_board_ctrl();
        });
        setupCtrl.start(WS_PORT);
    };

    var launch_board_ctrl = function() {
        //netUtils.start_supplicant();
        boardCtrl = boardCtrlF(BOARD_CONF_FILE);
        boardCtrl.start(WS_PORT);
    };

    return {
        start: start,
        stop: stop,
    };
};

module.exports = app;<commit_msg>use set_on_finished for setup_controller<commit_after>"use strict";

function app() {

    var APP_CONF_FILE = 'appstate.conf';
    var BOARD_CONF_FILE = 'boardstate.conf';
    var HTTP_PORT = 8000;
    var WS_PORT = 8001;

    var http = require('./http')();
    //var log = require('./log').create('App');
    var conf = require('./conf').create();
    var setupCtrlF = require('./fake_setup_controller');
    var boardCtrlF = require('./board_controller');
    //var netUtils = require('./network_utils')();

    var app_state;
    var setupCtrl;
    var boardCtrl;

    var start = function() {
        console.log('app.js Starting MakerNode...');

        http.listen(HTTP_PORT);

        conf.read(APP_CONF_FILE).then(function(o) {
            app_state = o;
            if (app_state.mode === 'setup') {
                launch_setup_ctrl();
            } else {
                launch_board_ctrl();
            }
        });
    };

    var stop = function() {
        if (app_state.mode === 'setup') {
            setupCtrl.stop();
            //netUtils.stop_access_point();
        } else {
            boardCtrl.stop();
            //netUtils.stop_supplicant();
        }
        conf.write(app_state);
    };

    var launch_setup_ctrl = function() {
        console.log('app.js launch setup control');
        //netUtils.start_access_point();
        setupCtrl = setupCtrlF(app_state.setup_state);
        console.log('app.js instantiated setup control');
        setupCtrl.set_on_finished(function(setup_state) {
            app_state.mode = 'control';
            app_state.setup_state = setup_state;
            conf.write();
            setupCtrl.stop();
            //netUtils.stop_access_point();
            launch_board_ctrl();
        });
        setupCtrl.start(WS_PORT);
    };

    var launch_board_ctrl = function() {
        //netUtils.start_supplicant();
        boardCtrl = boardCtrlF(BOARD_CONF_FILE);
        boardCtrl.start(WS_PORT);
    };

    return {
        start: start,
        stop: stop,
    };
};

module.exports = app;
{'fraction_non_alphanumeric': 0.1381498657554308, 'fraction_numerical': 0.003905296558457408, 'mean_word_length': 2.02212389380531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6385751', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1190, 'n_words': 214}