123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #include "dogthread.h"
- #include "../ytCore/yt_unit_shm.h"
- extern YT_UNIT_SHM *ytShm;
- dogThread::dogThread(QObject *parent, QStringList params) :
- QThread(parent)
- {
- QFile db_dir(QString(DB_PATH));
- QDateTime t = QDateTime::currentDateTime();
- start_t = t.toTime_t();
- start_h = t.time().hour();
- if(!db_dir.exists())
- system(QString("mkdir -p %1").arg(DB_PATH).toUtf8().data());
- Params.clear();
- if(params.length()>0)
- Params.append(params);
- }
- void dogThread::start_app()
- {
- QString cmd = QString("./%1 ").arg(APP_NAME);
- if(Params.length()>0)
- {
- for(int i=0;i<Params.length();i++)
- {
- if(Params.at(i).compare("&")!=0)
- cmd.append(QString("%1 ").arg(Params.at(i)));
- }
- }
- cmd.append(" &");
- system(cmd.toUtf8().data());
- }
- void dogThread::run()
- {
- start_app();
- system("./ytWidget -qws &");
- while(1)
- {
- bool restart_app = false;
- QDateTime curDatetime = QDateTime::currentDateTime();
- uint chkTime = curDatetime.toTime_t();
- ytShm->currentTime.YEAR = curDatetime.date().year()&0xffff;
- ytShm->currentTime.MONTH = curDatetime.date().month()&0xff;
- ytShm->currentTime.DAY = curDatetime.date().day()&0xff;
- ytShm->currentTime.HOUR = curDatetime.time().hour()&0xff;
- ytShm->currentTime.MINUTE = curDatetime.time().minute()&0xff;
- ytShm->currentTime.SECOND = curDatetime.time().second()&0xff;
- ytShm->currentTime.TIMESTAMP = chkTime;
- for(quint8 i=1;i<60;i++)
- {
- if(ytShm->dogTimeList.dogTime[i].ENABLED==0x01)
- if(ytShm->dogTimeList.dogTime[i].ENABLED==0x01){
- if((ytShm->dogTimeList.dogTime[i].LASTFEED<chkTime)
- &&((chkTime>(ytShm->dogTimeList.dogTime[i].LASTFEED
- +ytShm->dogTimeList.dogTime[i].WAITSEC))))
- {
- restart_app = true;
- break;
- }
- }
- }
- if(restart_app)
- {
- system(QString("killall %1").arg(APP_NAME).toUtf8().data());
- usleep(500000);
- start_app();
- }else if(curDatetime.time().hour()!=start_h){
- system("/usr/local/bin/clean_mem.sh");
- start_h = curDatetime.time().hour();
- }else if((QDateTime::fromTime_t(start_t).date().day()!=curDatetime.date().day())
- &&(curDatetime.time().hour()>3)&&(curDatetime.time().minute()>3)){
- system("/usr/local/bin/reboot.sh");
- }
- sleep(1);
- }
- }
|