Commit 6f1a9e76 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Some more crash fixes in handling of NotificationSubscribers

parent c6db044c
......@@ -85,19 +85,6 @@ void NotificationManager::registerConnection(quintptr socketDescriptor)
NotificationSubscriber *subscriber = new NotificationSubscriber(this, socketDescriptor);
qCDebug(AKONADISERVER_LOG) << "New notification connection (registered as" << subscriber << ")";
connect(subscriber, &QObject::destroyed,
this, [this, subscriber]() {
// Can't use mSubscribers.remove() because that would try to create
// a QPointer for the subscriber pointer triggering a Q_ASSERT in Qt
// (see QtSharedPointer::ExternalRefCountData::getAndRef)
auto it = std::find_if(mSubscribers.begin(), mSubscribers.end(),
[subscriber](const QPointer<NotificationSubscriber> &qptr) {
return qptr.data() == subscriber;
});
if (it != mSubscribers.end()) {
mSubscribers.erase(it);
}
});
connect(subscriber, &NotificationSubscriber::notificationDebuggingChanged,
this, [this](bool enabled) {
if (enabled) {
......@@ -112,6 +99,12 @@ void NotificationManager::registerConnection(quintptr socketDescriptor)
mSubscribers.push_back(subscriber);
}
void NotificationManager::forgetSubscriber(NotificationSubscriber *subscriber)
{
Q_ASSERT(QThread::currentThread() == thread());
mSubscribers.removeOne(subscriber);
}
void NotificationManager::connectNotificationCollector(NotificationCollector *collector)
{
connect(collector, &NotificationCollector::notify,
......@@ -167,6 +160,8 @@ private:
void NotificationManager::emitPendingNotifications()
{
Q_ASSERT(QThread::currentThread() == thread());
if (mNotifications.isEmpty()) {
return;
}
......
......@@ -46,6 +46,7 @@ public:
virtual ~NotificationManager();
void connectNotificationCollector(NotificationCollector *collector);
void forgetSubscriber(NotificationSubscriber *subscriber);
public Q_SLOTS:
void registerConnection(quintptr socketDescriptor);
......
......@@ -147,6 +147,7 @@ void NotificationSubscriber::disconnectSubscriber()
disconnect(mSocket, &QLocalSocket::disconnected,
this, &NotificationSubscriber::socketDisconnected);
mSocket->close();
mManager->forgetSubscriber(this);
deleteLater();
}
......@@ -670,6 +671,8 @@ void NotificationSubscriber::writeNotification(const Protocol::ChangeNotificatio
void NotificationSubscriber::writeCommand(qint64 tag, const Protocol::Command& cmd)
{
Q_ASSERT(QThread::currentThread() == thread());
QDataStream stream(mSocket);
stream << tag;
Protocol::serialize(mSocket, cmd);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment