📄 ctcommondoc.cpp
字号:
} else { strMsg.Format(_T("There are %d unresolved conflict%s."),conflicts.size(),1==conflicts.size()?_T(""):_T("s")); } rc=(IDYES==CUtils::MessageBoxFT(MB_YESNO|MB_DEFBUTTON2,_T("%s Make the change anyway?"),strMsg))?CdlInferenceCallbackResult_Continue:CdlInferenceCallbackResult_Cancel; } return rc;}// a CDL transaction handler to refresh the configuration treevoid CConfigToolDoc::CdlTransactionHandler (const CdlTransactionCallback & data){static int nNesting=0;TRACE(_T("Transaction handler: nesting level=%d\n"),nNesting++); CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); std::vector<CdlValuable>::const_iterator val_i; std::vector<CdlNode>::const_iterator node_i; std::list<CdlConflict>::const_iterator conf_i; CControlView *pControlView=CConfigTool::GetControlView(); for (val_i = data.value_changes.begin(); val_i != data.value_changes.end(); val_i++) { const CString strName((*val_i)->get_name().c_str()); TRACE(_T("%s %s : value change\n"), CString ((*val_i)->get_class_name().c_str()), strName); pControlView->Refresh(strName); if (strName==_T("CYGHWR_MEMORY_LAYOUT")){ // the memory layout has changed... pDoc->SwitchMemoryLayout (false); // ...so display a new one } } for (node_i = data.active_changes.begin(); node_i != data.active_changes.end(); node_i++) { const CString strName((*node_i)->get_name().c_str()); TRACE(_T("%s %s : this has become active or inactive\n"), CString ((*node_i)->get_class_name().c_str()), CString ((*node_i)->get_name().c_str())); if (! dynamic_cast<CdlInterface> (*node_i)){ // if not an interface node pControlView->Refresh(strName); } } for (val_i = data.legal_values_changes.begin(); val_i != data.legal_values_changes.end(); val_i++) { const CString strName((*node_i)->get_class_name().c_str()); TRACE(_T("%s %s : the legal_values list has changed, a new widget may be needed.\n"), CString ((*val_i)->get_class_name().c_str()), strName); } for (val_i = data.value_source_changes.begin(); val_i != data.value_source_changes.end(); val_i++) { const CString strName((*val_i)->get_name().c_str()); CdlValueSource source = (*val_i)->get_source(); TRACE(_T("%s %s : the value source has changed to %s\n"), CString ((*val_i)->get_class_name().c_str()), strName, CString ((CdlValueSource_Default == source) ? "default" : (CdlValueSource_Inferred == source) ? "inferred" : (CdlValueSource_Wizard == source) ? "wizard" : "user")); pControlView->Refresh (strName); } pDoc->UpdateFailingRuleCount();nNesting--;}// Three hack functions.const CString CConfigToolDoc::CurrentMemoryLayout (){ const CConfigItem * pItem = Find (_T("CYGHWR_MEMORY_LAYOUT"));#ifdef _DEBUG if(NULL==pItem){ TRACE(_T("Warning - CurrentMemoryLayout() returning NULL\n")); }#endif return pItem ? pItem->StringValue () : _T("");}const CString CConfigToolDoc::CurrentTestingIdentifier (){ // use the CDL target as the default testing identifier // override in the forthcoming testing identifier dialog as necessary return GetCdlConfig()->get_hardware ().c_str ();// const CConfigItem * pItem = Find (_T("CYGTST_TESTING_IDENTIFIER"));//#ifdef _DEBUG// if(NULL==pItem){// TRACE(_T("Warning - CurrentTestingIdentifier() returning NULL\n"));// }//#endif// return pItem ? pItem->StringValue () : _T("");}const CString CConfigToolDoc::CurrentStartup(){ const CConfigItem * pItem = Find (_T("CYG_HAL_STARTUP"));#ifdef _DEBUG if(NULL==pItem){ TRACE(_T("Warning - CurrentStartup() returning NULL\n")); }#endif return pItem ? pItem->StringValue () : _T(""); /* for(int nItem=0;nItem<ItemCount();nItem++){ CConfigItem *pItem=Item(nItem); const CString strName(pItem->Name()); if(0==strName.Compare(_T("Startup type")) && pItem->IsEnabled()){ return pItem->StringValue(); } } return _T("ram"); // FIXME - assume ram startup for now if no startup item */}void CConfigToolDoc::UpdateFailingRuleCount(){ int nCount=0; if (GetCdlConfig ()){ // if configuration information // calculate the number of conflicts nCount = // GetCdlConfig ()->get_structural_conflicts ().size () + ignore for now GetCdlConfig ()->get_all_conflicts ().size (); // update the conflicts view if (CConfigTool::GetRulesView ()) { CConfigTool::GetRulesView ()->FillRules (); } } if(CConfigTool::GetMain()){ CConfigTool::GetMain()->SetFailRulePane(nCount); }}void CConfigToolDoc::LogConflicts (const std::list<CdlConflict> & conflicts){ std::list<CdlConflict>::const_iterator conf_i; for (conf_i = conflicts.begin (); conf_i != conflicts.end (); conf_i++) // for each conflict { CString strExplain = (* conf_i)->get_explanation ().c_str (); // get the conflict explanation CConfigTool::Log (CUtils::StripExtraWhitespace (strExplain)); // display the message in the output window }}CString CConfigToolDoc::GetPackageName (const CString & strAlias){ const std::vector<std::string> & packages = m_CdlPkgData->get_packages (); std::vector<std::string>::const_iterator package_i; for (package_i = packages.begin (); package_i != packages.end (); package_i++) { const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i); CString strPackageAlias = aliases [0].c_str (); if (aliases.size () && (0 == strAlias.Compare (strPackageAlias))) return package_i->c_str (); } return _T("");}void CConfigToolDoc::DeleteContents() { TRACE(_T("###DeleteContents()\n"));#ifndef PLUGIN CDocument::DeleteContents();#endif RemoveAllItems(); TRACE(_T("###DeleteContents done\n"));}void CConfigToolDoc::SelectPackages (){ CCdlPackagesDialog dlg; // This map holds the CConfigItem pointers for the packages loaded before the dialog is invoked. // We cannot use Find(), which traverses all items - potentially those that have been removed CMapStringToPtr arLoadedPackages; // generate the contents of the add/remove list boxes const std::vector<std::string> & packages = m_CdlPkgData->get_packages (); std::vector<std::string>::const_iterator package_i; for (package_i = packages.begin (); package_i != packages.end (); package_i++) { // if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not list hardware packages { const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i); CString strMacroName = package_i->c_str (); // use the first alias (if any) as the package identifier CString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName; CConfigItem * pItem = Find (strMacroName); if (pItem) // if the package is loaded { arLoadedPackages.SetAt(strMacroName,pItem); // pass the currently selected package version string to the dialog box const CdlValuable valuable = pItem->GetCdlValuable(); dlg.Insert (strPackageName, TRUE, NULL, valuable ? (LPCTSTR) CString (valuable->get_value ().c_str ()) : NULL); } else { // pass version string of the most latest version to the dialog box dlg.Insert (strPackageName, FALSE, NULL, (LPCTSTR) CString (m_CdlPkgData->get_package_versions (* package_i) [0].c_str ())); } } } if (IDOK == dlg.DoModal ()) { bool bChanged = false; // until proved otherwise // determine whether each package has changed loaded/unloaded state for (package_i = packages.begin (); package_i != packages.end (); package_i++) // if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not check hardware packages { const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i); CString strMacroName = package_i->c_str (); // use the first alias (if any) as the package identifier CString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName; CConfigItem *pItem=NULL; bool bPreviouslyLoaded=arLoadedPackages.Lookup(strMacroName,(void *&)pItem); bool bNowLoaded=dlg.IsAdded (strPackageName); // unload packages which are no longer required before // loading new ones to avoid potential duplicate macro definitions if (! bNowLoaded && bPreviouslyLoaded){ // The package was loaded but should now be unloaded: bChanged|=pItem->Unload(); } else if (bNowLoaded) {// if the package should be loaded const CString strVersion(dlg.GetVersion (strPackageName)); if (bPreviouslyLoaded) { // if the package is not already loaded bChanged|=pItem->ChangeVersion(strVersion); } else { // the package was not loaded but should now be loaded TRACE (_T("Loading package %s\n"), strMacroName); try { GetCdlConfig()->load_package (CUtils::UnicodeToStdStr(strMacroName), CUtils::UnicodeToStdStr (strVersion), CConfigToolDoc::CdlParseErrorHandler, CConfigToolDoc::CdlParseWarningHandler); bChanged=true; } catch (CdlStringException exception) { CUtils::MessageBoxF(_T("Error loading package %s:\n\n%s"), strMacroName, CString (exception.get_message ().c_str ())); } catch (...) { CUtils::MessageBoxF(_T("Error loading package %s."), strMacroName); } } } } if (bChanged) {// at least one package was loaded, unloaded or changed version SetModifiedFlag(); RegenerateData(); } }}bool CConfigToolDoc::SetValue(CConfigItem &ti,ItemIntegerType nValue, CdlTransaction transaction/*=NULL*/){ switch(ti.Type()){ case CConfigItem::Enum: case CConfigItem::Integer: // case CConfigItem::Boolean: // case CConfigItem::Radio: break; case CConfigItem::None: case CConfigItem::String: default: ASSERT(FALSE); break; } bool rc=false; bool bChangingMemmap=MemoryMap.map_modified () && ((ti.Macro ().Compare (_T ("CYG_HAL_STARTUP")) == 0)); if(nValue==ti.Value()){ return true; } // test if the new integer value is in range if (CConfigItem::Integer == ti.Type ()) { const CdlValuable valuable = ti.GetCdlValuable(); CdlListValue list_value; CdlEvalContext context (NULL, ti.GetCdlItem (), ti.GetCdlItem ()->get_property (CdlPropertyId_LegalValues)); valuable->get_legal_values ()->eval (context, list_value); if (! list_value.is_member ((cdl_int) nValue)) { if (nValue==(ItemIntegerType) valuable->get_integer_value (CdlValueSource_Current) || IDNO == CUtils::MessageBoxFT (MB_YESNO, _T("%s is not a legal value for %s.\n\nDo you want to use this value anyway?"), CUtils::IntToStr (nValue, CConfigTool::GetConfigToolDoc ()->m_bHex), ti.Macro ())) goto Exit; }; } // if(!ti.CanSetValue(nValue)) // { // if(bInteractive){ // CString strExplanation; // if(CConfigItem::Integer==ti.Type()){ // strExplanation.Format(_T(" [value must lie in the range %d..%d]"), // CUtils::IntToStr(ti.Min(),m_bHex), // CUtils::IntToStr(ti.Max()),m_bHex); // } // CUtils::MessageBoxF( // _T("Cannot set '%s' to %s%s"), // ti.ItemNameOrMacro(), CUtils::IntToStr(nValue,m_bHex), strExplanation); // } // goto Exit; // } // warn the user if the current memory layout has been changed and will be lost // this will happen when the layout has been modified and the target-platform-startup is changed if (bChangingMemmap && IDCANCEL==CUtils::MessageBoxFT(MB_OKCANCEL,_T("Changes to the current memory layout will be lost."))){ goto Exit; } // Save state if(!ti.SetValue(nValue,transaction)){ // CanSetValue above should have caught this CUtils::MessageBoxF(_T("Cannot set '%s' to %d"),ti.ItemNameOrMacro(), nValue); goto Exit; } rc=true;Exit: if(rc){ SetModifiedFlag(); UpdateFailingRuleCount (); UpdateAllViews (NULL, CConfigToolDoc::ValueChanged, (CObject *)&ti); // switch to new memory layout when target, platform or startup changes // but ignore cases where a target or platform is being deactivated (PR 19363) // if (((CurrentTarget () != pOldTarget) || (CurrentPlatform () != strOldPlatform) || (ti.Name ().Compare (_T ("Startup type")) == 0)) && // ((ti.Type () != CConfigItem::Radio) || (nValue))) // SwitchMemoryLayout ((CurrentTarget () != pOldTarget) || (CurrentPlatform () != strOldPlatform)); } return rc;}bool CConfigToolDoc::OpenRepository(LPCTSTR pszRepository/*=NULL*/,bool bPromptInitially/*=false*/){ if(!m_bRepositoryOpen){ CWaitCursor wait; CIdleMessage IM(_T("Opening repository")); UpdateFailingRuleCount(); CFileName strNewRepository; while(!m_bRepositoryOpen){ if(bPromptInitially){ CFolderDialog dlg(/*BOOL bAllowCreation=*/false); dlg.m_strDesc=_T("Please specify the root of the eCos repository tree."); dlg.m_strTitle=_T("Choose folder for eCos repository"); dlg.m_strFolder=strNewRepository; CConfigTool::DismissSplash(); if(IDCANCEL==dlg.DoModal()){ return false; } strNewRepository=dlg.m_strFolder; } else { // Use what came in as parameter or what was found in registry
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -