chenluhua1980
2026-01-23 08fc60deca0fa2a0658a676d9dd76e0e69436312
SourceCode/Bond/Servo/PageLog.cpp
@@ -20,8 +20,9 @@
   m_hbrBkgnd = nullptr;
   m_pObserver = nullptr;
   m_nLevel = 0;
   m_strIncludeText = _T("");
   m_bIncludeRegex = FALSE;
   m_strFilterText = _T("");
   m_bRegex = FALSE;
   m_filterMode = FilterMode::Include;
}
CPageLog::~CPageLog()
@@ -52,7 +53,7 @@
// CLogDlg 消息处理程序
void CPageLog::InitRxWindow()
void CPageLog::InitRxWindows()
{
   /* code */
   // 订阅数据
@@ -70,19 +71,29 @@
               && pAny->getIntValue("exCode", level)) {
               if (level >= m_nLevel) {
                  CString strText = pszLogMsg;
                  BOOL bInclude = TRUE;
                  if (!m_strIncludeText.IsEmpty()) {
                     if (!m_bIncludeRegex) {
                        bInclude = (strText.Find(m_strIncludeText) >= 0);
                  BOOL bMatch = TRUE;
                  if (!m_strFilterText.IsEmpty()) {
                     if (!m_bRegex) {
                        bMatch = (strText.Find(m_strFilterText) >= 0);
                     }
                     else {
                        bInclude = std::regex_search((LPTSTR)(LPCTSTR)strText,
                           std::regex((LPTSTR)(LPCTSTR)m_strIncludeText));
                        CString strTemp = strText;
                        strTemp.TrimRight();
                        try {
                           bMatch = std::regex_match((LPTSTR)(LPCTSTR)strTemp,
                              std::regex((LPTSTR)(LPCTSTR)m_strFilterText));
                        }
                        catch (const std::regex_error& e) {
                           TRACE(_T("正在表达式匹配检测异常: %s\n"), e.what());
                        }
                     }
                     if (m_filterMode == FilterMode::Exclude) {
                        bMatch = !bMatch;
                     }
                  }
                  if (bInclude) {
                  if (bMatch) {
                     strText.Replace("\n", "\r\n");
                     AppendLog(level, (LPTSTR)(LPCTSTR)strText);
                  }
@@ -105,14 +116,17 @@
BOOL CPageLog::OnInitDialog()
{
   CDialogEx::OnInitDialog();
   InitRxWindow();
   InitRxWindows();
   // 缓存
   m_nLevel = theApp.m_model.m_configuration.getLogcatLevel();
   theApp.m_model.m_configuration.getLogcatIncludeText(m_strIncludeText);
   m_bIncludeRegex = theApp.m_model.m_configuration.isLogcatIncludeRegex();
   theApp.m_model.m_configuration.getLogcatIncludeText(m_strFilterText);
   m_bRegex = theApp.m_model.m_configuration.isLogcatIncludeRegex();
   theApp.m_model.m_configuration.getCustomLogcatIncludeTexts(m_customIncludeTexts);
   m_customIncludeTexts.clear();
   m_customIncludeTexts.push_back("包含");
   m_customIncludeTexts.push_back("排除");
   // Level
@@ -135,6 +149,9 @@
      strIcon1, IMAGE_ICON, 24, 24,
      LR_LOADFROMFILE | LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
   m_btnInclude.SetIcon(hIcon, hIcon, 24);
   m_filterMode = (FilterMode)theApp.m_model.m_configuration.getFilterMode();
   m_btnInclude.SetTextRight();
   m_btnInclude.SetWindowText(m_filterMode == FilterMode::Include ? "包含" : "排除");
   {
      HMENU hMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCEA(IDR_MENU_INCLUDE));
@@ -143,44 +160,20 @@
      int i = 0;
      for (auto& item : m_customIncludeTexts) {
         i++;
         InsertMenu(hSubMenu, 0, MF_BYPOSITION, 0x1998 + i, item.c_str());
         InsertMenu(hSubMenu, i, MF_BYPOSITION, 0x1998 + i, item.c_str());
         m_btnInclude.SetMenu(hMenu);
      }
   }
   SetDlgItemText(IDC_EDIT_INCLUDE, m_strIncludeText);
   SetDlgItemText(IDC_EDIT_INCLUDE, m_strFilterText);
   CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
   pCheckBox->SetCheck(m_bIncludeRegex ? BST_CHECKED : BST_UNCHECKED);
   pCheckBox->SetCheck(m_bRegex ? BST_CHECKED : BST_UNCHECKED);
   // 内容
   m_logEdit.SetMaxLineCount(500);
   m_logEdit.SetMaxLineCount(6000);
   m_logEdit.SetLimitText(-1);
<<<<<<< HEAD:SourceCode/Bond/Servo/LogDlg.cpp
   std::thread([this]() {
      constexpr int nMaxWaitMs = 3000;  // 最多等待 3 秒
      constexpr int nStepMs = 1;        // 每次等待 1ms
      int nElapsed = 0;
      while (nElapsed < nMaxWaitMs) {
         if (theApp.m_model.getObservable() != nullptr) {
            InitRxWindow();
            return;
         }
         std::this_thread::sleep_for(std::chrono::milliseconds(nStepMs));
         nElapsed += nStepMs;
      }
      // 超时也可以发消息记录下日志
      TRACE(_T("InitRxWindow 超时,未执行\n"));
   }).detach();
=======
>>>>>>> clh:SourceCode/Bond/Servo/PageLog.cpp
   Resize();
@@ -314,28 +307,22 @@
void CPageLog::OnButtonIncludeMenuClicked(NMHDR* pNMHDR, LRESULT* pResult)
{
   BLBUTTON_NMHDR* pblbNmhdr = reinterpret_cast<BLBUTTON_NMHDR*>(pNMHDR);
   int position = (int)pblbNmhdr->dwData;
   std::string& strInclude = m_customIncludeTexts.at(position);
   SetDlgItemText(IDC_EDIT_INCLUDE, strInclude.c_str());
   CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
   m_bIncludeRegex = FALSE;
   pCheckBox->SetCheck(BST_UNCHECKED);
   theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bIncludeRegex);
   theApp.m_model.m_configuration.setLogcatIncludeText(m_strIncludeText);
   m_filterMode = (FilterMode)pblbNmhdr->dwData;
   theApp.m_model.m_configuration.setFilterMode((int)m_filterMode);
   m_btnInclude.SetWindowText(m_filterMode == FilterMode::Include ? "包含" : "排除");
   *pResult = 0;
}
void CPageLog::OnEnChangeEditInclude()
{
   GetDlgItemText(IDC_EDIT_INCLUDE, m_strIncludeText);
   theApp.m_model.m_configuration.setLogcatIncludeText(m_strIncludeText);
   GetDlgItemText(IDC_EDIT_INCLUDE, m_strFilterText);
   theApp.m_model.m_configuration.setLogcatIncludeText(m_strFilterText);
}
void CPageLog::OnBnClickedCheckRegex()
{
   CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
   m_bIncludeRegex = pCheckBox->GetCheck();
   theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bIncludeRegex);
   m_bRegex = pCheckBox->GetCheck();
   theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bRegex);
}