mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Let xbus retry to connect to dbus in case it is not available
refs #615
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
#include "weather.h"
|
||||
#include "utils.h"
|
||||
#include "blackmisc/librarypath.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include <QTimer>
|
||||
#include <functional>
|
||||
|
||||
namespace {
|
||||
inline QString xbusServiceName() {
|
||||
@@ -33,21 +36,39 @@ namespace XBus
|
||||
|
||||
void CPlugin::startServer(const QString &address)
|
||||
{
|
||||
Q_ASSERT(! m_server);
|
||||
for (auto &item : m_startServerMenuItems) { item.setEnabled(false); }
|
||||
|
||||
m_service = new CService(this);
|
||||
m_traffic = new CTraffic(this);
|
||||
m_weather = new CWeather(this);
|
||||
|
||||
// XPLM API does not like to be called from a QTimer slot, so move the recurring part into a separate method.
|
||||
tryStartServer(address);
|
||||
}
|
||||
|
||||
void CPlugin::tryStartServer(const QString &address)
|
||||
{
|
||||
// Make sure that there are no calls to XPLM in this method
|
||||
Q_ASSERT(! m_server);
|
||||
auto previousLibraryPath = BlackMisc::getCustomLibraryPath();
|
||||
auto libraryPath = g_xplanePath + "Resources" + g_sep + "plugins" + g_sep + "xbus";
|
||||
#if !defined (Q_OS_MAC) && defined(WORD_SIZE_64)
|
||||
libraryPath = libraryPath + g_sep + "64";
|
||||
#endif
|
||||
BlackMisc::setCustomLibraryPath(libraryPath);
|
||||
|
||||
if (!BlackMisc::CDBusServer::isP2PAddress(address) && !BlackMisc::CDBusServer::isDBusAvailable(address))
|
||||
{
|
||||
constexpr int msec = 30000;
|
||||
BlackMisc::CLogMessage(this).warning("DBus daemon not available. Trying again in %1 sec.") << msec / 1000;
|
||||
QTimer::singleShot(msec, this, [&] { tryStartServer(address); });
|
||||
BlackMisc::setCustomLibraryPath(previousLibraryPath);
|
||||
return;
|
||||
}
|
||||
|
||||
m_server = new BlackMisc::CDBusServer(xbusServiceName(), address, this);
|
||||
BlackMisc::setCustomLibraryPath(previousLibraryPath);
|
||||
|
||||
m_service = new CService(this);
|
||||
m_traffic = new CTraffic(this);
|
||||
m_weather = new CWeather(this);
|
||||
m_server->addObject(CService::ObjectPath(), m_service);
|
||||
m_server->addObject(CTraffic::ObjectPath(), m_traffic);
|
||||
m_server->addObject(CWeather::ObjectPath(), m_weather);
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace XBus
|
||||
QVector<CMenuItem> m_startServerMenuItems;
|
||||
|
||||
void startServer(const QString &address);
|
||||
void tryStartServer(const QString &address);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user