2016-02-17 05:11:55 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
|
|
|
let loadModulesForCategory = require('./module_util.js').loadModulesForCategory;
|
|
|
|
|
|
|
|
// standard/deps
|
2016-06-21 03:05:47 +00:00
|
|
|
let async = require('async');
|
2016-02-17 05:11:55 +00:00
|
|
|
|
2016-06-21 03:05:47 +00:00
|
|
|
exports.startup = startup;
|
2016-02-17 05:11:55 +00:00
|
|
|
exports.shutdown = shutdown;
|
|
|
|
exports.recordMessage = recordMessage;
|
|
|
|
|
|
|
|
let msgNetworkModules = [];
|
|
|
|
|
|
|
|
function startup(cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function loadModules(callback) {
|
|
|
|
loadModulesForCategory('scannerTossers', (err, module) => {
|
|
|
|
if(!err) {
|
|
|
|
const modInst = new module.getModule();
|
2016-02-17 05:11:55 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
modInst.startup(err => {
|
|
|
|
if(!err) {
|
|
|
|
msgNetworkModules.push(modInst);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, err => {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
cb
|
|
|
|
);
|
2016-02-17 05:11:55 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 03:05:47 +00:00
|
|
|
function shutdown(cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
async.each(
|
|
|
|
msgNetworkModules,
|
|
|
|
(msgNetModule, next) => {
|
|
|
|
msgNetModule.shutdown( () => {
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
msgNetworkModules = [];
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
);
|
2016-02-17 05:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function recordMessage(message, cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
// Give all message network modules (scanner/tossers)
|
|
|
|
// a chance to do something with |message|. Any or all can
|
|
|
|
// choose to ignore it.
|
|
|
|
//
|
|
|
|
async.each(msgNetworkModules, (modInst, next) => {
|
|
|
|
modInst.record(message);
|
|
|
|
next();
|
|
|
|
}, err => {
|
|
|
|
cb(err);
|
|
|
|
});
|
2016-02-17 05:11:55 +00:00
|
|
|
}
|