123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #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<PanelSerialList> &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<PanelSerialList> &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;
- }
|