Browse Source

change view_message. test ok.

yuchuli 3 năm trước cách đây
mục cha
commit
751425d59c

+ 15 - 5
src/common/makeprotointerface/protointerface.cpp

@@ -189,24 +189,26 @@ void protointerface::Proc()
     WriteCodeLine("#include <iostream>",&xFileout);
     WriteCodeLine("#include <QString>",&xFileout);
     WriteCodeLine("#include <QStringList>",&xFileout);
+    WriteCodeLine("#include <QMutex>",&xFileout);
     WriteCodeLine("",&xFileout);
 
     char strline[1000];
-    WriteCodeLine("",&xFileout);
     WriteCodeLine("namespace iv",&xFileout);
     WriteCodeLine("{",&xFileout);
     WriteCodeLine("\tstruct protomsgtype",&xFileout);
     WriteCodeLine("\t{",&xFileout);
     WriteCodeLine("\t\tstd::string mstrtypename;",&xFileout);
-    WriteCodeLine("\t\t::google::protobuf::Message * mpmsg;",&xFileout);
+    WriteCodeLine("\t\tstd::shared_ptr<::google::protobuf::Message> mpmsg;",&xFileout);
     WriteCodeLine("\t};",&xFileout);
     WriteCodeLine("}",&xFileout);
     WriteCodeLine("",&xFileout);
 
 
     snprintf(strline,1000,"#define MSGCOUNT %u\n",(unsigned int)xvectorclassname.size());xFileout.write(strline);
-    snprintf(strline,1000,"const int typecount = %u;\n",(unsigned int)xvectorclassname.size());xFileout.write(strline);
-    snprintf(strline,1000,"iv::protomsgtype gmsgtype[MSGCOUNT];\n");xFileout.write(strline);
+    snprintf(strline,1000,"static const int typecount = %u;\n",(unsigned int)xvectorclassname.size());xFileout.write(strline);
+    snprintf(strline,1000,"static iv::protomsgtype gmsgtype[MSGCOUNT];\n");xFileout.write(strline);
+    WriteCodeLine("static bool gbUpdateMsgType = false;",&xFileout);
+    WriteCodeLine("static QMutex mMutexUpdateMstType;",&xFileout);
 
 
     WriteCodeLine("",&xFileout);
@@ -257,16 +259,24 @@ void protointerface::Proc()
 //    snprintf(strline,1000,"{\n");xFileout.write(strline);
     snprintf(strline,1000,"void InitMsgType()\n");xFileout.write(strline);
     snprintf(strline,1000,"{\n");xFileout.write(strline);
+    WriteCodeLine("\tmMutexUpdateMstType.lock();",&xFileout);
+    WriteCodeLine("\tif(gbUpdateMsgType)",&xFileout);
+    WriteCodeLine("\t{",&xFileout);
+    WriteCodeLine("\t\tmMutexUpdateMstType.unlock();",&xFileout);
+    WriteCodeLine("\t\treturn;",&xFileout);
+    WriteCodeLine("\t}",&xFileout);
     for(i=0;i<xvectorclassname.size();i++)
     {
 
         snprintf(strline,1000,"\tgmsgtype[%d].mstrtypename = \"%s\";\n",
                  i,xvectorclassname[i].data());
         xFileout.write(strline);
-        snprintf(strline,1000,"\tgmsgtype[%d].mpmsg  = (::google::protobuf::Message *)(new %s);\n",
+        snprintf(strline,1000,"\tgmsgtype[%d].mpmsg  = std::shared_ptr<::google::protobuf::Message>(new %s);\n",
                  i,xvectorclassname[i].data());
         xFileout.write(strline);
     }
+    WriteCodeLine("\tgbUpdateMsgType = true;",&xFileout);
+    WriteCodeLine("\tmMutexUpdateMstType.unlock();",&xFileout);
     snprintf(strline,1000,"}\n");xFileout.write(strline);
 
     snprintf(strline,1000,"\n");xFileout.write(strline);

+ 49 - 3
src/tool/view_message/dialogviewmessage.cpp

@@ -32,14 +32,16 @@ DialogViewMessage::DialogViewMessage(std::string strmsgname,QWidget *parent) :
     std::string gx = x.GetTypeName();
 
     connect(this,SIGNAL(msgupdate()),this,SLOT(UpdatePE()));
+    connect(this,SIGNAL(updatecb()),this,SLOT(UpdateCombo()));
 
     setWindowTitle(strmsgname.data());
 }
 
 void DialogViewMessage::closeEvent(QCloseEvent *e)
 {
-
+    iv::modulecomm::Unregister(mparaw);
     emit ViewMsgClose((void *)this);
+
 }
 
 DialogViewMessage::~DialogViewMessage()
