mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
Ref T173, unregister a DBus service before connecting
* In case there is a crash and we reconnect, the old service might be still registered * "private slots" -> "private"
This commit is contained in:
@@ -32,6 +32,7 @@ namespace BlackMisc
|
||||
case SERVERMODE_SESSIONBUS:
|
||||
{
|
||||
QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SessionBus, coreServiceName());
|
||||
connection.unregisterService(service); // allow reconnecting by removing still registered service
|
||||
if (! connection.isConnected() || ! connection.registerService(service))
|
||||
{
|
||||
// registration fails can either mean something wrong with DBus or service already exists
|
||||
@@ -43,6 +44,7 @@ namespace BlackMisc
|
||||
case SERVERMODE_SYSTEMBUS:
|
||||
{
|
||||
QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SystemBus, coreServiceName());
|
||||
connection.unregisterService(service); // allow reconnecting by removing still registered service
|
||||
if (! connection.isConnected() || ! connection.registerService(service))
|
||||
{
|
||||
// registration fails can either mean something wrong with DBus or service already exists
|
||||
@@ -70,7 +72,7 @@ namespace BlackMisc
|
||||
{
|
||||
CLogMessage(this).warning("DBus P2P connection failed: %1") << lastQDBusServerError().message();
|
||||
}
|
||||
connect(m_busServer.data(), &QDBusServer::newConnection, this, &CDBusServer::ps_registerObjectsWithP2PConnection);
|
||||
connect(m_busServer.data(), &QDBusServer::newConnection, this, &CDBusServer::registerObjectsWithP2PConnection);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -154,7 +156,7 @@ namespace BlackMisc
|
||||
return "";
|
||||
}
|
||||
|
||||
bool CDBusServer::ps_registerObjectsWithP2PConnection(QDBusConnection connection)
|
||||
bool CDBusServer::registerObjectsWithP2PConnection(QDBusConnection connection)
|
||||
{
|
||||
Q_ASSERT(! m_objects.isEmpty());
|
||||
m_connections.insert(connection.name(), connection);
|
||||
@@ -236,7 +238,7 @@ namespace BlackMisc
|
||||
|
||||
bool CDBusServer::hasQDBusServer() const
|
||||
{
|
||||
return ! m_busServer.isNull();
|
||||
return !m_busServer.isNull();
|
||||
}
|
||||
|
||||
void CDBusServer::removeAllObjects()
|
||||
|
||||
@@ -145,9 +145,8 @@ namespace BlackMisc
|
||||
return QDBusConnection::ExportAdaptors | QDBusConnection::ExportAllSignals | QDBusConnection::ExportAllSlots;
|
||||
}
|
||||
|
||||
private slots:
|
||||
//! Called when a new DBus client has connected in P2P mode
|
||||
bool ps_registerObjectsWithP2PConnection(QDBusConnection connection);
|
||||
bool registerObjectsWithP2PConnection(QDBusConnection connection);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user