#include "stdafx.h" #include "PanelSerialXMLControl.h" PanelSerialXMLControl::PanelSerialXMLControl() { m_ResData.add(CcosPSLPanelType, ""); m_ResData.add(CcosPSLPanelSerial, ""); m_ResData.add(CcosPSLActive, ""); m_ResData.add(CcosPSLIPAddress, ""); m_ResData.add(CcosPSLCalibrationTime, ""); m_ResData.add(CcosPSLPanelSize, ""); m_strPanelXMLPath = ""; } PanelSerialXMLControl::~PanelSerialXMLControl() { } bool PanelSerialXMLControl::SetPanelXMLPath(const char* strPanelXMLPath) { Thread_Lock(); string strTem = strPanelXMLPath; if (m_strPanelXMLPath == strTem) { Thread_UnLock(); return true; } m_strPanelXMLPath = strPanelXMLPath; if (!PathFileExists(strPanelXMLPath)) { m_ResPanelSerialList.add("Document", ""); m_ResPanelSerialList.SaveFile(m_strPanelXMLPath.c_str()); Thread_UnLock(); return true; } if (m_ResPanelSerialList.loadFile(strPanelXMLPath)) { Thread_UnLock(); return true; } Thread_UnLock(); return false; } bool PanelSerialXMLControl::AddNewPanelSerial(PanelSerialList PSL) { Thread_Lock(); try{ int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey); int nIdx = (int)m_ResPanelSerialList["Document"].GetFirstOf(CcosPSLPanelKey); int i = 0; for (; i < nDPCCount; i++) { string strSN = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial]; if (strSN == PSL.strPanelSN) { break; } nIdx = m_ResPanelSerialList["Document"].GetNextOf(CcosPSLPanelKey, nIdx); } if (i == nDPCCount) { //save 2 the config m_ResData[CcosPSLPanelType] = PSL.strPanelType.c_str(); m_ResData[CcosPSLPanelSerial] = PSL.strPanelSN.c_str(); m_ResData[CcosPSLActive] = PSL.strActive.c_str(); m_ResData[CcosPSLIPAddress] = PSL.strIPAddress.c_str(); m_ResData[CcosPSLCalibrationTime] = PSL.strCalibDate.c_str(); m_ResData[CcosPSLPanelSize] = PSL.strPanelSize.c_str(); m_ResPanelSerialList["Document"].add(CcosPSLPanelKey, m_ResData); } else if (i < nDPCCount) { m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelType] = PSL.strPanelType.c_str(); m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial] = PSL.strPanelSN.c_str(); m_ResPanelSerialList["Document"][nIdx][CcosPSLActive] = PSL.strActive.c_str(); m_ResPanelSerialList["Document"][nIdx][CcosPSLIPAddress] = PSL.strIPAddress.c_str(); m_ResPanelSerialList["Document"][nIdx][CcosPSLCalibrationTime] = PSL.strCalibDate.c_str(); m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSize] = PSL.strPanelSize.c_str(); } m_ResPanelSerialList.SaveFile(m_strPanelXMLPath.c_str()); } catch (...) { Thread_UnLock(); //printf("Add new panelserial failed, %s\r\n", e.what()); return false; } Thread_UnLock(); return true; } bool PanelSerialXMLControl::GetPanelSerialList(list &listPanelSerial) { Thread_Lock(); //重新加载一遍,避免多平板共享一个文件时,一块板修改了内容,另一个板还使用修改之前的内容 if (!m_ResPanelSerialList.loadFile(m_strPanelXMLPath.c_str())) { Thread_UnLock(); return false; } try{ int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey); int nIdx = (int)m_ResPanelSerialList["Document"].GetFirstOf(CcosPSLPanelKey); int i = 0; for (; i < nDPCCount; i++) { PanelSerialList PSL; PSL.strActive = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLActive]; PSL.strCalibDate = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLCalibrationTime]; PSL.strIPAddress = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLIPAddress]; PSL.strPanelSize = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSize]; PSL.strPanelSN = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial]; PSL.strPanelType = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelType]; listPanelSerial.push_back(PSL); nIdx = m_ResPanelSerialList["Document"].GetNextOf(CcosPSLPanelKey, nIdx); } } catch (...) { Thread_UnLock(); return false; } Thread_UnLock(); return true; } bool PanelSerialXMLControl::ClearSNList() { Thread_Lock(); try{ int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey); int i = 0; for (; i < nDPCCount; i++) { m_ResPanelSerialList["Document"].eraseOneOf(CcosPSLPanelKey, i); } m_ResPanelSerialList.SaveFile(m_strPanelXMLPath.c_str()); } catch (...) { Thread_UnLock(); return false; } Thread_UnLock(); return true; } bool PanelSerialXMLControl::GetActivedFDList(list &listActivedFD) { Thread_Lock(); try{ int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey); int nIdx = (int)m_ResPanelSerialList["Document"].GetFirstOf(CcosPSLPanelKey); int i = 0; for (; i < nDPCCount; i++) { string strActived = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLActive]; if (strActived == "true") { PanelSerialList PSL; PSL.strActive = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLActive]; PSL.strCalibDate = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLCalibrationTime]; PSL.strIPAddress = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLIPAddress]; PSL.strPanelSize = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSize]; PSL.strPanelSN = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial]; PSL.strPanelType = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelType]; listActivedFD.push_back(PSL); } nIdx = m_ResPanelSerialList["Document"].GetNextOf(CcosPSLPanelKey, nIdx); } } catch (...) { Thread_UnLock(); return false; } Thread_UnLock(); return true; }