File indexing completed on 2025-01-05 04:47:03

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akthread.h"
0010 
0011 #include "private/protocol_p.h"
0012 
0013 #include <QPointer>
0014 class QTimer;
0015 
0016 class NotificationManagerTest;
0017 class QThreadPool;
0018 
0019 namespace Akonadi
0020 {
0021 namespace Server
0022 {
0023 class NotificationSubscriber;
0024 class AggregatedCollectionFetchScope;
0025 class AggregatedItemFetchScope;
0026 class AggregatedTagFetchScope;
0027 
0028 class NotificationManager : public AkThread
0029 {
0030     Q_OBJECT
0031 
0032 protected:
0033     /**
0034      * Use AkThread::create() to create and start a new NotificationManager thread.
0035      */
0036     explicit NotificationManager(StartMode startMode = AutoStart);
0037 
0038 public:
0039     ~NotificationManager() override;
0040 
0041     void forgetSubscriber(NotificationSubscriber *subscriber);
0042 
0043     AggregatedCollectionFetchScope *collectionFetchScope() const
0044     {
0045         return mCollectionFetchScope;
0046     }
0047     AggregatedItemFetchScope *itemFetchScope() const
0048     {
0049         return mItemFetchScope;
0050     }
0051     AggregatedTagFetchScope *tagFetchScope() const
0052     {
0053         return mTagFetchScope;
0054     }
0055 
0056 public Q_SLOTS:
0057     void registerConnection(quintptr socketDescriptor);
0058 
0059     void emitPendingNotifications();
0060 
0061     void slotNotify(const Akonadi::Protocol::ChangeNotificationList &msgs);
0062 
0063 protected:
0064     void init() override;
0065     void quit() override;
0066 
0067     void emitDebugNotification(const Protocol::ChangeNotificationPtr &ntf, const QList<QByteArray> &listeners);
0068 
0069 private:
0070     Protocol::ChangeNotificationList mNotifications;
0071     QTimer *mTimer = nullptr;
0072 
0073     QThreadPool *mNotifyThreadPool = nullptr;
0074     QList<QPointer<NotificationSubscriber>> mSubscribers;
0075     int mDebugNotifications;
0076     AggregatedCollectionFetchScope *mCollectionFetchScope = nullptr;
0077     AggregatedItemFetchScope *mItemFetchScope = nullptr;
0078     AggregatedTagFetchScope *mTagFetchScope = nullptr;
0079 
0080     bool mWaiting = false;
0081     bool mQuitting = false;
0082 
0083     friend class NotificationSubscriber;
0084     friend class ::NotificationManagerTest;
0085 };
0086 
0087 } // namespace Server
0088 } // namespace Akonadi