|
@@ -9,6 +9,25 @@
|
|
|
#include <unistd.h>
|
|
|
#endif
|
|
|
|
|
|
+
|
|
|
+//#define RESET "\033[0m"
|
|
|
+//#define BLACK "\033[30m" /* Black */
|
|
|
+//#define RED "\033[31m" /* Red */
|
|
|
+//#define GREEN "\033[32m" /* Green */
|
|
|
+//#define YELLOW "\033[33m" /* Yellow */
|
|
|
+//#define BLUE "\033[34m" /* Blue */
|
|
|
+//#define MAGENTA "\033[35m" /* Magenta */
|
|
|
+//#define CYAN "\033[36m" /* Cyan */
|
|
|
+//#define WHITE "\033[37m" /* White */
|
|
|
+//#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
|
|
|
+//#define BOLDRED "\033[1m\033[31m" /* Bold Red */
|
|
|
+//#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
|
|
|
+//#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
|
|
|
+//#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
|
|
|
+//#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
|
|
|
+//#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
|
|
+//#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
|
|
+
|
|
|
class AttachThread : public QThread
|
|
|
{
|
|
|
public:
|
|
@@ -28,16 +47,44 @@ class AttachThread : public QThread
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+void procsm::threadAttachMon()
|
|
|
+{
|
|
|
+ std::cout<<"\033[1m\033[32m"<<mstrsmname<<" threadAttachMon run."<<"\033[0m"<<std::endl;
|
|
|
+
|
|
|
+ int nCount = 0;
|
|
|
+ while(mbAttachRun)
|
|
|
+ {
|
|
|
+ if(mbInitComplete)
|
|
|
+ {
|
|
|
+ std::cout<<"\033[1m\033[32m"<<mstrsmname<<" Init Succesffuly."<<"\033[0m"<<std::endl;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
+ nCount++;
|
|
|
+ if(nCount>300)
|
|
|
+ {
|
|
|
+ std::cout<<"\033[1m\033[31m"<<" modulecomm msg "<<mstrsmname<<" Attach Fail."<<" Now Exit."<<"\033[0m"<<std::endl;
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
+ exit(-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mbAttachThreadComplete = true;
|
|
|
+}
|
|
|
+
|
|
|
procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode)
|
|
|
{
|
|
|
// mnBufSize = nBufSize;
|
|
|
|
|
|
// qDebug("create dbus");
|
|
|
|
|
|
+
|
|
|
+
|
|
|
strncpy(mstrsmname,strsmname,256);
|
|
|
|
|
|
mpASMPtr = new QSharedMemory(strsmname);
|
|
|
|
|
|
+ mpthreadattmon = new std::thread(&procsm::threadAttachMon,this);
|
|
|
+
|
|
|
|
|
|
char strasmname[256];
|
|
|
|
|
@@ -63,6 +110,7 @@ procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ mbInitComplete = true;
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -159,6 +207,36 @@ procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ mbInitComplete = true;
|
|
|
+}
|
|
|
+
|
|
|
+procsm::~procsm()
|
|
|
+{
|
|
|
+ if(mbAttachThreadComplete == false)
|
|
|
+ {
|
|
|
+ std::cout<<" Try to end Attach Monitor Thread."<<std::endl;
|
|
|
+ mbAttachRun = false;
|
|
|
+ mpthreadattmon->join();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(mpASMPtr->isAttached())
|
|
|
+ {
|
|
|
+ std::cout<<"\033[32m"<<mstrsmname<<" detach ASMPtr "<<"\033[0m"<<std::endl;
|
|
|
+ mpASMPtr->lock();
|
|
|
+ if(mpASM->isAttached())
|
|
|
+ {
|
|
|
+ std::cout<<"\033[32m"<<mstrsmname<<" detach ASM "<<"\033[0m"<<std::endl;
|
|
|
+ mpASM->detach();
|
|
|
+ }
|
|
|
+ mpASMPtr->unlock();
|
|
|
+ delete mpASM;
|
|
|
+ mpASMPtr->detach();
|
|
|
+ }
|
|
|
+ delete mpASMPtr;
|
|
|
+ std::cout<<"\033[32m"<<mstrsmname<<" ~procsm() "<<"\033[0m"<<std::endl;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void procsm::recreateasm(int nbufsize)
|