File indexing completed on 2024-11-17 04:18:46

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef KUNIFIEDPUSH_CONNECTOR_P_H
0007 #define KUNIFIEDPUSH_CONNECTOR_P_H
0008 
0009 #include "connector.h"
0010 
0011 #ifndef Q_OS_ANDROID
0012 #include <QDBusServiceWatcher>
0013 #else
0014 #include <QJniObject>
0015 #endif
0016 #include <QObject>
0017 
0018 #include <deque>
0019 
0020 class OrgUnifiedpushDistributor1Interface;
0021 
0022 namespace KUnifiedPush {
0023 class ConnectorPrivate : public QObject
0024 {
0025     Q_OBJECT
0026 public:
0027     explicit ConnectorPrivate(Connector *qq);
0028     ~ConnectorPrivate();
0029 
0030     // platform-specific implementations
0031     void init();
0032     void deinit();
0033     void doSetDistributor(const QString &distServiceName);
0034     bool hasDistributor() const;
0035     void doRegister();
0036     void doUnregister();
0037 
0038     // D-Bus interface
0039     void Message(const QString &token, const QByteArray &message, const QString &messageIdentifier);
0040     void NewEndpoint(const QString &token, const QString &endpoint);
0041     void Unregistered(const QString &token);
0042 
0043     QString stateFile() const;
0044     void loadState();
0045     void storeState() const;
0046     void selectDistributor();
0047     void setDistributor(const QString &distServiceName);
0048 
0049     void setState(Connector::State state);
0050 
0051     enum class Command { None, Register, Unregister };
0052     void addCommand(Command cmd);
0053     void processNextCommand();
0054 
0055     Connector *q = nullptr;
0056     QString m_serviceName;
0057     QString m_token;
0058     QString m_endpoint;
0059     QString m_description;
0060     Connector::State m_state = Connector::Unregistered;
0061 
0062     Command m_currentCommand = Command::None;
0063     std::deque<Command> m_commandQueue;
0064 
0065 #ifndef Q_OS_ANDROID
0066     OrgUnifiedpushDistributor1Interface *m_distributor = nullptr;
0067     QDBusServiceWatcher m_serviceWatcher;
0068 #else
0069     QJniObject m_distributor;
0070     static std::vector<ConnectorPrivate*> s_instances;
0071 #endif
0072 };
0073 }
0074 
0075 #endif