Browse Source

add folder plugin for put some program had more dependency.

yuchuli 3 years ago
parent
commit
0e87682db6

+ 11 - 0
src/include/proto/plugmsg.proto

@@ -0,0 +1,11 @@
+syntax = "proto2";
+
+package iv.plugin;
+
+message plugmsg
+{
+  required string strattr = 1;
+  optional bytes strvalue = 2;
+};
+
+

+ 73 - 0
src/plugin/baidumapshow/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 0 - 0
src/plugin/baidumapshow/Readme.md


+ 44 - 0
src/plugin/baidumapshow/baidumapshow.pro

@@ -0,0 +1,44 @@
+QT       += core gui network webenginewidgets
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+CONFIG += c++11
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+    ../../include/msgtype/plugmsg.pb.cc \
+    main.cpp \
+    mainwindow.cpp \
+    plugbaidumapshow.cpp
+
+HEADERS += \
+    ../../include/msgtype/plugmsg.pb.h \
+    mainwindow.h \
+    plugbaidumapshow.h
+
+FORMS += \
+    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!" )
+}
+

+ 35 - 0
src/plugin/baidumapshow/main.cpp

@@ -0,0 +1,35 @@
+#include "mainwindow.h"
+
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    if(argc == 3)
+     {
+        qDebug("argc == 3");
+         QApplication a(argc, argv);
+
+         QString strcid = argv[2];
+         MainWindow w(strcid);
+//         w.show();
+         //end
+
+         WId wid = WId(QString(argv[1]).toInt());//通过参数列表获取父进程窗口的WinId
+         QWindow *window = QWindow::fromWinId(wid);//获取父进程窗口
+
+         w.setProperty("_q_embedded_native_parent_handle", QVariant(wid));//设置属性,这句是必须的
+
+         w.winId();//必须调用一次,生成winId
+         w.windowHandle()->setParent(window);//设置父窗口
+         w.show();//最后调用show,提前调用qt会为其生成窗口控件,这样就会和你原本想要嵌入进的父进程界面产生冲突
+//         w.setGeometry(100,30,600,600);
+
+         fprintf(stderr, "%lld", w.winId());//写入标准错误输出,stderr能立即输出,stdout则不行
+
+         return a.exec();
+     }
+    QApplication a(argc, argv);
+    MainWindow w("");
+    w.show();
+    return a.exec();
+}

+ 78 - 0
src/plugin/baidumapshow/mainwindow.cpp

@@ -0,0 +1,78 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <iostream>
+
+MainWindow::MainWindow(QString strcid,QWidget *parent)
+    : QMainWindow(parent)
+    , ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+
+    mMapview = new QWebEngineView(ui->centralwidget);
+    mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
+    mMapview->setGeometry(1000,100,500,500);
+
+    connect(this, SIGNAL(signalplug()) ,this,SLOT(ProcPlugMsg()));
+
+    QString strmsgname = "plugin_";
+    strmsgname = strmsgname + "baidumapshow";
+    strmsgname = strmsgname +"_"+strcid;
+
+    std::cout<<"msg name : "<<strmsgname.toStdString()<<std::endl;
+
+    ModuleFun funbaidmap = std::bind(&MainWindow::onPlugMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
+    mpa = iv::modulecomm::RegisterRecvPlus(strmsgname.toLatin1().data(),funbaidmap);
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+    (void )event;
+    QSize sizemain = ui->centralwidget->size();
+
+    mMapview->setGeometry(0,0,sizemain.width(),sizemain.height());
+}
+
+void MainWindow::onPlugMsg(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
+{
+    (void)index;
+    (void)dt;
+    (void)strmemname;
+    iv::plugin::plugmsg xplugmsg;
+    std::cout<<"onPlugMsg"<<std::endl;
+    if(xplugmsg.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"signal "<<std::endl;
+        mMutexPlug.lock();
+        mplugmsg.CopyFrom(xplugmsg);
+        mMutexPlug.unlock();
+        emit signalplug();
+    }
+    else
+    {
+        std::cout<<"MainWindow::onPlugMsg Parse Fail."<<std::endl;
+    }
+}
+
+void MainWindow::ProcPlugMsg()
+{
+
+    iv::plugin::plugmsg xplugmsg;
+    mMutexPlug.lock();
+    xplugmsg.CopyFrom(mplugmsg);
+    mMutexPlug.unlock();
+    std::cout<<" x name "<<xplugmsg.strattr()<<std::endl;
+    if(xplugmsg.strattr() == "geometry")
+    {
+        int x,y,w,h;
+        sscanf(xplugmsg.strvalue().data(), "%d %d %d %d",&x,&y,&w,&h);
+        setGeometry(x,y,w,h);
+    }
+}
+

+ 50 - 0
src/plugin/baidumapshow/mainwindow.h

@@ -0,0 +1,50 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QMutex>
+
+#include <QtWebEngineWidgets/QtWebEngineWidgets>
+
+#include "modulecomm.h"
+
+#include "plugmsg.pb.h"
+
+QT_BEGIN_NAMESPACE
+namespace Ui { class MainWindow; }
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow(QString strcid,QWidget *parent = nullptr);
+    ~MainWindow();
+
+private:
+    Ui::MainWindow *ui;
+
+signals:
+    void signalplug();
+
+
+private slots:
+    void ProcPlugMsg();
+
+private:
+    QWebEngineView * mMapview;
+
+    void  * mpa;
+
+public:
+     void resizeEvent(QResizeEvent *event);
+
+private:
+     void onPlugMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+
+private:
+     iv::plugin::plugmsg  mplugmsg;
+     QMutex mMutexPlug;
+};
+#endif // MAINWINDOW_H

