// 拼装客户端抓拍通用返回xml
IVS_INT32 OCXCapturePictureXMLProcess::LocalCaptureBuildXMLGeneric(LONG iEventCode, ULONG iWndID, const IVS_CHAR* pFileName, CXml &xml)
{
// 	CHECK_POINTER(pFileName, IVS_OPERATE_MEMORY_ERROR); // 可以为空
	IVS_DEBUG_TRACE("");
	char buf[IVS_FILE_NAME_LEN + 1] = {0};

	CHECK_SUCCESS(xml.AddDeclaration("1.0","UTF-8",""));
	CHECK_SUCCESS(xml.AddElem("Content"));
	CHECK_SUCCESS(xml.AddChildElem("WndID"));
	xml.IntoElem();
	(void)_itoa_s((int)iWndID, buf, 10);//lint !e713
	CHECK_SUCCESS(xml.SetElemValue(buf));
	
	CHECK_SUCCESS(xml.AddElem("EventID"));
	(void)_itoa_s(iEventCode, buf, 10);
	CHECK_SUCCESS(xml.SetElemValue(buf));
	
	if (NULL != pFileName)
	{
		CHECK_SUCCESS(xml.AddElem("FileName"));
		CHECK_SUCCESS(xml.SetElemValue(pFileName));
	}

	xml.OutOfElem();
	return IVS_SUCCEED;
}
//查询MU的资源预算是否达到上限及当前摄像机视频流是否被引用
IVS_INT32 CMediaXMLProcess::VideoNumAndResourceGetXML(const std::string& strCameraCode, CXml &xml)
{
	IVS_DEBUG_TRACE("");
	(void)xml.AddDeclaration("1.0", "UTF-8", "");
	(void)xml.AddElem("Content");
	(void)xml.AddChildElem("CameraCode");
	(void)(xml.IntoElem());
	(void)xml.SetElemValue(strCameraCode.c_str());
	xml.OutOfElem();
	return IVS_SUCCEED;
}
// 构建去选中图形消息XML
IVS_INT32 COCXDrawXMLProcess::UnSelectGraphicGetXML(CString &xmlToCU)
{
	IVS_DEBUG_TRACE("");
	CXml xmlGraphics;
	unsigned int uiLen = 0;

	CHECK_SUCCESS(xmlGraphics.AddDeclaration("1.0","UTF-8",""));
	CHECK_SUCCESS(xmlGraphics.AddElem("Content"));
	xmlToCU = xmlGraphics.GetXMLStream(uiLen);

	return IVS_SUCCEED;
}
// 构建获取图形失败的XML
IVS_INT32 COCXDrawXMLProcess::GetGraphicsGetErrXML(IVS_INT32 iResultCode, CXml& xmlGraphics)
{
	char val[64] = {0};
	IVS_DEBUG_TRACE("iResultCode: %d", iResultCode);

	CHECK_SUCCESS(xmlGraphics.AddDeclaration("1.0","UTF-8",""));
	CHECK_SUCCESS(xmlGraphics.AddElem("Content"));
	CHECK_SUCCESS(xmlGraphics.AddChildElem("ResultCode"));
	CHECK_SUCCESS(xmlGraphics.IntoElem());
	SET_ELEMENT_LONG(iResultCode, val, xmlGraphics);
	xmlGraphics.OutOfElem();

	return IVS_SUCCEED;

}
// 构建选中图形消息XML
IVS_INT32 COCXDrawXMLProcess::SelectGraphicGetXML(CString &xmlToCU, IVS_ULONG ulGraphicGroup)
{
	IVS_DEBUG_TRACE("GraphicGroup: %lu", ulGraphicGroup);
	CXml xmlGraphics;
	char val[64] = {0};
	unsigned int uiLen = 0;

	CHECK_SUCCESS(xmlGraphics.AddDeclaration("1.0","UTF-8",""));
	CHECK_SUCCESS(xmlGraphics.AddElem("Content"));
	CHECK_SUCCESS(xmlGraphics.AddChildElem("GraphicGroup"));
	CHECK_SUCCESS(xmlGraphics.IntoElem());
	SET_ELEMENT_LONG(ulGraphicGroup, val, xmlGraphics);
	xmlGraphics.OutOfElem();
	xmlToCU = xmlGraphics.GetXMLStream(uiLen);

	return IVS_SUCCEED;
}
 //通用的查询请求
 IVS_INT32 CXmlProcess::GetCommConfigGetXML(const IVS_CHAR* pDomainCode,const IVS_CHAR* pDevCode, CXml& xml, enConfigType enType)
 {
	 CHECK_POINTER(pDomainCode,IVS_OPERATE_MEMORY_ERROR);
	 CHECK_POINTER(pDevCode,IVS_OPERATE_MEMORY_ERROR);

	 (void)xml.AddDeclaration("1.0","UTF-8","");
	 (void)xml.AddElem("Content");

	 (void)xml.AddChildElem("DomainCode");
	 (void)xml.IntoElem();
	 (void)xml.SetElemValue(pDomainCode);
	 if (SDKCAMERA == enType)
	 {
		 (void)xml.AddElem("CameraCode");
	 }
	 else if (SDKDEVICE == enType)
	 {
		 (void)xml.AddElem("DevCode");
	 }
	 else if (SDKALARMINCODE == enType)
	 {
		 (void)xml.AddElem("AlarmInCode");
	 }
	 else if (SDKALARMOUTCODE == enType)
	 {
		 (void)xml.AddElem("AlarmOutCode");
	 }
	 else if (SDKSERIAL == enType)
	 {
		 (void)xml.AddElem("SerialCode");
	 }
	 else if (SDKVOICE == enType)
	 {
		 (void)xml.AddElem("VoiceCode");
	 }


	 (void)xml.SetElemValue(pDevCode);
	 xml.OutOfElem();

	 return IVS_SUCCEED;
 }
