Index: sources/device/DeviceController.h =================================================================== diff -u -re60d099fd4fbada632a974b9fc95d4d2c9652b1a -rb7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9 --- sources/device/DeviceController.h (.../DeviceController.h) (revision e60d099fd4fbada632a974b9fc95d4d2c9652b1a) +++ sources/device/DeviceController.h (.../DeviceController.h) (revision b7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9) @@ -18,6 +18,7 @@ #include #include #include +#include // Project #include "main.h" // Doxygen : do not remove @@ -33,6 +34,39 @@ namespace Device { +class TimedProcess : public QObject { + Q_OBJECT + + explicit TimedProcess(QObject *parent = nullptr) : QObject(parent) { } + int _id = 0; + int _interval = 0; + QProcess *_process = nullptr; + QString _command = ""; + +private slots: + void onFinish(int) { + killTimer(_id); + _process->kill(); + _process = nullptr; + deleteLater(); + } +public: + TimedProcess(QProcess *vProcess, const QString &vCommand, int vInterval) + : QObject(), _interval(vInterval), _process(vProcess), _command(vCommand) { + connect(_process, SIGNAL( finished(int)), + this , SLOT(onFinish (int))); + } + void start() { + _id = startTimer(_interval); + _process->start(_command); + } + +protected: + void timerEvent(QTimerEvent *) { + onFinish(-1); + } +}; + /*! * \brief The DeviceController class * \details This class is the device controller meaning all the device interactions and settings like Volume(Device), Brightness, WiFi, Date, Time, etc