diff --git a/red/nodes/flows.js b/red/nodes/flows.js index 8c5f0bd6b..2932a2aa6 100644 --- a/red/nodes/flows.js +++ b/red/nodes/flows.js @@ -41,10 +41,15 @@ events.on('type-registered',function(type) { } }); -var parseConfig = function() { +/** + * Parses the current activeConfig and creates the required node instances + */ +function parseConfig() { var i; var nt; missingTypes = []; + + // Scan the configuration for any unknown node types for (i=0;i 0) { util.log("[red] Waiting for missing types to be registered:"); for (i=0;i 0) { util.log("[red] Stopping flows"); @@ -101,6 +111,11 @@ var flowNodes = module.exports = { init: function(_storage) { storage = _storage; }, + + /** + * Load the current activeConfig from storage and start it running + * @return a promise for the loading of the config + */ load: function() { return storage.getFlows().then(function(flows) { return credentials.load().then(function() { @@ -113,13 +128,29 @@ var flowNodes = module.exports = { util.log("[red] Error loading flows : "+err); }); }, + + /** + * Add a node to the current active set + * @param n the node to add + */ add: function(n) { nodes[n.id] = n; n.on("log",log.log); }, + + /** + * Get a node + * @param i the node id + * @return the node + */ get: function(i) { return nodes[i]; }, + + /** + * Stops all active nodes and clears the active set + * @return a promise for the stopping of all active nodes + */ clear: function() { return when.promise(function(resolve) { events.emit("nodes-stopping"); @@ -143,6 +174,11 @@ var flowNodes = module.exports = { }); }); }, + + /** + * Provides an iterator over the active set of nodes + * @param cb a function to be called for each node in the active set + */ each: function(cb) { for (var n in nodes) { if (nodes.hasOwnProperty(n)) { @@ -151,9 +187,18 @@ var flowNodes = module.exports = { } }, + /** + * @return the active configuration + */ getFlows: function() { return activeConfig; }, + + /** + * Sets the current active config. + * @param config the configuration to enable + * @return a promise for the starting of the new flow + */ setFlows: function (config) { // Extract any credential updates for (var i=0; i