Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
Figured out timeout weirdness. Pass-by-reference with objects for the…
Browse files Browse the repository at this point in the history
… confusing win!
  • Loading branch information
filmaj committed Jan 25, 2013
1 parent 1eb952d commit f8e372d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 59 deletions.
67 changes: 21 additions & 46 deletions src/build/makers/blackberry.js
@@ -1,22 +1,15 @@
var shell = require('shelljs'),
path = require('path'),
et = require('elementtree'),
config= require('../../../config'),
semver= require('semver'),
scan = require('./blackberry/devices'),
playbook_builder = require('./blackberry/playbook_builder'),
bbten_builder = require('./blackberry/bbten_builder'),
n = require('ncallbacks'),
error_writer=require('./error_writer'),
fs = require('fs');
var shell = require('shelljs'),
path = require('path'),
et = require('elementtree'),
scan = require('./blackberry/devices'),
deploy = require('./blackberry/deploy'),
error_writer = require('./error_writer'),
fs = require('fs');

var blackberry_lib = path.join(__dirname, '..', '..', '..', 'lib', 'cordova-blackberry');
var mobile_spec = path.join(__dirname, '..', '..', '..', 'temp', 'mobspec');
var create = path.join(blackberry_lib, 'bin', 'create');

var bb10_sdk = config.blackberry.bb10.sdk;
var tablet_sdk = config.blackberry.tablet.sdk;

