3feabb8d6d49843a3ff58e243cb44aa9a1c0d3f7.svn-base 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. QDateTime t = QDateTime::currentDateTime();
  9. start_t = t.toTime_t();
  10. start_h = t.time().hour();
  11. if(!db_dir.exists())
  12. system(QString("mkdir -p %1").arg(DB_PATH).toUtf8().data());
  13. Params.clear();
  14. if(params.length()>0)
  15. Params.append(params);
  16. }
  17. void dogThread::start_app()
  18. {
  19. QString cmd = QString("./%1 ").arg(APP_NAME);
  20. if(Params.length()>0)
  21. {
  22. for(int i=0;i<Params.length();i++)
  23. {
  24. if(Params.at(i).compare("&")!=0)
  25. cmd.append(QString("%1 ").arg(Params.at(i)));
  26. }
  27. }
  28. cmd.append(" &");
  29. system(cmd.toUtf8().data());
  30. }
  31. void dogThread::run()
  32. {
  33. start_app();
  34. system("./ytWidget -qws &");
  35. while(1)
  36. {
  37. bool restart_app = false;
  38. QDateTime curDatetime = QDateTime::currentDateTime();
  39. uint chkTime = curDatetime.toTime_t();
  40. ytShm->currentTime.YEAR = curDatetime.date().year()&0xffff;
  41. ytShm->currentTime.MONTH = curDatetime.date().month()&0xff;
  42. ytShm->currentTime.DAY = curDatetime.date().day()&0xff;
  43. ytShm->currentTime.HOUR = curDatetime.time().hour()&0xff;
  44. ytShm->currentTime.MINUTE = curDatetime.time().minute()&0xff;
  45. ytShm->currentTime.SECOND = curDatetime.time().second()&0xff;
  46. ytShm->currentTime.TIMESTAMP = chkTime;
  47. for(quint8 i=1;i<60;i++)
  48. {
  49. if(ytShm->dogTimeList.dogTime[i].ENABLED==0x01)
  50. if(ytShm->dogTimeList.dogTime[i].ENABLED==0x01){
  51. if((ytShm->dogTimeList.dogTime[i].LASTFEED<chkTime)
  52. &&((chkTime>(ytShm->dogTimeList.dogTime[i].LASTFEED
  53. +ytShm->dogTimeList.dogTime[i].WAITSEC))))
  54. {
  55. restart_app = true;
  56. break;
  57. }
  58. }
  59. }
  60. if(restart_app)
  61. {
  62. system(QString("killall %1").arg(APP_NAME).toUtf8().data());
  63. usleep(500000);
  64. start_app();
  65. }else if(curDatetime.time().hour()!=start_h){
  66. system("/usr/local/bin/clean_mem.sh");
  67. start_h = curDatetime.time().hour();
  68. }else if((QDateTime::fromTime_t(start_t).date().day()!=curDatetime.date().day())
  69. &&(curDatetime.time().hour()>3)&&(curDatetime.time().minute()>3)){
  70. system("/usr/local/bin/reboot.sh");
  71. }
  72. sleep(1);
  73. }
  74. }