Picked up all the last-minute changes from the gh-pages branch (where I discovered a race condition between machines)
This commit is contained in:
parent
ff46c1d240
commit
23e78b971c
11 changed files with 965 additions and 946 deletions
|
|
@ -143,9 +143,10 @@ function SerialPort(parmsSerial) {
|
|||
this.connection = this.sendData = null;
|
||||
|
||||
/*
|
||||
* Export all functions required by initConnection(); currently, this is the bare minimum, with no flow control.
|
||||
* Export all functions required by initConnection(); currently, this is the bare minimum (no flow control yet).
|
||||
*/
|
||||
this['exports'] = {
|
||||
'connect': this.initConnection,
|
||||
'receiveData': this.receiveData
|
||||
};
|
||||
}
|
||||
|
|
@ -482,31 +483,44 @@ SerialPort.prototype.initBus = function(cmp, bus, cpu, dbg)
|
|||
* receiveData(data): called when we have data to transmit; aliased internally to sendData(data)
|
||||
*
|
||||
* For now, we're not going to worry about communication in the other direction, because when the target component
|
||||
* performs its own initConnection(), it will find our receiveByte(b) function, at which point communication in both
|
||||
* performs its own initConnection(), it will find our receiveData() function, at which point communication in both
|
||||
* directions should be established.
|
||||
*
|
||||
* For added robustness, if the target machine initializes much more slowly than we do, and our connection attempt
|
||||
* fails, that's OK, because when it finally initializes, its initConnection() will call our initConnection();
|
||||
* if we've already initialized, no harm done.
|
||||
*
|
||||
* @this {SerialPort}
|
||||
*/
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -523,11 +537,10 @@ SerialPort.prototype.powerUp = function(data, fRepower)
|
|||
if (!fRepower) {
|
||||
|
||||
/*
|
||||
* We needed to wait until now to make our first inter-machine connection attempt;
|
||||
* doing this in initBus() was still too early, because initBus() is called in the context
|
||||
* of onInit() processing for all machines of the same type (eg, PCx86), and if we're
|
||||
* trying to connect to the port of a machine of a DIFFERENT type (eg, PC8080), it may not
|
||||
* have been initialized yet.
|
||||
* This is as late as we can currently wait to make our first inter-machine connection attempt;
|
||||
* even so, the target machine's initialization process may still be ongoing, so any connection
|
||||
* may be not fully resolved until the target machine performs its own initConnection(), which will
|
||||
* in turn invoke our initConnection() again.
|
||||
*/
|
||||
this.initConnection();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue