| | |
| | | m_hWorkStop = nullptr; |
| | | m_hWorkThreadHandle = nullptr; |
| | | m_nTimeoutCount = 0; |
| | | m_onSyncingStateChanged = nullptr; |
| | | ::InitializeCriticalSection(&m_cs); |
| | | } |
| | | |
| | |
| | | m_nTimeoutCount = 0; |
| | | unlock(); |
| | | |
| | | if (m_onSyncingStateChanged != nullptr) { |
| | | m_onSyncingStateChanged(m_nSyncStatus); |
| | | } |
| | | |
| | | if (m_hWorkStop == nullptr) { |
| | | m_hWorkStop = ::CreateEvent(NULL, TRUE, FALSE, NULL); |
| | |
| | | m_nSyncStatus = SS_FAILED; |
| | | m_nTimeoutCount = 0; |
| | | unlock(); |
| | | |
| | | if (m_onSyncingStateChanged != nullptr) { |
| | | m_onSyncingStateChanged(m_nSyncStatus); |
| | | } |
| | | } |
| | | |
| | | void CRecipesManager::syncTimeout() |
| | | { |
| | | lock(); |
| | | m_nSyncStatus = SS_TIMEOUT; |
| | | m_nTimeoutCount = 0; |
| | | unlock(); |
| | | |
| | | if (m_onSyncingStateChanged != nullptr) { |
| | | m_onSyncingStateChanged(m_nSyncStatus); |
| | | } |
| | | } |
| | | |
| | | short CRecipesManager::decodeRecipeListReport(const char* pszData, size_t size) |
| | |
| | | |
| | | } |
| | | else if (reportType == RT_REQUEST_FROM_EAS) { |
| | | int nRet = pRecipeList->addRecipePacket(toatlGroupCount, currentGroupCount, pszIdsData, 250 * 2); |
| | | int nRet = pRecipeList->addRecipePacket(totalMasterRecipeCount, toatlGroupCount, currentGroupCount, pszIdsData, 250 * 2); |
| | | if (MRLRC_CURRENT_RECIPE_COMPLETE == nRet) { |
| | | lock(); |
| | | if (m_nTotalMasterRecipeCount == m_mapRecipesTemp.size()) { |
| | | for (auto item : m_mapRecipes) { |
| | | delete item.second; |
| | | } |
| | | m_mapRecipes = m_mapRecipesTemp; |
| | | m_mapRecipesTemp.clear(); |
| | | m_nSyncStatus = SS_COMPLETE; |
| | | unlock(); |
| | | return MRLRC_OK; |
| | | for (auto item : m_mapRecipes) { |
| | | delete item.second; |
| | | } |
| | | m_mapRecipes = m_mapRecipesTemp; |
| | | m_mapRecipesTemp.clear(); |
| | | m_nSyncStatus = SS_LIST_COMPLETE; |
| | | unlock(); |
| | | |
| | | if (m_onSyncingStateChanged != nullptr) { |
| | | m_onSyncingStateChanged(m_nSyncStatus); |
| | | } |
| | | |
| | | return MRLRC_OK; |
| | | } |
| | | else if (MRLRC_CONTINUE == nRet) { |
| | | return MRLRC_CONTINUE; |
| | |
| | | |
| | | |
| | | |
| | | // 找到对应CRecipeList, 找不到则新建 |
| | | /* |
| | | // 找到对应CRecipeList, 找不到则返回NG |
| | | lock(); |
| | | CRecipeList* pRecipeList = getRecipeListFromTemp(unitNo); |
| | | CRecipeList* pRecipeList = getRecipeList(unitNo); |
| | | if (pRecipeList == nullptr) { |
| | | pRecipeList = new CRecipeList(unitNo); |
| | | m_mapRecipesTemp[unitNo] = pRecipeList; |
| | | unlock(); |
| | | return MRLRC_NG; |
| | | } |
| | | unlock(); |
| | | ASSERT(pRecipeList); |
| | | */ |
| | | |
| | | /* |
| | | 1: Create |
| | |
| | | 3: Delete |
| | | 4: Request from EAS |
| | | */ |
| | | /* |
| | | if (reportType == RT_CREATE) { |
| | | |
| | | } |
| | |
| | | |
| | | } |
| | | else if (reportType == RT_REQUEST_FROM_EAS) { |
| | | int nRet = pRecipeList->addRecipePacket(toatlGroupCount, currentGroupCount, pszIdsData, 250 * 2); |
| | | int nRet = pRecipeList->addParamsPacket(totalParameterCount, toatlGroupCount, currentGroupCount, |
| | | unitNo, localRecipeId, |
| | | pszParameterData, 250 * 2); |
| | | if (MRLRC_CURRENT_RECIPE_COMPLETE == nRet) { |
| | | lock(); |
| | | if (m_nTotalMasterRecipeCount == m_mapRecipesTemp.size()) { |
| | | for (auto item : m_mapRecipes) { |
| | | delete item.second; |
| | | } |
| | | m_mapRecipes = m_mapRecipesTemp; |
| | | m_mapRecipesTemp.clear(); |
| | | m_nSyncStatus = SS_COMPLETE; |
| | | unlock(); |
| | | return MRLRC_OK; |
| | | } |
| | | m_nSyncStatus = SS_PARAMS_COMPLETE; |
| | | unlock(); |
| | | |
| | | if (m_onSyncingStateChanged != nullptr) { |
| | | m_onSyncingStateChanged(m_nSyncStatus); |
| | | } |
| | | |
| | | return MRLRC_OK; |
| | | } |
| | | else if (MRLRC_CONTINUE == nRet) { |
| | | return MRLRC_CONTINUE; |
| | | } |
| | | |
| | | return nRet; |
| | | } |
| | | */ |
| | | |
| | | |
| | | return MRLRC_OK; |
| | | } |
| | |
| | | auto iter = m_mapRecipesTemp.find(unitNo); |
| | | if (iter == m_mapRecipesTemp.end()) return nullptr; |
| | | return iter->second; |
| | | } |
| | | |
| | | CRecipeList* CRecipesManager::getRecipeList(int unitNo) |
| | | { |
| | | auto iter = m_mapRecipes.find(unitNo); |
| | | if (iter == m_mapRecipes.end()) return nullptr; |
| | | return iter->second; |
| | | } |
| | | |
| | | bool CRecipesManager::saveRecipeList(int unitNo, std::string& strFilepath) |
| | | { |
| | | CRecipeList* pRecipeList = getRecipeList(unitNo); |
| | | if (pRecipeList == nullptr) return false; |
| | | return pRecipeList->serialize(strFilepath); |
| | | } |
| | | |
| | | bool CRecipesManager::readRecipeList(int unitNo, std::string& strFilepath) |
| | | { |
| | | CRecipeList* pRecipeList = getRecipeList(unitNo); |
| | | if (pRecipeList == nullptr) { |
| | | pRecipeList = new CRecipeList(); |
| | | m_mapRecipes[unitNo] = pRecipeList; |
| | | } |
| | | return pRecipeList->deserialize(strFilepath); |
| | | } |
| | | |
| | | void CRecipesManager::setOnSyncingStateChanged(ONSYNCINGSTATECHANGED block) |
| | | { |
| | | m_onSyncingStateChanged = block; |
| | | } |
| | | |
| | | unsigned CRecipesManager::TimeoutCheckWorkingProc() |
| | |
| | | if (m_nSyncStatus == SS_SYNCING) { |
| | | m_nTimeoutCount++; |
| | | if (m_nTimeoutCount > 10) { |
| | | m_nSyncStatus = SS_TIMEOUT; |
| | | unlock(); |
| | | syncTimeout(); |
| | | TRACE("CRecipesManager::TimeoutCheckWorkingProc 超时退出\n"); |
| | | lock(); |
| | | } |
| | | } |
| | | |