Replace device:support:quit with util:lifecycle, which is usable by non-device processes too.

This commit is contained in:
Simo Kinnunen
2014-04-01 21:41:58 +09:00
parent e17f306d30
commit d6604bcda8
11 changed files with 75 additions and 179 deletions

View File

@@ -11,14 +11,14 @@ var keyutil = require('../../../util/keyutil')
var streamutil = require('../../../util/streamutil')
var logger = require('../../../util/logger')
var ms = require('../../../wire/messagestream')
var lifecycle = require('../../../util/lifecycle')
module.exports = syrup.serial()
.dependency(require('../support/adb'))
.dependency(require('../support/router'))
.dependency(require('../support/push'))
.dependency(require('../support/quit'))
.dependency(require('../resources/service'))
.define(function(options, adb, router, push, quit, apk) {
.define(function(options, adb, router, push, apk) {
var log = logger.createLogger('device:plugins:input')
var serviceQueue = []
@@ -49,18 +49,11 @@ module.exports = syrup.serial()
))
})
.then(function(out) {
lifecycle.share('InputAgent shell', out)
out.pipe(split())
.on('data', function(chunk) {
log.info('Agent says: "%s"', chunk)
})
.on('error', function(err) {
log.fatal('InputAgent shell had an error', err.stack)
quit.fatal()
})
.on('end', function() {
log.fatal('InputAgent shell ended')
quit.fatal()
})
})
.then(function() {
return devutil.waitForPort(adb, options.serial, agent.port)
@@ -69,14 +62,7 @@ module.exports = syrup.serial()
agent.socket = conn
agent.writer = new ms.DelimitingStream()
agent.writer.pipe(conn)
conn.on('error', function(err) {
log.fatal('InputAgent socket had an error', err.stack)
quit.fatal()
})
conn.on('end', function() {
log.fatal('InputAgent socket ended')
quit.fatal()
})
lifecycle.share('InputAgent connection', conn)
})
}
@@ -160,14 +146,7 @@ module.exports = syrup.serial()
})
service.writer = new ms.DelimitingStream()
service.writer.pipe(conn)
conn.on('error', function(err) {
log.fatal('InputService socket had an error', err.stack)
quit.fatal()
})
.on('end', function() {
log.fatal('InputService socket ended')
quit.fatal()
})
lifecycle.share('InputService connection', conn)
})
}