module.exports = function(output, sha, devices, callback) {
function log(msg) {
console.log('[BLACKBERRY] ' + msg + ' (sha: ' + sha.substr(0,7) + ')');
Expand Down Expand Up @@ -71,39 +64,21 @@ module.exports = function(output, sha, devices, callback) {
return;
}

// scan for devices, figure out which of each kind we have.
log('Scanning for BlackBerry devices.');
scan(function(err, devices) {
if (devices) {
// determine how many of each device we have
var tablets = {}, bbtens = {};
var num_ts = 0, num_bs = 0;
for (var ip in devices) if (devices.hasOwnProperty(ip)) {
var device = devices[ip];
var version = device.version;
if (semver.satisfies(version.substring(0,version.lastIndexOf('.')), '>=2.0.0 && < 3.0.0')) {
num_ts++;
tablets[ip] = device;
} else {
num_bs++;
bbtens[ip] = device;
}
}
log(num_ts + ' Tablets and ' + num_bs + ' BB-10s detected.');
var counter = (num_bs && bb10_sdk.length > 0 ? 1 : 0) + (num_ts && tablet_sdk.length > 0 ? 1 : 0);
var end = n(counter, callback);
// compile as needed, one for bb10, one for tablet
if (num_bs && bb10_sdk.length > 0) {
bbten_builder(bbtens, sha, end);
if (devices) {
deploy(sha, devices, callback);
} else {
log('Scanning for BlackBerry devices.');
scan(function(err, devices) {
if (err) {
// Could not obtain device list...
var error_message = devices;
log(error_message);
callback(true);
} else {
deploy(sha, devices, callback);
}
if (num_ts && tablet_sdk.length > 0) {
playbook_builder(tablets, sha, end);
}
} else {
log('No BlackBerry devices discovered. Aborting.');
callback();
}
});
});
}
}
});
}
Expand Down
32 changes: 19 additions & 13 deletions src/build/makers/blackberry/bbten_builder.js
Expand Up @@ -62,17 +62,20 @@ module.exports = function bbten_builder(tens, sha, callback) {
end();
} else {
log('Mobile-spec successfully launched on ' + ten.model + ' (' + ip + ').');

var inner_timer = {};
var timer = setTimeout(function() {
log('Mobile-spec timed out on ' + ten.model + ' (' + ip + ').');
error_writer('blackberry', sha, ten.version, ten.model, 'mobile-spec timed out', 'mobile-spec timed out after 5 minutes');
clearTimeout(inner_timer.timer);
inner_timer.timer = false;
//error_writer('blackberry', sha, ten.version, ten.model, 'mobile-spec timed out', 'mobile-spec timed out after 5 minutes');
end();
}, 1000 * 60 * 5);

when_app_finishes(ip, device_password, 'cordovaExample', function(err, message) {
inner_timer = when_app_finishes(ip, device_password, 'cordovaExample', function(err, message) {
clearTimeout(timer);
if (err) {
// TODO: post an error?
// probalby not.. deployment errors generally the cause here.
} else {
end();
}
Expand All @@ -89,9 +92,10 @@ module.exports = function bbten_builder(tens, sha, callback) {
};

function when_app_finishes(device_ip, device_password, package_name, callback) {
var to = {timer:null};
shell.exec(deploy + ' -listInstalledApps -device ' + device_ip + ' -password ' + device_password, {silent:true, async:true}, function(code, output) {
if (code > 0) {
console.log('omfg list installed apps failed on ' + device_ip);
console.log('[BLACKBERRY] [BUILDER:OS 10] omfg list installed apps failed on ' + device_ip);
callback(true, 'listInstalledAps failed: ' + output);
} else {
var package_id = output.split('\n').filter(function(l) {return l.indexOf(package_name) === 0})[0];
Expand All @@ -102,27 +106,29 @@ function when_app_finishes(device_ip, device_password, package_name, callback) {
} else {
callback(false);
}
});
}, to);
}
});
return to;
}
function is_app_running(device_ip, device_password, package_fullname, callback) {
console.log('checking if app ' + package_fullname + ' is running');
function is_app_running(device_ip, device_password, package_fullname, callback, timer_object) {
timer_object.timer = true;
shell.exec(deploy + ' -isAppRunning -device ' + device_ip + ' -password ' + device_password + ' -package-fullname ' + package_fullname, {silent:true, async:true}, function(code, output) {
if (code > 0) {
console.log('omfg isapprunning failed wtf');
console.log('[BLACKBERRY] [BUILDER:OS 10] omfg isapprunning failed wtf');
callback(true, output);
} else {
var result = (output.split('\n').filter(function(l) { return l.indexOf('result') === 0})[0].split('::')[1] == 'true');
if (result) {
// If app is still running, test again in 5 seconds
console.log(package_fullname + ' is still running, delaying by 5 seconds');
setTimeout(function() {
is_app_running(device_ip, device_password, package_fullname, callback);
}, 1000 * 5);
if (timer_object.timer) {
timer_object.timer = setTimeout(function() {
is_app_running(device_ip, device_password, package_fullname, callback, timer_object);
}, 1000 * 5);
} else {
}
} else {
// Not running anymore!
console.log(package_fullname + ' is DONE');
callback(false);
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/build/makers/blackberry/deploy.js
@@ -0,0 +1,42 @@
var semver = require('semver'),
playbook_builder = require('./playbook_builder'),
n = require('ncallbacks'),
config = require('../../../../config'),
bbten_builder = require('./bbten_builder');

var bb10_sdk = config.blackberry.bb10.sdk;
var tablet_sdk = config.blackberry.tablet.sdk;

module.exports = function deploy(sha, devices, callback) {
function log(msg) {
console.log('[BLACKBERRY] [DEPLOY] ' + msg + ' (sha: ' + sha.substr(0,7) + ')');
}
function done() {
log('No BlackBerry devices connected. Aborting.');
callback();
}
// determine how many of each device we have
var tablets = {}, bbtens = {};
var num_ts = 0, num_bs = 0;
for (var ip in devices) if (devices.hasOwnProperty(ip)) {
var device = devices[ip];
var version = device.version;
if (semver.satisfies(version.substring(0,version.lastIndexOf('.')), '>=2.0.0 && < 3.0.0')) {
num_ts++;
tablets[ip] = device;
} else {
num_bs++;
bbtens[ip] = device;
}
}
log(num_ts + ' Tablets and ' + num_bs + ' BB-10s detected.');
var counter = (num_bs && bb10_sdk.length > 0 ? 1 : 0) + (num_ts && tablet_sdk.length > 0 ? 1 : 0);
var end = n(counter, callback);
// compile as needed, one for bb10, one for tablet
if (num_bs && bb10_sdk.length > 0) {
bbten_builder(bbtens, sha, end);
}
if (num_ts && tablet_sdk.length > 0) {
playbook_builder(tablets, sha, end);
}
};

0 comments on commit f8e372d

Please sign in to comment.