|
@@ -9,6 +9,9 @@
|
|
|
#include <unistd.h>
|
|
|
#endif
|
|
|
|
|
|
+#include <QFile>
|
|
|
+#include <QDir>
|
|
|
+
|
|
|
|
|
|
//#define RESET "\033[0m"
|
|
|
//#define BLACK "\033[30m" /* Black */
|
|
@@ -63,6 +66,7 @@ void procsm::threadAttachMon()
|
|
|
nCount++;
|
|
|
if(nCount>300)
|
|
|
{
|
|
|
+ setfailmark();
|
|
|
std::cerr<<"\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);
|
|
@@ -71,6 +75,46 @@ void procsm::threadAttachMon()
|
|
|
mbAttachThreadComplete = true;
|
|
|
}
|
|
|
|
|
|
+void procsm::setfailmark()
|
|
|
+{
|
|
|
+ char strfailpath[300];
|
|
|
+ QDateTime xdt = QDateTime::currentDateTime();
|
|
|
+ snprintf(strfailpath,300,"/dev/shm/%04d%02d%02d-%s",xdt.date().year(),
|
|
|
+ xdt.date().month(),xdt.date().day(),mstrsmname);
|
|
|
+ std::cerr<<"\033[1m\033[31m"<<" modulecomm msg "<<mstrsmname<<" fail. set mark file"<<strfailpath<<"\033[0m"<<std::endl;
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(strfailpath);
|
|
|
+ if(xFile.open(QIODevice::ReadWrite))
|
|
|
+ {
|
|
|
+ xFile.write(strfailpath,strnlen(strfailpath,256));
|
|
|
+ xFile.close();
|
|
|
+ std::cerr<<"\033[1m\033[31m"<<" modulecomm msg "<<mstrsmname<<" had save mark"<<"\033[0m"<<std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr<<"\033[1m\033[31m"<<" modulecomm msg "<<mstrsmname<<" save mark fail."<<"\033[0m"<<std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool procsm::checkfailmark()
|
|
|
+{
|
|
|
+ char strfailpath[300];
|
|
|
+ QDateTime xdt = QDateTime::currentDateTime();
|
|
|
+ snprintf(strfailpath,300,"/dev/shm/%04d%02d%02d-%s",xdt.date().year(),
|
|
|
+ xdt.date().month(),xdt.date().day(),mstrsmname);
|
|
|
+
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(strfailpath);
|
|
|
+ if(xFile.exists())
|
|
|
+ {
|
|
|
+ QDir xDir("/dev/shm");
|
|
|
+ xDir.remove(strfailpath);
|
|
|
+ std::cout<<"\033[1m\033[32m"<<" Last Time Attach Fail. Now Direct Create."<<"\033[0m"<<std::endl;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode)
|
|
|
{
|
|
|
// mnBufSize = nBufSize;
|
|
@@ -90,12 +134,39 @@ procsm::procsm(const char * strsmname,const unsigned int nBufSize,const unsigned
|
|
|
|
|
|
if(nMode == ModeWrite)
|
|
|
{
|
|
|
- bool bres = mpASMPtr->attach();
|
|
|
- if(bres == false)
|
|
|
- {
|
|
|
- mpASMPtr->create(sizeof(ASM_PTR));
|
|
|
+ bool bres;
|
|
|
+// if(checkfailmark())
|
|
|
+// {
|
|
|
+// bres = false;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// bres = mpASMPtr->attach();
|
|
|
+// }
|
|
|
+// if(bres == false)
|
|
|
+// {
|
|
|
+// mpASMPtr->create(sizeof(ASM_PTR));
|
|
|
+
|
|
|
+// }
|
|
|
|
|
|
+ bres = mpASMPtr->create(sizeof(ASM_PTR));
|
|
|
+ if(bres == true)
|
|
|
+ {
|
|
|
+ std::cout<<"\033[1m\033[32m"<<mstrsmname<<" create successfully."<<"\033[0m"<<std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bres = mpASMPtr->attach();
|
|
|
+ if(bres == true)
|
|
|
+ {
|
|
|
+ std::cout<<"\033[1m\033[32m"<<mstrsmname<<" exist. attach successfully."<<"\033[0m"<<std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
ASM_PTR * pasm = (ASM_PTR *)mpASMPtr->data();
|
|
|
if(pasm == NULL)
|
|
|
{
|