+ 30 - 0
src/plugin/baidumapshow/mainwindow.ui

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget"/>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>28</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 33 - 0
src/plugin/baidumapshow/plugbaidumapshow.cpp

@@ -0,0 +1,33 @@
+#include "plugbaidumapshow.h"
+
+plugbaidumapshow::plugbaidumapshow(WId parentwinid, QString strappname,const char * strdir)
+{
+   QString strapppath;
+   if(strdir == NULL)strapppath = strappname;
+   else
+   {
+       strapppath = strdir;
+       strapppath = strapppath + "/" + strappname;
+   }
+
+   mproc = new QProcess();
+   QStringList xarg;
+   xarg.push_back(QString::number(parentwinid));
+   mproc->start(strapppath,xarg);
+
+   QString strmsgname = "plugin-" + strappname;
+   mpa = iv::modulecomm::RegisterSend(strmsgname.toLatin1().data(),1000,1);
+
+}
+
+plugbaidumapshow::~plugbaidumapshow()
+{
+    iv::modulecomm::Unregister(mpa);
+    mproc->terminate();
+    mproc->waitForFinished(100);
+}
+
+void plugbaidumapshow::SetGeometry(int x, int y, int w, int h)
+{
+
+}

+ 24 - 0
src/plugin/baidumapshow/plugbaidumapshow.h

@@ -0,0 +1,24 @@
+#ifndef PLUGBAIDUMAPSHOW_H
+#define PLUGBAIDUMAPSHOW_H
+
+#include <QWidget>
+#include <QProcess>
+
+#include "modulecomm.h"
+
+class plugbaidumapshow
+{
+public:
+    plugbaidumapshow( WId parentwinid,  QString strappname,const char * strdir = NULL);
+    ~plugbaidumapshow();
+
+private:
+    QProcess * mproc;
+    void * mpa;
+
+
+public:
+    void SetGeometry(int x, int y,int w,int h);
+};
+
+#endif // PLUGBAIDUMAPSHOW_H

+ 0 - 0
src/plugin/common/Readme.md


+ 98 - 0
src/plugin/common/pluginapp.cpp

