Esempio n. 1
0
    this.load = function() {
        var fbp = require("fbp");

        for (var compName in this.definition.components) {
            var comp = this.definition.components[compName];
            if (comp.graph || comp.graphFile) {
                // FIXME: don't read file syncronously
                // FIXME: do not require fbp to instantiate class
                if (fbp) {
                    var graph = comp.graph;
                    if (!graph && comp.graphFile) {
                        var p = path.join(this.baseDirectory, comp.graphFile);
                        console.log(p);
                        graph = fbp.parse(fs.readFileSync(p, {encoding: "utf-8"}));
                        this.definition.components[compName].graph = graph;
                    }
                    console.log(graph);

                    var exports = {};
                    for (var i=0; i<graph.exports.length; i++) {
                        exports[graph.exports[i]['public']] = {id: i};
                    }

                    // FIXME: separate between inport and outports. Requires https://github.com/noflo/noflo/issues/118
                    this.definition.components[compName].inPorts = exports;
                    this.definition.components[compName].outPorts = exports;
                }
            }
        }
    }
Esempio n. 2
0
    fs.readFile(filename, {encoding: "utf8"}, function(err, data) {
        if (err) callback(err);

        var def;
        if (path.extname(filename) == ".fbp") {
            def = fbp.parse(data);
        } else {
            def = JSON.parse(data);
        }
        callback(undefined, def);
    });
Esempio n. 3
0
    it('gives one response per command', function(finish){

        var s = new microflo.simulator.RuntimeSimulator();

        var graph = fbp.parse("a(Forward) OUT -> IN b(Forward) OUT -> IN c(Forward)");
        var cmdstream = microflo.commandstream.cmdStreamFromGraph(componentLib, graph);

        var expectedResponses = 8;
        var actualResponses = 0;
        // TODO: API should allow to get callback when everything is completed
        var handleFunc = function() {
            actualResponses++;
            if (arguments[0] === "NETSTART") {
                assert.equal(actualResponses, expectedResponses);
                finish();
            }
        }

        s.start();
        microflo.runtime.uploadGraph(s.transport, cmdstream, graph, handleFunc);
    })
Esempio n. 4
0
 return function() {
     try {
         let path = Runtime.resolvePath(vpath);
         let source = Utils.loadTextFileContent(path);
         let def;
         if (path.indexOf('.fbp') >= 0)
             def = Fbp.parse(source);
         else
             def = JSON.parse(source);
         def.properties = {
             name: this.name,
             id: this.name,
             library: this.moduleName,
         };
         return def;
     } catch (e) {
         log('Failed to load graph definition : ' + vpath + ' : ' + e.message);
         throw e;
     }
     return null;
 };
Esempio n. 5
0
      files.forEach(function(file){
        var ext = path.extname(file);
        if (ext != ".fbp") return;

        fbpFiles.push(file);

        var fbpData = fs.readFileSync(pkg.path(file), 'utf-8');
        try {
          var json = fbp.parse(fbpData);
        } catch (e) {
          // Rewrite message to include more information
          e.message = "Error parsing " + file + " : " + e.message;
          if (e.line && e.column) {
            e.message = e.message + ' @ line=' + e.line + ',column=' + e.column;
          }
          throw e;
        }

        var js = "module.exports = JSON.parse('"+JSON.stringify(json).replace(/'/g, "\\'")+"');";

        pkg.addFile('scripts', file, js);
      });
Esempio n. 6
0
 this.uploadFBP = function(prog, callback) {
     this.uploadGraph(fbp.parse(prog), callback);
 }