/* * ProcessNode.cc * * Created on: Oct 31, 2012 * Author: f.casimir */ #include #include "ProcessNode.hh" #include #include #include #include #include #include #include "Config.hh" using namespace AMDA::Parameters; using namespace boost; namespace AMDA { namespace XMLParameterConfigurator { ProcessNode::ProcessNode() : NodeCfg() { } ProcessNode::~ProcessNode() { } std::string injectResamplingIntoProcess(const double& pTimeresolution, const double& pGapThreshold, const char* pExpression) { std::stringstream lBuffer; bool isAParam = false; unsigned int length = strlen(pExpression); for ( unsigned int i = 0; i < length; ++i) { switch(pExpression[i]) { case '$': isAParam = true; lBuffer << "#sampling_classic($"; break; default: if( isAParam && ! (isalnum(pExpression[i]) || (pExpression[i]=='_'))) { lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")"; isAParam=false; } lBuffer << pExpression[i]; break; } } if (isAParam) { lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")"; } return std::string(lBuffer.str()); } void ProcessNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "ProcessNode::proceed"); Parameter* lParameter = pContext.get(); double lTimeResolution = lParameter->getTimeResolution(); double lGapThreshold = lParameter->getGapThreshold(); Process *lProcess = ServicesServer::getInstance()->getProcess("standard", *lParameter); //process description xmlChar *lProcessDesc = xmlGetProp(pNode, (const xmlChar *) "description"); if (lProcessDesc != NULL) { lProcess->setDescription(std::string((const char *)lProcessDesc)); xmlFree(lProcessDesc); } //user process xmlChar *lUserProcess = xmlGetProp(pNode, (const xmlChar *) "userProcess"); if (lUserProcess != NULL) { lProcess->setIsUserProcess(strcasecmp ((const char*)lUserProcess, "true") == 0); xmlFree(lUserProcess); } DataWriterSPtr lDataWriter( lProcess); std::string* xmlFileName = pContext.get(); lDataWriter->setSignatureTrigger(*xmlFileName); lParameter->setDataWriter(lDataWriter); if (pNode->children && pNode->children->content && pNode->children->content[0] != '\0') { xmlChar* lExpression = pNode->children->content; if ( lTimeResolution != 0 ) { // Inject Resampling lProcess->setExpression(injectResamplingIntoProcess(lTimeResolution, lGapThreshold,(char*)lExpression)); } else { lProcess->setExpression((char*)lExpression); } } else { if ( lParameter->getParameterList().size() == 1 ) { // Inject Resampling if ( lTimeResolution != 0 ) { lProcess = ServicesServer::getInstance()->getProcess("sampling_classic",*lParameter); std::stringstream lBuffer; lBuffer.str(""); lBuffer << lTimeResolution; lProcess->getAttributList().push_back(lBuffer.str()); lBuffer.str(""); lBuffer << lGapThreshold; lProcess->getAttributList().push_back(lBuffer.str()); lBuffer.str(""); lBuffer << "$" << (*lParameter->getParameterList().begin())->getId(); lProcess->setExpression(lBuffer.str()); lDataWriter.reset( lProcess); lParameter->setDataWriter(lDataWriter); } else //only one parameter + no process => use the same info (*lParameter->getParameterList().begin())->setInfoId(lParameter->getInfoId()); } else { ERROR_EXCEPTION( "Too many ParamGet with no process"); } } } } /* namespace XMLParameterConfigurator */ } /* namespace AMDA */