KUnifiedPush

distributor.h
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KUNIFIEDPUSH_DISTRIBUTOR_H
7#define KUNIFIEDPUSH_DISTRIBUTOR_H
8
9#include "abstractpushprovider.h"
10#include "command.h"
11
12#include "../shared/clientinfo_p.h"
13#include "../shared/distributorstatus_p.h"
14#include "../shared/urgency_p.h"
15
16#include <QDBusContext>
17#include <QObject>
18#include <QTimer>
19
20#include <deque>
21#include <memory>
22#include <vector>
23
24namespace Solid {
25class Device;
26}
27
28namespace KUnifiedPush {
29
30class Client;
31class Message;
32
33/** UnifiedPush distributor service. */
34class Distributor : public QObject, public QDBusContext
35{
37public:
38 explicit Distributor(QObject *parent = nullptr);
39 ~Distributor();
40
41 // UnifiedPush D-Bus interface v1
42 [[nodiscard]] QString Register(const QString &serviceName, const QString &token, const QString &description, QString &registrationResultReason);
43 void Unregister(const QString &token);
44
45 // UnifiedPush D-Bus interface v2
46 [[nodiscard]] QVariantMap Register(const QVariantMap &args);
47 [[nodiscard]] QVariantMap Unregister(const QVariantMap &args);
48
49 // KCM D-Bus interface
50 [[nodiscard]] int status() const;
51 [[nodiscard]] QString errorMessage() const;
52 [[nodiscard]] QString pushProviderId() const;
53 [[nodiscard]] QVariantMap pushProviderConfiguration(const QString &pushProviderId) const;
54 void setPushProvider(const QString &pushProviderId, const QVariantMap &config);
55 [[nodiscard]] QList<KUnifiedPush::ClientInfo> registeredClients() const;
56 void forceUnregisterClient(const QString &token);
57
58 // internal
59 void messageAcknowledged(const Client &client, const QString &messageIdentifier);
60
62 void statusChanged();
63 void errorMessageChanged();
64 void pushProviderChanged();
65 void registeredClientsChanged();
66
67private:
68 void messageReceived(const Message &msg);
69 void connectOnDemand();
70 void clientRegistered(const Client &client, AbstractPushProvider::Error error, const QString &errorMsg);
71 void clientUnregistered(const Client &client, AbstractPushProvider::Error error);
72 void providerConnected();
73 void providerDisconnected(AbstractPushProvider::Error error, const QString &errorMsg);
74 void providerMessageAcknowledged(const Client &client, const QString &messageIdentifier);
75 void providerUrgencyChanged();
76 void retryTimeout();
77
78 [[nodiscard]] QStringList clientTokens() const;
79
80 [[nodiscard]] bool setupPushProvider(bool newSetup = false);
81 void purgeUnavailableClients();
82
83 [[nodiscard]] bool hasCurrentCommand() const;
84 void processNextCommand();
85 void doProcessNextCommand();
86
87 void setStatus(DistributorStatus::Status status);
88 void setErrorMessage(const QString &errMsg);
89
90 [[nodiscard]] bool isNetworkAvailable() const;
91
92 // determine current urgency level based on network and batter state as per RFC 8030
93 [[nodiscard]] Urgency determineUrgency() const;
94 void setUrgency(Urgency urgency);
95 void addBattery(const Solid::Device &batteryDevice);
96
97 std::unique_ptr<AbstractPushProvider> m_pushProvider;
98 std::vector<Client> m_clients;
99 Command m_currentCommand;
100 std::deque<Command> m_commandQueue;
101 DistributorStatus::Status m_status = DistributorStatus::Unknown;
102 Urgency m_urgency = AllUrgencies;
103 QString m_errorMessage;
104 QTimer m_retryTimer;
105};
106
107}
108
109#endif // KUNIFIEDPUSH_DISTRIBUTOR_H
Information about a registered client.
Definition client.h:20
Distributor command queue entries.
Definition command.h:17
A received push notification message.
Definition message.h:15
Client-side integration with UnifiedPush.
Definition connector.h:14
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 12:05:39 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.