mirror of
https://github.com/openstf/stf
synced 2025-10-06 03:50:04 +02:00
Switch to protocol buffers for communication.
This commit is contained in:
parent
f60cf2008b
commit
90e405a341
8 changed files with 354 additions and 36 deletions
|
@ -1,9 +1,15 @@
|
|||
var path = require('path')
|
||||
|
||||
var adb = require('adbkit')
|
||||
var Promise = require('bluebird')
|
||||
var zmq = require('zmq')
|
||||
|
||||
var logger = require('../util/logger')
|
||||
var wire = require('../wire')
|
||||
var wireutil = require('../util/wireutil')(wire)
|
||||
|
||||
module.exports = function(options) {
|
||||
var log = require('../util/logger').createLogger('provider')
|
||||
var log = logger.createLogger('provider')
|
||||
var client = Promise.promisifyAll(adb.createClient())
|
||||
var workers = Object.create(null)
|
||||
|
||||
|
@ -43,6 +49,11 @@ module.exports = function(options) {
|
|||
})
|
||||
})
|
||||
|
||||
function pushDeviceStatus(device, type) {
|
||||
push.send([wireutil.global,
|
||||
wireutil.makeDeviceStatusMessage(device.id, type)])
|
||||
}
|
||||
|
||||
function isWantedDevice(device) {
|
||||
return options.filter ? options.filter(device) : true
|
||||
}
|
||||
|
@ -63,6 +74,7 @@ module.exports = function(options) {
|
|||
|
||||
function maybeConnect(device) {
|
||||
if (isConnectable(device) && !isConnected(device)) {
|
||||
pushDeviceStatus(device, device.type)
|
||||
log.info('Spawning worker for device "%s"', device.id)
|
||||
var proc = options.fork(device)
|
||||
proc.on('error', function(err) {
|
||||
|
@ -100,6 +112,7 @@ module.exports = function(options) {
|
|||
|
||||
function maybeDisconnect(device) {
|
||||
if (isConnected(device)) {
|
||||
pushDeviceStatus(device, 'absent')
|
||||
log.info('Releasing worker of %s', device.id)
|
||||
gracefullyKillWorker(device.id, function() { /* noop */ })
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue