예제 #1
0
	void convertXmlParameterToEvent(EventData &eventdata, XmlParameter const &xmlparameter)
	{
		eventdata.clear();
		
		EventData::DType dtype = (EventData::DType)xmlparameter.getParameter("dtype").getAsInt();
		EventData::EType etype = (EventData::EType)xmlparameter.getParameter("etype").getAsInt();

				
		eventdata.getEventType() = etype;
		eventdata.setType(dtype);

		double miliss = xmlparameter.getParameter("etime").getAsDate();
		if (miliss > 0)
			eventdata.setEventDate( miliss/ 1000.0 );
		else
			eventdata.setEventDate(-1);


		eventdata.eventSource_m = xmlparameter.getParameter("source").getAsString();
		eventdata.parentUid_m = xmlparameter.getParameter("puid").getAsUid();
		eventdata.uid_m = xmlparameter.getParameter("uid").getAsUid();

		if (dtype==EventData::DT_Log) {
		
			XmlParameter const& logParam = xmlparameter.getXmlParameter("log");
			CommonLog& log = eventdata.getAsLog(true);

			double miliss = logParam.getParameter("time").getAsDate();
			if (miliss > 0)
				log.logDate_m = miliss / 1000.0;
			else
				log.logDate_m = -1;

			log.logLevel_m  = logParam.getParameter("level").getAsInt();
			log.context_m = logParam.getParameter("context").getAsString();
			log.content_m = logParam.getParameter("content").getAsString();
			log.session_m = logParam.getParameter("session").getAsString();
			log.logThread_m = logParam.getParameter("thread").getAsInt();

						

		}
		else if (dtype==EventData::DT_CommonXml) {
			eventdata.getAsXmlParameter(true) = xmlparameter.getXmlParameter("commonxml");
		}
		else if (dtype==EventData::DT_String) {
			eventdata.getAsString(true) = xmlparameter.getParameter("str").getAsString();
		}
		else if (dtype==EventData::DT_StringList) {
			eventdata.getAsStringList(true) = xmlparameter.getParameter("strlist").getAsStringList();
		}
		else if (dtype==EventData::DT_StringMap) {
			
			CppUtils::StringMap& strmap = eventdata.getAsStringMap(true);

			XmlParameter const& strMapParam = xmlparameter.getXmlParameter("strmap");
			CppUtils::StringList keys;
			strMapParam.getValueKeys(keys);
			for(int i = 0; i < keys.size(); i++) {
				strmap[ keys[ i ] ] = strMapParam.getParameter(keys[ i ]).getAsString();
			}
			
		}
		else if (dtype==EventData::DT_Ticker) {
			convertFromXmlParameter( eventdata.getAsRtData(), xmlparameter.getXmlParameter("ticker"));
		}
		else if (eventdata.getType()==EventData::DT_TickerList) {
			
			RtDataList& rtlist = eventdata.getAsRtDataList(true);

			XmlParameter::XmlParameterList const& tickerMapParamList = xmlparameter.getXmlParameterList("tickerlist");
			RtData rtdata;

			for(int i = 0; i < tickerMapParamList.size(); i++) {
				convertFromXmlParameter( rtdata, tickerMapParamList[ i ]);
				rtlist.push_back(rtdata);
			}

		}
		else if (dtype==EventData::DT_Level2Data) {
			//convertLevel2FromXmlParameter( eventdata.getAsLevel2Data(), xmlparameter.getXmlParameter("level2data"));
			HTASSERT(false);
		}
		else if (dtype==EventData::DT_Level1Data) {
			convertLevel1FromXmlParameter( eventdata.getAsLevel1Data(), xmlparameter.getXmlParameter("level1data"));
		}
		else if (dtype==EventData::DT_DrawableObject) {
			convertDrawableObjFromXmlParameter( eventdata.getAsDrawableObject(), xmlparameter.getXmlParameter("drawobj"));
		}
		else {
			HTASSERT(false);
		}


	}
예제 #2
0
	// conversion functions
	void convertEventToXmlParameter(EventData const& eventdata, XmlParameter &xmlparameter)
	{
		xmlparameter.clear();
		xmlparameter.getName() = "event_packet";

		xmlparameter.getParameter("source").getAsString(true) = eventdata.getSource();
		xmlparameter.getParameter("puid").getAsUid(true) = eventdata.getParentEventUid();
		xmlparameter.getParameter("uid").getAsUid(true) = eventdata.getEventUid();
		xmlparameter.getParameter("etype").getAsInt(true) = eventdata.getEventType();
		xmlparameter.getParameter("dtype").getAsInt(true) = eventdata.getType();
		
		double sec = eventdata.getEventDate();
		if (sec <= 0)
			xmlparameter.getParameter("etime").getAsDate(true)  =-1;
		else
			xmlparameter.getParameter("etime").getAsDate(true) = sec * 1000.0;

		if (eventdata.getType()==EventData::DT_Log) {
			XmlParameter logParam;
			CommonLog const& log = eventdata.getAsLog();
			double sec = log.logDate_m;

			if (sec <= 0)
				logParam.getParameter("time").getAsDate(true) = -1;
			else	
				logParam.getParameter("time").getAsDate(true) = sec * 1000.0;
			
			logParam.getParameter("level").getAsInt(true) = log.logLevel_m;
			logParam.getParameter("context").getAsString(true) = log.context_m;
			logParam.getParameter("content").getAsString(true) = CppUtils::wrapToCDataTags(log.content_m);
			logParam.getParameter("session").getAsString(true) = log.session_m;
			logParam.getParameter("thread").getAsInt(true) = log.logThread_m;
			
		
			xmlparameter.getXmlParameter("log") = logParam;
		}
		else if (eventdata.getType()==EventData::DT_CommonXml) {
			xmlparameter.getXmlParameter("commonxml") = eventdata.getAsXmlParameter();
		}
		else if (eventdata.getType()==EventData::DT_String) {
			xmlparameter.getParameter("str").getAsString(true) = eventdata.getAsString();

		}
		else if (eventdata.getType()==EventData::DT_StringList) {
			xmlparameter.getParameter("strlist").getAsStringList(true) = eventdata.getAsStringList();
		}
		else if (eventdata.getType()==EventData::DT_StringMap) {
			XmlParameter strMapParam;
			
			CppUtils::StringMap const& strmap = eventdata.getAsStringMap();
			for(CppUtils::StringMap::const_iterator it = strmap.begin(); it != strmap.end(); it++) {
				strMapParam.getParameter(it->first).getAsString(true) = it->second;
			}

			xmlparameter.getXmlParameter("strmap") = strMapParam;
		}
		else if (eventdata.getType()==EventData::DT_Ticker) {
			convertToXmlParameter(eventdata.getAsRtData(), xmlparameter.getXmlParameter("ticker"));
		}
		else if (eventdata.getType()==EventData::DT_TickerList) {
			XmlParameter tickerParam;
			RtDataList const& rtlist = eventdata.getAsRtDataList();
			for(int i = 0; i < rtlist.size(); i++) {
				convertToXmlParameter(rtlist[ i ], tickerParam);
				xmlparameter.getXmlParameterList("tickerlist").push_back(tickerParam);
			}

		}
		else if (eventdata.getType()==EventData::DT_Dummy) {
			// no-op
		}
		else if (eventdata.getType()==EventData::DT_Level2Data) {
			//convertLevel2ToXmlParameter(eventdata.getAsLevel2Data(), xmlparameter.getXmlParameter("level2data"));
			HTASSERT(false);
		}
		else if (eventdata.getType()==EventData::DT_Level1Data) {
			convertLevel1ToXmlParameter(eventdata.getAsLevel1Data(), xmlparameter.getXmlParameter("level1data"));
		}
		else if (eventdata.getType()==EventData::DT_DrawableObject) {
			convertDrawableObjToXmlParameter(eventdata.getAsDrawableObject(), xmlparameter.getXmlParameter("drawobj"));
		}
		else {
			// dummy
			HTASSERT(false);
		}

	}