2016-02-17 05:11:55 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
|
|
|
let loadModulesForCategory = require('./module_util.js').loadModulesForCategory;
|
|
|
|
|
|
|
|
// standard/deps
|
|
|
|
let async = require('async');
|
|
|
|
|
|
|
|
exports.startup = startup
|
|
|
|
exports.shutdown = shutdown;
|
|
|
|
exports.recordMessage = recordMessage;
|
|
|
|
|
|
|
|
let msgNetworkModules = [];
|
|
|
|
|
|
|
|
function startup(cb) {
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function loadModules(callback) {
|
|
|
|
loadModulesForCategory('scannerTossers', (err, module) => {
|
|
|
|
if(!err) {
|
|
|
|
const modInst = new module.getModule();
|
|
|
|
|
|
|
|
modInst.startup(err => {
|
|
|
|
if(!err) {
|
|
|
|
msgNetworkModules.push(modInst);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, err => {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
cb
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function shutdown() {
|
|
|
|
msgNetworkModules.forEach(mod => {
|
|
|
|
mod.shutdown();
|
|
|
|
});
|
|
|
|
|
|
|
|
msgNetworkModules = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
function recordMessage(message, cb) {
|
|
|
|
//
|
|
|
|
// 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) => {
|
2016-02-21 00:57:38 +00:00
|
|
|
modInst.record(message);
|
|
|
|
next();
|
2016-02-17 05:11:55 +00:00
|
|
|
}, err => {
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
}
|