123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #ifndef PROGMON_H
- #define PROGMON_H
- #include <string>
- #include <vector>
- #include <thread>
- #include <QProcess>
- #include <QtXml>
- #include <QMutex>
- // Used For Program Monitor
- #include "cpumem.h"
- #include "ivlog.h"
- #include "ivfault.h"
- #include "QtDBus/QDBusMessage"
- #include "QtDBus/QDBusConnection"
- #include "progunit.h"
- #include "procmemstat.h"
- #ifdef IV_OS_WIN
- #include <windows.h>
- #endif
- class stdoutunit
- {
- public:
- QProcess * mpProc;
- QByteArray mba;
- public:
- stdoutunit(QProcess * pProc,QByteArray & ba)
- {
- mpProc = pProc;
- mba = ba;
- }
- };
- class ProgMon : public QThread
- {
- Q_OBJECT
- private slots:
- void onProcessStarted();
- void onProcessEnd();
- void onChRead();
- //add tjc
- void onProcessErrorStarted(QProcess::ProcessError error);
- //test
- void StopProcTest();
- void onReadStandardOutput();
- void onReadStandardError();
- public slots:
- bool onCheckExit(ProgUnit * pu);
- public:
- /* From A XML Load Program List */
- ProgMon(std::string path);
- ~ProgMon();
- /* Program List */
- std::vector<ProgUnit> mvectorprog;
- /* Start A Process */
- void StartProc(ProgUnit * pu);
- /* Stop A Process */
- void StopProc(ProgUnit * pu);
- /* fault stop process */
- void ForceStopProc(ProgUnit * pu);
- void restartProc(ProgUnit *pu);
- //判断启动状态
- bool checkStartState(ProgUnit *pu);
- void updatexml(std::string path);
- std::vector<ProgUnit> loadprogunit(std::string path);
- void StartProc(std::string strappname,std::string strargs="");
- void StopProc(std::string strappname,std::string strargs="");
- private:
- QMutex mMutex;
- ProgUnit * FindProcByName(std::string strappname,std::string strargs);
- signals:
- /* Signal when proc started */
- void SigProcStarted(ProgUnit * pu);
- /* Signal When proc stoped */
- void SigProcStoped(ProgUnit * pu);
- void checkExit(ProgUnit * pu);
- private:
- void run();
- bool mbquit = false;
- public:
- void setquit();
- private:
- void threadstdout();
- void threaderrout();
- std::vector<stdoutunit> mvectorstdout;
- QMutex mMutex_stdout;
- bool mbstdoutrun = true;
- std::vector<stdoutunit> mvectorerrout;
- QMutex mMutex_errout;
- bool mberroutrun = true;
- bool mbAllNoLog = true;
- std::thread * mpthread_stdout;
- std::thread * mpthread_errout;
- private:
- inline void LogError(QProcess * proc,QByteArray & ba);
- QFile mFileLog;
- bool mbFileLog = false;
- void InitLog();
- void WriteLog(const char * strlog);
- QFile mFileStdLog;
- bool mbFileStdLog = false;
- void WriteStdLog(const char * strlog);
- int get_path_availspace(const QString & path);
- private:
- qint64 mPhyMemTotal;
- qint64 mPhyMemAvail;
- qint64 mMemTotal;
- float mfCPULoad;
- std::vector<float> mvectorcpuload;
- void UpdateCPUMemStat();
- ProcMemStat mPMS;
- QString mstrsysInfo = "";
- QMutex mMutexSysinfo;
- public:
- QString GetSysInfo();
- };
- #endif // PROGMON_H
|