void CFileNode::configure(CNodeConfig &config) { // Add parameters config.addFilename("input_file", "Input File", "Path of the file to read from disk."); config.addBool("binary", "Binary format", "Parse the file contents as binary data.", true); config.setCategory("Input"); // Add inputs and outputs config.addOutput("out", "file"); }
void CPythonNode::configure(CNodeConfig &config) { config.setDescription("Run Python scripts as nodes."); config.setCategory("Script"); // Add parameters config.addFilename("input_script", "Python Script", "Python script to execute."); // Add the gates. config.addInput("in_table", "table"); config.addInput("in_flow", "tcpstreams"); config.addOutput("out", "table"); }
bool CNodeMesh::addNode(QVariantMap &node_json) { CLogInfo log; CNodeConfig conf; bool ok; QString node_name; QString node_class; QString node_desc(""); QString node_category(""); QVariant v; v = node_json["name"]; if(v.isValid()) { node_name = v.toString(); } v = node_json["class"]; if(v.isValid()) { node_class = v.toString(); } // Optional in the json file. v = node_json["description"]; if(v.isValid()) { node_desc = v.toString(); } //Get the category v = node_json["category"]; if(v.isValid()) { node_category = v.toString(); } // Verify that this Node was defined properly. if(node_name.isEmpty() || node_class.isEmpty()) { log.setMsg("The JSON Node definition did not include class or name."); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::warning); log.setTime(QDateTime::currentDateTime()); log.print(); return false; } // Verify that a Node with the same name does not exist already in the map. if(m_nodes.contains(node_name)) { log.setMsg( QString("A node with the name '%1' has already been added to the mesh.") .arg(node_name)); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::warning); log.setTime(QDateTime::currentDateTime()); log.print(); return false; } // Verify that the requested node class is available. ok = CNodeFactory::instance().nodeAvailable(node_class); if(!ok) { log.setMsg( QString("Cannot create the node '%1'. The node class '%2' does not exist.") .arg(node_class)); log.setName("Anise"); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::error); log.setTime(QDateTime::currentDateTime()); log.print(); return false; } // Get the configuration template of the requested node. ok = CNodeFactory::instance().configTemplate( node_class, conf); if(!ok) { // The template for the desired Node class was not found. log.setMsg( QString("The node class '%1' failed to set its config template.") .arg(node_name)); log.setName("Anise"); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::warning); log.setTime(QDateTime::currentDateTime()); log.print(); return false; } // Set the node name. conf.setName(node_name); // Add a description if it was supplied. if(!node_desc.isEmpty()) { conf.setDescription(node_desc); } // Add a category if it was supplied. if(!node_category.isEmpty()) { conf.setCategory(node_category); } // Set the node Parameters. for(QVariant p : node_json["params"].toList()) { QVariantMap param = p.toMap(); for(QVariant key : param.keys()) { ok = conf.setParameter(key.toString(), param.value(key.toString())); if(!ok) { log.setMsg(QString("Failed to set the parameter '%1' in Node '%2'.") .arg(key.toString(), node_name)); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::error); log.setTime(QDateTime::currentDateTime()); log.print(); return false; } } } // Create the node we've been asked for. CNode *node = CNodeFactory::instance().createNode(node_class, conf); if(node == nullptr) { log.setMsg("Could not create Node " + node_class + " ."); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::warning); log.setTime(QDateTime::currentDateTime()); log.print(); return false; } m_nodes.insert(node_name, QSharedPointer<CNode>(node)); // Keep track of the processing status of the node. QObject::connect(node, SIGNAL(processing(bool)), this, SLOT(onNodeProcessing(bool))); return true; }