Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
static void _dump_node_basic(QSP_ARG_DECL  Vec_Expr_Node *enp)
{
	Tree_Code code;
	int i;
	const char *s;

	if( enp==NULL ) return;

	/* print the node "name", and a code that tells about shape knowledge */

// Temporarily print to stderr instead of stdout for debugging...
	prt_node(enp,msg_str);
	prt_msg_frag(msg_str);

	if( SHOWING_LHS_REFS ){
		sprintf(msg_str,"\t%d",VN_LHS_REFS(enp));
		prt_msg_frag(msg_str);
	}

	if( SHOWING_COST ){
		if( VN_SHAPE(enp) != NULL ){
			sprintf(msg_str,"\t%d", SHP_N_MACH_ELTS(VN_SHAPE(enp)));
		}

		prt_msg_frag(msg_str);

		sprintf(msg_str,"\t%d\t%d", VN_FLOPS(enp),VN_N_MATH(enp));
		prt_msg_frag(msg_str);
	}

	if( IS_CURDLED(enp) ){
		sprintf(msg_str,"\t%s (curdled!?)", NNAME(enp));
		prt_msg(msg_str);
		return;
	}

	sprintf(msg_str,"\t%s", NNAME(enp));
	prt_msg_frag(msg_str);

	/* print the special op-dependent args in human-readable form */

	code = VN_CODE(enp);

	if( code==T_DYN_OBJ || code == T_UNDEF || code == T_PROTO || code==T_POINTER || code==T_FUNCPTR || code==T_STR_PTR ){
		sprintf(msg_str,"\t%s",VN_STRING(enp));
		prt_msg_frag(msg_str);
		if( code == T_POINTER ){
			Identifier *idp;
			/* We don't use get_set_ptr() here because we don't want an error msg... */
			idp = id_of(VN_STRING(enp));
			if( idp != NULL && IS_POINTER(idp) && POINTER_IS_SET(idp) ){
				if( PTR_REF(ID_PTR(idp)) == NULL ){
					/* how could this ever happen??? */
					prt_msg_frag("->???");
				} else {
					Data_Obj *dp;
					dp = REF_OBJ(PTR_REF(ID_PTR(idp)));
					sprintf(msg_str,"->%s",OBJ_NAME(dp));
					prt_msg_frag(msg_str);
				}
			}
		}
	} else if( code == T_STATIC_OBJ ){
		sprintf(msg_str,"\t%s",OBJ_NAME(VN_OBJ(enp)));
		prt_msg_frag(msg_str);
#ifdef SCALARS_NOT_OBJECTS
	} else if( code == T_SCALAR_VAR ){
		sprintf(msg_str,"\t%s",VN_STRING(enp));
		prt_msg_frag(msg_str);
#endif // SCALARS_NOT_OBJECTS
	} else if ( code == T_FUNCREF ){
		Subrt *srp;
		srp=VN_SUBRT(enp);
		sprintf(msg_str,"\t%s",SR_NAME(srp));
		prt_msg_frag(msg_str);
	} else if( code == T_SIZE_FN ){
		sprintf(msg_str,"\t%s",FUNC_NAME(VN_FUNC_PTR(enp)));
		prt_msg_frag(msg_str);
	}
#ifdef NOT_YET
	else if(code == T_CALL_NATIVE ){
		// was kw_token???
		// curr_native_func_tbl...
		sprintf(msg_str,"\t%s",FUNC_NAME(VN_FUNC_PTR(enp)));
		prt_msg_frag(msg_str);
	}
#endif /* NOT_YET */
	else if(code == T_TYPECAST ){
		// BUG not how we do precision any more!!!
		//sprintf(msg_str,"  %s",NAME_FOR_PREC_CODE(VN_INTVAL(enp)));
        if( VN_SHAPE(enp) == NULL ) error1("CAUTIOUS:  null node shape for typecast node!?");
        else {
            sprintf(msg_str,"  %s",PREC_NAME(VN_PREC_PTR(enp)));
            prt_msg_frag(msg_str);
        }
    } else if( code == T_SUBRT_DECL || code == T_SCRIPT ){
		Subrt *srp;
		srp=VN_SUBRT(enp);
		sprintf(msg_str,"\t%s",SR_NAME(srp));
		prt_msg_frag(msg_str);
	} else if( code==T_DECL_STAT ){
		//sprintf(msg_str," %s",NAME_FOR_PREC_CODE(VN_INTVAL(enp)));
		sprintf(msg_str," %s",PREC_NAME(VN_DECL_PREC(enp)));
		prt_msg_frag(msg_str);
	} else if( IS_DECL(code) ){
		sprintf(msg_str," %s",VN_STRING(enp));
		prt_msg_frag(msg_str);
	} else if( code==T_ADVISE ){
		/* BUG need to elim yylex_qsp */
		s=eval_string(VN_CHILD(enp,0));
		sprintf(msg_str,"\t\"%s\"",s);
		prt_msg_frag(msg_str);
	} else if( code==T_WARN ){
		/* BUG need to elim yylex_qsp */
		s=eval_string(VN_CHILD(enp,0));
		sprintf(msg_str,"\t\"%s\"",s);
		prt_msg_frag(msg_str);
	} else if( code==T_STRING ){
		sprintf(msg_str,"\t\"%s\"",VN_STRING(enp));
		prt_msg_frag(msg_str);
	} else if( code == T_LABEL || code ==T_GO_BACK || code == T_GO_FWD ){
		sprintf(msg_str," %s",VN_STRING(enp));
		prt_msg_frag(msg_str);
	} else if( code==T_LIT_DBL ){
		sprintf(msg_str," %g",VN_DBLVAL(enp));
		prt_msg_frag(msg_str);
	} else if( code == T_MATH0_FN ){
		sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp)));
		prt_msg_frag(msg_str);
	} else if( code == T_MATH1_FN ){
		sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp)));
		prt_msg_frag(msg_str);
	} else if( code == T_MATH2_FN ){
		sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp)));
		prt_msg_frag(msg_str);
	} else if (
		   code == T_MATH0_VFN
		|| code == T_MATH1_VFN
		|| code == T_MATH2_VFN
		|| code == T_MATH2_VSFN
		|| code == T_CHAR_VFN
			/* BUG? shouldn't there bre a VSFN2 ??? */
		|| code == T_VS_FUNC
		|| code == T_VV_FUNC
		){
		sprintf(msg_str," %s",VF_NAME(FIND_VEC_FUNC(VN_VFUNC_CODE(enp))));
		prt_msg_frag(msg_str);
	} else if( code==T_CALLFUNC ){
assert(VN_SUBRT(enp)!=NULL);
		sprintf(msg_str," %s", SR_NAME(VN_SUBRT(enp)));
		prt_msg_frag(msg_str);
	} else if( code==T_LIT_INT ){
		sprintf(msg_str," %"PRId64, VN_INTVAL(enp) );
		prt_msg_frag(msg_str);
	} else if( code==T_ASSIGN ){
		prt_msg_frag("\t");
	} else if( code==T_MAXVAL ){
		prt_msg_frag("\t");
	} else if( code==T_MINVAL ){
		prt_msg_frag("\t");
	} else if( code==T_RAMP ){
		prt_msg_frag("\t");
	}

	/* Now print the addresses of the child nodes */

	if( VN_CHILD(enp,0)!=NULL){
		sprintf(msg_str,"\t\tn%d",VN_SERIAL(VN_CHILD(enp,0)));
		prt_msg_frag(msg_str);
	}
	for(i=1;i<MAX_CHILDREN(enp);i++){
		if( VN_CHILD(enp,i)!=NULL){
			sprintf(msg_str,", n%d",VN_SERIAL(VN_CHILD(enp,i)));
			prt_msg_frag(msg_str);
		}
	}
	prt_msg("");

	if( SHOWING_SHAPES && VN_SHAPE(enp) != NULL ){
		prt_msg_frag("\t");
		if( OWNS_SHAPE(enp) ){
			sprintf(msg_str,"* 0x%lx  ",(u_long)VN_SHAPE(enp));
			prt_msg_frag(msg_str);
		}
		else {
			sprintf(msg_str,"@ 0x%lx  ",(u_long)VN_SHAPE(enp));
			prt_msg_frag(msg_str);
		}
		prt_msg_frag("\t");
		describe_shape(VN_SHAPE(enp));
	}

	if( SHOWING_RESOLVERS && VN_RESOLVERS(enp)!=NULL ){
		Node *np; Vec_Expr_Node *enp2;
		prt_msg("\tResolvers:");
		np=QLIST_HEAD(VN_RESOLVERS(enp));
		while(np!=NULL){
			enp2=(Vec_Expr_Node *)NODE_DATA(np);
			sprintf(msg_str,"\t\t%s",node_desc(enp2));
			prt_msg(msg_str);
			np=NODE_NEXT(np);
		}
	}
}