@@ -0,0 +1,98 @@
+#include "pluginapp.h"
+
+#include <memory>
+#include <iostream>
+
+#include <QThread>
+
+pluginapp::pluginapp(WId parentwinid, QString cid,QString strappname,const char * strdir)
+{
+   QString strapppath;
+   if(strdir == NULL)strapppath = strappname;
+   else
+   {
+       strapppath = strdir;
+       strapppath = strapppath + "/" + strappname;
+   }
+
+   QString strmsgname = "plugin_" + strappname+"_"+cid;
+   mpa = iv::modulecomm::RegisterSend(strmsgname.toLatin1().data(),1000,1);
+
+   mproc = new QProcess();
+   connect(mproc,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOut()));
+   connect(mproc,SIGNAL(started()),this,SLOT(onProcStarted()));
+   QStringList xarg;
+   xarg.push_back(QString::number(parentwinid));
+   xarg.push_back(cid);
+   mproc->start(strapppath,xarg);
+
+
+
+}
+
+pluginapp::~pluginapp()
+{
+    iv::modulecomm::Unregister(mpa);
+    mproc->terminate();
+    mproc->waitForFinished(100);
+}
+
+void pluginapp::SetGeometry(int x, int y, int w, int h)
+{
+    char strvalue[256];
+    snprintf(strvalue,256,"%d %d %d %d",x,y,w,h);
+    SetAttr("geometry",strvalue,strnlen(strvalue,256));
+}
+
+void pluginapp::SetAttr(const char *strattr, const char *strvalue, const int nvaluelen)
+{
+    iv::plugin::plugmsg xmsg;
+    xmsg.set_strattr(strattr);
+    xmsg.set_strvalue(strvalue,nvaluelen);
+
+    if(mbStarted == false)
+    {
+        std::cout<<"push to vector"<<std::endl;
+        mvectormsg.push_back(xmsg);
+        return;
+    }
+
+    int ndatasize = xmsg.ByteSize();
+    std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[ndatasize]);
+    if(xmsg.SerializeToArray(pstr_ptr.get(),ndatasize))
+    {
+        iv::modulecomm::ModuleSendMsg(mpa,pstr_ptr.get(),ndatasize);
+    }
+    else
+    {
+        std::cout<<" pluginapp::SetAttr seriazlize error."<<std::endl;
+    }
+}
+
+void pluginapp::onReadStandardOut()
+{
+    QProcess * proc = (QProcess *)sender();
+    QByteArray ba = proc->readAllStandardOutput();
+    std::cout<<ba.data()<<std::endl;
+}
+
+void pluginapp::onProcStarted()
+{
+    mpTimer = new QTimer(this);
+    connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
+    mpTimer->start(1000);
+
+    std::cout<<"started."<<std::endl;
+
+}
+
+void pluginapp::onTimer()
+{
+    mbStarted = true;
+    if(mvectormsg.size()>0)
+    {
+        std::cout<<"write msg"<<std::endl;
+        SetAttr(mvectormsg[mvectormsg.size()-1].strattr().data(),mvectormsg[mvectormsg.size()-1].strvalue().data(),mvectormsg[mvectormsg.size()-1].strvalue().size());
+        mvectormsg.clear();
+    }
+}

+ 40 - 0
src/plugin/common/pluginapp.h

@@ -0,0 +1,40 @@
+#ifndef PLUGINAPP_H
+#define PLUGINAPP_H
+
+#include <QWidget>
+#include <QProcess>
+
+#include "plugmsg.pb.h"
+
+#include "modulecomm.h"
+#include <QTimer>
+
+class pluginapp : public QObject
+{
+    Q_OBJECT
+public:
+    pluginapp( WId parentwinid, QString cid, QString strappname,const char * strdir = NULL);
+    ~pluginapp();
+
+private:
+    QProcess * mproc;
+    void * mpa;
+
+    std::vector<iv::plugin::plugmsg> mvectormsg;
+
+private slots:
+    void onReadStandardOut();
+    void onProcStarted();
+    void onTimer();
+
+
+public:
+    void SetGeometry(int x, int y,int w,int h);
+    void SetAttr(const char * strattr,const char * strvalue,const int nvaluelen);
+
+private:
+    bool mbStarted = false;
+    QTimer * mpTimer;
+};
+
+#endif // PLUGINAPP_H

+ 6 - 0
src/tool/RemoteCtrl_Thread/RemoteCtrl_Thread.pro

