databoardcore.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "databoardcore.h"
  2. #include "../ytDashBoardDog/dataprecess.h"
  3. DataBoardCore::DataBoardCore(QObject *parent) : QObject(parent)
  4. {
  5. mDay = -1;
  6. dbThread = new DatabaseThread(this);
  7. ws = new WebSocketServer(this);
  8. logThread = new LogThread(this);
  9. infoServer = new InfoCenterServer(this);
  10. timer = new QTimer(this);
  11. connect(ws,&WebSocketServer::weblog,this,&DataBoardCore::weblog);
  12. connect(infoServer,&InfoCenterServer::weblog,this,&DataBoardCore::weblog);
  13. connect(timer,&QTimer::timeout,this,&DataBoardCore::timeout);
  14. qRegisterMetaType<QList<QStringList>>("QList<QStringList>");
  15. connect(dbThread,&DatabaseThread::sendpatrol,this,&DataBoardCore::receivepatrol);
  16. dbThread->start();
  17. }
  18. void DataBoardCore::start()
  19. {
  20. ws->start();
  21. logThread->start();
  22. infoServer->start();
  23. timer->start(5);
  24. }
  25. void DataBoardCore::weblog(QString receivelog)
  26. {
  27. logThread->appendData(receivelog);
  28. }
  29. //清除超过一个月的日志文件
  30. void DataBoardCore::timeout()
  31. {
  32. dataProcessShm->UpTime = QDateTime::currentDateTime().toTime_t();
  33. if(mDay != QDate::currentDate().day()){
  34. mDay = QDate::currentDate().day();
  35. uint l_time = QDateTime::currentDateTime().toTime_t()-30*86400;
  36. QDir dir("/opt/log");
  37. QFileInfoList file_list = dir.entryInfoList(QDir::Files);
  38. for(int i=0;i<file_list.size();i++){
  39. QFileInfo f_info = file_list.at(i);
  40. if(f_info.lastModified().toTime_t()<l_time){
  41. QFile(f_info.canonicalFilePath()).remove();
  42. }
  43. }
  44. }
  45. }
  46. void DataBoardCore::receivepatrol(QList<QStringList > receivePatrolList)
  47. {
  48. ws->patrolrecord(receivePatrolList);
  49. }