@@ -72,6 +74,13 @@ void DialogViewMessage::UpdateRawMsg(const char *strdata, const unsigned int nSi
     if(mvectorprob.size() == 0)
     {
         mvectorprob = GetProbProtoIndex(strxdata,nSize,mvectorprobname);
+        if(mvectorprob.size()>0)
+        {
+            mMutexcb.lock();
+            mvectorcbname = mvectorprobname;
+            mMutexcb.unlock();
+            emit updatecb();
+        }
     }
 
 //    iv::testmodulecommext * pt = new iv::testmodulecommext;
@@ -81,10 +90,12 @@ void DialogViewMessage::UpdateRawMsg(const char *strdata, const unsigned int nSi
 //    bool bx2 = pt2->ParseFromArray(strdata,nSize);
 
 //    qDebug("prob size is %d ",mvectorprob.size());
-    if(mvectorprob.size() > 0)
+
+    int indexprob = mcbindex;
+    if((mvectorprob.size() > 0)&&((unsigned int)indexprob<mvectorprob.size()))
     {
 
-        std::shared_ptr<google::protobuf::Message> msg_ptr = GetProtoMessage(strxdata,nSize,mvectorprob[0]);
+        std::shared_ptr<google::protobuf::Message> msg_ptr = GetProtoMessage(strxdata,nSize,mvectorprob[indexprob]);
         if(msg_ptr != NULL)
         {
             qDebug("parse ok.");
@@ -112,9 +123,44 @@ void DialogViewMessage::UpdateRawMsg(const char *strdata, const unsigned int nSi
 
 void DialogViewMessage::UpdatePE()
 {
+    if(mbPause)return;
     std::string strinfo;
     mMutexInfo.lock();
     strinfo = mstrmsginfo;
     mMutexInfo.unlock();
     ui->plainTextEdit->setPlainText(strinfo.data());
 }
+
+void DialogViewMessage::on_pushButton_clicked()
+{
+    if(mbPause)
+    {
+        mbPause = false;
+        ui->pushButton->setText("Continue");
+    }
+    else
+    {
+        mbPause = true;
+        ui->pushButton->setText("Pause");
+    }
+}
+
+void DialogViewMessage::UpdateCombo()
+{
+    std::vector<std::string> xvectorcbname;
+    mMutexcb.lock();
+    xvectorcbname = mvectorcbname;
+    mMutexcb.unlock();
+
+    ui->comboBox->clear();
+    unsigned int i;
+    for(i=0;i<xvectorcbname.size();i++)
+    {
+        ui->comboBox->addItem(xvectorcbname[i].data());
+    }
+}
+
+void DialogViewMessage::on_comboBox_currentIndexChanged(int index)
+{
+    if(index>=0)mcbindex = index;
+}

+ 13 - 0
src/tool/view_message/dialogviewmessage.h

@@ -29,10 +29,17 @@ private slots:
     void closeEvent(QCloseEvent * e);
     void UpdatePE();
 
+    void UpdateCombo();
+
+
+    void on_pushButton_clicked();
+
+    void on_comboBox_currentIndexChanged(int index);
 
 signals:
     void ViewMsgClose(void * handle);
     void msgupdate();
+    void updatecb();
 
 private:
     Ui::DialogViewMessage *ui;
@@ -43,6 +50,8 @@ private:
     QMutex mMutexInfo;
 
 
+    bool mbPause = false;
+
     void * mparaw;
 
     iv::modulecommext::modulecommmsg<iv::testmodulecommext> * mpa;
@@ -52,6 +61,10 @@ private:
     std::vector<unsigned int> mvectorprob;
     std::vector<std::string> mvectorprobname;
 
+    QMutex mMutexcb;
+    std::vector<std::string> mvectorcbname;
+    int mcbindex = 0;
+
     void UpdateMsg(::google::protobuf::Message & xmsg);
     void UpdateRawMsg(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);
 

+ 37 - 1
src/tool/view_message/dialogviewmessage.ui

@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>461</width>
+    <width>466</width>
     <height>365</height>
    </rect>
   </property>
@@ -23,6 +23,42 @@
     </rect>
    </property>
   </widget>
+  <widget class="QPushButton" name="pushButton">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>3</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Pause</string>
+   </property>
+  </widget>
+  <widget class="QComboBox" name="comboBox">
+   <property name="geometry">
+    <rect>
+     <x>137</x>
+     <y>45</y>
+     <width>171</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>50</y>
+     <width>91</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>消息类型:</string>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>

+ 2 - 2
src/tool/view_message/mainwindow.cpp

@@ -109,6 +109,6 @@ void MainWindow::onTimer()
 
 void MainWindow::onViewWindowClose(void *phandle)
 {
-//    DialogViewMessage * pdlg = (DialogViewMessage * )phandle;
-//    delete pdlg;
+    DialogViewMessage * pdlg = (DialogViewMessage * )phandle;
+    delete pdlg;
 }