From 2722e76f513ba7be80e63f1f49f2095d39759f09 Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Thu, 10 Sep 2015 20:40:15 +0200 Subject: more towards views --- pcilib/xml.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 233 insertions(+), 6 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index 73a3deb..852f319 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -39,12 +39,15 @@ #include "register.h" #include "xml.h" #include "error.h" +#include "views.h" #define BANKS_PATH ((xmlChar*)"/model/banks/bank/bank_description") /**< path to complete nodes of banks.*/ //#define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**< all standard registers nodes.*/ //#define BIT_REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits") /**< all bits registers nodes.*/ #define REGISTERS_PATH ((xmlChar*)"../registers/register") /**< all standard registers nodes.*/ #define BIT_REGISTERS_PATH ((xmlChar*)"./registers_bits/register_bits") /**< all bits registers nodes.*/ +#define VIEWS_PATH ((xmlChar*)"/model/views/view") /**< path to complete nodes of views.*/ + static char *pcilib_xml_bank_default_format = "0x%lx"; @@ -67,7 +70,74 @@ static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr } */ -static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_description_t *xml_desc, xmlDocPtr doc, xmlNodePtr node, pcilib_register_bank_description_t *bdesc) { + +/** + * get the associated views of a register, to fill its register context + */ +static int +pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextPtr xpath,pcilib_register_t id){ + char* VIEWS_NAME_PATH="/model/banks/bank/registers/register[@name=\"%s\"]/views/view"; + char* path; + xmlXPathObjectPtr nodes; + xmlNodeSetPtr nodeset; + char* view_name; + + /*we get first the nodes corresponding to the given register*/ + path=malloc(strlen(VIEWS_NAME_PATH)+strlen(reg_name)); + if(!(path)){ + pcilib_error("can't allocate memory for getting path to get associated views of %s",reg_name); + return PCILIB_ERROR_MEMORY; + } + + sprintf(path,VIEWS_NAME_PATH,reg_name); + nodes = xmlXPathEvalExpression((xmlChar*)path, xpath); + nodeset = nodes->nodesetval; + + if (!xmlXPathNodeSetIsEmpty(nodeset)) { + int i,k,l; + /*if we correctly get a nodeset, then we iterate through the nodeset to get all views, using their names*/ + for (i = 0; i < nodeset->nodeNr; i++) { + view_name=(char*)nodeset->nodeTab[i]->children->content; + + /* if the view name obtained is for an enum view, we get all pcilib_view_enum_t corresponding to the register*/ + for(k=0; ctx->enum_views[k].enums_list[0].value;k++){ + if(!(strcasecmp(view_name, ctx->enum_views[k].name))){ + ctx->register_ctx[id].enums=malloc(sizeof(pcilib_view_enum_t)); + + if(!(ctx->register_ctx[id].enums)){ + pcilib_error("error allocating memory for enum views in register context %i",id); + return PCILIB_ERROR_MEMORY; + } + + for(l=0; ctx->enum_views[k].enums_list[l].value;l++){ + ctx->register_ctx[id].enums=realloc(ctx->register_ctx[id].enums,(l+1)*sizeof(pcilib_view_enum_t)); + ctx->register_ctx[id].enums[l]=ctx->enum_views[k].enums_list[l]; + } + } + } + + /*here it is for formula, i assume we have only one formula view per register*/ + for(k=0; ctx->formula_views[k].name[0];k++){ + if(!(strcasecmp(view_name,ctx->formula_views[k].name))){ + ctx->register_ctx[id].formulas=malloc(sizeof(pcilib_view_formula_t)); + if(!(ctx->register_ctx[id].formulas)){ + pcilib_error("error allocating memory for formula views in register context %i",id); + return PCILIB_ERROR_MEMORY; + } + + ctx->register_ctx[id].formulas=&(ctx->formula_views[k]); + } + } + + } + } + + xmlXPathFreeObject(nodes); + return 0; +} + + +static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_description_t *xml_desc, xmlDocPtr doc, xmlNodePtr node, pcilib_register_bank_description_t *bdesc, int* views_ok) { pcilib_register_description_t *desc = (pcilib_register_description_t*)xml_desc; xmlNodePtr cur; @@ -166,6 +236,9 @@ static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_descript } else if (!strcasecmp(name,"description")) { desc->description = value; } + else if (!strcasecmp(name,"views")) { + *views_ok=1; + } } return 0; @@ -173,6 +246,7 @@ static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_descript static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { int err; + int views_ok=0; xmlXPathObjectPtr nodes; xmlNodeSetPtr nodeset; @@ -187,7 +261,7 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank desc.base.mode = PCILIB_REGISTER_R; desc.base.type = PCILIB_REGISTER_STANDARD; - err = pcilib_xml_parse_register(ctx, &desc, doc, node, &ctx->banks[bank]); + err = pcilib_xml_parse_register(ctx, &desc, doc, node, &ctx->banks[bank],&views_ok); if (err) { pcilib_error("Error (%i) parsing an XML register", err); return err; @@ -202,6 +276,12 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank ctx->register_ctx[reg].xml = node; ctx->register_ctx[reg].min = desc.min; ctx->register_ctx[reg].max = desc.max; + + /* if the register had a node of type views, then we compute its associated registers. I do that here as i need the index for register context*/ + if(views_ok){ + err=pcilib_get_associated_views(ctx,desc.base.name,xpath,reg); + if(err) pcilib_warning("can't get correctly the associated views of the register %s",desc.base.name); + } xpath->node = node; nodes = xmlXPathEvalExpression(BIT_REGISTERS_PATH, xpath); @@ -228,7 +308,7 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank fdesc.base.rwmask = desc.base.rwmask; fdesc.base.type = PCILIB_REGISTER_BITS; - err = pcilib_xml_parse_register(ctx, &fdesc, doc, nodeset->nodeTab[i], &ctx->banks[bank]); + err = pcilib_xml_parse_register(ctx, &fdesc, doc, nodeset->nodeTab[i], &ctx->banks[bank],&views_ok); if (err) { pcilib_error("Error parsing field in the XML register %s", desc.base.name); continue; @@ -243,6 +323,10 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank ctx->register_ctx[reg].xml = nodeset->nodeTab[i]; ctx->register_ctx[reg].min = fdesc.min; ctx->register_ctx[reg].max = fdesc.max; + if(views_ok){ + err=pcilib_get_associated_views(ctx, desc.base.name,xpath,reg); + if(err) pcilib_warning("can't get correctly the associated views of the register %s",fdesc.base.name); + } } } xmlXPathFreeObject(nodes); @@ -397,6 +481,131 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo } +/** + * function that create a view from a view node, and populate ctx views list + */ +static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { + int err; + + pcilib_view_enum2_t complete_enum_desc={0}; + pcilib_view_enum_t enum_desc = {0}; + pcilib_view_formula_t formula_desc= {0}; + xmlNodePtr cur; + char *value, *name; + char *endptr; + xmlAttr *attr; + int i=0; + + /*must i initialize? i think it's only needed if we want to include a description property*/ + enum_desc.name="default"; + enum_desc.value=0; + enum_desc.min=0; + enum_desc.max=0; + + complete_enum_desc.name="default enum"; + complete_enum_desc.enums_list=malloc(sizeof(pcilib_view_enum_t)); + if(!(complete_enum_desc.enums_list)){ + pcilib_error("can't allocate memory for the complete enum type"); + return PCILIB_ERROR_MEMORY; + } + complete_enum_desc.enums_list[0]=enum_desc; + + formula_desc.name="formula_default"; + formula_desc.read_formula="@reg"; + formula_desc.write_formula="@reg"; + + /* we get the attribute type of the view node*/ + attr=node->properties; + value=(char*)attr->children->content; + /* regarding the architecture, i decided to follow what has been done for registers and banks. but without the context*/ + /*if the view is of type enum, we get recursively its properties and then populate ctx enum views*/ + if(!(strcasecmp(value,"enum"))){ + for (cur = node->children; cur != NULL; cur = cur->next) { + if (!cur->children) continue; + if (!xmlNodeIsText(cur->children)) continue; + + name = (char*)cur->name; + value = (char*)cur->children->content; + if (!value) continue; + + if (!(strcasecmp((char*)name,"name"))) { + complete_enum_desc.name = value; + }else if (!(strcasecmp((char*)name,"enum"))) { + + complete_enum_desc.enums_list=realloc(complete_enum_desc.enums_list,(i+1)*sizeof(pcilib_view_enum_t)); + complete_enum_desc.enums_list[i].name=value; + + /* we need to iterate through the different attributes of an enum node to get all properties*/ + for(attr=cur->properties; attr!=NULL;attr=attr->next){ + if(!attr->children) continue; + if(!xmlNodeIsText(attr->children)) continue; + + name=(char*)attr->name; + value=(char*)attr->children->content; + + if(!(strcasecmp(name,"value"))){ + pcilib_register_value_t dat_value = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid value (%s) is specified in the XML enum node", value); + return PCILIB_ERROR_INVALID_DATA; + } + complete_enum_desc.enums_list[i].value=dat_value; + }else if(!(strcasecmp(name,"min"))){ + pcilib_register_value_t dat_min = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid min (%s) is specified in the XML enum node", value); + return PCILIB_ERROR_INVALID_DATA; + } + complete_enum_desc.enums_list[i].min=dat_min; + }else if(!(strcasecmp(name,"max"))){ + pcilib_register_value_t dat_max = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid max (%s) is specified in the XML enum node", value); + return PCILIB_ERROR_INVALID_DATA; + } + + complete_enum_desc.enums_list[i].max=dat_max; + } + } + i++; + } + } + err=pcilib_add_views_enum(ctx,1,&complete_enum_desc); + if (err) { + pcilib_error("Error (%i) adding a new enum view (%s) to the pcilib_t", err, complete_enum_desc.name); + return err; + } + + /* we do the same here but for a iew of type formula if the attribute gives formula*/ + }else if(!(strcasecmp(value,"formula"))){ + for (cur = node->children; cur != NULL; cur = cur->next) { + if (!cur->children) continue; + if (!xmlNodeIsText(cur->children)) continue; + + name = (char*)cur->name; + value = (char*)cur->children->content; + if (!value) continue; + + if (!(strcasecmp((char*)name,"name"))) { + formula_desc.name = value; + }else if (!(strcasecmp((char*)name,"read_from_register"))) { + formula_desc.read_formula=value; + }else if (!(strcasecmp((char*)name,"write_to_register"))) { + formula_desc.write_formula=value; + } + } + err=pcilib_add_views_formula(ctx,1,&formula_desc); + if (err) { + pcilib_error("Error (%i) adding a new formula view (%s) to the pcilib_t", err, formula_desc.name); + return err; + } + + } + + return 0; +} + + /** pcilib_xml_initialize_banks * * function to create the structures to store the banks from the AST @@ -405,12 +614,14 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo * @param[in] pci the pcilib_t running, which will be filled */ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) { - xmlXPathObjectPtr bank_nodes; + xmlXPathObjectPtr bank_nodes,views_nodes; xmlNodeSetPtr nodeset; + int i; + xmlErrorPtr xmlerr; bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath); if (!bank_nodes) { - xmlErrorPtr xmlerr = xmlGetLastError(); + xmlerr = xmlGetLastError(); if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message); else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH); return PCILIB_ERROR_FAILED; @@ -419,13 +630,29 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon nodeset = bank_nodes->nodesetval; if (!xmlXPathNodeSetIsEmpty(nodeset)) { - int i; for (i = 0; i < nodeset->nodeNr; i++) { pcilib_xml_create_bank(ctx, xpath, doc, nodeset->nodeTab[i]); } } xmlXPathFreeObject(bank_nodes); + + views_nodes=xmlXPathEvalExpression(VIEWS_PATH,xpath); + if(!views_nodes){ + xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message); + else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH); + return PCILIB_ERROR_FAILED; + } + + nodeset=views_nodes->nodesetval; + if(!xmlXPathNodeSetIsEmpty(nodeset)){ + for(i=0;i < nodeset->nodeNr; i++){ + pcilib_xml_create_view(ctx,xpath,doc,nodeset->nodeTab[i]); + } + } + xmlXPathFreeObject(views_nodes); + return 0; } -- cgit v1.2.3 From 60c6bf9f6916b6ae2c05a499675ff54480256ece Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Fri, 11 Sep 2015 19:40:33 +0200 Subject: more towards views --- pcilib/xml.c | 80 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 31 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index 852f319..ace38a6 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -75,32 +75,36 @@ static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr * get the associated views of a register, to fill its register context */ static int -pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextPtr xpath,pcilib_register_t id){ - char* VIEWS_NAME_PATH="/model/banks/bank/registers/register[@name=\"%s\"]/views/view"; +pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextPtr xpath,pcilib_register_t id,int mode){ + + /* i find this solution pretty elegant, but what about perf?*/ + char* VIEWS_NAME_PATH_BITS="/model/banks/bank/registers/register[./name=\"%s\"]/registers_bits/register_bits/views/view"; + char* VIEWS_NAME_PATH="/model/banks/bank/registers/register[./name=\"%s\"]/views/view"; char* path; xmlXPathObjectPtr nodes; xmlNodeSetPtr nodeset; char* view_name; /*we get first the nodes corresponding to the given register*/ - path=malloc(strlen(VIEWS_NAME_PATH)+strlen(reg_name)); + if(mode==1) path=malloc(strlen(VIEWS_NAME_PATH)+strlen(reg_name)); + else path=malloc(strlen(VIEWS_NAME_PATH_BITS)+strlen(reg_name)); if(!(path)){ pcilib_error("can't allocate memory for getting path to get associated views of %s",reg_name); return PCILIB_ERROR_MEMORY; } - sprintf(path,VIEWS_NAME_PATH,reg_name); + if(mode==1) sprintf(path,VIEWS_NAME_PATH,reg_name); + else sprintf(path,VIEWS_NAME_PATH_BITS,reg_name); nodes = xmlXPathEvalExpression((xmlChar*)path, xpath); nodeset = nodes->nodesetval; - if (!xmlXPathNodeSetIsEmpty(nodeset)) { int i,k,l; /*if we correctly get a nodeset, then we iterate through the nodeset to get all views, using their names*/ for (i = 0; i < nodeset->nodeNr; i++) { view_name=(char*)nodeset->nodeTab[i]->children->content; - + /* if the view name obtained is for an enum view, we get all pcilib_view_enum_t corresponding to the register*/ - for(k=0; ctx->enum_views[k].enums_list[0].value;k++){ + for(k=0; ctx->enum_views[k].enums_list[0].value; k++){ if(!(strcasecmp(view_name, ctx->enum_views[k].name))){ ctx->register_ctx[id].enums=malloc(sizeof(pcilib_view_enum_t)); @@ -109,29 +113,34 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP return PCILIB_ERROR_MEMORY; } + /*!!!!!!!!!!this loop here is buggy*/ for(l=0; ctx->enum_views[k].enums_list[l].value;l++){ ctx->register_ctx[id].enums=realloc(ctx->register_ctx[id].enums,(l+1)*sizeof(pcilib_view_enum_t)); ctx->register_ctx[id].enums[l]=ctx->enum_views[k].enums_list[l]; + // printf("names %s %s\n",ctx->register_ctx[id].enums[l].name,ctx->enum_views[k].enums_list[l].name); } + return 0; } } /*here it is for formula, i assume we have only one formula view per register*/ for(k=0; ctx->formula_views[k].name[0];k++){ if(!(strcasecmp(view_name,ctx->formula_views[k].name))){ + ctx->register_ctx[id].formulas=malloc(sizeof(pcilib_view_formula_t)); if(!(ctx->register_ctx[id].formulas)){ pcilib_error("error allocating memory for formula views in register context %i",id); return PCILIB_ERROR_MEMORY; } - ctx->register_ctx[id].formulas=&(ctx->formula_views[k]); + ctx->register_ctx[id].formulas[0]=ctx->formula_views[k]; + break; } } } } - + xmlXPathFreeObject(nodes); return 0; } @@ -247,7 +256,8 @@ static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_descript static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { int err; int views_ok=0; - + int h; + xmlXPathObjectPtr nodes; xmlNodeSetPtr nodeset; @@ -255,7 +265,7 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank pcilib_xml_register_description_t fdesc; pcilib_register_t reg; - + desc.base.bank = ctx->banks[bank].addr; desc.base.rwmask = PCILIB_REGISTER_ALL_BITS; desc.base.mode = PCILIB_REGISTER_R; @@ -279,7 +289,7 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank /* if the register had a node of type views, then we compute its associated registers. I do that here as i need the index for register context*/ if(views_ok){ - err=pcilib_get_associated_views(ctx,desc.base.name,xpath,reg); + err=pcilib_get_associated_views(ctx,desc.base.name,xpath,reg,1); if(err) pcilib_warning("can't get correctly the associated views of the register %s",desc.base.name); } @@ -324,7 +334,7 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank ctx->register_ctx[reg].min = fdesc.min; ctx->register_ctx[reg].max = fdesc.max; if(views_ok){ - err=pcilib_get_associated_views(ctx, desc.base.name,xpath,reg); + err=pcilib_get_associated_views(ctx, desc.base.name,xpath,reg,0); if(err) pcilib_warning("can't get correctly the associated views of the register %s",fdesc.base.name); } } @@ -503,6 +513,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo enum_desc.max=0; complete_enum_desc.name="default enum"; + complete_enum_desc.description="default description"; complete_enum_desc.enums_list=malloc(sizeof(pcilib_view_enum_t)); if(!(complete_enum_desc.enums_list)){ pcilib_error("can't allocate memory for the complete enum type"); @@ -513,6 +524,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo formula_desc.name="formula_default"; formula_desc.read_formula="@reg"; formula_desc.write_formula="@reg"; + formula_desc.description="default description"; /* we get the attribute type of the view node*/ attr=node->properties; @@ -530,6 +542,10 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo if (!(strcasecmp((char*)name,"name"))) { complete_enum_desc.name = value; + + }else if (!(strcasecmp((char*)name,"description"))) { + complete_enum_desc.description = value; + }else if (!(strcasecmp((char*)name,"enum"))) { complete_enum_desc.enums_list=realloc(complete_enum_desc.enums_list,(i+1)*sizeof(pcilib_view_enum_t)); @@ -567,7 +583,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo complete_enum_desc.enums_list[i].max=dat_max; } } - i++; + i++; } } err=pcilib_add_views_enum(ctx,1,&complete_enum_desc); @@ -584,6 +600,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo name = (char*)cur->name; value = (char*)cur->children->content; + if (!value) continue; if (!(strcasecmp((char*)name,"name"))) { @@ -592,6 +609,8 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo formula_desc.read_formula=value; }else if (!(strcasecmp((char*)name,"write_to_register"))) { formula_desc.write_formula=value; + }else if (!(strcasecmp((char*)name,"description"))) { + formula_desc.description=value; } } err=pcilib_add_views_formula(ctx,1,&formula_desc); @@ -619,6 +638,22 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon int i; xmlErrorPtr xmlerr; + views_nodes=xmlXPathEvalExpression(VIEWS_PATH,xpath); + if(!views_nodes){ + xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message); + else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH); + return PCILIB_ERROR_FAILED; + } + + nodeset=views_nodes->nodesetval; + if(!xmlXPathNodeSetIsEmpty(nodeset)){ + for(i=0;i < nodeset->nodeNr; i++){ + pcilib_xml_create_view(ctx,xpath,doc,nodeset->nodeTab[i]); + } + } + xmlXPathFreeObject(views_nodes); + bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath); if (!bank_nodes) { xmlerr = xmlGetLastError(); @@ -636,23 +671,6 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon } xmlXPathFreeObject(bank_nodes); - - views_nodes=xmlXPathEvalExpression(VIEWS_PATH,xpath); - if(!views_nodes){ - xmlerr = xmlGetLastError(); - if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message); - else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH); - return PCILIB_ERROR_FAILED; - } - - nodeset=views_nodes->nodesetval; - if(!xmlXPathNodeSetIsEmpty(nodeset)){ - for(i=0;i < nodeset->nodeNr; i++){ - pcilib_xml_create_view(ctx,xpath,doc,nodeset->nodeTab[i]); - } - } - xmlXPathFreeObject(views_nodes); - return 0; } -- cgit v1.2.3 From 2dfb23016c39a331bf5ed4111b630dffa330edbb Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 11:56:38 +0200 Subject: views working fine, units in progress --- pcilib/xml.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index ace38a6..fb9128f 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -70,7 +70,24 @@ static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr } */ - +/** + * get the associated units of a view + * this function is maybe completekly useless : we need to decide if we iterate directly in ctx or n view when we want to apply a unit. (in the second choice of course keep it). +* +static void +pcilib_get_associated_units(pcilib_t* ctx, pcilib_view_formula_t* myview){ + int i,j,k=2; + for(i=0;myview->units[0].other_units.name[0];i++){ + for(j=0;ctx->units[j].name[0];i++){ + if(!(strcasecmp(myview->units[0].other_units.name,ctx->units[i].name))){ + myview.units=realloc(myview.units,k*sizeof(pcilib_unit_t)); + myview.units[k-1]=ctx->units[i]; + k++; + } + } + } + }*/ + /** * get the associated views of a register, to fill its register context */ @@ -490,7 +507,52 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return 0; } +/*static int pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { + int err; + + int override = 0; + pcilib_unit_t desc = {0}; + xmlNodePtr cur; + char *value, *name, *value2; + char *endptr; + xmlXPathObjectPtr nodes; + xmlNodeSetPtr nodeset; + xmlAttr *attr; + int i=0; + + /* we get the attribute type of the view node* + attr=node->properties; + value=(char*)attr->children->content; + desc.name=value; + desc.other_units=malloc(sizeof(pcilib_transform_unit_t)); + + for (cur = node->children; cur != NULL; cur = cur->next) { + if (!cur->children) continue; + if (!xmlNodeIsText(cur->children)) continue; + + name = (char*)cur->name; + value = (char*)cur->children->content; + attr= cur->properties; + value2=(char*)attr->children->content; + if (!value || !attr) continue; + + if (!strcasecmp(name, "convert_unit")) { + desc.other_units=realloc(des.other_units,sizeof((i+1)*sizeof(pcilib_transform_unit_t))); + desc.other_units[i].name=value2; + desc.other_units[i].transform_formula=value; + } + } + + err = pcilib_add_units(ctx, 1, &desc); + if (err) { + pcilib_error("Error adding unit (%s) specified in the XML", desc.name); + return err; + } + + return 0; +} +*/ /** * function that create a view from a view node, and populate ctx views list */ @@ -505,6 +567,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo char *endptr; xmlAttr *attr; int i=0; + int ok_min=0, ok_max=0; /*must i initialize? i think it's only needed if we want to include a description property*/ enum_desc.name="default"; @@ -573,15 +636,19 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return PCILIB_ERROR_INVALID_DATA; } complete_enum_desc.enums_list[i].min=dat_min; + ok_min=1; }else if(!(strcasecmp(name,"max"))){ pcilib_register_value_t dat_max = strtol(value, &endptr, 0); if ((strlen(endptr) > 0)) { pcilib_error("Invalid max (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - complete_enum_desc.enums_list[i].max=dat_max; + ok_max=1; } + if(ok_min==0) complete_enum_desc.enums_list[i].min=complete_enum_desc.enums_list[i].value; + if(ok_max==0) complete_enum_desc.enums_list[i].max=complete_enum_desc.enums_list[i].value; + } i++; } -- cgit v1.2.3 From a1bf5e300e2345b642d0a13e7e26d22c56156e47 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 15:49:46 +0200 Subject: views with units functionnal (beware, as formulas are completely crap now, we could get segfault, for example if we want to write a negative value in register) --- pcilib/xml.c | 97 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 33 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index fb9128f..dbe6ac7 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -47,6 +47,7 @@ #define REGISTERS_PATH ((xmlChar*)"../registers/register") /**< all standard registers nodes.*/ #define BIT_REGISTERS_PATH ((xmlChar*)"./registers_bits/register_bits") /**< all bits registers nodes.*/ #define VIEWS_PATH ((xmlChar*)"/model/views/view") /**< path to complete nodes of views.*/ +#define UNITS_PATH ((xmlChar*)"/model/units/unit") /**< path to complete nodes of units.*/ static char *pcilib_xml_bank_default_format = "0x%lx"; @@ -71,22 +72,21 @@ static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr */ /** - * get the associated units of a view + * get the associated unit of a view * this function is maybe completekly useless : we need to decide if we iterate directly in ctx or n view when we want to apply a unit. (in the second choice of course keep it). -* + */ static void -pcilib_get_associated_units(pcilib_t* ctx, pcilib_view_formula_t* myview){ - int i,j,k=2; - for(i=0;myview->units[0].other_units.name[0];i++){ - for(j=0;ctx->units[j].name[0];i++){ - if(!(strcasecmp(myview->units[0].other_units.name,ctx->units[i].name))){ - myview.units=realloc(myview.units,k*sizeof(pcilib_unit_t)); - myview.units[k-1]=ctx->units[i]; - k++; - } - } +pcilib_get_unit_of_view(pcilib_t* ctx,pcilib_view_formula_t* myview, char* base_unit){ + int j; + + for(j=0;ctx->units[j].name;j++){ + if(!(strcasecmp(base_unit,ctx->units[j].name))){ + myview->base_unit=ctx->units[j]; + break; + } } - }*/ + +} /** * get the associated views of a register, to fill its register context @@ -141,7 +141,7 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP } /*here it is for formula, i assume we have only one formula view per register*/ - for(k=0; ctx->formula_views[k].name[0];k++){ + for(k=0; ctx->formula_views[k].name;k++){ if(!(strcasecmp(view_name,ctx->formula_views[k].name))){ ctx->register_ctx[id].formulas=malloc(sizeof(pcilib_view_formula_t)); @@ -149,7 +149,7 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP pcilib_error("error allocating memory for formula views in register context %i",id); return PCILIB_ERROR_MEMORY; } - + pcilib_get_unit_of_view(ctx,&(ctx->formula_views[k]),ctx->formula_views[k].base_unit.name); ctx->register_ctx[id].formulas[0]=ctx->formula_views[k]; break; } @@ -273,8 +273,6 @@ static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_descript static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { int err; int views_ok=0; - int h; - xmlXPathObjectPtr nodes; xmlNodeSetPtr nodeset; @@ -507,28 +505,33 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return 0; } -/*static int pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { +/** + * function to create a unit from a unit xml node, then populating ctx with it + *@param[in,out] ctx - the pcilib_t running + *@param[in] xpath - the xpath context of the unis xml file + *@param[in] doc - the AST of the unit xml file + *@param[in] node - the node representing the unit + *@return an error code: 0 if evrythinh is ok + */ +static int +pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { int err; - int override = 0; pcilib_unit_t desc = {0}; xmlNodePtr cur; char *value, *name, *value2; - char *endptr; - xmlXPathObjectPtr nodes; - xmlNodeSetPtr nodeset; xmlAttr *attr; int i=0; - /* we get the attribute type of the view node* + /* we get the attribute type of the view node*/ attr=node->properties; value=(char*)attr->children->content; desc.name=value; desc.other_units=malloc(sizeof(pcilib_transform_unit_t)); for (cur = node->children; cur != NULL; cur = cur->next) { - if (!cur->children) continue; + if (!cur->children) continue; if (!xmlNodeIsText(cur->children)) continue; name = (char*)cur->name; @@ -536,11 +539,12 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo attr= cur->properties; value2=(char*)attr->children->content; if (!value || !attr) continue; - + if (!strcasecmp(name, "convert_unit")) { - desc.other_units=realloc(des.other_units,sizeof((i+1)*sizeof(pcilib_transform_unit_t))); + desc.other_units=realloc(desc.other_units,(i+1)*sizeof(pcilib_transform_unit_t)); desc.other_units[i].name=value2; desc.other_units[i].transform_formula=value; + i++; } } @@ -552,7 +556,7 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return 0; } -*/ + /** * function that create a view from a view node, and populate ctx views list */ @@ -678,8 +682,11 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo formula_desc.write_formula=value; }else if (!(strcasecmp((char*)name,"description"))) { formula_desc.description=value; + }else if (!(strcasecmp((char*)name,"unit"))){ + formula_desc.base_unit.name=value; } } + err=pcilib_add_views_formula(ctx,1,&formula_desc); if (err) { pcilib_error("Error (%i) adding a new formula view (%s) to the pcilib_t", err, formula_desc.name); @@ -700,17 +707,28 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo * @param[in] pci the pcilib_t running, which will be filled */ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) { - xmlXPathObjectPtr bank_nodes,views_nodes; + xmlXPathObjectPtr bank_nodes,views_nodes, units_nodes; xmlNodeSetPtr nodeset; int i; xmlErrorPtr xmlerr; + + units_nodes=xmlXPathEvalExpression(UNITS_PATH,xpath); + if(!units_nodes){ + goto views; + } + + nodeset=units_nodes->nodesetval; + if(!xmlXPathNodeSetIsEmpty(nodeset)){ + for(i=0;i < nodeset->nodeNr; i++){ + pcilib_xml_create_unit(ctx,xpath,doc,nodeset->nodeTab[i]); + } + } + xmlXPathFreeObject(units_nodes); + views: views_nodes=xmlXPathEvalExpression(VIEWS_PATH,xpath); if(!views_nodes){ - xmlerr = xmlGetLastError(); - if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message); - else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH); - return PCILIB_ERROR_FAILED; + goto banks; } nodeset=views_nodes->nodesetval; @@ -720,7 +738,7 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon } } xmlXPathFreeObject(views_nodes); - + banks: bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath); if (!bank_nodes) { xmlerr = xmlGetLastError(); @@ -850,6 +868,8 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { struct dirent *file = NULL; char *model_dir, *model_path; + int i; + model_dir = getenv("PCILIB_MODEL_DIR"); if (!model_dir) model_dir = PCILIB_MODEL_DIR; @@ -870,6 +890,17 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { if (err) pcilib_error("Error processing XML file %s", file->d_name); } + for(i=0;inum_formula_views;i++){ + pcilib_get_unit_of_view(ctx,&(ctx->formula_views[i]),ctx->formula_views[i].base_unit.name); + } + + for(i=0;inum_reg;i++){ + if(ctx->register_ctx[i].formulas){ + pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].formulas[0]),ctx->register_ctx[i].formulas[0].base_unit.name); + } + } + + closedir(rep); return 0; -- cgit v1.2.3 From 6a8b4a516689daa34951ccca841c2a4f57412b0e Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 09:34:52 +0200 Subject: first compil ok with addition of generic views --- pcilib/xml.c | 140 ++++++++++++++++++++++------------------------------------- 1 file changed, 53 insertions(+), 87 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index dbe6ac7..fe25cf7 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -76,16 +76,16 @@ static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr * this function is maybe completekly useless : we need to decide if we iterate directly in ctx or n view when we want to apply a unit. (in the second choice of course keep it). */ static void -pcilib_get_unit_of_view(pcilib_t* ctx,pcilib_view_formula_t* myview, char* base_unit){ +pcilib_get_unit_of_view(pcilib_t* ctx,pcilib_view_t* myview, char* base_unit){ int j; - - for(j=0;ctx->units[j].name;j++){ - if(!(strcasecmp(base_unit,ctx->units[j].name))){ - myview->base_unit=ctx->units[j]; - break; + if((strcasecmp(base_unit,"name"))){ + for(j=0;ctx->units[j].name;j++){ + if(!(strcasecmp(base_unit,ctx->units[j].name))){ + myview->base_unit=ctx->units[j]; + break; + } + } } - } - } /** @@ -114,44 +114,23 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP else sprintf(path,VIEWS_NAME_PATH_BITS,reg_name); nodes = xmlXPathEvalExpression((xmlChar*)path, xpath); nodeset = nodes->nodesetval; + ctx->register_ctx[id].views=malloc(sizeof(pcilib_view_t)); + if(!(ctx->register_ctx[id].views)){ + pcilib_error("error allocating memory for enum views in register context %i",id); + return PCILIB_ERROR_MEMORY; + } + if (!xmlXPathNodeSetIsEmpty(nodeset)) { - int i,k,l; + int i,k; /*if we correctly get a nodeset, then we iterate through the nodeset to get all views, using their names*/ for (i = 0; i < nodeset->nodeNr; i++) { view_name=(char*)nodeset->nodeTab[i]->children->content; /* if the view name obtained is for an enum view, we get all pcilib_view_enum_t corresponding to the register*/ - for(k=0; ctx->enum_views[k].enums_list[0].value; k++){ - if(!(strcasecmp(view_name, ctx->enum_views[k].name))){ - ctx->register_ctx[id].enums=malloc(sizeof(pcilib_view_enum_t)); - - if(!(ctx->register_ctx[id].enums)){ - pcilib_error("error allocating memory for enum views in register context %i",id); - return PCILIB_ERROR_MEMORY; - } - - /*!!!!!!!!!!this loop here is buggy*/ - for(l=0; ctx->enum_views[k].enums_list[l].value;l++){ - ctx->register_ctx[id].enums=realloc(ctx->register_ctx[id].enums,(l+1)*sizeof(pcilib_view_enum_t)); - ctx->register_ctx[id].enums[l]=ctx->enum_views[k].enums_list[l]; - // printf("names %s %s\n",ctx->register_ctx[id].enums[l].name,ctx->enum_views[k].enums_list[l].name); - } - return 0; - } - } - - /*here it is for formula, i assume we have only one formula view per register*/ - for(k=0; ctx->formula_views[k].name;k++){ - if(!(strcasecmp(view_name,ctx->formula_views[k].name))){ - - ctx->register_ctx[id].formulas=malloc(sizeof(pcilib_view_formula_t)); - if(!(ctx->register_ctx[id].formulas)){ - pcilib_error("error allocating memory for formula views in register context %i",id); - return PCILIB_ERROR_MEMORY; - } - pcilib_get_unit_of_view(ctx,&(ctx->formula_views[k]),ctx->formula_views[k].base_unit.name); - ctx->register_ctx[id].formulas[0]=ctx->formula_views[k]; - break; + for(k=0; ctx->views[k].name; k++){ + if(!(strcasecmp(view_name, ctx->views[k].name))){ + ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(k+1)*sizeof(pcilib_view_enum_t)); + ctx->register_ctx[id].views[k]=ctx->views[k]; } } @@ -563,9 +542,7 @@ pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, x static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { int err; - pcilib_view_enum2_t complete_enum_desc={0}; - pcilib_view_enum_t enum_desc = {0}; - pcilib_view_formula_t formula_desc= {0}; + pcilib_view_t desc={0}; xmlNodePtr cur; char *value, *name; char *endptr; @@ -573,32 +550,17 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo int i=0; int ok_min=0, ok_max=0; - /*must i initialize? i think it's only needed if we want to include a description property*/ - enum_desc.name="default"; - enum_desc.value=0; - enum_desc.min=0; - enum_desc.max=0; - - complete_enum_desc.name="default enum"; - complete_enum_desc.description="default description"; - complete_enum_desc.enums_list=malloc(sizeof(pcilib_view_enum_t)); - if(!(complete_enum_desc.enums_list)){ - pcilib_error("can't allocate memory for the complete enum type"); - return PCILIB_ERROR_MEMORY; - } - complete_enum_desc.enums_list[0]=enum_desc; - - formula_desc.name="formula_default"; - formula_desc.read_formula="@reg"; - formula_desc.write_formula="@reg"; - formula_desc.description="default description"; - + desc.description="default description"; + /* we get the attribute type of the view node*/ attr=node->properties; value=(char*)attr->children->content; /* regarding the architecture, i decided to follow what has been done for registers and banks. but without the context*/ /*if the view is of type enum, we get recursively its properties and then populate ctx enum views*/ if(!(strcasecmp(value,"enum"))){ + desc.op=&operation_enum; + desc.parameters=malloc(sizeof(pcilib_view_enum_t)); + desc.base_unit.name="name"; for (cur = node->children; cur != NULL; cur = cur->next) { if (!cur->children) continue; if (!xmlNodeIsText(cur->children)) continue; @@ -608,15 +570,15 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo if (!value) continue; if (!(strcasecmp((char*)name,"name"))) { - complete_enum_desc.name = value; + desc.name = value; }else if (!(strcasecmp((char*)name,"description"))) { - complete_enum_desc.description = value; + desc.description = value; }else if (!(strcasecmp((char*)name,"enum"))) { - complete_enum_desc.enums_list=realloc(complete_enum_desc.enums_list,(i+1)*sizeof(pcilib_view_enum_t)); - complete_enum_desc.enums_list[i].name=value; + desc.parameters=realloc(desc.parameters,(i+1)*sizeof(pcilib_view_enum_t)); + ((pcilib_view_enum_t*)(desc.parameters))[i].name=value; /* we need to iterate through the different attributes of an enum node to get all properties*/ for(attr=cur->properties; attr!=NULL;attr=attr->next){ @@ -632,14 +594,14 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo pcilib_error("Invalid value (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - complete_enum_desc.enums_list[i].value=dat_value; + ((pcilib_view_enum_t*)(desc.parameters))[i].value=dat_value; }else if(!(strcasecmp(name,"min"))){ pcilib_register_value_t dat_min = strtol(value, &endptr, 0); if ((strlen(endptr) > 0)) { pcilib_error("Invalid min (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - complete_enum_desc.enums_list[i].min=dat_min; + ((pcilib_view_enum_t*)(desc.parameters))[i].min=dat_min; ok_min=1; }else if(!(strcasecmp(name,"max"))){ pcilib_register_value_t dat_max = strtol(value, &endptr, 0); @@ -647,24 +609,26 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo pcilib_error("Invalid max (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - complete_enum_desc.enums_list[i].max=dat_max; + ((pcilib_view_enum_t*)(desc.parameters))[i].max=dat_max; ok_max=1; } - if(ok_min==0) complete_enum_desc.enums_list[i].min=complete_enum_desc.enums_list[i].value; - if(ok_max==0) complete_enum_desc.enums_list[i].max=complete_enum_desc.enums_list[i].value; + if(ok_min==0) ((pcilib_view_enum_t*)(desc.parameters))[i].min=((pcilib_view_enum_t*)(desc.parameters))[i].value; + if(ok_max==0) ((pcilib_view_enum_t*)(desc.parameters))[i].max=((pcilib_view_enum_t*)(desc.parameters))[i].value; } i++; } } - err=pcilib_add_views_enum(ctx,1,&complete_enum_desc); + err=pcilib_add_views(ctx,1,&desc); if (err) { - pcilib_error("Error (%i) adding a new enum view (%s) to the pcilib_t", err, complete_enum_desc.name); + pcilib_error("Error (%i) adding a new enum view (%s) to the pcilib_t", err, desc.name); return err; } /* we do the same here but for a iew of type formula if the attribute gives formula*/ }else if(!(strcasecmp(value,"formula"))){ + desc.op=&operation_formula; + desc.parameters=malloc(sizeof(pcilib_formula_t)); for (cur = node->children; cur != NULL; cur = cur->next) { if (!cur->children) continue; if (!xmlNodeIsText(cur->children)) continue; @@ -675,21 +639,21 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo if (!value) continue; if (!(strcasecmp((char*)name,"name"))) { - formula_desc.name = value; + desc.name = value; }else if (!(strcasecmp((char*)name,"read_from_register"))) { - formula_desc.read_formula=value; + ((pcilib_formula_t*)(desc.parameters))->read_formula=value; }else if (!(strcasecmp((char*)name,"write_to_register"))) { - formula_desc.write_formula=value; + ((pcilib_formula_t*)(desc.parameters))->write_formula=value; }else if (!(strcasecmp((char*)name,"description"))) { - formula_desc.description=value; + desc.description=value; }else if (!(strcasecmp((char*)name,"unit"))){ - formula_desc.base_unit.name=value; + desc.base_unit.name=value; } } - err=pcilib_add_views_formula(ctx,1,&formula_desc); + err=pcilib_add_views(ctx,1,&desc); if (err) { - pcilib_error("Error (%i) adding a new formula view (%s) to the pcilib_t", err, formula_desc.name); + pcilib_error("Error (%i) adding a new formula view (%s) to the pcilib_t", err, desc.name); return err; } @@ -868,7 +832,7 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { struct dirent *file = NULL; char *model_dir, *model_path; - int i; + int i,j; model_dir = getenv("PCILIB_MODEL_DIR"); if (!model_dir) model_dir = PCILIB_MODEL_DIR; @@ -890,16 +854,18 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { if (err) pcilib_error("Error processing XML file %s", file->d_name); } - for(i=0;inum_formula_views;i++){ - pcilib_get_unit_of_view(ctx,&(ctx->formula_views[i]),ctx->formula_views[i].base_unit.name); + for(i=0;inum_views;i++){ + pcilib_get_unit_of_view(ctx,&(ctx->views[i]),ctx->views[i].base_unit.name); } for(i=0;inum_reg;i++){ - if(ctx->register_ctx[i].formulas){ - pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].formulas[0]),ctx->register_ctx[i].formulas[0].base_unit.name); + for(j=0;jnum_views;j++){ + if(!(ctx->register_ctx[i].views[j].name)) break; + if(ctx->register_ctx[i].views){ + pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].views[j]),ctx->register_ctx[i].views[j].base_unit.name); + } } } - closedir(rep); -- cgit v1.2.3 From c71075ca84d896c650dd0b65c7664149ed51dcec Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 11:36:20 +0200 Subject: addition of other remarks, cleaning in progress --- pcilib/xml.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index fe25cf7..5be5abd 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -138,6 +138,7 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP } xmlXPathFreeObject(nodes); + free(path); return 0; } @@ -507,7 +508,6 @@ pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, x attr=node->properties; value=(char*)attr->children->content; desc.name=value; - desc.other_units=malloc(sizeof(pcilib_transform_unit_t)); for (cur = node->children; cur != NULL; cur = cur->next) { if (!cur->children) continue; @@ -520,7 +520,6 @@ pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, x if (!value || !attr) continue; if (!strcasecmp(name, "convert_unit")) { - desc.other_units=realloc(desc.other_units,(i+1)*sizeof(pcilib_transform_unit_t)); desc.other_units[i].name=value2; desc.other_units[i].transform_formula=value; i++; -- cgit v1.2.3 From 33db9c07bd08fae74c145c547f1b0e9f55ab25ae Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 12:07:04 +0200 Subject: merge views and units, some name homogeneisation --- pcilib/xml.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index 5be5abd..ebef91e 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -126,10 +126,10 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP for (i = 0; i < nodeset->nodeNr; i++) { view_name=(char*)nodeset->nodeTab[i]->children->content; - /* if the view name obtained is for an enum view, we get all pcilib_view_enum_t corresponding to the register*/ + /* if the view name obtained is for an enum view, we get all pcilib_enum_t corresponding to the register*/ for(k=0; ctx->views[k].name; k++){ if(!(strcasecmp(view_name, ctx->views[k].name))){ - ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(k+1)*sizeof(pcilib_view_enum_t)); + ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(k+1)*sizeof(pcilib_enum_t)); ctx->register_ctx[id].views[k]=ctx->views[k]; } } @@ -520,8 +520,8 @@ pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, x if (!value || !attr) continue; if (!strcasecmp(name, "convert_unit")) { - desc.other_units[i].name=value2; - desc.other_units[i].transform_formula=value; + desc.transforms[i].name=value2; + desc.transforms[i].transform_formula=value; i++; } } @@ -558,7 +558,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo /*if the view is of type enum, we get recursively its properties and then populate ctx enum views*/ if(!(strcasecmp(value,"enum"))){ desc.op=&operation_enum; - desc.parameters=malloc(sizeof(pcilib_view_enum_t)); + desc.parameters=malloc(sizeof(pcilib_enum_t)); desc.base_unit.name="name"; for (cur = node->children; cur != NULL; cur = cur->next) { if (!cur->children) continue; @@ -576,8 +576,8 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo }else if (!(strcasecmp((char*)name,"enum"))) { - desc.parameters=realloc(desc.parameters,(i+1)*sizeof(pcilib_view_enum_t)); - ((pcilib_view_enum_t*)(desc.parameters))[i].name=value; + desc.parameters=realloc(desc.parameters,(i+1)*sizeof(pcilib_enum_t)); + ((pcilib_enum_t*)(desc.parameters))[i].name=value; /* we need to iterate through the different attributes of an enum node to get all properties*/ for(attr=cur->properties; attr!=NULL;attr=attr->next){ @@ -593,14 +593,14 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo pcilib_error("Invalid value (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - ((pcilib_view_enum_t*)(desc.parameters))[i].value=dat_value; + ((pcilib_enum_t*)(desc.parameters))[i].value=dat_value; }else if(!(strcasecmp(name,"min"))){ pcilib_register_value_t dat_min = strtol(value, &endptr, 0); if ((strlen(endptr) > 0)) { pcilib_error("Invalid min (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - ((pcilib_view_enum_t*)(desc.parameters))[i].min=dat_min; + ((pcilib_enum_t*)(desc.parameters))[i].min=dat_min; ok_min=1; }else if(!(strcasecmp(name,"max"))){ pcilib_register_value_t dat_max = strtol(value, &endptr, 0); @@ -608,11 +608,11 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo pcilib_error("Invalid max (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - ((pcilib_view_enum_t*)(desc.parameters))[i].max=dat_max; + ((pcilib_enum_t*)(desc.parameters))[i].max=dat_max; ok_max=1; } - if(ok_min==0) ((pcilib_view_enum_t*)(desc.parameters))[i].min=((pcilib_view_enum_t*)(desc.parameters))[i].value; - if(ok_max==0) ((pcilib_view_enum_t*)(desc.parameters))[i].max=((pcilib_view_enum_t*)(desc.parameters))[i].value; + if(ok_min==0) ((pcilib_enum_t*)(desc.parameters))[i].min=((pcilib_enum_t*)(desc.parameters))[i].value; + if(ok_max==0) ((pcilib_enum_t*)(desc.parameters))[i].max=((pcilib_enum_t*)(desc.parameters))[i].value; } i++; -- cgit v1.2.3 From 1234f4a7e2410b127120aaa20dfe3c996ad34ef4 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 14:17:23 +0200 Subject: correction of some fails to load correct --- pcilib/xml.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index ebef91e..31b9926 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -121,20 +121,22 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP } if (!xmlXPathNodeSetIsEmpty(nodeset)) { - int i,k; + int i,k,l=0; /*if we correctly get a nodeset, then we iterate through the nodeset to get all views, using their names*/ for (i = 0; i < nodeset->nodeNr; i++) { view_name=(char*)nodeset->nodeTab[i]->children->content; - /* if the view name obtained is for an enum view, we get all pcilib_enum_t corresponding to the register*/ for(k=0; ctx->views[k].name; k++){ if(!(strcasecmp(view_name, ctx->views[k].name))){ - ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(k+1)*sizeof(pcilib_enum_t)); - ctx->register_ctx[id].views[k]=ctx->views[k]; + ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(l+1)*sizeof(pcilib_view_t)); + ctx->register_ctx[id].views[l]=ctx->views[k]; + l++; } } - } + ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(l+1)*sizeof(pcilib_view_t)); + ctx->register_ctx[id].views[l].name=NULL; + } xmlXPathFreeObject(nodes); @@ -305,6 +307,7 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank int i; for (i = 0; i < nodeset->nodeNr; i++) { + views_ok=0; memset(&fdesc, 0, sizeof(pcilib_xml_register_description_t)); fdesc.base.bank = desc.base.bank; @@ -575,7 +578,6 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo desc.description = value; }else if (!(strcasecmp((char*)name,"enum"))) { - desc.parameters=realloc(desc.parameters,(i+1)*sizeof(pcilib_enum_t)); ((pcilib_enum_t*)(desc.parameters))[i].name=value; @@ -700,6 +702,7 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon pcilib_xml_create_view(ctx,xpath,doc,nodeset->nodeTab[i]); } } + xmlXPathFreeObject(views_nodes); banks: bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath); @@ -718,7 +721,6 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon } } xmlXPathFreeObject(bank_nodes); - return 0; } @@ -852,20 +854,20 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { err = pcilib_xml_load_file(ctx, model_path, file->d_name); if (err) pcilib_error("Error processing XML file %s", file->d_name); } - + for(i=0;inum_views;i++){ pcilib_get_unit_of_view(ctx,&(ctx->views[i]),ctx->views[i].base_unit.name); } for(i=0;inum_reg;i++){ + if(!(ctx->register_ctx[i].views)) continue; for(j=0;jnum_views;j++){ if(!(ctx->register_ctx[i].views[j].name)) break; - if(ctx->register_ctx[i].views){ + if(ctx->register_ctx[i].views[j].name){ pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].views[j]),ctx->register_ctx[i].views[j].base_unit.name); } } } - closedir(rep); return 0; -- cgit v1.2.3 From c871ef59e748678b11d964e21debab05082948a0 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 14:56:35 +0200 Subject: soka --- pcilib/xml.c | 1 + 1 file changed, 1 insertion(+) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index 31b9926..47bcf5c 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -864,6 +864,7 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { for(j=0;jnum_views;j++){ if(!(ctx->register_ctx[i].views[j].name)) break; if(ctx->register_ctx[i].views[j].name){ + printf("register %s view %s\n",ctx->registers[i].name,ctx->register_ctx[i].views[j].name); pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].views[j]),ctx->register_ctx[i].views[j].base_unit.name); } } -- cgit v1.2.3 From e43b676d8294f37410ea0fa1f9fa39d10df64408 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 17:27:27 +0200 Subject: not perfect but working --- pcilib/xml.c | 1 - 1 file changed, 1 deletion(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index 47bcf5c..31b9926 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -864,7 +864,6 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { for(j=0;jnum_views;j++){ if(!(ctx->register_ctx[i].views[j].name)) break; if(ctx->register_ctx[i].views[j].name){ - printf("register %s view %s\n",ctx->registers[i].name,ctx->register_ctx[i].views[j].name); pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].views[j]),ctx->register_ctx[i].views[j].base_unit.name); } } -- cgit v1.2.3