@@ -33,8 +33,10 @@ SOURCES += \
     ../../include/msgtype/gps.pb.cc \
     ../../include/msgtype/gpsimu.pb.cc \
     ../../include/msgtype/imu.pb.cc \
+    ../../include/msgtype/plugmsg.pb.cc \
     ../../include/msgtype/rawpic.pb.cc \
     ../../include/msgtype/remotectrl.pb.cc \
+    ../../plugin/common/pluginapp.cpp \
     dialogbigpic.cpp \
     dialogsetpassword.cpp \
     dialogsetting.cpp \
@@ -59,8 +61,10 @@ HEADERS += \
     ../../include/msgtype/gps.pb.h \
     ../../include/msgtype/gpsimu.pb.h \
     ../../include/msgtype/imu.pb.h \
+    ../../include/msgtype/plugmsg.pb.h \
     ../../include/msgtype/rawpic.pb.h \
     ../../include/msgtype/remotectrl.pb.h \
+    ../../plugin/common/pluginapp.h \
     dialogbigpic.h \
     dialogsetpassword.h \
     dialogsetting.h \
@@ -98,6 +102,8 @@ INCLUDEPATH += /usr/include/opencv4
 INCLUDEPATH += $$PWD/../../driver/driver_cloud_grpc_pc_thread
 INCLUDEPATH += $$PWD/../../driver/driver_cloud_grpc_thread
 
+INCLUDEPATH += $$PWD/../../plugin/common
+
 
 LIBS += -lprotobuf -lyaml-cpp
 

+ 4 - 0
src/tool/RemoteCtrl_Thread/mainwindow.cpp

@@ -219,6 +219,8 @@ MainWindow::MainWindow(QWidget *parent)
 
 
 
+    mpbaiduapp = new pluginapp(this->winId(),"baidu","baidumapshow","/home/yuchuli/qt/modularization/src/plugin/build-baidumapshow-Debug");
+
     setWindowTitle(mstrProgName +mstrVIN+  mstrGPSTime + mstrPicTime);
 
 }
@@ -294,6 +296,8 @@ void MainWindow::resizeEvent(QResizeEvent *event)
 
     mMapview->setGeometry(10,10,sizemain.width()/2,sizemain.height()*3/5);
 
+    mpbaiduapp->SetGeometry(10,30,sizemain.width()/2,sizemain.height()*3/5);
+
     mmyview->setGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
 
     ui->lineEdit_lat->setGeometry(sizemain.width()-100,10,90,30);

+ 4 - 1
src/tool/RemoteCtrl_Thread/mainwindow.h

@@ -35,7 +35,7 @@
 #include "dialogsetpassword.h"
 #include "dialogsetting.h"
 
-
+#include "pluginapp.h"
 
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
@@ -201,5 +201,8 @@ private:
     std::string mstrVehVIN = "AAAAAAAAAAAAAAAAA";
     std::string mstrqueryMD5 = "5d41402abc4b2a76b9719d911017c592";
     std::string mstrctrlMD5 = "5d41402abc4b2a76b9719d911017c592";
+
+private:
+    pluginapp * mpbaiduapp;
 };
 #endif // MAINWINDOW_H

+ 4 - 4
src/ui/ui_ads_hmi/ADCIntelligentVehicle.ui

@@ -1966,7 +1966,7 @@ background-color: rgb(85, 87, 83);</string>
 &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
 p, li { white-space: pre-wrap; }
 &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_12">
@@ -2087,7 +2087,7 @@ gridline-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(
 &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
 p, li { white-space: pre-wrap; }
 &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
        </property>
       </widget>
       <widget class="QTextEdit" name="textEdit_aobzdis_tj">
@@ -2142,7 +2142,7 @@ p, li { white-space: pre-wrap; }
 &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
 p, li { white-space: pre-wrap; }
 &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
        </property>
       </widget>
       <widget class="QTextEdit" name="textEdit_aocftime_tj">
@@ -2525,7 +2525,7 @@ background-color: rgb(85, 87, 83);</string>
      <x>0</x>
      <y>0</y>
      <width>1900</width>
-     <height>22</height>
+     <height>28</height>
     </rect>
    </property>
   </widget>