trafficMxml.h
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef _TRAFFIC_MXML_H
#define _TRAFFIC_MXML_H
#include "include/include/mxml.h"
#include "include/include/ScErr.h"
#include <errno.h>
static mxml_node_t* hTrafficMxml = NULL;
FILE *fp;
#define SETTING_CONFIG_XML "settingsConfig.xml"
mxml_node_t* getTrafficMxml()
{
if(hTrafficMxml == NULL)
{
FILE *fp = NULL;
fp = fopen(SETTING_CONFIG_XML, "r");
if(fp != NULL)
{
hTrafficMxml = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK);
if(hTrafficMxml == NULL)
{
printf("------------------------hTrafficMxml = NULL---------------------------\n");
}
else
{
printf("------------------------hTrafficMxml OK---------------------------\n");
}
fclose(fp);
}
else
{
perror("fopen FAILED:");
}
}
return hTrafficMxml;
}
/*
从指定好的mxml中获取出keyId对应的keyName, valueType, source
*/
ScErr getConfigInfoFromMxml(char *inKeyId, const char** outKeyName, const char** outValueType, const char** outKeySource)
{
mxml_node_t* pTrafficMxml = getTrafficMxml();
if(pTrafficMxml == NULL)
return SC_ErrNoResources;
mxml_node_t *idNode = NULL;
if(((idNode = mxmlFindElement(pTrafficMxml, pTrafficMxml, NULL, "keyId", inKeyId, MXML_DESCEND)) != NULL) &&
((*outKeyName = mxmlElementGetAttr(idNode, "keyName")) != NULL) &&
((*outValueType = mxmlElementGetAttr(idNode, "valueType")) != NULL) &&
((*outKeySource = mxmlElementGetAttr(idNode, "keySource")) != NULL))
{
// printf("-----------------------查找的结果为:---------------------\n");
// printf("id=%s, keyName=%s, valueType=%s, source=%s\n", inKeyId, outKeyName, outValueType, outSource);
// printf("---------------------------------------------------------\n");
return SC_ErrSuccess;
}
else
{
return SC_ErrUnknow;
}
}
/*
mxml_node_t *infoDevice = mxmlFindElement(tree, tree, "deviceInfo", NULL, NULL, MXML_DESCEND);
mxml_node_t *itemConfig = mxmlGetFirstChild(infoDevice);
while(itemConfig != NULL)
{
if(mxmlGetType(itemConfig) == MXML_ELEMENT)
{
const char *keyId = mxmlElementGetAttr(itemConfig, "keyId");
const char *keyName = mxmlElementGetAttr(itemConfig, "keyName");
const char *valueType = mxmlElementGetAttr(itemConfig, "valueType");
const char *source = mxmlElementGetAttr(itemConfig, "source");
printf("id=%s, keyName=%s, valueType=%s, source=%s\n", keyId, keyName, valueType, source);
printf("---------------------------------------------------------\n");
}
itemConfig = mxmlGetNextSibling(itemConfig);
}
*/
#endif