📄 comfunction.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////文件名:ComFunction.cpp///////////////////////////////////////////////////////////////////////////////#include "ComFunction.h"#include "Com_wzser.h"#include "Com_lzser.h"tagCommuncatorFactoryConfig* ComFunction::m_config = new tagCommuncatorFactoryConfig;bool ComFunction::m_IsLoaded = false;/////////////////////////////////////////////////////////////////////////////////从communcatorfactory.xml中载入配置参数//可以用libxml2解析器进行处理int ComFunction::GetParameterFromXML(){ int iRetval = 0, counter, seccounter; char conpath[50]; memset( conpath, 0x0, sizeof(conpath)); sprintf( conpath, "%s/etc/%s", getenv("WORKDIR"), CONFIGFILE); CBaseNode baseNode(conpath); bool bRetval = baseNode.IsReady(); if(bRetval) //如果对XML初始化成功 那么开始读入XML中内容 { baseNode.GetAttributeValue(baseNode.GetRootNode(), "concreteclasscount", m_config->theCountOfConcreteClass, "0"); m_config->concreteClasses = (tagConcreteClass *)malloc(sizeof(tagConcreteClass) * atoi(m_config->theCountOfConcreteClass)); NODELIST tagList = baseNode.GetRootNode()->children; counter = 0; while(tagList != NULL) { if(baseNode.IsRightNode(tagList, "concreteclass")) { baseNode.GetAttributeValue(tagList, "parametercount", m_config->concreteClasses[counter].theCountOfParameter, "0"); baseNode.GetAttributeValue(tagList, "name", m_config->concreteClasses[counter].ClassName, ""); //get parameter m_config->concreteClasses[counter].pameters = (tagParameter *)malloc(sizeof(tagParameter) * atoi(m_config->concreteClasses[counter].theCountOfParameter)); NODELIST chiList = tagList->children; seccounter = 0; while(chiList != NULL) { if(baseNode.IsRightNode(chiList, "parameter")) { baseNode.GetAttributeValue(chiList, "name", m_config->concreteClasses[counter].pameters[seccounter].name, ""); baseNode.GetAttributeValue(chiList, "value" , m_config->concreteClasses[counter].pameters[seccounter].value, ""); seccounter++; } chiList = chiList->next; } counter++; } tagList = tagList->next; } } m_IsLoaded = true; return iRetval;}///////////////////////////////////////////////////////////////////////////////得到指定具体类的某一个参数int ComFunction::GetConcreteClassOnePameterValue(const char* ConcreteClassName, const char* ParameterName, char* value){ int I, J; bool bFindIt = false; if(!m_IsLoaded) { GetParameterFromXML(); } if(atoi(m_config->theCountOfConcreteClass) > 0) { for(I = 0 ; I < atoi(m_config->theCountOfConcreteClass); I++) { if(strcmp(m_config->concreteClasses[I].ClassName, ConcreteClassName) == 0 ) { for(J = 0 ; J < atoi(m_config->concreteClasses[I].theCountOfParameter); J++) { if(strcmp(m_config->concreteClasses[I].pameters[J].name, ParameterName) == 0 ) { memcpy(value, m_config->concreteClasses[I].pameters[J].value, strlen(m_config->concreteClasses[I].pameters[J].value)); value[strlen(m_config->concreteClasses[I].pameters[J].value)] = 0; bFindIt = true; break; } } } if(bFindIt) break; } } return (bFindIt ? 0 : -1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -