Explorar el Código

change sometimes can't attach in modulecomm. near solved.

yuchuli hace 2 años
padre
commit
725f40fcdc

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

@@ -127,6 +127,7 @@ procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned
     char strasmname[300];
     char strasmname[300];
 
 
 
 
+    mnMode = nMode;
     if(nMode == ModeWrite)
     if(nMode == ModeWrite)
     {
     {
         int nrtn = CreateASMPTR(strasmname,nBufSize,nMaxPacCount);
         int nrtn = CreateASMPTR(strasmname,nBufSize,nMaxPacCount);
@@ -314,6 +315,7 @@ int procsm::CreateAndAttachASM(char * strasmname,const unsigned int nBufSize,con
                 mpinfo->mNext = 0;
                 mpinfo->mNext = 0;
                 mpinfo->mLock = 0;
                 mpinfo->mLock = 0;
                 mpASM->unlock();
                 mpASM->unlock();
+                std::cout<<"recreate successfully."<<std::endl;
             }
             }
             else
             else
             {
             {
@@ -345,9 +347,10 @@ int procsm::CreateAndAttachASM(char * strasmname,const unsigned int nBufSize,con
     }
     }
 
 
 
 
+    std::cout<<strsmname<<"  is attached."<<std::endl;
     if(mpASM->isAttached())
     if(mpASM->isAttached())
     {
     {
-
+        std::cout<<strsmname<<" attach succesfully."<<std::endl;
         mbAttach = true;
         mbAttach = true;
         char * p = (char *)mpASM->data();
         char * p = (char *)mpASM->data();
         mpinfo = (procsm_info *)p;
         mpinfo = (procsm_info *)p;
@@ -524,18 +527,45 @@ bool procsm::AttachMem()
             mphead = (procsm_head *)(p+sizeof(procsm_info));
             mphead = (procsm_head *)(p+sizeof(procsm_info));
             mnMaxPacCount = mpinfo->mCap;
             mnMaxPacCount = mpinfo->mCap;
             mnBufSize = mpinfo->mnBufSize;
             mnBufSize = mpinfo->mnBufSize;
+
+            ivstdcolorout("AttachMem Successfully.");
             return true;
             return true;
         }
         }
         else
         else
         {
         {
+            std::cout<<" mode: "<<mnMode<<" asm name: "<<mASM_State.mstrshmname<<std::endl;
+            ivstdcolorout(" AttachMem: ASM Attach Fail. ",iv::STDCOLOR_BOLDYELLOW);
+            if(mnMode == ModeWrite)
+            {
+
+
+                int nrtn = CreateAndAttachASM(pasmptr->mstrshmname,mmodulemsg_type.mnBufSize,
+                                              mmodulemsg_type.mnMsgBufCount,mmodulemsg_type.mstrmsgidname);
+                if(nrtn <0 )
+                {
+                    char strerr[256];
+                    snprintf(strerr,256,"AttachMem  CreateAndAttachASMFail. error code: %d",nrtn);
+                    ivstdcolorout(strerr,iv::STDCOLOR_BOLDRED);
+                    return false;
+                }
+                else
+                {
+                    return true;
+                }
+
+            }
+
+
             return false;
             return false;
         }
         }
     }
     }
     else
     else
     {
     {
+        ivstdcolorout(" AttachMem: Attach Fail. ",iv::STDCOLOR_BOLDYELLOW);
         return false;
         return false;
     }
     }
 
 
+    ivstdcolorout("Fail in reattach. check modulecomm code......");
     return false;
     return false;
     mpASM->attach();
     mpASM->attach();
     if(mpASM->isAttached())
     if(mpASM->isAttached())
@@ -616,10 +646,19 @@ int  procsm::checkasm()
     if((pASM_PTR->mnUpdateTime == mASM_State.mnUpdateTime) && (mbAttach == true) )
     if((pASM_PTR->mnUpdateTime == mASM_State.mnUpdateTime) && (mbAttach == true) )
     {
     {
 
 
+
         mpASMPtr->unlock();
         mpASMPtr->unlock();
         return 0;
         return 0;
     }
     }
     qDebug("reattch mem.");
     qDebug("reattch mem.");
+    if(pASM_PTR->mnUpdateTime == mASM_State.mnUpdateTime)
+    {
+        std::cout<<" checkasm: mbAttach is false";
+    }
+    else
+    {
+        std::cout<<" updateTime not equal."<<std::endl;
+    }
     mbAttach = false;
     mbAttach = false;
     AttachMem();
     AttachMem();
     mpASMPtr->unlock();
     mpASMPtr->unlock();

+ 2 - 0
src/common/modulecomm/shm/procsm.h

@@ -115,6 +115,8 @@ public:
 
 
     iv::modulemsg_type mmodulemsg_type;
     iv::modulemsg_type mmodulemsg_type;
 
 
+    int mnMode;
+
 #ifndef USE_GROUPUDP
 #ifndef USE_GROUPUDP
 #ifdef USEDBUS
 #ifdef USEDBUS
 private slots:
 private slots:

+ 73 - 0
src/test/testmodule1/.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
+

+ 49 - 0
src/test/testmodule1/main.cpp

@@ -0,0 +1,49 @@
+#include <QCoreApplication>
+
+
+#include "modulecomm.h"
+
+#include <thread>
+
+void threadsend(void * pa)
+{
+    while(1)
+    {
+        char str[1000];
+        iv::modulecomm::ModuleSendMsg(pa,str,30);
+        std::this_thread::sleep_for(std::chrono::milliseconds(100));
+    }
+}
+
+void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+
+}
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    void * pa1,*pa2,*pa3,*pa4,*pa5;
+    void * pb1,*pb2,*pb3,*pb4,*pb5;
+
+    pa1 = iv::modulecomm::RegisterSend("b1",100,1);
+    pa2 = iv::modulecomm::RegisterSend("b2",1000,1);
+    pa3 = iv::modulecomm::RegisterSend("b3",10000,1);
+    pa4 = iv::modulecomm::RegisterSend("b4",100000,1);
+    pa5 = iv::modulecomm::RegisterSend("b6",10000000,1);
+
+    pb1 = iv::modulecomm::RegisterRecv("a1",ListenPointCloud);
+    pb2 = iv::modulecomm::RegisterRecv("a2",ListenPointCloud);
+    pb3 = iv::modulecomm::RegisterRecv("a3",ListenPointCloud);
+    pb4 = iv::modulecomm::RegisterRecv("a4",ListenPointCloud);
+    pb5 = iv::modulecomm::RegisterRecv("a6",ListenPointCloud);
+
+    std::thread * pthread1 = new std::thread(threadsend,pa1);
+    std::thread * pthread2 = new std::thread(threadsend,pa2);
+    std::thread * pthread3 = new std::thread(threadsend,pa3);
+    std::thread * pthread4 = new std::thread(threadsend,pa4);
+    std::thread * pthread5 = new std::thread(threadsend,pa5);
+
+    return a.exec();
+}

+ 22 - 0
src/test/testmodule1/testmodule1.pro

@@ -0,0 +1,22 @@
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as 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 you use 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 += main.cpp
+
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}