mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
refs #883, improved detection if core is running
* use proxy to really ping core (not only checking connection) * avoid closing Qt default connections -> crash * some refactoring
This commit is contained in:
committed by
Mathew Sutcliffe
parent
d918ee4cfd
commit
6c72f8491c
@@ -9,10 +9,10 @@
|
||||
|
||||
#include "blackcore/context/contextapplicationproxy.h"
|
||||
#include "blackmisc/dbus.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/genericdbusinterface.h"
|
||||
#include "blackmisc/identifierlist.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QLatin1Literal>
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Context
|
||||
@@ -179,5 +180,28 @@ namespace BlackCore
|
||||
if (fileName.isEmpty()) { return false; }
|
||||
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("existsFile"), fileName);
|
||||
}
|
||||
|
||||
bool CContextApplicationProxy::isContextResponsive(const QString &dBusAddress, QString &msg, int timeoutMs)
|
||||
{
|
||||
const bool connected = CDBusServer::isDBusAvailable(dBusAddress, msg, timeoutMs);
|
||||
if (!connected) { return false; }
|
||||
|
||||
static const QString dBusName("contexttest");
|
||||
QDBusConnection connection = CDBusServer::connectToDBus(dBusAddress, dBusName);
|
||||
CContextApplicationProxy proxy(BlackMisc::CDBusServer::coreServiceName(), connection, CCoreFacadeConfig::Remote, nullptr);
|
||||
const CIdentifier id("swift proxy test");
|
||||
const CIdentifier pingId = proxy.registerApplication(id);
|
||||
const bool ok = (id == pingId);
|
||||
if (ok)
|
||||
{
|
||||
proxy.unregisterApplication(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "Mismatch in proxy ping, context not ready.";
|
||||
}
|
||||
CDBusServer::disconnectFromDBus(connection, dBusAddress);
|
||||
return ok;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace BlackCore
|
||||
virtual bool existsFile(const QString &fileName) const override;
|
||||
//! @}
|
||||
|
||||
//! Used to test if there is a core running?
|
||||
//! \note creates and connects via proxy object, so not meant for very frequent tests
|
||||
//! \sa CDBusServer::isDBusAvailable as lightweight, but less accurate alternative
|
||||
static bool isContextResponsive(const QString &dbusAddress, QString &msg, int timeoutMs = 1500);
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CContextApplicationProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr) {}
|
||||
|
||||
Reference in New Issue
Block a user