Fixes to machine save support

This commit is contained in:
Jeff Parsons 2016-02-17 11:05:27 -08:00
commit 585a851ce5
14 changed files with 2476 additions and 2315 deletions

View file

@ -140,7 +140,8 @@ function Computer(parmsComputer, parmsMachine, fSuspended) {
Component.call(this, "Computer", parmsComputer, Computer, Messages.COMPUTER);
this.aFlags.fPowered = false;
this.parmsMachine = parmsMachine;
this.setMachineParms(parmsMachine);
this.fAutoPower = this.getMachineParm('autoPower', parmsComputer);
@ -193,7 +194,7 @@ function Computer(parmsComputer, parmsMachine, fSuspended) {
*/
var iComponent, component;
var aComponents = Component.getComponents(this.id);
this.panel = Component.getComponentByType("Panel", this.id);
this.panel = /** @type {Panel} */ (Component.getComponentByType("Panel", this.id));
if (this.panel && this.panel.controlPrint) {
for (iComponent = 0; iComponent < aComponents.length; iComponent++) {
@ -337,10 +338,35 @@ Computer.prototype.getMachineID = function()
return this.sMachineID;
};
/**
* setMachineParms(parmsMachine)
*
* If no explicit machine parms were provided, then we check for 'parms' in the bundled resources (if any).
*
* @param {Object} [parmsMachine]
*/
Computer.prototype.setMachineParms = function(parmsMachine)
{
if (!parmsMachine) {
var sParms;
if (typeof resources == 'object' && (sParms = resources['parms'])) {
try {
parmsMachine = /** @type {Object} */ (eval("(" + sParms + ")"));
} catch(e) {
Component.error(e.message + " (" + sParms + ")");
}
}
}
this.parmsMachine = parmsMachine;
};
/**
* getMachineParm(sParm, parmsComponent)
*
* If the machine parameter doesn't exist, and component parameters have been provided, we'll automatically look up the latter.
* If the machine parameter doesn't exist, we check for a matching component parameter (if parmsComponent is provided),
* and failing that, we check the bundled resources (if any).
*
* At the moment, the only bundled resource match we expect to encounter is 'state'.
*
* @param {string} sParm
* @param {Object} [parmsComponent]
@ -348,12 +374,27 @@ Computer.prototype.getMachineID = function()
*/
Computer.prototype.getMachineParm = function(sParm, parmsComponent)
{
var value = null;
if (this.parmsMachine) {
if (this.parmsMachine[sParm] != null) {
return this.parmsMachine[sParm];
}
value = this.parmsMachine[sParm];
}
return parmsComponent? parmsComponent[sParm] : null;
if (value == null && parmsComponent) {
value = parmsComponent[sParm];
}
if (value == null && typeof resources == 'object') {
value = resources[sParm];
}
return value;
};
/**
* saveMachineParms()
*
* @return {string|null}
*/
Computer.prototype.saveMachineParms = function()
{
return this.parmsMachine? JSON.stringify(this.parmsMachine) : null;
};
/**
@ -1425,7 +1466,7 @@ Computer.show = function()
for (var iComputer = 0; iComputer < aeComputers.length; iComputer++) {
var eComputer = aeComputers[iComputer];
var parmsComputer = Component.getComponentParms(eComputer);
var computer = Component.getComponentByType("Computer", parmsComputer['id']);
var computer = /** @type {Computer} */ (Component.getComponentByType("Computer", parmsComputer['id']));
if (computer) {
if (DEBUG && computer.messageEnabled()) {
@ -1474,7 +1515,7 @@ Computer.exit = function()
for (var iComputer = 0; iComputer < aeComputers.length; iComputer++) {
var eComputer = aeComputers[iComputer];
var parmsComputer = Component.getComponentParms(eComputer);
var computer = Component.getComponentByType("Computer", parmsComputer['id']);
var computer = /** @type {Computer} */ (Component.getComponentByType("Computer", parmsComputer['id']));
if (computer) {
if (DEBUG && computer.messageEnabled()) {

View file

@ -6366,23 +6366,23 @@ if (DEBUGGER) {
}
if (sAddr == "state") {
var s = this.cmp.powerOff(true);
var sState = this.cmp.powerOff(true);
if (sLen == "console") {
/*
* Console buffers are notoriously small, and even the following code, which breaks the
* data into parts (eg, "d state console 1", "d state console 2", etc) just isn't that helpful.
*
* var nPart = +sBytes;
* if (nPart) s = s.substr(1000000 * (nPart-1), 1000000);
* if (nPart) sState = sState.substr(1000000 * (nPart-1), 1000000);
*
* So, the best way to capture a large machine state is to run your own local server and use
* server-side storage. Take a look at the "Save" binding in computer.js, which binds an HTML
* control to the computer.powerOff() and computer.saveServerState() functions.
*/
console.log(s);
console.log(sState);
} else {
this.doClear();
this.println(s);
this.println(sState);
}
return;
}