mirror of
https://github.com/tnodir/fort
synced 2024-11-15 10:45:10 +00:00
UI: RPC: Setup DriverManager signals.
This commit is contained in:
parent
246066cad6
commit
6e6849e397
@ -13,7 +13,7 @@ enum Command : qint8 {
|
||||
Rpc_AppInfoManager_lookupAppInfo,
|
||||
Rpc_AppInfoManager_checkLookupFinished,
|
||||
Rpc_ConfManager_,
|
||||
Rpc_DriverManager_,
|
||||
Rpc_DriverManager_updateState,
|
||||
Rpc_QuotaManager_alert,
|
||||
Rpc_StatManager_,
|
||||
Rpc_TaskManager_,
|
||||
|
@ -25,52 +25,61 @@ DriverManager::~DriverManager()
|
||||
|
||||
QString DriverManager::errorMessage() const
|
||||
{
|
||||
return (m_errorCode == 0) ? QString() : OsUtil::errorMessage(m_errorCode);
|
||||
return (errorCode() == 0) ? QString() : OsUtil::errorMessage(errorCode());
|
||||
}
|
||||
|
||||
void DriverManager::updateError(bool success)
|
||||
void DriverManager::setErrorCode(quint32 v)
|
||||
{
|
||||
m_errorCode = success ? 0 : OsUtil::lastErrorCode();
|
||||
emit errorMessageChanged();
|
||||
if (m_errorCode != v) {
|
||||
m_errorCode = v;
|
||||
emit errorCodeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DriverManager::updateErrorCode(bool success)
|
||||
{
|
||||
setErrorCode(success ? 0 : OsUtil::lastErrorCode());
|
||||
}
|
||||
|
||||
bool DriverManager::isDeviceError() const
|
||||
{
|
||||
return m_errorCode != 0 && m_errorCode != DriverCommon::userErrorCode();
|
||||
return errorCode() != 0 && errorCode() != DriverCommon::userErrorCode();
|
||||
}
|
||||
|
||||
void DriverManager::setupWorker()
|
||||
{
|
||||
QThreadPool::globalInstance()->start(m_driverWorker);
|
||||
QThreadPool::globalInstance()->start(driverWorker());
|
||||
}
|
||||
|
||||
void DriverManager::abortWorker()
|
||||
{
|
||||
m_driverWorker->abort();
|
||||
driverWorker()->abort();
|
||||
}
|
||||
|
||||
bool DriverManager::isDeviceOpened() const
|
||||
{
|
||||
return m_device->isOpened();
|
||||
return device()->isOpened();
|
||||
}
|
||||
|
||||
bool DriverManager::openDevice()
|
||||
{
|
||||
const bool res = m_device->open(DriverCommon::deviceName());
|
||||
|
||||
updateError(res);
|
||||
const bool res = device()->open(DriverCommon::deviceName());
|
||||
|
||||
emit isDeviceOpenedChanged();
|
||||
|
||||
updateErrorCode(res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool DriverManager::closeDevice()
|
||||
{
|
||||
const bool res = m_device->close();
|
||||
const bool res = device()->close();
|
||||
|
||||
emit isDeviceOpenedChanged();
|
||||
|
||||
updateErrorCode(true);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -101,11 +110,11 @@ bool DriverManager::writeData(quint32 code, QByteArray &buf, int size)
|
||||
if (!isDeviceOpened())
|
||||
return true;
|
||||
|
||||
m_driverWorker->cancelAsyncIo();
|
||||
driverWorker()->cancelAsyncIo();
|
||||
|
||||
const bool res = m_device->ioctl(code, buf.data(), size);
|
||||
const bool res = device()->ioctl(code, buf.data(), size);
|
||||
|
||||
updateError(res);
|
||||
updateErrorCode(res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -20,8 +20,10 @@ public:
|
||||
~DriverManager() override;
|
||||
CLASS_DELETE_COPY_MOVE(DriverManager)
|
||||
|
||||
Device *device() const { return m_device; }
|
||||
DriverWorker *driverWorker() const { return m_driverWorker; }
|
||||
|
||||
quint32 errorCode() const { return m_errorCode; }
|
||||
QString errorMessage() const;
|
||||
bool isDeviceError() const;
|
||||
|
||||
@ -31,7 +33,7 @@ public:
|
||||
virtual void uninstallDriver();
|
||||
|
||||
signals:
|
||||
void errorMessageChanged();
|
||||
void errorCodeChanged();
|
||||
void isDeviceOpenedChanged();
|
||||
|
||||
public slots:
|
||||
@ -44,8 +46,11 @@ public slots:
|
||||
bool writeApp(QByteArray &buf, int size, bool remove = false);
|
||||
bool writeZones(QByteArray &buf, int size, bool onlyFlags = false);
|
||||
|
||||
protected:
|
||||
void setErrorCode(quint32 v);
|
||||
|
||||
private:
|
||||
void updateError(bool success);
|
||||
void updateErrorCode(bool success);
|
||||
|
||||
void setupWorker();
|
||||
void abortWorker();
|
||||
|
@ -495,7 +495,7 @@ void OptionsPage::setupDriverIcon()
|
||||
refreshDriverIcon();
|
||||
|
||||
connect(driverManager(), &DriverManager::isDeviceOpenedChanged, this, refreshDriverIcon);
|
||||
connect(driverManager(), &DriverManager::errorMessageChanged, this,
|
||||
connect(driverManager(), &DriverManager::errorCodeChanged, this,
|
||||
&OptionsPage::retranslateDriverMessage);
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,12 @@ DriverManagerRpc::DriverManagerRpc(FortManager *fortManager, QObject *parent) :
|
||||
{
|
||||
}
|
||||
|
||||
bool DriverManagerRpc::isDeviceOpened() const
|
||||
void DriverManagerRpc::setIsDeviceOpened(bool v)
|
||||
{
|
||||
return m_isDeviceOpened;
|
||||
if (m_isDeviceOpened != v) {
|
||||
m_isDeviceOpened = v;
|
||||
emit isDeviceOpenedChanged();
|
||||
}
|
||||
}
|
||||
|
||||
RpcManager *DriverManagerRpc::rpcManager() const
|
||||
@ -22,6 +25,12 @@ void DriverManagerRpc::reinstallDriver() { }
|
||||
|
||||
void DriverManagerRpc::uninstallDriver() { }
|
||||
|
||||
void DriverManagerRpc::updateState(quint32 errorCode, bool isDeviceOpened)
|
||||
{
|
||||
setIsDeviceOpened(isDeviceOpened);
|
||||
setErrorCode(errorCode);
|
||||
}
|
||||
|
||||
bool DriverManagerRpc::openDevice()
|
||||
{
|
||||
return false;
|
||||
|
@ -13,7 +13,8 @@ class DriverManagerRpc : public DriverManager
|
||||
public:
|
||||
explicit DriverManagerRpc(FortManager *fortManager, QObject *parent = nullptr);
|
||||
|
||||
bool isDeviceOpened() const override;
|
||||
bool isDeviceOpened() const override { return m_isDeviceOpened; }
|
||||
void setIsDeviceOpened(bool v);
|
||||
|
||||
FortManager *fortManager() const { return m_fortManager; }
|
||||
RpcManager *rpcManager() const;
|
||||
@ -21,6 +22,8 @@ public:
|
||||
void reinstallDriver() override;
|
||||
void uninstallDriver() override;
|
||||
|
||||
void updateState(quint32 errorCode, bool isDeviceOpened);
|
||||
|
||||
public slots:
|
||||
bool openDevice() override;
|
||||
bool closeDevice() override;
|
||||
|
@ -68,6 +68,7 @@ void RpcManager::initialize()
|
||||
void RpcManager::setupServerSignals()
|
||||
{
|
||||
setupAppInfoManagerSignals();
|
||||
setupDriverManagerSignals();
|
||||
setupQuotaManagerSignals();
|
||||
}
|
||||
|
||||
@ -79,6 +80,16 @@ void RpcManager::setupAppInfoManagerSignals()
|
||||
});
|
||||
}
|
||||
|
||||
void RpcManager::setupDriverManagerSignals()
|
||||
{
|
||||
const auto updateClientStates = [&] {
|
||||
invokeOnClients(Control::Rpc_DriverManager_updateState,
|
||||
{ driverManager()->errorCode(), driverManager()->isDeviceOpened() });
|
||||
};
|
||||
connect(driverManager(), &DriverManager::errorCodeChanged, this, updateClientStates);
|
||||
connect(driverManager(), &DriverManager::isDeviceOpenedChanged, this, updateClientStates);
|
||||
}
|
||||
|
||||
void RpcManager::setupQuotaManagerSignals()
|
||||
{
|
||||
connect(quotaManager(), &QuotaManager::alert, this, [&](qint8 alertType) {
|
||||
@ -124,9 +135,13 @@ bool RpcManager::processCommandRpc(
|
||||
case Control::Rpc_ConfManager_:
|
||||
confManager();
|
||||
return true;
|
||||
case Control::Rpc_DriverManager_:
|
||||
driverManager();
|
||||
return true;
|
||||
case Control::Rpc_DriverManager_updateState:
|
||||
if (settings()->isServiceClient()) {
|
||||
auto dm = qobject_cast<DriverManagerRpc *>(driverManager());
|
||||
dm->updateState(args.value(0).toUInt(), args.value(1).toBool());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case Control::Rpc_QuotaManager_alert:
|
||||
emit quotaManager()->alert(args.value(0).toInt());
|
||||
return true;
|
||||
@ -138,6 +153,7 @@ bool RpcManager::processCommandRpc(
|
||||
return true;
|
||||
default:
|
||||
errorMessage = "Unknown command";
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
private:
|
||||
void setupServerSignals();
|
||||
void setupAppInfoManagerSignals();
|
||||
void setupDriverManagerSignals();
|
||||
void setupQuotaManagerSignals();
|
||||
|
||||
void setupClient();
|
||||
|
Loading…
Reference in New Issue
Block a user