Using update.h/.cpp and thread pool
This commit is contained in:
		
							
								
								
									
										17
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								main.cpp
									
									
									
									
									
								
							@@ -16,7 +16,7 @@
 | 
			
		||||
#include <QRunnable>
 | 
			
		||||
#include <QThreadPool>
 | 
			
		||||
 | 
			
		||||
#include "utils.h"
 | 
			
		||||
#include "update.h"
 | 
			
		||||
 | 
			
		||||
#ifdef PTU5
 | 
			
		||||
#define SERIAL_PORT "ttymxc2"
 | 
			
		||||
@@ -25,11 +25,13 @@
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class Work : public QRunnable {
 | 
			
		||||
    Utils m_utils;
 | 
			
		||||
    QString m_update_ctrl_file;
 | 
			
		||||
public:
 | 
			
		||||
    explicit Work(QString update_ctrl_file)  : m_utils(update_ctrl_file) {}
 | 
			
		||||
    explicit Work(QString update_ctrl_file)
 | 
			
		||||
        : m_update_ctrl_file(update_ctrl_file) {}
 | 
			
		||||
    void run() {
 | 
			
		||||
        m_utils.doUpdate();
 | 
			
		||||
        Update m_update(m_update_ctrl_file);
 | 
			
		||||
        m_update.doUpdate();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -47,11 +49,14 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
    if (argc == 2) {
 | 
			
		||||
        update_ctrl_file = argv[1];
 | 
			
		||||
    }
 | 
			
		||||
    qCritical() << "Using" << update_ctrl_file << "as update logfile";
 | 
			
		||||
    qInfo() << "Using" << update_ctrl_file << "as update logfile";
 | 
			
		||||
 | 
			
		||||
    Work work(update_ctrl_file);
 | 
			
		||||
    work.setAutoDelete(false);
 | 
			
		||||
    QThreadPool *threadPool = QThreadPool::globalInstance();
 | 
			
		||||
    threadPool->start(&work);
 | 
			
		||||
    return threadPool->waitForDone();
 | 
			
		||||
    if (!threadPool->waitForDone()) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user