Przeglądaj źródła

change tool/view_message. but not complete.

yuchuli 3 lat temu
rodzic
commit
f531d248a7

+ 1 - 0
src/common/modulecomm/ivmodulemsg_type.h

@@ -4,6 +4,7 @@
 namespace iv {
 struct modulemsg_type
 {
+    char mstrmsgidname[256];
     char mstrmsgname[256];
     int mnBufSize;
     int mnMsgBufCount;

+ 1 - 1
src/common/modulecomm/shm/procsm.cpp

@@ -68,7 +68,7 @@ procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned
 
     if(nMode == ModeWrite)
     {
-
+        strncpy(mmodulemsg_type.mstrmsgidname,strsmname,255);
         mmodulemsg_type.mnBufSize = nBufSize;
         mmodulemsg_type.mnMsgBufCount = nMaxPacCount;
         strncpy(mmodulemsg_type.mstrmsgname,strasmname,255);

+ 30 - 0
src/tool/view_message/dialogaddmsg.cpp

@@ -0,0 +1,30 @@
+#include "dialogaddmsg.h"
+#include "ui_dialogaddmsg.h"
+
+DialogAddMsg::DialogAddMsg(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogAddMsg)
+{
+    ui->setupUi(this);
+
+    setWindowTitle("Manual Add");
+}
+
+DialogAddMsg::~DialogAddMsg()
+{
+    delete ui;
+}
+
+void DialogAddMsg::on_pushButton_Add_clicked()
+{
+    mstrmsgname = ui->lineEdit_Name->text().toStdString();
+    if(mstrmsgname.size() > 0)
+        this->accept();
+    else
+        this->reject();
+}
+
+std::string DialogAddMsg::GetMessageName()
+{
+    return mstrmsgname;
+}

+ 29 - 0
src/tool/view_message/dialogaddmsg.h

@@ -0,0 +1,29 @@
+#ifndef DIALOGADDMSG_H
+#define DIALOGADDMSG_H
+
+#include <QDialog>
+
+namespace Ui {
+class DialogAddMsg;
+}
+
+class DialogAddMsg : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogAddMsg(QWidget *parent = nullptr);
+    ~DialogAddMsg();
+
+    std::string GetMessageName();
+
+private slots:
+    void on_pushButton_Add_clicked();
+
+private:
+    Ui::DialogAddMsg *ui;
+
+    std::string mstrmsgname;
+};
+
+#endif // DIALOGADDMSG_H

+ 55 - 0
src/tool/view_message/dialogaddmsg.ui

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogAddMsg</class>
+ <widget class="QDialog" name="DialogAddMsg">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>374</width>
+    <height>244</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="pushButton_Add">
+   <property name="geometry">
+    <rect>
+     <x>120</x>
+     <y>120</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Add</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_Name">
+   <property name="geometry">
+    <rect>
+     <x>150</x>
+     <y>50</y>
+     <width>181</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>50</y>
+     <width>101</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Name:</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 53 - 0
src/tool/view_message/dialogviewmessage.cpp

@@ -0,0 +1,53 @@
+#include "dialogviewmessage.h"
+#include "ui_dialogviewmessage.h"
+
+DialogViewMessage::DialogViewMessage(std::string strmsgname,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogViewMessage)
+{
+    ui->setupUi(this);
+
+    mstrmsgname = strmsgname;
+
+    mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
+
+    ModuleExtFun funext = std::bind(&DialogViewMessage::UpdateMsg,this,std::placeholders::_1);
+    mpa->RegisterRecvPlus(strmsgname.data(),funext);
+    iv::testmodulecommext x;
+
+    ::google::protobuf::Message * px = &x;
+    px->GetTypeName();
+
+    std::string gx = x.GetTypeName();
+
+    setWindowTitle(strmsgname.data());
+}
+
+void DialogViewMessage::closeEvent(QCloseEvent *e)
+{
+
+    emit ViewMsgClose((void *)this);
+}
+
+DialogViewMessage::~DialogViewMessage()
+{
+//    delete px;
+    delete ui;
+}
+
+void DialogViewMessage::resizeEvent(QResizeEvent *event)
+{
+    QSize size = this->size();
+
+    ui->plainTextEdit->setGeometry(10,90,size.width()-20,size.height()-100);
+
+}
+
+void DialogViewMessage::UpdateMsg(google::protobuf::Message &xmsg)
+{
+    mMutexMsg.lock();
+
+    mMutexMsg.unlock();
+    qDebug("update");
+    emit msgupdate();
+}

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

@@ -0,0 +1,50 @@
+#ifndef DIALOGVIEWMESSAGE_H
+#define DIALOGVIEWMESSAGE_H
+
+#include <QDialog>
+
+#include <QPlainTextEdit>
+
+#include <QMutex>
+
+#include "modulecommext.h"
+#include "testmodulecommext.pb.h"
+
+namespace Ui {
+class DialogViewMessage;
+}
+
+class DialogViewMessage : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogViewMessage(std::string strmsgname,QWidget *parent = nullptr);
+    ~DialogViewMessage();
+
+public:
+     void resizeEvent(QResizeEvent *event);
+
+private slots:
+    void closeEvent(QCloseEvent * e);
+
+
+
+signals:
+    void ViewMsgClose(void * handle);
+    void msgupdate();
+
+private:
+    Ui::DialogViewMessage *ui;
+
+    std::string mstrmsgname;
+
+    iv::modulecommext::modulecommmsg<iv::testmodulecommext> * mpa;
+
+    QMutex mMutexMsg;
+
+    void UpdateMsg(::google::protobuf::Message & xmsg);
+
+};
+
+#endif // DIALOGVIEWMESSAGE_H

+ 29 - 0
src/tool/view_message/dialogviewmessage.ui

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogViewMessage</class>
+ <widget class="QDialog" name="DialogViewMessage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>461</width>
+    <height>365</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPlainTextEdit" name="plainTextEdit">
+   <property name="geometry">
+    <rect>
+     <x>10</x>
+     <y>90</y>
+     <width>441</width>
+     <height>261</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 82 - 0
src/tool/view_message/mainwindow.cpp

@@ -1,12 +1,30 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
+#include <QMessageBox>
+#include <iostream>
+
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
 {
     ui->setupUi(this);
 
+    mmsg = QDBusMessage::createSignal("/catarc/adc",  "adciv.interface", "modulemsgquery");
+    mmsg<<1;
+    bool bconnect = QDBusConnection::sessionBus().connect(QString(),"/catarc/adc",  "adciv.interface", "modulemsgres",this,SLOT(onQuery(QByteArray)));
+
+    if(bconnect == false)
+    {
+        qDebug("connect dbus fail.");
+    }
+    QTimer * timer = new QTimer();
+    connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
+ //   timer->start(5000);
+
+    mpTimer = timer;
+
+
     setWindowTitle("Message View");
 }
 
@@ -18,15 +36,79 @@ MainWindow::~MainWindow()
 
 void MainWindow::on_pushButton_refresh_clicked()
 {
+    mSendQueryTime = QDateTime::currentMSecsSinceEpoch();
+    mvectormsgname_temp.clear();
+
+   QDBusConnection::sessionBus().send(mmsg);
+
+   mpTimer->start(1000);
+   ui->pushButton_refresh->setEnabled(false);
+
 
 }
 
 void MainWindow::on_pushButton_view_clicked()
 {
+    if(ui->comboBox_message->count()<1)
+    {
+        QMessageBox::warning(this,"Warning","Please Refresh or Manual Add Message.",QMessageBox::YesAll);
+        return;
+    }
+
+    std::string strmsgname = ui->comboBox_message->currentText().toStdString();
 
+    DialogViewMessage * pdlgviewmsg = new DialogViewMessage(strmsgname);
+    connect(pdlgviewmsg,SIGNAL(ViewMsgClose(void*)),this,SLOT(onViewWindowClose(void*)));
+    pdlgviewmsg->show();
 }
 
 void MainWindow::on_pushButton_manualadd_clicked()
 {
+    DialogAddMsg dialogadd(this);
+    if(dialogadd.exec() == QDialog::Accepted)
+    {
+        std::string strnewmsg = dialogadd.GetMessageName();
+        ui->comboBox_message->addItem(strnewmsg.data());
+    }
+}
+
+void MainWindow::onQuery(QByteArray ba)
+{
+    if(ba.size() < sizeof(iv::modulemsg_type))
+    {
+        std::cout<<" querymsg::onQuery size error."<<std::endl;
+        return;
+    }
+
+    iv::modulemsg_type xmodulemsg;
+    memcpy((char *)&xmodulemsg,ba.data(),sizeof(iv::modulemsg_type));
+
+    std::string strmsgname = xmodulemsg.mstrmsgidname;
+    mvectormsgname_temp.push_back(strmsgname);
+    qDebug("id name: %s share name: %s bufsize:%d bufcount:%d",
+           xmodulemsg.mstrmsgidname,xmodulemsg.mstrmsgname,
+           xmodulemsg.mnBufSize,xmodulemsg.mnMsgBufCount);
+}
+
+void MainWindow::onTimer()
+{
+    mpTimer->stop();
+    ui->comboBox_message->clear();
+    ui->pushButton_refresh->setEnabled(true);
+    mvectormsg = mvectormsgname_temp;
 
+
+    unsigned int i;
+    for(i=0;i<mvectormsg.size();i++)
+    {
+        ui->comboBox_message->addItem(mvectormsg[i].data());
+    }
+
+    QMessageBox::information(this,"Info","Refresh succefully.",QMessageBox::YesAll);
+}
+
+void MainWindow::onViewWindowClose(void *phandle)
+{
+//    DialogViewMessage * pdlg = (DialogViewMessage * )phandle;
+//    delete pdlg;
 }

+ 27 - 0
src/tool/view_message/mainwindow.h

@@ -3,6 +3,18 @@
 
 #include <QMainWindow>
 
+#include <QDateTime>
+
+#include <QObject>
+#include <QtDBus/qdbusmessage.h>
+#include <QtDBus/QDBusConnection>
+#include <QTimer>
+
+#include "ivmodulemsg_type.h"
+
+#include "dialogaddmsg.h"
+#include "dialogviewmessage.h"
+
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
 QT_END_NAMESPACE
@@ -22,7 +34,22 @@ private slots:
 
     void on_pushButton_manualadd_clicked();
 
+    void onQuery(QByteArray ba);
+
+    void onTimer();
+
+    void onViewWindowClose(void * phandle);
+
 private:
     Ui::MainWindow *ui;
+
+    qint64 mSendQueryTime;
+
+    std::vector<std::string> mvectormsgname_temp;
+    std::vector<std::string> mvectormsg;
+
+    QDBusMessage mmsg;
+
+    QTimer * mpTimer;
 };
 #endif // MAINWINDOW_H

+ 23 - 1
src/tool/view_message/view_message.pro

@@ -1,5 +1,7 @@
 QT       += core gui
 
+QT +=  dbus
+
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
 CONFIG += c++11
@@ -16,16 +18,36 @@ DEFINES += QT_DEPRECATED_WARNINGS
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 SOURCES += \
+    ../../include/msgtype/testmodulecommext.pb.cc \
+    dialogaddmsg.cpp \
+    dialogviewmessage.cpp \
     main.cpp \
     mainwindow.cpp
 
 HEADERS += \
-    mainwindow.h
+    ../../include/msgtype/testmodulecommext.pb.h \
+    dialogaddmsg.h \
+    dialogviewmessage.h \
+    mainwindow.h \
+    ../../common/ModuleComm/ivmodulemsg_type.h
+
+
+INCLUDEPATH += $$PWD/../../common/modulecomm
 
 FORMS += \
+    dialogaddmsg.ui \
+    dialogviewmessage.ui \
     mainwindow.ui
 
 # Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}