void put_actions(FILE* actor_src, node_t* someInstanceNode, node_t* someActionNode, node_t* someEventNode) { char *actionName; int open_brackets = 0; read_immediately_after(actor_src, "// Actions"); while((actionName = read_next_action(actor_src, &open_brackets)) != NULL) { someActionNode = roxml_add_node(someInstanceNode, 0, ROXML_ELM_NODE, "Action", NULL); roxml_add_node(someActionNode, 0, ROXML_ATTR_NODE, "id", actionName); read_upto_end_of_function(actor_src, &open_brackets); someEventNode = roxml_add_node(someActionNode, 0, ROXML_ELM_NODE, "event", NULL); roxml_add_node(someEventNode, 0, ROXML_ATTR_NODE, "id", "PAPI_TOT_INS"); someEventNode = roxml_add_node(someActionNode, 0, ROXML_ELM_NODE, "event", NULL); roxml_add_node(someEventNode, 0, ROXML_ATTR_NODE, "id", "PAPI_L1_DCM"); } }
int xcf_creator(int argc, char *project_path) { FILE* actor_src; int j, k, n,size_of_config, size_of_partitioning, size_of_partition, size_of_papi, len, actor_num, number_of_actions, number_of_events; int num = 0; node_t *configuration, *partitioning, *partition, *instance, *papi, *actor_instance, *action, *event; char *actor_path; char *mapping_file_path; if ((mapping_file_path = findMappingFile(project_path)) == NULL) { printf("Unable to locate a mapping file, make sure you are using the root path to the RVC CAL generated code with the C backend\n"); exit(1); } int actors_num = get_actors_num(mapping_file_path); configuration = roxml_load_doc(mapping_file_path); //a: LIBROXML node http://www.libroxml.net/public-api.html if (configuration == NULL) { printf("I/O error when reading mapping file.\n"); exit(1); } node_t *papi_root_node = roxml_add_node(configuration, 0, ROXML_ELM_NODE, "Papi", NULL); node_t *papi_instance_node, *papi_action_node, *papi_event_node; size_of_config = roxml_get_chld_nb(configuration); //a: This function return the number of children for a given node if(DEBUG)printf("Found %d configuration\n", size_of_config); partitioning = roxml_get_chld(configuration, NULL, 0); //a: This function returns a given child of a node either by name, or the nth child. (node, child name, number of the child to get) size_of_partitioning = roxml_get_chld_nb(partitioning); //a: This function return the number of children for a given node if(DEBUG)printf(" Found %d partitionings\n", size_of_partitioning); for (j = 0; j < size_of_partitioning; j++) { partition = roxml_get_chld(partitioning, NULL, j); if(DEBUG)printf(" Found partition, id = '%s'\n", roxml_get_content(roxml_get_attr(partition, "id", 0), NULL, 0, &len)); size_of_partition = roxml_get_chld_nb(partition); for (k = 0; k < size_of_partition; k++) { instance = roxml_get_chld(partition, NULL, k); if(DEBUG)printf(" Found instance, id = '%s'\n", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len)); papi_instance_node = roxml_add_node(papi_root_node, 0, ROXML_ELM_NODE, "Instance", NULL); roxml_add_node(papi_instance_node, 0, ROXML_ATTR_NODE, "id", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len)); //this goes for every action in the actor: actor_path = malloc(strlen(project_path)+strlen(roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len))+10); strcpy(actor_path,project_path); actor_path = strcat(actor_path,"/src/"); actor_path = strcat(actor_path,roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len)); actor_path = strcat(actor_path,".c"); printf("opening %s\n", actor_path); actor_src = fopen(actor_path,"r"); put_actions(actor_src, papi_instance_node, papi_action_node, papi_event_node); fclose(actor_src); } } char *mapping_file_cpy = malloc(strlen(mapping_file_path)+strlen(".papi.xcf")+1); strcpy(mapping_file_cpy, mapping_file_path); strcat(mapping_file_cpy, ".papi.xcf"); //tmp = roxml_add_node(tmp, 0, ROXML_ELM_NODE, "price", "24"); roxml_commit_changes(configuration, mapping_file_cpy, NULL, 1); //roxml_close(configuration); // release the last allocated buffer even if no pointer is maintained by the user roxml_release(RELEASE_LAST); // here no memory leak can occur. roxml_close(configuration); return 0; }
int XHCPcmd_SETRULE_handle (int sockd, int argc, char **argv, char *data) { node_t *nTmp; node_t **lstNodes; char *newId = NULL; int nb; // A supprimer !!! char *zaza = NULL; printf ("Entree XHCPcmd_SETRULE_handle avec %d arguments\n", argc); int i; for ( i=0; i<argc; i++ ) printf ( "%d - %s\n", i, argv[i]); if ( (nTmp = roxml_load_buf (data)) == NULL ) { XHCP_printXHCPResponse (sockd, RES_SYNTAXERR); // Syntax Error return XHCP_EXE_ERROR; } printf ("Chargement XML OK\n"); if ( argc == 2 ) // pas de node mais id donné en argument newId = strdup(argv[1]); // On recherche si un id est présent if ( (lstNodes = roxml_xpath (nTmp, "//determinator[@guid]", &nb )) != NULL ) { node_t *attr_tmp = roxml_get_attr (lstNodes[0], "guid", 0); if ( newId == NULL && argc == 1 ) { newId = roxml_get_content(attr_tmp, NULL, 0, NULL); } roxml_del_node(attr_tmp); } if ( newId == NULL ) newId = XHCP_getUuid(); printf("a la fin id = %s\n",newId==NULL ? "NULL":newId); lstNodes = roxml_xpath (nTmp, "//determinator", &nb ); if ( nb == 1 ) nTmp = lstNodes[0]; else { printf("Pas trouve //derterminator, nb=%d\n",nb); XHCP_printXHCPResponse (sockd, RES_SYNTAXERR); // Syntax Error return XHCP_EXE_ERROR; } // Ajout d'un nouveau noeud roxml_add_node(nTmp, 0, ROXML_ATTR_NODE, "guid", newId); printf("attribut ajouté\n"); printf("Nouvel arbre determinator\n"); roxml_commit_changes (nTmp, NULL, &zaza, 1); printf("%s\n", zaza); free(zaza); lstNodes = roxml_xpath (rootConfig, "//determinators", &nb ); if ( nb != 1 ) { printf("Pas trouve //determinators, nb=%d\n",nb); XHCP_printXHCPResponse (sockd, RES_INTNERROR); // Internal error return XHCP_EXE_ERROR; } /* On ratache le nouveau determinator à la liste */ roxml_parent_node(lstNodes[0], nTmp); saveHal4lConfig (HAL4L_getConfigFile ()); //roxml_close (nTmp); loadHal4lConfig (HAL4L_getConfigFile ()); free(newId); XHCP_printXHCPResponse (sockd, RES_CFGDOCUPL ); // Configuration document uploaded return XHCP_EXE_SUCCESS; }