mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
Ref T192, improved display/log of DBus connection
* log level * more detailed messages
This commit is contained in:
@@ -26,7 +26,9 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
CDBusServer::CDBusServer(const QString &service, const QString &address, QObject *parent) : QObject(parent)
|
CDBusServer::CDBusServer(const QString &service, const QString &address, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
m_serverMode = modeOfAddress(address);
|
static const QString desc("Mode: %1 Address: '%2' Service: '%3'");
|
||||||
|
m_serverMode = CDBusServer::modeOfAddress(address);
|
||||||
|
this->setObjectName(desc.arg(CDBusServer::modeToString(m_serverMode), address, service.isEmpty() ? "-" : service));
|
||||||
switch (m_serverMode)
|
switch (m_serverMode)
|
||||||
{
|
{
|
||||||
case SERVERMODE_SESSIONBUS:
|
case SERVERMODE_SESSIONBUS:
|
||||||
@@ -60,13 +62,14 @@ namespace BlackMisc
|
|||||||
dbusAddress = dbusAddress.toLower().trimmed().replace(' ', "");
|
dbusAddress = dbusAddress.toLower().trimmed().replace(' ', "");
|
||||||
if (! dbusAddress.contains("bind=")) { dbusAddress = dbusAddress.append(",bind=*"); } // bind to all network interfaces
|
if (! dbusAddress.contains("bind=")) { dbusAddress = dbusAddress.append(",bind=*"); } // bind to all network interfaces
|
||||||
|
|
||||||
m_busServer.reset(new QDBusServer(dbusAddress, parent));
|
m_busServer.reset(new QDBusServer(dbusAddress, this));
|
||||||
|
m_busServer->setObjectName("QDBusServer: " + this->objectName());
|
||||||
m_busServer->setAnonymousAuthenticationAllowed(true);
|
m_busServer->setAnonymousAuthenticationAllowed(true);
|
||||||
|
|
||||||
// Note: P2P has no service name
|
// Note: P2P has no service name
|
||||||
if (m_busServer->isConnected())
|
if (m_busServer->isConnected())
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << "Server listening on address:" << m_busServer->address();
|
CLogMessage(this).info("DBus P2P Server listening on address: '%1'") << m_busServer->address();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -171,14 +174,21 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
Q_ASSERT(! m_objects.isEmpty());
|
Q_ASSERT(! m_objects.isEmpty());
|
||||||
m_connections.insert(connection.name(), connection);
|
m_connections.insert(connection.name(), connection);
|
||||||
CLogMessage(this).debug() << "New Connection from:" << connection.name();
|
CLogMessage(this).info("New Connection from: '%1'") << connection.name();
|
||||||
bool success = true;
|
bool success = true;
|
||||||
for (auto i = m_objects.cbegin(); i != m_objects.cend(); ++i)
|
for (auto i = m_objects.cbegin(); i != m_objects.cend(); ++i)
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << "Adding" << i.key() << getDBusInterfaceFromClassInfo(i.value()) << "to the new connection.";
|
const QString key(i.key());
|
||||||
bool ok = connection.registerObject(i.key(), i.value(), registerOptions());
|
const bool ok = connection.registerObject(key, i.value(), registerOptions());
|
||||||
Q_ASSERT_X(ok, "CDBusServer::newConnection", "Registration failed");
|
if (ok)
|
||||||
if (! ok) { success = false; }
|
{
|
||||||
|
CLogMessage(this).info("Adding '%1' to the new connection '%2'") << key << this->getDBusInterfaceFromClassInfo(i.value());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CLogMessage(this).info("Adding '%1' failed, connection '%2', error '%3'") << key << this->getDBusInterfaceFromClassInfo(i.value()) << connection.lastError().message();
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -195,7 +205,7 @@ namespace BlackMisc
|
|||||||
QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SessionBus, coreServiceName());
|
QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SessionBus, coreServiceName());
|
||||||
if (connection.registerObject(path, object, registerOptions()))
|
if (connection.registerObject(path, object, registerOptions()))
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << "Adding" << path << getDBusInterfaceFromClassInfo(object) << "to session bus.";
|
CLogMessage(this).info("Adding '%1' '%2' to session DBus") << path << getDBusInterfaceFromClassInfo(object);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -208,7 +218,7 @@ namespace BlackMisc
|
|||||||
QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SystemBus, coreServiceName());
|
QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SystemBus, coreServiceName());
|
||||||
if (connection.registerObject(path, object, registerOptions()))
|
if (connection.registerObject(path, object, registerOptions()))
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << "Adding" << path << getDBusInterfaceFromClassInfo(object) << "to system bus.";
|
CLogMessage(this).info("Adding '%1' '%2' to system DBus") << path << getDBusInterfaceFromClassInfo(object);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -222,7 +232,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
if (connection.registerObject(path, object, registerOptions()))
|
if (connection.registerObject(path, object, registerOptions()))
|
||||||
{
|
{
|
||||||
CLogMessage(this).debug() << "Adding" << path << getDBusInterfaceFromClassInfo(object) << "to" << connection.name();
|
CLogMessage(this).info("Adding '%1' '%2' to P2P DBus '%3'") << path << getDBusInterfaceFromClassInfo(object) << connection.name();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -403,6 +413,22 @@ namespace BlackMisc
|
|||||||
else { return SERVERMODE_P2P; }
|
else { return SERVERMODE_P2P; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &CDBusServer::modeToString(CDBusServer::ServerMode mode)
|
||||||
|
{
|
||||||
|
static const QString p2p = "P2P";
|
||||||
|
static const QString session = "session";
|
||||||
|
static const QString system = "system";
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case SERVERMODE_P2P: return p2p;
|
||||||
|
case SERVERMODE_SYSTEMBUS: return system;
|
||||||
|
case SERVERMODE_SESSIONBUS:
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
bool CDBusServer::isDBusAvailable(const QString &address, int port, int timeoutMs)
|
bool CDBusServer::isDBusAvailable(const QString &address, int port, int timeoutMs)
|
||||||
{
|
{
|
||||||
QString unused;
|
QString unused;
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ namespace BlackMisc
|
|||||||
//! Return the server mode of the given address
|
//! Return the server mode of the given address
|
||||||
static ServerMode modeOfAddress(QString address);
|
static ServerMode modeOfAddress(QString address);
|
||||||
|
|
||||||
|
//! Mode to string
|
||||||
|
static const QString &modeToString(ServerMode mode);
|
||||||
|
|
||||||
//! True if a valid Qt DBus address, e.g. "unix:tmpdir=/tmp", "tcp:host=127.0.0.1,port=45000"
|
//! True if a valid Qt DBus address, e.g. "unix:tmpdir=/tmp", "tcp:host=127.0.0.1,port=45000"
|
||||||
static bool isQtDBusAddress(const QString &address);
|
static bool isQtDBusAddress(const QString &address);
|
||||||
|
|
||||||
@@ -143,10 +146,7 @@ namespace BlackMisc
|
|||||||
static QString getDBusInterfaceFromClassInfo(QObject *object);
|
static QString getDBusInterfaceFromClassInfo(QObject *object);
|
||||||
|
|
||||||
//! Register options with connection
|
//! Register options with connection
|
||||||
static QDBusConnection::RegisterOptions registerOptions()
|
static QDBusConnection::RegisterOptions registerOptions();
|
||||||
{
|
|
||||||
return QDBusConnection::ExportAdaptors | QDBusConnection::ExportAllSignals | QDBusConnection::ExportAllSlots;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Called when a new DBus client has connected in P2P mode
|
//! Called when a new DBus client has connected in P2P mode
|
||||||
bool registerObjectsWithP2PConnection(QDBusConnection connection);
|
bool registerObjectsWithP2PConnection(QDBusConnection connection);
|
||||||
|
|||||||
@@ -324,22 +324,21 @@ void SwiftGuiStd::setContextAvailability()
|
|||||||
|
|
||||||
void SwiftGuiStd::updateGuiStatusInformation()
|
void SwiftGuiStd::updateGuiStatusInformation()
|
||||||
{
|
{
|
||||||
QString network("unavailable");
|
|
||||||
if (m_coreAvailable)
|
if (m_coreAvailable)
|
||||||
{
|
{
|
||||||
|
static const QString dBusTimestamp("%1 %2");
|
||||||
|
static const QString local("local");
|
||||||
const QString now = QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd HH:mm:ss");
|
const QString now = QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd HH:mm:ss");
|
||||||
bool dBus = sGui->getCoreFacadeConfig().requiresDBusConnection();
|
const bool dBus = sGui->getCoreFacadeConfig().requiresDBusConnection();
|
||||||
network = dBus ? now : "local";
|
|
||||||
ui->comp_InfoBarStatus->setDBusStatus(dBus && m_coreAvailable);
|
ui->comp_InfoBarStatus->setDBusStatus(dBus && m_coreAvailable);
|
||||||
|
ui->comp_InfoBarStatus->setDBusTooltip(dBus ? dBusTimestamp.arg(now, sGui->getCoreFacadeConfig().getDBusAddress()) : local);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
static const QString unavailable("unavailable");
|
||||||
ui->comp_InfoBarStatus->setDBusStatus(false);
|
ui->comp_InfoBarStatus->setDBusStatus(false);
|
||||||
|
ui->comp_InfoBarStatus->setDBusTooltip(unavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update status fields
|
|
||||||
const QString s = QString("network: %1").arg(network);
|
|
||||||
ui->comp_InfoBarStatus->setDBusTooltip(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwiftGuiStd::onChangedWindowOpacity(int opacity)
|
void SwiftGuiStd::onChangedWindowOpacity(int opacity)
|
||||||
|
|||||||
Reference in New Issue
Block a user