/*
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
import Instance from "./Instance.mjs"
/**
* Class representing the basic interface for managing instances of emulated machines.
*/
class InstanceManager {
/**
* Create an Instance Manager.
* @param {Object} [options] - Options for configuring the instance manager.
* @param {boolean} [options.screen=true] - Spawn screen option.
* @param {boolean} [options.term=false] - Spawn terminal option.
* @param {string} [options.instanceName="Host"] - Name of the instance.
* @param {number} [options.memory=1024] - Memory size for the instance; must be power of two.
* @param {HTMLElement} [options.spawnRoot=undefined] - Htlm element where instance should be spawned.
* @param {boolean} [options.autoStart=true] - Whether to automatically start the instance.
* @param {string} [options.remote="./"] - Remote URL, defaults to origin.
* @param {string} [options.wsUrl=""] - Websocket URL option.
*/
constructor(options) {
const defaultOptions = {
term: false,
screen: false,
instanceName: "Host",
memory: 1024,
spawnRoot: undefined,
autoStart: true,
remote: "./",
wsUrl: "",
};
const instanceOptions = { ...defaultOptions, ...options };
this.instances = {};
this.instanceNames = [];
this.curr_inst = 0;
this.instanceNames.push(instanceOptions.instanceName);
this.instances[instanceOptions.instanceName] = new Instance(instanceOptions);
}
/**
* Create an instance with given options and adds it to the pool of instances.
* @param {Object} options - Options for configuring the instance.
* @returns {Promise