"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrackingEngineImpl = void 0;
const tracking_storage_1 = require("./tracking-storage");
const env_1 = require("@things-factory/env");
const child_process_1 = require("child_process");
const tree_kill_1 = __importDefault(require("tree-kill"));
const visionConfig = env_1.config.get('vision', {});
const program = (_a = visionConfig.objectTracker) === null || _a === void 0 ? void 0 : _a.program;
const NOOP = () => { };
class TrackingEngineImpl {
    // _interval: any
    constructor(name) {
        this.trackingStorage = new tracking_storage_1.ROIStateStorageImpl();
        this.name = name;
    }
    start(options) {
        var { onstdout, onstderr, onexit } = options;
        var { trackables: trackables, rois: rois } = this.fetchSensors();
        this.trackables = trackables;
        this.rois = rois;
        var executable = program[0];
        var params = [...program.slice(1), this.name];
        this.childProcess = (0, child_process_1.spawn)(executable, params);
        this.childProcess.stdout.on('data', onstdout || NOOP);
        this.childProcess.stderr.on('data', onstderr || NOOP);
        this.childProcess.on('exit', onexit || NOOP);
        // this._interval = setInterval(this.evaluate.bind(this), this.duration)
    }
    stop() {
        this.childProcess && (0, tree_kill_1.default)(this.childProcess.pid);
        // clearInterval(this._interval)
    }
    evaluate() {
        this.trackables.forEach(trackable => trackable.detect(this.trackingStorage));
    }
    fetchSensors() {
        return {
            trackables: [],
            rois: []
        };
    }
}
exports.TrackingEngineImpl = TrackingEngineImpl;
//# sourceMappingURL=tracking-engine.js.map