/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-05 11:33:48 UTC
  • mto: This revision was merged to the branch mainline in revision 353.
  • Revision ID: vchernov@inr.ru-20160205113348-l4gmpvm9df3n22sx
Add support for python script properties. Correct pcilib python wrapping. Update examples. Update cmakelists for work in shadow build mode.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "view.h"
43
43
#include "views/enum.h"
44
44
#include "views/transform.h"
 
45
#include "views/script.h"
45
46
 
46
47
 
47
48
#define BANKS_PATH ((xmlChar*)"/model/bank")                                    /**< path to complete nodes of banks */
48
49
#define REGISTERS_PATH ((xmlChar*)"./register")                                 /**< all standard registers nodes */
49
50
#define BIT_REGISTERS_PATH ((xmlChar*)"./field")                                /**< all bits registers nodes */
50
51
#define REGISTER_VIEWS_PATH ((xmlChar*)"./view")                                /**< supported register & field views */
51
 
#define TRANSFORM_VIEWS_PATH ((xmlChar*)"/model/transform")                     /**< path to complete nodes of views */
 
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 */
52
54
#define ENUM_VIEWS_PATH ((xmlChar*)"/model/enum")                               /**< path to complete nodes of views */
53
55
#define ENUM_ELEMENTS_PATH ((xmlChar*)"./name")                                 /**< all elements in the enum */
54
56
#define UNITS_PATH ((xmlChar*)"/model/unit")                                    /**< path to complete nodes of units */
55
 
#define UNIT_TRANSFORMS_PATH ((xmlChar*)"./transform")                          /**< all transforms of the unit */
 
57
#define UNIT_TRANSFORMS_PATH ((xmlChar*)"./transform")                  /**< all transforms of the unit */
56
58
 
57
59
 
58
60
 
543
545
    return 0;
544
546
}
545
547
 
 
548
static int pcilib_xml_create_script_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
 
549
    int err;
 
550
    xmlAttrPtr cur;
 
551
    const char *value, *name;
 
552
    pcilib_view_context_t *view_ctx;
 
553
 
 
554
    pcilib_access_mode_t mode = 0;
 
555
    pcilib_script_view_description_t desc = {{0}};
 
556
 
 
557
    desc.base.api = &pcilib_script_view_api;
 
558
    desc.base.type = PCILIB_TYPE_DOUBLE;
 
559
    desc.base.mode = PCILIB_ACCESS_RW;
 
560
    desc.py_script_module = NULL;
 
561
    desc.script_name = NULL;
 
562
 
 
563
    err = pcilib_xml_parse_view(ctx, xpath, doc, node, (pcilib_view_description_t*)&desc);
 
564
    if (err) return err;
 
565
 
 
566
    for (cur = node->properties; cur != NULL; cur = cur->next) {
 
567
        if (!cur->children) continue;
 
568
        if (!xmlNodeIsText(cur->children)) continue;
 
569
 
 
570
        name = (char*)cur->name;
 
571
        value = (char*)cur->children->content;
 
572
        if (!value) continue;
 
573
 
 
574
        if (!strcasecmp(name, "script")) {
 
575
                        //write script name to struct
 
576
                        desc.script_name = malloc(strlen(value));
 
577
                        sprintf(desc.script_name, "%s", value);
 
578
                        //set read access
 
579
                        mode |= PCILIB_ACCESS_R;
 
580
            }
 
581
    }
 
582
    
 
583
    desc.base.mode &= mode;
 
584
 
 
585
    err = pcilib_add_views_custom(ctx, 1, (pcilib_view_description_t*)&desc, &view_ctx);
 
586
    if (err) return err;
 
587
 
 
588
    view_ctx->xml = node;
 
589
    return 0;
 
590
}
 
591
 
 
592
 
546
593
static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
547
594
    int err;
548
595
    xmlAttrPtr cur;
822
869
 */
823
870
static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) {
824
871
    int err;
825
 
    xmlXPathObjectPtr bank_nodes = NULL, transform_nodes = NULL, enum_nodes = NULL, unit_nodes = NULL;
 
872
    xmlXPathObjectPtr bank_nodes = NULL, transform_nodes = NULL, enum_nodes = NULL, unit_nodes = NULL, script_nodes = NULL;
826
873
    xmlNodeSetPtr nodeset;
827
874
    int i;
828
875
 
829
876
    bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath);
830
877
    if (bank_nodes) transform_nodes = xmlXPathEvalExpression(TRANSFORM_VIEWS_PATH, xpath);
831
 
    if (transform_nodes) enum_nodes = xmlXPathEvalExpression(ENUM_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);
832
880
    if (enum_nodes) unit_nodes = xmlXPathEvalExpression(UNITS_PATH, xpath);
 
881
    
833
882
 
834
883
    if (!unit_nodes) {
835
884
        const unsigned char *expr = (enum_nodes?UNITS_PATH:(transform_nodes?ENUM_VIEWS_PATH:(bank_nodes?TRANSFORM_VIEWS_PATH:BANKS_PATH)));
850
899
            if (err) pcilib_error("Error (%i) creating unit", err);
851
900
        }
852
901
    }
 
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
    }
853
910
 
854
911
    nodeset = transform_nodes->nodesetval;
855
912
    if (!xmlXPathNodeSetIsEmpty(nodeset)) {