abb154dbd15f39914969e1b2016cd107e08d4dec.svn-base 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "dogthread.h"
  2. #include "../ytCore/yt_unit_shm.h"
  3. extern YT_UNIT_SHM *ytShm;
  4. dogThread::dogThread(QObject *parent, QStringList params) :
  5. QThread(parent)
  6. {
  7. QFile db_dir(QString(DB_PATH));
  8. if(!db_dir.exists())
  9. system(QString("mkdir -p %1").arg(DB_PATH).toUtf8().data());
  10. Params.clear();
  11. if(params.length()>0)
  12. Params.append(params);
  13. }
  14. void dogThread::start_app()
  15. {
  16. QString cmd = QString("./%1 ").arg(APP_NAME);
  17. if(Params.length()>0)
  18. {
  19. for(int i=0;i<Params.length();i++)
  20. {
  21. if(Params.at(i).compare("&")!=0)
  22. cmd.append(QString("%1 ").arg(Params.at(i)));
  23. }
  24. }
  25. cmd.append(" &");
  26. system(cmd.toUtf8().data());
  27. }
  28. void dogThread::run()
  29. {
  30. start_app();
  31. system("./ytWidget -qws &");
  32. while(1)
  33. {
  34. bool restart_app = false;
  35. QDateTime curDatetime = QDateTime::currentDateTime();
  36. uint chkTime = curDatetime.toTime_t();
  37. ytShm->currentTime.YEAR = curDatetime.date().year()&0xffff;
  38. ytShm->currentTime.MONTH = curDatetime.date().month()&0xff;
  39. ytShm->currentTime.DAY = curDatetime.date().day()&0xff;
  40. ytShm->currentTime.HOUR = curDatetime.time().hour()&0xff;
  41. ytShm->currentTime.MINUTE = curDatetime.time().minute()&0xff;
  42. ytShm->currentTime.SECOND = curDatetime.time().second()&0xff;
  43. ytShm->currentTime.TIMESTAMP = chkTime;
  44. for(quint8 i=1;i<64;i++)
  45. {
  46. if(ytShm->dogTimeList.dogTime[i].ENABLED==0x01)
  47. if(ytShm->dogTimeList.dogTime[i].ENABLED==0x01){
  48. if((ytShm->dogTimeList.dogTime[i].LASTFEED<chkTime)
  49. &&((chkTime>(ytShm->dogTimeList.dogTime[i].LASTFEED
  50. +ytShm->dogTimeList.dogTime[i].WAITSEC))))
  51. {
  52. restart_app = true;
  53. break;
  54. }
  55. }
  56. }
  57. if(restart_app)
  58. {
  59. system(QString("killall %1").arg(APP_NAME).toUtf8().data());
  60. usleep(500000);
  61. start_app();
  62. }
  63. sleep(1);
  64. }
  65. }