/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/xml.c

  • Committer: Vasilii Chernov
  • Date: 2016-02-08 10:55:33 UTC
  • mto: This revision was merged to the branch mainline in revision 353.
  • Revision ID: vchernov@inr.ru-20160208105533-fl0uue3ukv6di13b
Add support for setting register value to script transfrom. Add set_property and get_property functions to pcipywrap. Cleaning cmakelists from unused dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
#define BIT_REGISTERS_PATH ((xmlChar*)"./field")                                /**< all bits registers nodes */
51
51
#define REGISTER_VIEWS_PATH ((xmlChar*)"./view")                                /**< supported register & field views */
52
52
#define TRANSFORM_VIEWS_PATH ((xmlChar*)"/model/transform")             /**< path to complete nodes of views */
53
 
#define SCRIPT_VIEWS_PATH ((xmlChar*)"/model/script")                   /**< path to complete nodes of views */
54
53
#define ENUM_VIEWS_PATH ((xmlChar*)"/model/enum")                               /**< path to complete nodes of views */
55
54
#define ENUM_ELEMENTS_PATH ((xmlChar*)"./name")                                 /**< all elements in the enum */
56
55
#define UNITS_PATH ((xmlChar*)"/model/unit")                                    /**< path to complete nodes of units */
575
574
                        //write script name to struct
576
575
                        desc.script_name = malloc(strlen(value));
577
576
                        sprintf(desc.script_name, "%s", value);
578
 
                        //set read access
 
577
                        //set read write access
579
578
                        mode |= PCILIB_ACCESS_R;
 
579
                        mode |= PCILIB_ACCESS_W;
580
580
            }
581
581
    }
582
582
    
589
589
    return 0;
590
590
}
591
591
 
592
 
 
593
592
static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
594
593
    int err;
595
594
    xmlAttrPtr cur;
644
643
    return 0;
645
644
}
646
645
 
 
646
static int pcilib_xml_create_script_or_transform_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
 
647
    int err;
 
648
    xmlAttrPtr cur;
 
649
    const char *name;
 
650
 
 
651
    int has_read_from_register = 0;
 
652
    int has_write_to_register = 0;
 
653
    int has_script = 0;
 
654
 
 
655
    //getting transform name in case of error
 
656
    pcilib_view_description_t desc = {0};
 
657
    err = pcilib_xml_parse_view(ctx, xpath, doc, node, &desc);
 
658
 
 
659
    for (cur = node->properties; cur != NULL; cur = cur->next) {
 
660
        if (!cur->children) continue;
 
661
        if (!xmlNodeIsText(cur->children)) continue;
 
662
 
 
663
        name = (char*)cur->name;
 
664
 
 
665
        if (!strcasecmp(name, "read_from_register"))
 
666
            has_read_from_register = 1;
 
667
        if (!strcasecmp(name, "write_to_register"))
 
668
            has_write_to_register = 1;
 
669
        if (!strcasecmp(name, "script"))
 
670
            has_script = 1;
 
671
    }
 
672
 
 
673
    if (has_script && (has_read_from_register || has_write_to_register)) {
 
674
        pcilib_error("Invalid transform group attributes specified in XML property (%s)."
 
675
                     "Transform could not contains both script and read_from_register"
 
676
                     " or write_to_register attributes at same time.", desc.name);
 
677
        return PCILIB_ERROR_INVALID_DATA;
 
678
    }
 
679
 
 
680
    if(has_script)
 
681
        return pcilib_xml_create_script_view(ctx, xpath, doc, node);
 
682
    else
 
683
        return pcilib_xml_create_transform_view(ctx, xpath, doc, node);
 
684
}
 
685
 
647
686
 
648
687
static int pcilib_xml_parse_value_name(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node, pcilib_register_value_name_t *desc) {
649
688
    xmlAttr *cur;
869
908
 */
870
909
static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) {
871
910
    int err;
872
 
    xmlXPathObjectPtr bank_nodes = NULL, transform_nodes = NULL, enum_nodes = NULL, unit_nodes = NULL, script_nodes = NULL;
 
911
    xmlXPathObjectPtr bank_nodes = NULL, transform_nodes = NULL, enum_nodes = NULL, unit_nodes = NULL;
873
912
    xmlNodeSetPtr nodeset;
874
913
    int i;
875
914
 
876
915
    bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath);
877
916
    if (bank_nodes) transform_nodes = xmlXPathEvalExpression(TRANSFORM_VIEWS_PATH, xpath);
878
 
    if (transform_nodes) script_nodes = xmlXPathEvalExpression(SCRIPT_VIEWS_PATH, xpath);
879
 
    if (script_nodes) enum_nodes = xmlXPathEvalExpression(ENUM_VIEWS_PATH, xpath);
 
917
    if (transform_nodes) enum_nodes = xmlXPathEvalExpression(ENUM_VIEWS_PATH, xpath);
880
918
    if (enum_nodes) unit_nodes = xmlXPathEvalExpression(UNITS_PATH, xpath);
881
919
    
882
920
 
899
937
            if (err) pcilib_error("Error (%i) creating unit", err);
900
938
        }
901
939
    }
902
 
    
903
 
    nodeset = script_nodes->nodesetval;
904
 
    if(!xmlXPathNodeSetIsEmpty(nodeset)) {
905
 
        for(i=0; i < nodeset->nodeNr; i++) {
906
 
                        err = pcilib_xml_create_script_view(ctx, xpath, doc, nodeset->nodeTab[i]);
907
 
            if (err) pcilib_error("Error (%i) creating script transform", err);
908
 
        }
909
 
    }
910
940
 
911
941
    nodeset = transform_nodes->nodesetval;
912
942
    if (!xmlXPathNodeSetIsEmpty(nodeset)) {
913
943
        for(i=0; i < nodeset->nodeNr; i++) {
914
 
            err = pcilib_xml_create_transform_view(ctx, xpath, doc, nodeset->nodeTab[i]);
 
944
            err = pcilib_xml_create_script_or_transform_view(ctx, xpath, doc, nodeset->nodeTab[i]);
915
945
            if (err) pcilib_error("Error (%i) creating register transform", err);
916
946
        }
917
947
    }