Browse Source

change some module for add ivexit.

yuchuli 3 years ago
parent
commit
175b3d1f71

+ 30 - 1
src/driver/driver_camera_ioctl/main.cpp

@@ -34,6 +34,11 @@
 
 #include "ivversion.h"
 
+#include "ivexit.h"
+#include <signal.h>
+
+QCoreApplication * gApp;
+
 
 void * gpa;
 
@@ -257,10 +262,25 @@ void threadcapture()
 
 }
 
+void ExitFunc()
+{
+    gApp->quit();
+    std::this_thread::sleep_for(std::chrono::milliseconds(100));
+}
+
+void signal_handler(int sig)
+{
+    if(sig == SIGINT)
+    {
+        ExitFunc();
+    }
+}
+
 int main(int argc, char *argv[])
 {
     showversion("driver_camera_ioctl");
     QCoreApplication a(argc, argv);
+    gApp = &a;
 
     QString strpath = QCoreApplication::applicationDirPath();
 //    QString apppath = strpath;
@@ -323,5 +343,14 @@ int main(int argc, char *argv[])
 //    (void)conthread;
 //    (void)compressthread;
 
-    return a.exec();
+    iv::ivexit::RegIVExitCall(ExitFunc);
+    signal(SIGINT,signal_handler);
+
+    int nrc = a.exec();
+
+    iv::modulecomm::Unregister(gpa);
+
+    std::cout<<"driver_camera_ioctl quit."<<nrc<<std::endl;
+
+    return nrc;
 }

+ 11 - 0
src/driver/driver_can_nvidia_agx/main.cpp

@@ -15,6 +15,7 @@
 
 #include "ivversion.h"
 #include "ivexit.h"
+#include <signal.h>
 
 
 static canctrl * gpcanctrl;
@@ -38,6 +39,14 @@ void exitfunc()
 
 }
 
+void signal_handler(int sig)
+{
+    if(sig == SIGINT)
+    {
+        exitfunc();
+    }
+}
+
 
 int main(int argc, char *argv[])
 {
@@ -63,6 +72,8 @@ int main(int argc, char *argv[])
 
     iv::ivexit::RegIVExitCall(exitfunc);
 
+    signal(SIGINT,signal_handler);
+
  //   std::thread b(func);
 
     return a.exec();

+ 61 - 3
src/driver/driver_grpc_server/main.cpp

@@ -18,6 +18,10 @@
 
 #include "modulecomm.h"
 
+#include "ivexit.h"
+
+#include <signal.h>
+
 using grpc::Server;
 using grpc::ServerBuilder;
 using grpc::ServerContext;
@@ -38,6 +42,10 @@ std::vector<iv::rpcmsgunit> gvectorctrlmsgunit;
 
 qint64 gnqueryindex = 0;
 
+static std::unique_ptr<Server> gserver_grpc;
+
+static QCoreApplication * gApp;
+
 void dec_yaml(const char * stryamlpath)
 {
 
@@ -221,12 +229,14 @@ void RunServer() {
   // clients. In this case it corresponds to an *synchronous* service.
   builder.RegisterService(&service);
   // Finally assemble the server.
-  std::unique_ptr<Server> server(builder.BuildAndStart());
+//  std::unique_ptr<Server> server(builder.BuildAndStart());
+  gserver_grpc = builder.BuildAndStart();
   std::cout << "Server listening on " << server_address << std::endl;
 
+
   // Wait for the server to shutdown. Note that some other thread must be
   // responsible for shutting down the server for this call to ever return.
-  server->Wait();
+  gserver_grpc->Wait();
 }
 
 void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
@@ -272,6 +282,25 @@ void Init()
     {
         gvectorquerymsgunit[i].mpa = iv::modulecomm::RegisterRecv(gvectorquerymsgunit[i].mstrmsgname,ListenData);
     }
+
+
+}
+
+void UnInit()
+{
+    unsigned int i;
+    for(i=0;i<gvectorctrlmsgunit.size();i++)
+    {
+        iv::modulecomm::Unregister(gvectorctrlmsgunit[i].mpa);
+
+    }
+
+    for(i=0;i<gvectorquerymsgunit.size();i++)
+    {
+        iv::modulecomm::Unregister(gvectorquerymsgunit[i].mpa);
+    }
+
+    std::cout<<"driver_grpc_server UnInit."<<std::endl;
 }
 
 #include <thread>
@@ -306,9 +335,26 @@ void ServerThread()
 
 static std::thread * gpthreadserver;
 
+
+void ExitFunc()
+{
+    gApp->quit();
+
+    std::this_thread::sleep_for(std::chrono::milliseconds(100));
+}
+
+void signal_handler(int sig)
+{
+    if(sig == SIGINT)
+    {
+        ExitFunc();
+    }
+}
+
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
+    gApp = &a;
 
 //    std::thread * pt = new std::thread(testthread);
 
@@ -327,5 +373,17 @@ int main(int argc, char *argv[])
 
     gpthreadserver = new std::thread(ServerThread);
 
-    return a.exec();
+    iv::ivexit::RegIVExitCall(ExitFunc);
+
+    signal(SIGINT,signal_handler);
+
+    int nrc =  a.exec();
+
+    UnInit();
+
+    gserver_grpc->Shutdown();
+
+    std::cout<<"driver_grpc_server quit. code : "<<nrc<<std::endl;
+
+    return nrc;
 }

