File indexing completed on 2024-04-21 04:44:12

0001 /*
0002    SPDX-FileCopyrightText: 2015 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003 
0004    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #ifndef UPNPABSTRACTSERVICE_H
0008 #define UPNPABSTRACTSERVICE_H
0009 
0010 #include "upnplibqt_export.h"
0011 
0012 #include <QList>
0013 #include <QObject>
0014 #include <QPair>
0015 #include <QString>
0016 #include <QUrl>
0017 #include <QVariant>
0018 
0019 #include <memory>
0020 
0021 class UpnpAbstractServicePrivate;
0022 class UpnpActionDescription;
0023 class UpnpStateVariableDescription;
0024 class UpnpEventSubscriber;
0025 class QIODevice;
0026 class UpnpServiceDescription;
0027 
0028 /**
0029  * @brief The UpnpAbstractService is the base class to implement a wrapper around an UPnP service
0030  *
0031  * It can be derived into a subclass to implement support for a specific service type or can be used directly to interact with a service.
0032  */
0033 class UPNPLIBQT_EXPORT UpnpAbstractService : public QObject
0034 {
0035     Q_OBJECT
0036 
0037     Q_PROPERTY(UpnpServiceDescription description
0038             READ description
0039                 WRITE setDescription
0040                     NOTIFY descriptionChanged)
0041 
0042 public:
0043     explicit UpnpAbstractService(QObject *parent = nullptr);
0044 
0045     ~UpnpAbstractService() override;
0046 
0047     [[nodiscard]] QIODevice *buildAndGetXmlDescription();
0048 
0049     [[nodiscard]] QPointer<UpnpEventSubscriber> subscribeToEvents(const QByteArray &requestData, const QMap<QByteArray, QByteArray> &headers);
0050 
0051     void unsubscribeToEvents(const QByteArray &requestData, const QMap<QByteArray, QByteArray> &headers);
0052 
0053     void addAction(const UpnpActionDescription &newAction);
0054 
0055     [[nodiscard]] const UpnpActionDescription &action(const QString &name) const;
0056 
0057     [[nodiscard]] QList<QString> actions() const;
0058 
0059     void addStateVariable(const UpnpStateVariableDescription &newVariable);
0060 
0061     [[nodiscard]] const UpnpStateVariableDescription &stateVariable(const QString &name) const;
0062 
0063     [[nodiscard]] QList<QString> stateVariables() const;
0064 
0065     [[nodiscard]] virtual QVector<QPair<QString, QVariant>> invokeAction(const QString &actionName, const QVector<QVariant> &arguments, bool &isInError);
0066 
0067     void setDescription(const UpnpServiceDescription &value);
0068 
0069     [[nodiscard]] UpnpServiceDescription &description();
0070 
0071     [[nodiscard]] const UpnpServiceDescription &description() const;
0072 
0073 Q_SIGNALS:
0074 
0075     void descriptionChanged();
0076 
0077 public Q_SLOTS:
0078 
0079 private:
0080     void sendEventNotification(const QPointer<UpnpEventSubscriber> &currentSubscriber);
0081 
0082     std::unique_ptr<UpnpAbstractServicePrivate> d;
0083 };
0084 
0085 #endif // UPNPABSTRACTSERVICE_H