瀏覽代碼

0927 新增单例log类

caizm 1 年之前
父節點
當前提交
f7645b56bc

+ 1 - 0
CAE_Solution/src/Rabbitmq/Rabbitmq.pri

@@ -1,3 +1,4 @@
 include( $$PWD/c_rabbitmq/c_rabbitmq.pri)#封装的rabbitmq,接口
 include( $$PWD/rabbitClient/rabbitClient.pri)#利用封装的库写的客户端
 include( $$PWD/ReadConf/ReadConf.pri)#读取rabbitmq连接的配置文件
+include( $$PWD/sendLogMsg/sendLogMsg.pri)#发送日志类消息

+ 2 - 1
CAE_Solution/src/Rabbitmq/rabbitClient/rabbitclient.cpp

@@ -8,11 +8,12 @@
 #include <QJsonParseError>
 #include <QDebug>
 #include <QJsonDocument>
+#include "../sendLogMsg/logmsg.h"
 
 
 rabbitClient::rabbitClient(QObject *parent) : QObject(parent)
 {
-
+    connect(LogMsg::getInstance(),SIGNAL(send_to_sendClient(string)),this,SLOT(sendMsg(std::string)));
 
 }
 

+ 25 - 0
CAE_Solution/src/Rabbitmq/sendLogMsg/logmsg.h

@@ -0,0 +1,25 @@
+#ifndef LOGMSG_H
+#define LOGMSG_H
+#include <stdlib.h>
+#include <QObject>
+using namespace std;
+
+class LogMsg:public QObject
+{
+    Q_OBJECT
+private:
+    LogMsg(){}
+    LogMsg(const LogMsg&);
+    LogMsg& operator =(const LogMsg&);
+    ~LogMsg(){}
+
+public:
+    static LogMsg* getInstance(){
+        static LogMsg log;
+        return &log;
+    }
+signals:
+    void send_to_sendClient(string);
+};
+
+#endif // LOGMSG_H

+ 29 - 33
CAE_Solution/src/acis/cmdmainprocess.cpp

@@ -11,7 +11,7 @@
 #include "ga_api.hxx"
 #include "at_str.hxx"
 #include "at_int.hxx"
-
+#include "../Rabbitmq/sendLogMsg/logmsg.h"
 
 
 // Global variables to control the demonstration of advanced meshing functionalities
@@ -38,18 +38,12 @@ cmdMainProcess::cmdMainProcess()
     szmp_iso_point_t_ = nullptr;
     SampleUtils_ = NULL;//new DPMvolClass();
     object = NULL;
-
-    sm = NULL;
 }
 
 cmdMainProcess::~cmdMainProcess()
 {
     if(object)
         object = NULL;
-    if(sm){
-        delete sm;
-        sm = NULL;
-    }
 }
 
 /**
@@ -263,12 +257,12 @@ bool cmdMainProcess::CreateProcess_(string pathGeo)
 bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
 {
     Q_UNUSED(pathParam);
-    sm = new stateMachine("sendClient");
+
     // Note that 3DPM-Hexa does not respect the input surface mesh //3dpm-hexa不遵循曲面网格
     // If USE_HEXA is set to 1,
     // then both APPLY_PERIODICITY and USE_LOCAL_PHYSICAL_SIZE are set to 0
     //iniACIS();
-    sm->sendClient->sendMsg(object->ToJson("log","1.--read cad surf parameter"));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log","1.--read cad surf parameter"));
     //1.--read cad surf parameter
     //Get ENTITY_LIST;
     ENTITY_LIST Whole_ents;
@@ -285,7 +279,8 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
         msg_str = "Read all entity body count is ";
         msg_str.append(to_string(readRowEnt.count()));
         msg_str.append(";");
-        sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+
         //printf("Read all entity body count is %d;\n", readRowEnt.count());
         for (ENTITY *entC = readRowEnt.first(); entC != 0; entC = readRowEnt.next())
         {
@@ -298,7 +293,8 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
         msg_str.append("Body's count is ");
         msg_str.append(to_string(ent.count()));
         msg_str.append(";");
-        sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+
         //--获取边的信息
         ENTITY_LIST EdgeEnt = geo->GetEdges();
         const char *name = "entity_index";
@@ -311,7 +307,8 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
                 ATTRIB_GEN_INTEGER* pId = NULL;
                 outcome result = api_find_named_attribute(EdgeEnt[kk], name, reinterpret_cast<ATTRIB_GEN_NAME*&>(pId));
                 printf("find result : %d\n", result.ok());
-                sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+                emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+
                 if (pId && (result.ok() == TRUE))
                 {
                     /*	const char*name = pId->value();
@@ -350,7 +347,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
         msg_str.append("Whole_ents after unite is : ");
         msg_str.append(to_string(testEnt.count()));
         msg_str.append(",then use stitch function");
-        sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
         if (testEnt.count()==1)
         {
             //exit_on_bad_outcome(api_n_body_unite(ent, false));
@@ -367,7 +364,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
             msg_str.append("Whole_ents after attach is : ");
             msg_str.append(to_string(testEnt.count()));
             msg_str.append(";");
-            sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
             /*for (int kk = 0; kk < ent.count(); kk++)
             {
                 printf("kk%d is %d; ", kk, is_BODY(ent[kk]));
@@ -385,7 +382,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
             msg_str.append("geomStitch count is ");
             msg_str.append(to_string(Whole_ents.count()));
             msg_str.append(";");
-            sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
         }
         //--
 
@@ -405,8 +402,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     msg_str.append("Load Geometry OK!Whole_ents is : ");
     msg_str.append(to_string(Whole_ents.count()));
     msg_str.append(";");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
-
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     ENTITY_LIST ents;
     ents = Whole_ents;
 
@@ -419,8 +415,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     msg_str.append("face count : ");
     msg_str.append(to_string(face_list.count()));
     msg_str.append(";");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
-
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     ENTITY_LIST edge_list;
     api_get_edges(Whole_ents[0], edge_list);
     printf("edge count is : %d\n", edge_list.count());
@@ -429,7 +424,8 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     msg_str.append("edge count is: ");
     msg_str.append(to_string(edge_list.count()));
     msg_str.append(";");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+
     //api_ct_get_all_cells(face_list[0], cells);
 
     api_ct_get_all_cells(ents, cells);
@@ -439,8 +435,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     msg_str.append("Cells count is: ");
     msg_str.append(to_string(cells.count()));
     msg_str.append(";");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
-
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     //const char*cpName = ((ATTRIB_GEN_STRING *)tNAME)->value();
     //--test end
 
@@ -448,7 +443,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     //--
     msg_str.clear();
     msg_str.append("2.--read cad surf parameter");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     QString dDir=QDir::currentPath();
     printf("path:%s\n",dDir.toLatin1().data());
     //--
@@ -456,7 +451,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     msg_str.append("path:");
     msg_str.append(dDir.toLatin1().data());
     msg_str.append(";");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     ADIParam_.useDefaultParam();
     CRWriteFile* crw = new CRWriteFile();
 
@@ -470,26 +465,27 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     //--
     msg_str.clear();
     msg_str.append("3.--create surf.0");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     Createcadsurf(ents, cadsurf_);
     //4.--Set parameters and create mesh
     //--
     msg_str.clear();
     msg_str.append("4.--Set parameters and create mesh");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     cadsurfParams_ = setADIParamTo3dpm(ADIParam_);
     //-4.1-size map for vol
     //--
     msg_str.clear();
     msg_str.append("4.1-size map for vol");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+
     CreateLocalSizeMap();
 
     //5.--output surfmesh with cleaner or not
     //--
     msg_str.clear();
     msg_str.append("5.--output surfmesh with cleaner or not");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     if(!OutPutSurfMesh(cadsurf_, surfMesh_, &cadsurfParams_))return 1;
 
     //-5.1-for vol
@@ -499,7 +495,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     msg_str.append("style=");
     msg_str.append(to_string(ADIParam_.style));
     msg_str.append(";");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     if(ADIParam_.style)
     {
         createVol(ADIParam_.style, cells);
@@ -510,7 +506,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     //--
     msg_str.clear();
     msg_str.append("6. Save the surface mesh to .mesh (optional)");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     QString appPath = dDir+"\\Data\\";//qy 2023-03-24修改路径
     QDateTime data = QDateTime::currentDateTime();
     QString strName;
@@ -539,12 +535,12 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     //--
     msg_str.clear();
     msg_str.append("Successfully wrote SurfMesh to .mesh format");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     //-6.1Deletesome Clean up MeshGems Sizemaps
     //--
     msg_str.clear();
     msg_str.append("6.1Deletesome Clean up MeshGems Sizemaps");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     if (szmp_iso_face_t_)
         meshgems_sizemap_delete(szmp_iso_face_t_);
     if (szmp_iso_edge_t_)
@@ -555,7 +551,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     //--
     msg_str.clear();
     msg_str.append("7. Termination");
-    sm->sendClient->sendMsg(object->ToJson("log",msg_str));
+    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     //closeACIS();
     if(crw!=NULL)
     {

+ 1 - 2
CAE_Solution/src/acis/cmdmainprocess.h

@@ -37,7 +37,7 @@
 
 #include "rwritefile.h"
 #include <iostream>
-#include "../threadPool_and_statemachine/stateMachine/statemachine.h"
+
 using namespace std;
 
 class cmdMainProcess
@@ -65,7 +65,6 @@ private:
     DPMvolClass *SampleUtils_;
 
     boostJsonObject *object;//0831 append
-    stateMachine *sm;
 private:
     Spa3dpm::Parameters setADIParamTo3dpm(const DPM_ADIParam &p);
     bool Createcadsurf(const ENTITY_LIST &inEnts, Spa3dpm::CadSurfSession &surf);

+ 1 - 1
CAE_Solution/src/main.cpp

@@ -62,6 +62,6 @@ int main(int argc, char *argv[])
     QObject::connect(handle,SIGNAL(sendImg_handlePoolToSendstate(std::string)),sendstate,SLOT(getImg_handlePoolToSendstate(std::string)));
     QObject::connect(recvstate,SIGNAL(sendmsg_recvstateTohandlePool(std::string)),handle,SLOT(getmsg_recvstateTohandlePool(std::string)));
 
-    closeACIS();
+    //closeACIS();
     return a.exec();
 }

+ 1 - 1
CAE_Solution/src/threadPool_and_statemachine/dealWith/handlepool.h

@@ -38,7 +38,7 @@
 #include <QDebug>
 #include "boostjsonobject.h"
 #include "map_manager.h"
-
+#include "../../Rabbitmq/sendLogMsg/logmsg.h"
 
 
 using namespace std;