+ 37 - 7
src/driver/driver_map_xodrload/main.cpp

@@ -1,6 +1,7 @@
 #include <QCoreApplication>
 #include <math.h>
 #include <string>
+#include <thread>
 
 #include <QFile>
 
@@ -29,6 +30,8 @@
 
 #include "ivbacktrace.h"
 
+#include <signal.h>
+
 OpenDrive mxodr;
 xodrdijkstra * gpxd;
 bool gmapload = false;
@@ -49,6 +52,8 @@ void * gpav2x;
 iv::Ivfault *gfault = nullptr;
 iv::Ivlog *givlog = nullptr;
 
+static QCoreApplication * gApp;
+
 
 namespace iv {
 struct simpletrace
@@ -833,10 +838,34 @@ void UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned i
     std::cout<<"src hdg is "<<gsrc.fhgdsrc<<std::endl;
 }
 
+void ExitFunc()
+{
+//    gApp->quit();
+    iv::modulecomm::Unregister(gpasimple);
+    iv::modulecomm::Unregister(gpav2x);
+    iv::modulecomm::Unregister(gpagps);
+    iv::modulecomm::Unregister(gpasrc);
+    iv::modulecomm::Unregister(gpmap);
+    iv::modulecomm::Unregister(gpa);
+    std::cout<<"driver_map_xodrload exit."<<std::endl;
+    gApp->quit();
+    std::this_thread::sleep_for(std::chrono::milliseconds(100));
+//    std::this_thread::sleep_for(std::chrono::milliseconds(900));
+}
+
+void signal_handler(int sig)
+{
+    if(sig == SIGINT)
+    {
+        ExitFunc();
+    }
+}
+
 int main(int argc, char *argv[])
 {
     showversion("driver_map_xodrload");
     QCoreApplication a(argc, argv);
+    gApp = &a;
 
     RegisterIVBackTrace();
 
@@ -859,11 +888,6 @@ int main(int argc, char *argv[])
     }
 
 
-
-
-
-
-
     iv::xmlparam::Xmlparam xp(strparapath);
     xp.GetParam(std::string("he"),std::string("1"));
     std::string strlat0 = xp.GetParam("lat0","39");
@@ -943,7 +967,13 @@ int main(int argc, char *argv[])
 //    SetPlan(xo);
 
 
-    void * pivexit = iv::ivexit::RegIVExitCall(0);
+    void * pivexit = iv::ivexit::RegIVExitCall(ExitFunc);
+
+    signal(SIGINT,signal_handler);
+
+    int nrc = a.exec();
+
+    std::cout<<"driver_map_xodr app exit. code :"<<nrc<<std::endl;
 
-    return a.exec();
+    return nrc;
 }

+ 5 - 1
src/tool/IVSysMan/progmon.cpp

@@ -19,6 +19,7 @@ ProgMon::~ProgMon()
         if(mvectorprog[i].mProcess != 0)
         {
             mvectorprog[i].mProcess->kill();
+  //          mvectorprog[i].mProcess->close();
         }
     }
     mvectorprog.clear();
@@ -315,7 +316,10 @@ void ProgMon::onChRead()
 {
     QProcess * proc = (QProcess *)sender();
     QByteArray ba = proc->readAll();
-//    qDebug("process INFO: %s ",ba.data());
+
+#ifdef QT_DEBUG
+    qDebug("process INFO: %s ", ba.data());
+#endif
 
 //    qDebug("read chanel count is :%d ",proc->readChannelCount());
 }