//请求录像加密的工作密钥或者异或因子xml
IVS_INT32 CMediaXMLProcess::ApplyStreamencryPwdGetXML(const std::string& strCameraCode,const std::string& strDomainCode,
	const std::string& strDestModule,int& iStreamType,const std::string& strSessionID,const std::string& strSecurityTransID, CXml &xml)
{
	IVS_DEBUG_TRACE("");
	(void)xml.AddDeclaration("1.0", "UTF-8", "");
	(void)xml.AddElem("Content");
	(void)xml.AddChildElem("CameraCode");
	(void)(xml.IntoElem());
	(void)xml.SetElemValue(strCameraCode.c_str());

	(void)xml.AddElem("DomainCode");
	(void)(xml.IntoElem());
	(void)xml.SetElemValue(strDomainCode.c_str());

	(void)xml.AddElem("DestModule");
	(void)(xml.IntoElem());
	(void)xml.SetElemValue(strDestModule.c_str());

	if(!strSessionID.empty())
	{
		(void)xml.AddElem("SessionID");
		(void)(xml.IntoElem());
		(void)xml.SetElemValue(strSessionID.c_str());
	}

	(void)xml.AddElem("StreamID");
	(void)(xml.IntoElem());
	(void)xml.SetElemValue(CToolsHelp::Int2Str(iStreamType).c_str());

	(void)xml.AddElem("ExchangeTransNo");
	(void)(xml.IntoElem());
	(void)xml.SetElemValue(strSecurityTransID.c_str());

	xml.OutOfElem();
	return IVS_SUCCEED;
}
// 通用查询转换成XML
IVS_INT32 CXmlProcess::GetUnifiedFormatQueryXML(const IVS_QUERY_UNIFIED_FORMAT* pUnifiedQuery, CXml &xml,
	const IVS_CHAR* pDomainCode/* = NULL*/,const IVS_CHAR* pCamerCode)
{
	// pDomainCode不要事先判空,作为默认参数
	CHECK_POINTER(pUnifiedQuery, IVS_OPERATE_MEMORY_ERROR);  

	(void)xml.AddDeclaration("1.0","UTF-8","");
	(void)xml.AddElem("Content");	
	if (NULL != pDomainCode)
	{
		(void)xml.AddChildElem("DomainCode");
		(void)xml.IntoElem();
		(void)xml.SetElemValue(pDomainCode);
		(void)xml.AddElem("PageInfo");
	}
	else
	{
		(void)xml.AddChildElem("PageInfo");
	}
	
	(void)xml.IntoElem();
	(void)xml.AddChildElem("FromIndex");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>((pUnifiedQuery->stIndex).uiFromIndex)).c_str());
	(void)xml.AddElem("ToIndex");
	(void)xml.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>((pUnifiedQuery->stIndex).uiToIndex)).c_str());

	IVS_UINT32 iFieldNum = static_cast<IVS_UINT32>(pUnifiedQuery->iFieldNum);	

	if (iFieldNum > 0) //如果是0的话,这个QueryCond节点都不要了
	{
		IVS_CHAR szValue[IVS_QUERY_VALUE_LEN+1]={0};
		(void)xml.AddElem("QueryCond");	
		for (unsigned int i=0;i < iFieldNum;i++)
		{	
			if (0 == i)
			{
				(void)xml.AddChildElem("QueryField");
			}
			else
			{
				(void)xml.AddElem("QueryField");	
			}

			(void)xml.IntoElem();
			(void)xml.AddChildElem("Field");
			(void)xml.IntoElem();

			std::string  iField = QUERYFILED.GetValue(pUnifiedQuery->stQueryField[i].eFieID);
			(void)xml.SetElemValue(iField.c_str());
			(void)xml.AddElem("Value");
			if (QUERY_CAMERA_CODE == pUnifiedQuery->stQueryField[i].eFieID || QUERY_OPERATION_OBJECT_CODE == pUnifiedQuery->stQueryField[i].eFieID)
			{
				if (NULL != pCamerCode)
				{
					(void)xml.SetElemValue(pCamerCode);
				}
				else
				{
					IVS_CHAR chDevCode[IVS_DEV_CODE_LEN+1];
					IVS_CHAR chDomaCode[IVS_DOMAIN_CODE_LEN+1];
					(IVS_VOID)CXmlProcess::ParseDevCode(pUnifiedQuery->stQueryField[i].cValue, chDevCode, chDomaCode);
					(void)xml.SetElemValue(chDevCode);
				}
			}
			else
			{
				if (!CToolsHelp::Memcpy(szValue, IVS_QUERY_VALUE_LEN, pUnifiedQuery->stQueryField[i].cValue, IVS_QUERY_VALUE_LEN))
				{
					BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Unified Format Query XML", "Memcpy szValue failed");
					return IVS_ALLOC_MEMORY_ERROR;
				}
				(void)xml.SetElemValue(szValue);
			}

			//注意如果这里的值不是0/1,直接返回参数错误的错误码
			CHECK_IVSBOOL(pUnifiedQuery->stQueryField[i].bExactQuery);
			
			(void)xml.AddElem("QueryType");
			if (MATCHED_SUCCEED == pUnifiedQuery->stQueryField[i].bExactQuery)
			{
				(void)xml.SetElemValue("EXACT");
			}
			else
			{
				(void)xml.SetElemValue("INEXACT");
			}
			xml.OutOfElem();
		}
		xml.OutOfElem();

		//注意如果这里的值不是0/1,直接返回参数错误的错误码
		CHECK_IVSBOOL(pUnifiedQuery->stOrderCond.bEnableOrder);

		if (pUnifiedQuery->stOrderCond.bEnableOrder)
		{
			(void)xml.AddElem("OrderCond");
			(void)xml.AddChildElem("OrderField");
			(void)xml.IntoElem();	
			std::string iOrderField = QUERYFILED.GetValue(pUnifiedQuery->stOrderCond.eFieID);
			(void)xml.SetElemValue(iOrderField.c_str());

			//注意如果这里的值不是0/1,直接返回参数错误的错误码
			CHECK_IVSBOOL(pUnifiedQuery->stOrderCond.bUp);

			(void)xml.AddElem("Order");
			if (MATCHED_SUCCEED==pUnifiedQuery->stOrderCond.bUp)
			{
				(void)xml.SetElemValue("UP");
			}
			else
			{
				(void)xml.SetElemValue("DOWN");
			}
			xml.OutOfElem();
		}
	}
	xml.OutOfElem();

	return IVS_SUCCEED;
}
// 拼装查询操作日志响应的xml
IVS_INT32 COCXLogMgrXMLProcess::GetResOperationLogXML(IVS_OPERATION_LOG_LIST* pOperationLogList, CXml& xmlRes)
{
	CHECK_POINTER(pOperationLogList, IVS_XML_INVALID);
	IVS_DEBUG_TRACE("");
	
	(void)xmlRes.AddDeclaration("1.0","UTF-8","");
	(void)xmlRes.AddElem("Content");
	(void)xmlRes.AddChildElem("ResultCode");
	(void)xmlRes.IntoElem();
	(void)xmlRes.SetElemValue("0");	

	(void)xmlRes.AddElem("PageInfo");
	(void)xmlRes.IntoElem();
	(void)xmlRes.AddChildElem("RealNum");
	(void)xmlRes.IntoElem();

	(void)xmlRes.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(pOperationLogList->uiTotal)).c_str());	
	(void)xmlRes.AddElem("FromIndex");
	(void)xmlRes.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>((pOperationLogList->stIndexRange).uiFromIndex)).c_str());	

	(void)xmlRes.AddElem("ToIndex");
	(void)xmlRes.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>((pOperationLogList->stIndexRange).uiToIndex)).c_str());	
	xmlRes.OutOfElem();

	(void)xmlRes.AddElem("OperationLogList");

	
	IVS_UINT32 uiFromIndex = pOperationLogList->stIndexRange.uiFromIndex;
	IVS_UINT32 uiToIndex = pOperationLogList->stIndexRange.uiToIndex;
	IVS_UINT32 uiTotal = pOperationLogList->uiTotal;
    IVS_UINT32 uiRestltNum = 0;
	// 判断实际返回来的数据有多少条
	if (uiTotal <= uiToIndex )
	{
		uiRestltNum = (uiTotal - uiFromIndex) + 1;
	}
	else 
	{
		uiRestltNum = (uiToIndex - uiFromIndex) + 1;
	}
	IVS_UINT32  i = 0;
	while(i < uiRestltNum)
	{
		IVS_OPERATION_LOG_INFO &pOperationLogInfo = pOperationLogList->stOperationInfo[i];
		i == 0?(void)xmlRes.AddChildElem("OperationLogInfo"):(void)xmlRes.AddElem("OperationLogInfo");
		(void)xmlRes.IntoElem();
		(void)xmlRes.AddChildElem("Account");
		(void)xmlRes.IntoElem();

		IVS_CHAR szAccount[IVS_NAME_LEN + 1];
		memset(szAccount, 0x0, IVS_NAME_LEN + 1);
		if (!CToolsHelp::Memcpy(szAccount, IVS_NAME_LEN, pOperationLogInfo.cAccount, IVS_NAME_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cAccount failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.SetElemValue(szAccount);

		IVS_CHAR szClientIP[IVS_IP_LEN + 1];
		memset(szClientIP, 0x0, IVS_IP_LEN + 1);
		if (!CToolsHelp::Memcpy(szClientIP, IVS_IP_LEN, pOperationLogInfo.cClientIp, IVS_IP_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cClientIp failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("ClientIP");
		(void)xmlRes.SetElemValue(szClientIP);

		(void)xmlRes.AddElem("Grade");
		(void)xmlRes.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(pOperationLogInfo.iGrade)).c_str());

		IVS_CHAR szServiceCode[IVS_DESCRIBE_LEN + 1];
		memset(szServiceCode, 0x0, IVS_DESCRIBE_LEN + 1);
		if (!CToolsHelp::Memcpy(szServiceCode, IVS_DESCRIBE_LEN, pOperationLogInfo.cServiceCode, IVS_DESCRIBE_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cServiceCode failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("ServiceCode");
		(void)xmlRes.SetElemValue(szServiceCode);

		IVS_CHAR szModuleType[IVS_DESCRIBE_LEN + 1];
		memset(szModuleType, 0x0, IVS_DESCRIBE_LEN + 1);
		if (!CToolsHelp::Memcpy(szModuleType, IVS_DESCRIBE_LEN, pOperationLogInfo.cModuleType, IVS_DESCRIBE_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cModuleType failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("ModuleType");
		(void)xmlRes.SetElemValue(szModuleType);

		IVS_CHAR szModuleCode[IVS_DEV_CODE_LEN + 1];
		memset(szModuleCode, 0x0, IVS_DEV_CODE_LEN + 1);
		if (!CToolsHelp::Memcpy(szModuleCode, IVS_DEV_CODE_LEN, pOperationLogInfo.cModuleCode, IVS_DEV_CODE_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cModuleCode failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("ModuleCode");
		(void)xmlRes.SetElemValue(szModuleCode); 

		IVS_CHAR szOperationCode[IVS_DEV_CODE_LEN + 1];
		memset(szOperationCode, 0x0, IVS_DEV_CODE_LEN + 1);
		if (!CToolsHelp::Memcpy(szOperationCode, IVS_DEV_CODE_LEN, pOperationLogInfo.cOperationCode, IVS_DEV_CODE_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cOperationCode failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("OperationCode");
		(void)xmlRes.SetElemValue(szOperationCode);

		IVS_CHAR szOperationObjectCode[IVS_DESCRIBE_LEN + 1];
		memset(szOperationObjectCode, 0x0, IVS_DESCRIBE_LEN + 1);
		if (!CToolsHelp::Memcpy(szOperationObjectCode, IVS_DESCRIBE_LEN, pOperationLogInfo.cOperationObjectCode, IVS_DESCRIBE_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cOperationCode failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("OperationObjectCode");
		(void)xmlRes.SetElemValue(szOperationObjectCode);

		IVS_CHAR szOccurTime[IVS_TIME_LEN + 1];
		memset(szOccurTime, 0x0, IVS_TIME_LEN + 1);
		if (!CToolsHelp::Memcpy(szOccurTime, IVS_TIME_LEN, pOperationLogInfo.cOccurTime, IVS_TIME_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy szOccurTime failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("OccurTime");
		(void)xmlRes.SetElemValue(szOccurTime);

		IVS_CHAR szErrorCode[IVS_DESCRIBE_LEN + 1];
		memset(szErrorCode, 0x0, IVS_DESCRIBE_LEN + 1);
		if (!CToolsHelp::Memcpy(szErrorCode, IVS_DESCRIBE_LEN, pOperationLogInfo.cErrorCode, IVS_DESCRIBE_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cErrorCode failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("ErrorCode");
		(void)xmlRes.SetElemValue(szErrorCode);

		(void)xmlRes.AddElem("Result");
		(void)xmlRes.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(pOperationLogInfo.iResult)).c_str());	

		IVS_CHAR szAdditionalInfo[IVS_DESCRIBE_LEN + 1];
		memset(szAdditionalInfo, 0x0, IVS_DESCRIBE_LEN + 1);
		if (!CToolsHelp::Memcpy(szAdditionalInfo, IVS_DESCRIBE_LEN, pOperationLogInfo.cAdditionalInfo, IVS_DESCRIBE_LEN))
		{
			BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Response Operation Log XML", "Memcpy cAdditionalInfo failed");
			return IVS_ALLOC_MEMORY_ERROR;
		}
		(void)xmlRes.AddElem("AdditionalInfo");
		(void)xmlRes.SetElemValue(szAdditionalInfo);

		xmlRes.OutOfElem();
		i++;
	}

	xmlRes.OutOfElem();
	xmlRes.OutOfElem();

	return IVS_SUCCEED;
}
// 构建获取图形的XML
IVS_INT32 COCXDrawXMLProcess::GetGraphicsGetXML(const IA_GRAPHICS *pGraphicsArr, IVS_INT32 iResultCode, ULONG ulNum, CXml& xmlGraphics, const SIZE &szGraphic)
{
	CHECK_POINTER(pGraphicsArr, IVS_FAIL);
	IVS_DEBUG_TRACE("iResultCode: %d, ulNum:%d, GraphicWidth: %d, GraphicHeight: %d", iResultCode, ulNum, szGraphic.cx, szGraphic.cy);

	char val[64] = {0};

	CHECK_SUCCESS(xmlGraphics.AddDeclaration("1.0","UTF-8",""));
	CHECK_SUCCESS(xmlGraphics.AddElem("Content"));
	CHECK_SUCCESS(xmlGraphics.AddChildElem("ResultCode"));
	CHECK_SUCCESS(xmlGraphics.IntoElem());
	SET_ELEMENT_LONG(iResultCode, val, xmlGraphics);

	CHECK_SUCCESS(xmlGraphics.AddElem("Graphics"));
	CHECK_SUCCESS(xmlGraphics.AddChildElem("GraphicNum"));
	CHECK_SUCCESS(xmlGraphics.IntoElem());
	SET_ELEMENT_LONG(ulNum, val, xmlGraphics);
	if (0 == ulNum)
	{
		xmlGraphics.OutOfElem();
		xmlGraphics.OutOfElem();
		return IVS_SUCCEED;
	}

	CHECK_SUCCESS(xmlGraphics.AddElem("GraphicList"));
	for (ULONG i = 0; i < ulNum; i++)
	{
		if (i == 0)
		{
			CHECK_SUCCESS(xmlGraphics.AddChildElem("GraphicInfo"));
			CHECK_SUCCESS(xmlGraphics.IntoElem());
		}
		else
		{
			CHECK_SUCCESS(xmlGraphics.AddElem("GraphicInfo"));
		}

		CHECK_SUCCESS(xmlGraphics.AddChildElem("GraphicType"));
		CHECK_SUCCESS(xmlGraphics.IntoElem());
		SET_ELEMENT_LONG(pGraphicsArr[i].ulGraphicType, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("GraphicGroup"));
		SET_ELEMENT_LONG(pGraphicsArr[i].ulGraphicGroup, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("GraphicGroupName"));
		SET_ELEMENT_STRING(pGraphicsArr[i].GraphicGroupName, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("GraphicBackgroundColor"));
		CHECK_SUCCESS(xmlGraphics.AddChildElem("Opacity"));
		CHECK_SUCCESS(xmlGraphics.IntoElem());
		SET_ELEMENT_LONG(pGraphicsArr[i].BgColor.Alpha, val, xmlGraphics);
		CHECK_SUCCESS(xmlGraphics.AddElem("Red"));
		SET_ELEMENT_LONG(pGraphicsArr[i].BgColor.Red, val, xmlGraphics);
		CHECK_SUCCESS(xmlGraphics.AddElem("Green"));
		SET_ELEMENT_LONG(pGraphicsArr[i].BgColor.Green, val, xmlGraphics);
		CHECK_SUCCESS(xmlGraphics.AddElem("Blue"));
		SET_ELEMENT_LONG(pGraphicsArr[i].BgColor.Blue, val, xmlGraphics);
		xmlGraphics.OutOfElem();

		CHECK_SUCCESS(xmlGraphics.AddElem("GraphicLineColor"));
		CHECK_SUCCESS(xmlGraphics.AddChildElem("Opacity"));
		CHECK_SUCCESS(xmlGraphics.IntoElem());
		SET_ELEMENT_LONG(pGraphicsArr[i].LineColor.Alpha, val, xmlGraphics);
		CHECK_SUCCESS(xmlGraphics.AddElem("Red"));
		SET_ELEMENT_LONG(pGraphicsArr[i].LineColor.Red, val, xmlGraphics);
		CHECK_SUCCESS(xmlGraphics.AddElem("Green"));
		SET_ELEMENT_LONG(pGraphicsArr[i].LineColor.Green, val, xmlGraphics);
		CHECK_SUCCESS(xmlGraphics.AddElem("Blue"));
		SET_ELEMENT_LONG(pGraphicsArr[i].LineColor.Blue, val, xmlGraphics);
		xmlGraphics.OutOfElem();

		CHECK_SUCCESS(xmlGraphics.AddElem("GraphicLineWidth"));
		SET_ELEMENT_LONG(pGraphicsArr[i].ulLineWidth, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("PointNum"));
		SET_ELEMENT_LONG(pGraphicsArr[i].ulPointsNum, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("PointList"));
		for (ULONG j = 0; j < pGraphicsArr[i].ulPointsNum; j++)
		{
			if (0 == j)
			{
				CHECK_SUCCESS(xmlGraphics.AddChildElem("Point"));
				CHECK_SUCCESS(xmlGraphics.IntoElem());
			}
			else
			{
				CHECK_SUCCESS(xmlGraphics.AddElem("Point"));
			}

			CHECK_SUCCESS(xmlGraphics.AddChildElem("X"));
			CHECK_SUCCESS(xmlGraphics.IntoElem());
			if ((0 == szGraphic.cx) || (0 == szGraphic.cy))
			{			
				SET_ELEMENT_LONG(pGraphicsArr[i].IAPoints[j].x, val, xmlGraphics);
				CHECK_SUCCESS(xmlGraphics.AddElem("Y"));
				SET_ELEMENT_LONG(pGraphicsArr[i].IAPoints[j].y, val, xmlGraphics);
			}
			else
			{
				char cPointValue[10];
				memset(cPointValue, 0, sizeof(cPointValue));
				double dPointValue = (double)pGraphicsArr[i].IAPoints[j].x / szGraphic.cx;

				(void)_snprintf_s(cPointValue, sizeof(cPointValue) - 1, "%f", dPointValue);
                cPointValue[8] = '\0';
				CHECK_SUCCESS(xmlGraphics.SetElemValue(cPointValue)); 

				CHECK_SUCCESS(xmlGraphics.AddElem("Y"));
				memset(cPointValue, 0, sizeof(cPointValue));
				dPointValue = (double)pGraphicsArr[i].IAPoints[j].y / szGraphic.cy;
				(void)_snprintf_s(cPointValue, sizeof(cPointValue) - 1, "%f", dPointValue);
                cPointValue[8] = '\0';
                CHECK_SUCCESS(xmlGraphics.SetElemValue(cPointValue)); 

			}
			xmlGraphics.OutOfElem();
		}
		xmlGraphics.OutOfElem();

		CHECK_SUCCESS(xmlGraphics.AddElem("NamePosition"));
		SET_ELEMENT_LONG(pGraphicsArr[i].NamePosition, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("DeleteByMouse"));
		SET_ELEMENT_LONG(pGraphicsArr[i].bAllowDelete, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("AddNewPoint"));
		SET_ELEMENT_LONG(pGraphicsArr[i].bAllowAddNewPoint, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("AllowModifySize"));
		SET_ELEMENT_LONG(pGraphicsArr[i].bAllowModifySize, val, xmlGraphics);
	
		CHECK_SUCCESS(xmlGraphics.AddElem("ArrowType"));
		SET_ELEMENT_LONG(pGraphicsArr[i].ulArrowType, val, xmlGraphics);

		CHECK_SUCCESS(xmlGraphics.AddElem("KeepHorizon"));
		SET_ELEMENT_LONG(pGraphicsArr[i].bKeepHorizon, val, xmlGraphics);

		xmlGraphics.OutOfElem();
	}
	xmlGraphics.OutOfElem();

	xmlGraphics.OutOfElem();
	return IVS_SUCCEED;

}
//查询平台抓拍计划:将响应结构体转换为结果XML
IVS_INT32 OCXCapturePictureXMLProcess::GetSnapshotPlanGetXML(IVS_INT32 iRet,const IVS_CHAR* pCameraCode,const IVS_SNAPSHOT_PLAN* pSnapShotPlan,CXml &xml)
{ 
	CHECK_POINTER(pCameraCode, IVS_PARA_INVALID);
	CHECK_POINTER(pSnapShotPlan, IVS_PARA_INVALID);
	IVS_DEBUG_TRACE("");

	(void)xml.AddDeclaration("1.0","UTF-8","");
	(void)xml.AddElem("Content");
	(void)xml.AddChildElem("ResultCode");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(iRet)).c_str());
	(void)xml.AddElem("SnapshotPlanInfo");
	(void)xml.AddChildElem("CameraCode");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(pCameraCode);
	(void)xml.AddElem("IsEnable");   
	(void)xml.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(pSnapShotPlan->bEnable)).c_str());
	(void)xml.AddElem("PlanType");
	(void)xml.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(pSnapShotPlan->uiPlanType)).c_str());

	(void)xml.AddElem("PlanList");
	IVS_CHAR cStartTime[IVS_TIME_LEN+1] = {0};
	IVS_CHAR cEndTime[IVS_TIME_LEN+1] = {0}; 
	for (IVS_UINT32 i=0; i<pSnapShotPlan->uiPlanInfoNum; i++)
	{
		if (i == 0)
		{        
			(void)xml.AddChildElem("PlanInfo");   
			(void)xml.IntoElem();// ------------4    
		}
		else
		{
			(void)xml.AddElem("PlanInfo"); 
		}

		(void)xml.AddChildElem("DayType");
		(void)xml.IntoElem();//  -------------3
		(void)xml.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(pSnapShotPlan->stPlanInfo[i].uiDayType)).c_str());
		(void)xml.AddElem("TimeList");    
		for (IVS_UINT32 j=0; j<pSnapShotPlan->stPlanInfo[i].uiTimeSpanInfoNum; j++)
		{
			if (j == 0)
			{
				(void)xml.AddChildElem("TimeInfo");
				(void)xml.IntoElem();// ---------------------- 2
			}
			else{
				(void)xml.AddElem("TimeInfo");
			}
			if (!CToolsHelp::Memcpy(cStartTime, IVS_TIME_LEN, pSnapShotPlan->stPlanInfo[i].stTimeSpanInfo[j].cStart, IVS_TIME_LEN))
			{
				BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Snapshot Plan Get XML", "Memcpy cStartTime failed");
				return IVS_ALLOC_MEMORY_ERROR;
			}
			if (!CToolsHelp::Memcpy(cEndTime, IVS_TIME_LEN, pSnapShotPlan->stPlanInfo[i].stTimeSpanInfo[j].cEnd, IVS_TIME_LEN))
			{
				BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Get Snapshot Plan Get XML", "Memcpy cEndTime failed");
				return IVS_ALLOC_MEMORY_ERROR;
			}
			(void)xml.AddChildElem("StartTime");
			(void)xml.IntoElem();//-------------------------1
			(void)xml.SetElemValue(cStartTime);
			(void)xml.AddElem("EndTime");
			(void)xml.SetElemValue(cEndTime); 
			(void)xml.AddElem("SnapInterval");
			(void)xml.SetElemValue(CToolsHelp::Int2Str(static_cast<IVS_INT32>(pSnapShotPlan->stPlanInfo[i].stTimeSpanInfo[j].SnapInterval)).c_str()); 
			xml.OutOfElem();//-------------------------1
		}  
		xml.OutOfElem();// ---------------------2
		xml.OutOfElem();//----------------3
	}
	xml.OutOfElem();//----------------4
	xml.OutOfElem();

	return IVS_SUCCEED;
}
IVS_INT32 CMediaXMLProcess::GetURLXML(const ST_URL_MEDIA_INFO& stUrlMediaInfo,
										const ST_SRU_LOGIN_RSP& /*stSRULoginRsp*/, CXml &xml)
{
	IVS_DEBUG_TRACE("");
	(void)xml.AddDeclaration("1.0","UTF-8","");
	(void)xml.AddElem("Content");
	if ( 0 != strlen(stUrlMediaInfo.cDomainCode))
	{
		(void)xml.AddChildElem("DomainCode");
		(void)(xml.IntoElem());	
		(void)xml.SetElemValue(stUrlMediaInfo.cDomainCode);
		(void)xml.AddElem("MediaInfo");
		(void)xml.IntoElem();
	}
	else
	{
		(void)xml.AddChildElem("MediaInfo");
		(void)xml.IntoElem();
	}
	// {
	(void)xml.AddChildElem("ServiceType");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(CToolsHelp::Int2Str(stUrlMediaInfo.ServiceType).c_str());
	(void)xml.AddElem("SrcCode");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(stUrlMediaInfo.szSrcCode);

	(void)xml.AddElem("DstCode");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(stUrlMediaInfo.szDstCode);

	const IVS_MEDIA_PARA& stMediaPara = stUrlMediaInfo.MediaPara;
	std::string strStreamType = CToolsHelp::Int2Str(stMediaPara.StreamType);
	(void)xml.AddElem("StreamID");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(strStreamType.c_str());
	(void)xml.AddElem("DstTP");
	(void)xml.IntoElem();
	std::string strProtocolType = CToolsHelp::Int2Str(stMediaPara.ProtocolType);
	(void)xml.SetElemValue(strProtocolType.c_str());
	(void)xml.AddElem("DstPP");
	(void)xml.IntoElem();
	std::string strPP = CToolsHelp::Int2Str(PACK_PROTOCOL_ES);
	(void)xml.SetElemValue(strPP.c_str());
	(void)xml.AddElem("DstCast");
	(void)xml.IntoElem();
	std::string strBroadcastType = CToolsHelp::Int2Str(stMediaPara.BroadCastType);
	(void)xml.SetElemValue(strBroadcastType.c_str());
	(void)xml.AddElem("DstIP");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(stUrlMediaInfo.szDstIP);
	(void)xml.AddElem("DstPort");
	(void)xml.IntoElem();
	(void)xml.SetElemValue(stUrlMediaInfo.szDstPort);
	if(stUrlMediaInfo.ServiceType != SERVICE_TYPE_AUDIO_CALL && stUrlMediaInfo.ServiceType != SERVICE_TYPE_AUDIO_BROADCAST)
	{
		(void)xml.AddElem("VMedia");
		(void)xml.IntoElem();
		// 视频格式改为由MU去数据库中查,SDK只把MP的视频解码能力通知给MU
		std::string strVideoDecType = IVS_C02_VIDEO_DEC_ABILITY;
		(void)xml.SetElemValue(strVideoDecType.c_str());
	}
	(void)xml.AddElem("AMedia");
	(void)xml.IntoElem();
    // 音频格式改为由MU去数据库中查,SDK只把MP的音频解码能力通知给MU
	std::string strAudioDecType = IVS_C02_AUDIO_DEC_ABILITY;
	(void)xml.SetElemValue(strAudioDecType.c_str());
	if(SERVICE_TYPE_PLAYBACK == stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_PU_PLAYBACK == stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_DOWNLOAD == stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_PU_DOWNLOAD == stUrlMediaInfo.ServiceType
        || SERVICE_TYPE_BACKUPRECORD_DOWNLOAD == stUrlMediaInfo.ServiceType
        || SERVICE_TYPE_BACKUPRECORD_PLAYBACK == stUrlMediaInfo.ServiceType
        // add by lilongxin 
        || SERVICE_TYPE_DISASTEBACKUP_DOWNLOAD == stUrlMediaInfo.ServiceType
        || SERVICE_TYPE_DISASTEBACKUP_PLAYBACK == stUrlMediaInfo.ServiceType
        )
	{
		(void)xml.AddElem("TimeSpan");
		(void)xml.IntoElem();
		(void)xml.SetElemValue(stUrlMediaInfo.szTimeSpan);
		//add by c00206592 添加NVRCode
		if (0 != strlen(stUrlMediaInfo.szNVRCode))
		{
			(void)xml.AddElem("NVRCode");
			(void)xml.IntoElem();
			(void)xml.SetElemValue(stUrlMediaInfo.szNVRCode);
		}
		//end add
	}
	(void)xml.AddElem("TransMode");
	(void)xml.IntoElem();
	std::string strTransMode = CToolsHelp::Int2Str(stMediaPara.TransMode);
	(void)xml.SetElemValue(strTransMode.c_str());
	if(0!=stUrlMediaInfo.iClientType)
	{
		std::string strClientType = CToolsHelp::Int2Str(stUrlMediaInfo.iClientType);
		(void)xml.AddElem("ClientType");
		(void)xml.IntoElem();
		(void)xml.SetElemValue(strClientType.c_str());	
	}
	if(strlen(stUrlMediaInfo.szEncryAlgorithm)>0)
	{		
		(void)xml.AddElem("EncryAlgorithm");
		(void)xml.IntoElem();
		(void)xml.SetElemValue(stUrlMediaInfo.szEncryAlgorithm);
	}
	if(SERVICE_TYPE_PLAYBACK == stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_PU_PLAYBACK == stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_PU_DOWNLOAD == stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_DOWNLOAD  ==  stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_BACKUPRECORD_DOWNLOAD == stUrlMediaInfo.ServiceType
		|| SERVICE_TYPE_BACKUPRECORD_PLAYBACK == stUrlMediaInfo.ServiceType
        // add by lilongxin 
        || SERVICE_TYPE_DISASTEBACKUP_DOWNLOAD == stUrlMediaInfo.ServiceType
        || SERVICE_TYPE_DISASTEBACKUP_PLAYBACK == stUrlMediaInfo.ServiceType
        )
	{
		(void)xml.AddElem("FileName");
		(void)xml.IntoElem();
		(void)xml.SetElemValue(stUrlMediaInfo.szFileName);
	}
	xml.OutOfElem();
	//}

	return IVS_SUCCEED;
}