mirror of
https://github.com/tnodir/fort
synced 2024-11-15 13:06:36 +00:00
UI: RPC: Wait result.
This commit is contained in:
parent
2e53990ce4
commit
22677b1217
@ -9,6 +9,8 @@ enum Command : qint8 {
|
||||
CommandNone = 0,
|
||||
Conf,
|
||||
Prog,
|
||||
Rpc_Result_Ok,
|
||||
Rpc_Result_Error,
|
||||
Rpc_RpcManager_initClient,
|
||||
Rpc_AppInfoManager_lookupAppInfo,
|
||||
Rpc_AppInfoManager_checkLookupFinished,
|
||||
|
@ -99,6 +99,8 @@ bool ControlWorker::sendCommand(Control::Command command, const QVariantList &ar
|
||||
socket()->write(buffer);
|
||||
}
|
||||
|
||||
socket()->flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -107,6 +109,11 @@ bool ControlWorker::waitForSent(int msecs) const
|
||||
return socket()->waitForBytesWritten(msecs);
|
||||
}
|
||||
|
||||
bool ControlWorker::waitForRead(int msecs) const
|
||||
{
|
||||
return socket()->waitForReadyRead(msecs);
|
||||
}
|
||||
|
||||
void ControlWorker::processRequest()
|
||||
{
|
||||
if (!readRequest()) {
|
||||
|
@ -25,9 +25,10 @@ public:
|
||||
|
||||
void setupForAsync();
|
||||
|
||||
bool sendCommand(Control::Command command, const QVariantList &args);
|
||||
bool sendCommand(Control::Command command, const QVariantList &args = {});
|
||||
|
||||
bool waitForSent(int msecs = 1000) const;
|
||||
bool waitForRead(int msecs = 1000) const;
|
||||
|
||||
static QVariantList buildArgs(const QStringList &list);
|
||||
|
||||
|
@ -33,8 +33,17 @@ void ConfManagerRpc::setupAppEndTimer() { }
|
||||
bool ConfManagerRpc::saveToDbIni(FirewallConf &newConf, bool onlyFlags)
|
||||
{
|
||||
rpcManager()->invokeOnServer(Control::Rpc_ConfManager_save,
|
||||
{ newConf.toVariant(onlyFlags), onlyFlags, confVersion() });
|
||||
// TODO: get result
|
||||
// showErrorMessage("Save Conf: Service error.");
|
||||
{ newConf.toVariant(onlyFlags), confVersion(), onlyFlags });
|
||||
|
||||
if (!rpcManager()->waitResult()) {
|
||||
showErrorMessage("Save Conf: Service isn't responding.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rpcManager()->resultCommand() != Control::Rpc_Result_Ok) {
|
||||
showErrorMessage("Save Conf: Service error.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -117,6 +117,23 @@ void RpcManager::invokeOnServer(Control::Command cmd, const QVariantList &args)
|
||||
client()->sendCommand(cmd, args);
|
||||
}
|
||||
|
||||
bool RpcManager::waitResult()
|
||||
{
|
||||
m_resultCommand = Control::CommandNone;
|
||||
|
||||
do {
|
||||
if (!client()->waitForRead())
|
||||
return false;
|
||||
} while (m_resultCommand == Control::CommandNone);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RpcManager::sendResult(ControlWorker *w, bool ok)
|
||||
{
|
||||
w->sendCommand(ok ? Control::Rpc_Result_Ok : Control::Rpc_Result_Error);
|
||||
}
|
||||
|
||||
void RpcManager::invokeOnClients(Control::Command cmd, const QVariantList &args)
|
||||
{
|
||||
const auto clients = controlManager()->clients();
|
||||
@ -149,6 +166,10 @@ bool RpcManager::processCommandRpc(
|
||||
ControlWorker *w, Control::Command cmd, const QVariantList &args, QString &errorMessage)
|
||||
{
|
||||
switch (cmd) {
|
||||
case Control::Rpc_Result_Ok:
|
||||
case Control::Rpc_Result_Error:
|
||||
m_resultCommand = cmd;
|
||||
return true;
|
||||
case Control::Rpc_RpcManager_initClient:
|
||||
initClientOnServer(w);
|
||||
return true;
|
||||
@ -166,7 +187,7 @@ bool RpcManager::processCommandRpc(
|
||||
case Control::Rpc_ConfManager_save: {
|
||||
const bool ok = confManager()->saveVariant(
|
||||
args.value(0), args.value(1).toInt(), args.value(2).toBool());
|
||||
w->sendCommand(Control::Rpc_ConfManager_saveResult, { ok });
|
||||
sendResult(w, ok);
|
||||
return true;
|
||||
}
|
||||
case Control::Rpc_DriverManager_updateState:
|
||||
|
@ -24,6 +24,8 @@ class RpcManager : public QObject
|
||||
public:
|
||||
explicit RpcManager(FortManager *fortManager, QObject *parent = nullptr);
|
||||
|
||||
Control::Command resultCommand() const { return m_resultCommand; }
|
||||
|
||||
FortManager *fortManager() const { return m_fortManager; }
|
||||
FortSettings *settings() const;
|
||||
ControlManager *controlManager() const;
|
||||
@ -39,6 +41,9 @@ public:
|
||||
|
||||
void invokeOnServer(Control::Command cmd, const QVariantList &args = {});
|
||||
|
||||
bool waitResult();
|
||||
void sendResult(ControlWorker *w, bool ok);
|
||||
|
||||
bool processCommandRpc(ControlWorker *w, Control::Command cmd, const QVariantList &args,
|
||||
QString &errorMessage);
|
||||
|
||||
@ -59,6 +64,8 @@ private:
|
||||
QVariantList driverManager_updateState_args() const;
|
||||
|
||||
private:
|
||||
Control::Command m_resultCommand = Control::CommandNone;
|
||||
|
||||
FortManager *m_fortManager = nullptr;
|
||||
|
||||
ControlWorker *m_client = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user