LCOV - code coverage report
Current view: top level - manager-lib - intentaminterface.h (source / functions) Coverage Total Hit
Test: QtApplicationManager Lines: 100.0 % 1 1
Test Date: 2024-07-27 10:03:26 Functions: - 0 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 2 1

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2021 The Qt Company Ltd.
       2                 :             : // Copyright (C) 2019 Luxoft Sweden AB
       3                 :             : // Copyright (C) 2018 Pelagicore AG
       4                 :             : // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
       5                 :             : 
       6                 :             : #ifndef INTENTAMINTERFACE_H
       7                 :             : #define INTENTAMINTERFACE_H
       8                 :             : 
       9                 :             : #include <QtCore/QObject>
      10                 :             : #include <QtCore/QVector>
      11                 :             : #include <QtCore/QString>
      12                 :             : #include <QtCore/QVariantMap>
      13                 :             : #include <QtCore/QList>
      14                 :             : #include <QtCore/QUrl>
      15                 :             : #include <QtAppManCommon/global.h>
      16                 :             : 
      17                 :             : #if QT_CONFIG(am_multi_process)
      18                 :             : #  include <QtDBus/QDBusConnection>
      19                 :             : #  include <QtDBus/QDBusContext>
      20                 :             : #endif
      21                 :             : #include <QtAppManIntentServer/intentserversysteminterface.h>
      22                 :             : #include <QtAppManIntentServer/intent.h>
      23                 :             : #include <QtAppManIntentClient/intentclientsysteminterface.h>
      24                 :             : #include <QtAppManIntentClient/intenthandler.h>
      25                 :             : #include <QtAppManApplication/intentinfo.h>
      26                 :             : 
      27                 :             : class IntentInterfaceAdaptor;
      28                 :             : 
      29                 :             : QT_BEGIN_NAMESPACE_AM
      30                 :             : 
      31                 :             : class Application;
      32                 :             : class PackageManager;
      33                 :             : class IntentServerRequest;
      34                 :             : 
      35                 :             : namespace IntentAMImplementation {
      36                 :             : IntentServer *createIntentServerAndClientInstance(PackageManager *packageManager, int disambiguationTimeout,
      37                 :             :                                                   int startApplicationTimeout, int replyFromApplicationTimeout,
      38                 :             :                                                   int replyFromSystemTimeout);
      39                 :             : }
      40                 :             : 
      41                 :             : // the server side
      42         [ +  - ]:          52 : class IntentServerAMImplementation : public IntentServerSystemInterface
      43                 :             : {
      44                 :             :     Q_OBJECT
      45                 :             : 
      46                 :             : public:
      47                 :             :     void setIntentClientSystemInterface(IntentClientSystemInterface *iface);
      48                 :             :     IntentClientSystemInterface *intentClientSystemInterface() const;
      49                 :             : 
      50                 :             :     void initialize(IntentServer *intentServer) override;
      51                 :             : 
      52                 :             :     bool checkApplicationCapabilities(const QString &applicationId,
      53                 :             :                                       const QStringList &requiredCapabilities) override;
      54                 :             : 
      55                 :             :     IpcConnection *findClientIpc(const QString &appId) override;
      56                 :             : 
      57                 :             :     void startApplication(const QString &appId) override;
      58                 :             :     void requestToApplication(IpcConnection *clientIPC, IntentServerRequest *isr) override;
      59                 :             :     void replyFromSystem(IpcConnection *clientIPC, IntentServerRequest *isr) override;
      60                 :             : 
      61                 :             : private:
      62                 :             :     IntentClientSystemInterface *m_icsi = nullptr;
      63                 :             : };
      64                 :             : 
      65                 :             : // the in-process client side
      66                 :             : class IntentClientAMImplementation : public IntentClientSystemInterface
      67                 :             : {
      68                 :             :     Q_OBJECT
      69                 :             : 
      70                 :             : public:
      71                 :             :     IntentClientAMImplementation(IntentServerAMImplementation *serverInterface);
      72                 :             : 
      73                 :             :     void initialize(IntentClient *intentClient) noexcept(false) override;
      74                 :             :     bool isSystemUI() const override;
      75                 :             :     QString currentApplicationId(QObject *hint) override;
      76                 :             : 
      77                 :             :     void requestToSystem(const QPointer<IntentClientRequest> &icr) override;
      78                 :             :     void replyFromApplication(const QPointer<IntentClientRequest> &icr) override;
      79                 :             : 
      80                 :             : private:
      81                 :             :     IntentServerSystemInterface *m_issi;
      82                 :             : };
      83                 :             : 
      84                 :             : // each instance represents one server->client connection
      85                 :             : class IntentServerIpcConnection : public QObject
      86                 :             : {
      87                 :             :     Q_OBJECT
      88                 :             : 
      89                 :             : public:
      90                 :             :     ~IntentServerIpcConnection() override;
      91                 :             : 
      92                 :             :     static IntentServerIpcConnection *find(const QString &appId);
      93                 :             : 
      94                 :             :     Application *application() const;
      95                 :             :     virtual QString applicationId() const;
      96                 :             :     bool isInProcess() const;
      97                 :             : 
      98                 :             :     bool isReady() const;
      99                 :             :     void setReady(Application *application);
     100                 :             : 
     101                 :             :     virtual void replyFromSystem(IntentServerRequest *isr) = 0;
     102                 :             :     virtual void requestToApplication(IntentServerRequest *isr) = 0;
     103                 :             : 
     104                 :             : Q_SIGNALS:
     105                 :             :     void applicationIsReady(const QString &applicationId);
     106                 :             : 
     107                 :             : protected:
     108                 :             :     IntentServerIpcConnection(bool inProcess, Application *application, IntentServerAMImplementation *iface);
     109                 :             : 
     110                 :             :     Application *m_application;
     111                 :             :     IntentServerAMImplementation *m_interface;
     112                 :             :     bool m_inprocess = true;
     113                 :             :     bool m_ready = false;
     114                 :             : 
     115                 :             :     static QList<IntentServerIpcConnection *> s_ipcConnections;
     116                 :             : };
     117                 :             : 
     118                 :             : // ... derived for in-process clients
     119                 :             : class IntentServerInProcessIpcConnection : public IntentServerIpcConnection
     120                 :             : {
     121                 :             :     Q_OBJECT
     122                 :             : 
     123                 :             : public:
     124                 :             :     static IntentServerInProcessIpcConnection *create(Application *application, IntentServerAMImplementation *iface);
     125                 :             :     static IntentServerInProcessIpcConnection *createSystemUi(IntentServerAMImplementation *iface);
     126                 :             : 
     127                 :             :     QString applicationId() const override;
     128                 :             : 
     129                 :             :     void replyFromSystem(IntentServerRequest *isr) override;
     130                 :             :     void requestToApplication(IntentServerRequest *isr) override;
     131                 :             : 
     132                 :             : private:
     133                 :             :     IntentServerInProcessIpcConnection(Application *application, IntentServerAMImplementation *iface);
     134                 :             : 
     135                 :             :     bool m_isSystemUi = false;
     136                 :             : };
     137                 :             : 
     138                 :             : #if QT_CONFIG(am_multi_process)
     139                 :             : 
     140                 :             : // ... derived for P2P DBus clients
     141                 :             : class IntentServerDBusIpcConnection : public IntentServerIpcConnection, public QDBusContext
     142                 :             : {
     143                 :             :     Q_OBJECT
     144                 :             : 
     145                 :             : public:
     146                 :             :     static IntentServerDBusIpcConnection *create(const QDBusConnection &connection,
     147                 :             :                                                  Application *application,
     148                 :             :                                                  IntentServerAMImplementation *iface);
     149                 :             :     static IntentServerDBusIpcConnection *find(const QDBusConnection &connection);
     150                 :             : 
     151                 :             :     ~IntentServerDBusIpcConnection() override;
     152                 :             : 
     153                 :             :     QString requestToSystem(const QString &intentId, const QString &applicationId, const QVariantMap &parameters);
     154                 :             :     void replyFromSystem(IntentServerRequest *isr) override;
     155                 :             :     void requestToApplication(IntentServerRequest *isr) override;
     156                 :             :     void replyFromApplication(const QString &requestId, bool error, const QVariantMap &result);
     157                 :             : 
     158                 :             : 
     159                 :             : private:
     160                 :             :     IntentServerDBusIpcConnection(const QDBusConnection &connection, Application *application,
     161                 :             :                                   IntentServerAMImplementation *iface);
     162                 :             : 
     163                 :             :     QString m_connectionName;
     164                 :             :     ::IntentInterfaceAdaptor *m_adaptor = nullptr;
     165                 :             : };
     166                 :             : 
     167                 :             : #endif // QT_CONFIG(am_multi_process)
     168                 :             : 
     169                 :             : // server-side IntentHandlers
     170                 :             : class IntentServerHandler : public AbstractIntentHandler
     171                 :             : {
     172                 :             :     Q_OBJECT
     173                 :             :     // The following properties cannot be changed after construction (hence, also no real 'changed'
     174                 :             :     // signal). These replace the meta-data that's provided through the info.yaml manifests for
     175                 :             :     // client-side handlers.
     176                 :             :     Q_PROPERTY(QStringList intentIds READ intentIds WRITE setIntentIds NOTIFY dummyChanged FINAL)
     177                 :             :     Q_PROPERTY(QUrl icon READ icon WRITE setIcon NOTIFY dummyChanged FINAL)
     178                 :             :     Q_PROPERTY(QVariantMap names READ names WRITE setNames NOTIFY dummyChanged FINAL)
     179                 :             :     Q_PROPERTY(QVariantMap descriptions READ descriptions WRITE setDescriptions NOTIFY dummyChanged FINAL)
     180                 :             :     Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY dummyChanged FINAL)
     181                 :             :     Q_PROPERTY(QtAM::Intent::Visibility visibility READ visibility WRITE setVisibility NOTIFY dummyChanged FINAL)
     182                 :             :     Q_PROPERTY(QStringList requiredCapabilities READ requiredCapabilities WRITE setRequiredCapabilities NOTIFY dummyChanged FINAL)
     183                 :             :     Q_PROPERTY(QVariantMap parameterMatch READ parameterMatch WRITE setParameterMatch NOTIFY dummyChanged FINAL)
     184                 :             : 
     185                 :             : public:
     186                 :             :     IntentServerHandler(QObject *parent = nullptr);
     187                 :             :     ~IntentServerHandler() override;
     188                 :             : 
     189                 :             :     QUrl icon() const;
     190                 :             :     QVariantMap names() const;
     191                 :             :     QVariantMap descriptions() const;
     192                 :             :     QStringList categories() const;
     193                 :             :     Intent::Visibility visibility() const;
     194                 :             :     QStringList requiredCapabilities() const;
     195                 :             :     QVariantMap parameterMatch() const;
     196                 :             : 
     197                 :             :     void setIntentIds(const QStringList &intentId);
     198                 :             :     void setIcon(const QUrl &icon);
     199                 :             :     void setNames(const QVariantMap &names);
     200                 :             :     void setDescriptions(const QVariantMap &descriptions);
     201                 :             :     void setCategories(const QStringList &categories);
     202                 :             :     void setVisibility(Intent::Visibility visibility);
     203                 :             :     void setRequiredCapabilities(const QStringList &requiredCapabilities);
     204                 :             :     void setParameterMatch(const QVariantMap &parameterMatch);
     205                 :             : 
     206                 :             : Q_SIGNALS:
     207                 :             :     void intentIdsChanged();
     208                 :             :     void requestReceived(QtAM::IntentClientRequest *request);
     209                 :             :     void dummyChanged(); // never emitted
     210                 :             : 
     211                 :             : protected:
     212                 :             :     void classBegin() override;
     213                 :             :     void componentComplete() override;
     214                 :             :     void internalRequestReceived(IntentClientRequest *request) override;
     215                 :             : 
     216                 :             : private:
     217                 :             :     Intent *m_intent = nullptr; // DRY: just a container for our otherwise needed members vars
     218                 :             :     QVector<Intent *> m_registeredIntents;
     219                 :             :     bool m_completed = false;
     220                 :             : 
     221                 :             :     Q_DISABLE_COPY_MOVE(IntentServerHandler)
     222                 :             : };
     223                 :             : 
     224                 :             : QT_END_NAMESPACE_AM
     225                 :             : 
     226                 :             : #endif // INTENTAMINTERFACE_H
        

Generated by: LCOV version 2.0-1