trafficMxml.h 2.44 KB
#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