Worked around initConnection() failures due to machines that initialize more slowly, by also allowing each machine to invoke the other's initConnection(); if it turns out to be unnecessary, it's simply ignored

This commit is contained in:
Jeff Parsons 2016-08-19 12:35:18 -07:00
commit 983651610c
14 changed files with 1035 additions and 937 deletions

View file

@ -136,6 +136,7 @@ function SerialPort8080(parmsSerial) {
* Export all functions required by initConnection(); currently, this is the bare minimum, with no flow control.
*/
this['exports'] = {
'connect': this.initConnection,
'receiveData': this.receiveData
};
}
@ -428,24 +429,33 @@ SerialPort8080.prototype.initBus = function(cmp, bus, cpu, dbg)
*/
SerialPort8080.prototype.initConnection = function()
{
var sConnection = this.cmp.getMachineParm("connection");
if (sConnection) {
var asParts = sConnection.split('->');
if (asParts.length == 2) {
var sSourceID = str.trim(asParts[0]);
if (sSourceID != this.idComponent) return; // this connection string is intended for another instance
var sTargetID = str.trim(asParts[1]);
this.connection = Component.getComponentByID(sTargetID);
if (this.connection) {
var exports = this.connection['exports'];
if (exports) {
this.sendData = exports['receiveData'];
this.status(this.idMachine + '.' + sSourceID + " connected to " + sTargetID);
return;
if (!this.connection) {
var sConnection = this.cmp.getMachineParm("connection");
if (sConnection) {
var asParts = sConnection.split('->');
if (asParts.length == 2) {
var sSourceID = str.trim(asParts[0]);
if (sSourceID != this.idComponent) return; // this connection string is intended for another instance
var sTargetID = str.trim(asParts[1]);
this.connection = Component.getComponentByID(sTargetID);
if (this.connection) {
var exports = this.connection['exports'];
if (exports) {
var fnConnect = exports['connect'];
if (fnConnect) fnConnect.call(this.connection);
this.sendData = exports['receiveData'];
if (this.sendData) {
this.status(this.idMachine + '.' + sSourceID + " connected to " + sTargetID);
return;
}
}
}
}
/*
* Changed from notice() to status() because sometimes a connection fails simply because one of us is a laggard.
*/
this.status("Unable to establish connection: " + sConnection);
}
this.notice("Unable to establish connection: " + sConnection);
}
};

View file

@ -146,6 +146,7 @@ function SerialPort(parmsSerial) {
* Export all functions required by initConnection(); currently, this is the bare minimum, with no flow control.
*/
this['exports'] = {
'connect': this.initConnection,
'receiveData': this.receiveData
};
}
@ -489,24 +490,33 @@ SerialPort.prototype.initBus = function(cmp, bus, cpu, dbg)
*/
SerialPort.prototype.initConnection = function()
{
var sConnection = this.cmp.getMachineParm("connection");
if (sConnection) {
var asParts = sConnection.split('->');
if (asParts.length == 2) {
var sSourceID = str.trim(asParts[0]);
if (sSourceID != this.idComponent) return; // this connection string is intended for another instance
var sTargetID = str.trim(asParts[1]);
this.connection = Component.getComponentByID(sTargetID);
if (this.connection) {
var exports = this.connection['exports'];
if (exports) {
this.sendData = exports['receiveData'];
this.status(this.idMachine + '.' + sSourceID + " connected to " + sTargetID);
return;
if (!this.connection) {
var sConnection = this.cmp.getMachineParm("connection");
if (sConnection) {
var asParts = sConnection.split('->');
if (asParts.length == 2) {
var sSourceID = str.trim(asParts[0]);
if (sSourceID != this.idComponent) return; // this connection string is intended for another instance
var sTargetID = str.trim(asParts[1]);
this.connection = Component.getComponentByID(sTargetID);
if (this.connection) {
var exports = this.connection['exports'];
if (exports) {
var fnConnect = exports['connect'];
if (fnConnect) fnConnect.call(this.connection);
this.sendData = exports['receiveData'];
if (this.sendData) {
this.status(this.idMachine + '.' + sSourceID + " connected to " + sTargetID);
return;
}
}
}
}
/*
* Changed from notice() to status() because sometimes a connection fails simply because one of us is a laggard.
*/
this.status("Unable to establish connection: " + sConnection);
}
this.notice("Unable to establish connection: " + sConnection);
}
};

View file

@ -226,17 +226,9 @@ Component.subclass = function(subclass, superclass, methods, statics)
* various resources used by that machine.
*/
if (window) {
if (!window['PCjs']) {
window['PCjs'] = {
'Machines': {},
'Components': []
};
}
/*
* Alias the new global objects above to their original property names, to minimize code changes.
*/
Component.machines = window['PCjs']['Machines'];
Component.components = window['PCjs']['Components'];
if (!window['PCjs']) window['PCjs'] = {};
Component.machines = window['PCjs']['Machines'] || (window['PCjs']['Machines'] = {});
Component.components = window['PCjs']['Components'] || (window['PCjs']['Components'] = []);
}
else {
/*