Statistics
| Revision:

root / logic / trunk / src / init / devicelist.c @ 14

History | View | Annotate | Download (2.76 KB)

1
#include "devicelist.h"
2
#include <string.h>
3
#include <mxml.h>
4

    
5
device *hDevice; //device list
6

    
7
void setDeviceList()
8
{
9
    device *curr, *head;
10
    head = NULL;
11

    
12
    FILE *fp;
13
    mxml_node_t *tree, *node;
14

    
15
        fp = fopen("devicetree.xml", "r"); //TODO !hardcoded
16
        tree = mxmlLoadFile(NULL, fp, MXML_IGNORE_CALLBACK);
17
        node = tree;
18
        fclose(fp);
19

    
20
    /* //structure of XML tree
21
    ?xml
22
      |
23
    devicetree
24
      |
25
    dev1 - dev2 - ...
26
      |      |
27
      |      |
28
      |     ID - name - minvalue - maxvalue - action - param
29
    ID - name - minvalue - maxvalue - action - param
30
    /**/
31
    //getting to the correct level of the xml tree (descend 2 levels)
32
    node=node->child->child;
33
    printf("hDevice %d\n", hDevice);
34

    
35
    // fill the list of known devices
36
    // sorry for the ugly chunk of code, but I had to allocate memory
37
    // for each string separately in order to keep it scalable
38
    while(node!=NULL)
39
    {
40
        curr = (device *)malloc(sizeof(device));
41

    
42
        curr->id = (char *)malloc(sizeof(node->value.element.attrs->value));
43
        strcpy(curr->id, node->value.element.attrs->value);
44

    
45
        // getting data for individual device
46
        mxml_node_t *mxml_deviceNode;
47
        mxml_deviceNode=node->child;
48
        //TODO malloc()
49
        curr->name = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
50
        strcpy(curr->name, mxml_deviceNode->value.element.attrs->value);
51
            mxml_deviceNode= mxml_deviceNode->next;
52

    
53
        curr->minval= atoi(mxml_deviceNode->value.element.attrs->value);
54
            mxml_deviceNode= mxml_deviceNode->next;
55

    
56
        curr->maxval= atoi(mxml_deviceNode->value.element.attrs->value);
57
            mxml_deviceNode= mxml_deviceNode->next;
58

    
59
        curr->action = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
60
        strcpy(curr->action, mxml_deviceNode->value.element.attrs->value);
61
            mxml_deviceNode= mxml_deviceNode->next;
62

    
63
        curr->param = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
64
        strcpy(curr->param, mxml_deviceNode->value.element.attrs->value);
65
        // done
66
        // moving to the next XML node
67
        node=node->next;
68

    
69
        curr->nxt = head;
70
        head = curr;
71
    }
72
    //delete obsolete xml tree
73
    mxmlDelete(tree);
74
    mxmlDelete(node);
75
    /*
76
    // TODO delete - test
77
    hDevice=head;
78
    curr=head;
79
    printf("test device list\n");
80
    //*
81
    while(curr)
82
    {
83
        printf("name:\t %s\n", curr->name );
84
        printf("id:\t %s\n", curr->id );
85
        printf("minval:\t %d\n", curr->minval );
86
        printf("maxval:\t %d\n", curr->maxval );
87
        printf("action:\t %s\n", curr->action );
88
        printf("param:\t %s\n", curr->param );
89
        curr=curr->nxt;
90
    }
91
    /**/
92
}
93

    
94
/*
95
void updateDeviceList(device_d *deviceList)
96
{
97

98
}
99
/**/