|
@@ -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;
|
|
|
}
|