From f8b43bbf991cd433be0a2447614b29e310c720e7 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 13 May 2021 19:06:11 +0300 Subject: [PATCH] UI: DriverManagerRpc: Don't use driver device. --- src/ui/driver/drivermanager.cpp | 23 ++++++++++------------- src/ui/driver/drivermanager.h | 7 ++++--- src/ui/fortmanager.cpp | 2 ++ src/ui/rpc/drivermanagerrpc.h | 5 +++++ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/ui/driver/drivermanager.cpp b/src/ui/driver/drivermanager.cpp index 0f0e1ec1..0c6f170b 100644 --- a/src/ui/driver/drivermanager.cpp +++ b/src/ui/driver/drivermanager.cpp @@ -10,13 +10,7 @@ #include "../util/osutil.h" #include "driverworker.h" -DriverManager::DriverManager(QObject *parent) : - QObject(parent), - m_device(new Device(this)), - m_driverWorker(new DriverWorker(m_device)) // autoDelete = true -{ - setupWorker(); -} +DriverManager::DriverManager(QObject *parent) : QObject(parent) { } DriverManager::~DriverManager() { @@ -46,8 +40,16 @@ bool DriverManager::isDeviceError() const return errorCode() != 0 && errorCode() != DriverCommon::userErrorCode(); } -void DriverManager::setupWorker() +bool DriverManager::isDeviceOpened() const { + return device()->isOpened(); +} + +void DriverManager::initialize() +{ + m_device = new Device(this); + m_driverWorker = new DriverWorker(device()); // autoDelete = true + QThreadPool::globalInstance()->start(driverWorker()); } @@ -56,11 +58,6 @@ void DriverManager::abortWorker() driverWorker()->abort(); } -bool DriverManager::isDeviceOpened() const -{ - return device()->isOpened(); -} - bool DriverManager::openDevice() { const bool res = device()->open(DriverCommon::deviceName()); diff --git a/src/ui/driver/drivermanager.h b/src/ui/driver/drivermanager.h index f031a09a..474cda21 100644 --- a/src/ui/driver/drivermanager.h +++ b/src/ui/driver/drivermanager.h @@ -29,6 +29,8 @@ public: virtual bool isDeviceOpened() const; + virtual void initialize(); + virtual void reinstallDriver(); virtual void uninstallDriver(); @@ -49,12 +51,11 @@ public slots: protected: void setErrorCode(quint32 v); + virtual void abortWorker(); + private: void updateErrorCode(bool success); - void setupWorker(); - void abortWorker(); - bool writeData(quint32 code, QByteArray &buf, int size); static void executeCommand(const QString &fileName); diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index a09065ab..ec6d30cc 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -181,6 +181,8 @@ void FortManager::removeDriver() bool FortManager::setupDriver() { + driverManager()->initialize(); + bool ok = driverManager()->openDevice(); if (ok && !confManager()->validateDriver()) { diff --git a/src/ui/rpc/drivermanagerrpc.h b/src/ui/rpc/drivermanagerrpc.h index 0680bbcc..ad993632 100644 --- a/src/ui/rpc/drivermanagerrpc.h +++ b/src/ui/rpc/drivermanagerrpc.h @@ -19,6 +19,8 @@ public: FortManager *fortManager() const { return m_fortManager; } RpcManager *rpcManager() const; + void initialize() override { } + void reinstallDriver() override; void uninstallDriver() override; @@ -28,6 +30,9 @@ public slots: bool openDevice() override; bool closeDevice() override; +protected: + void abortWorker() override { } + private: bool m_isDeviceOpened : 1;