// Copyright (C) 2021 The Qt Company Ltd. // Copyright (C) 2019 Luxoft Sweden AB // Copyright (C) 2018 Pelagicore AG // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef INTENTCLIENTREQUEST_H #define INTENTCLIENTREQUEST_H #include #include #include #include #include #include QT_BEGIN_NAMESPACE_AM class IntentClient; class IntentClientRequest : public QObject { Q_OBJECT Q_PROPERTY(QString requestId READ requestIdAsString NOTIFY requestIdChanged FINAL) Q_PROPERTY(QtAM::IntentClientRequest::Direction direction READ direction CONSTANT FINAL) Q_PROPERTY(QString intentId READ intentId CONSTANT FINAL) Q_PROPERTY(QString applicationId READ applicationId CONSTANT FINAL) Q_PROPERTY(QString requestingApplicationId READ requestingApplicationId CONSTANT FINAL) Q_PROPERTY(QVariantMap parameters READ parameters CONSTANT FINAL) Q_PROPERTY(bool succeeded READ succeeded NOTIFY replyReceived FINAL) Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY replyReceived FINAL) Q_PROPERTY(QVariantMap result READ result NOTIFY replyReceived FINAL) Q_PROPERTY(bool broadcast READ isBroadcast CONSTANT REVISION(2, 1) FINAL) public: enum class Direction { ToSystem, ToApplication }; Q_ENUM(Direction) ~IntentClientRequest() override; QUuid requestId() const; QString requestIdAsString() const; Direction direction() const; QString intentId() const; QString applicationId() const; QString requestingApplicationId() const; QVariantMap parameters() const; bool isBroadcast() const; const QVariantMap result() const; bool succeeded() const; QString errorMessage() const; Q_INVOKABLE void sendReply(const QVariantMap &result); Q_INVOKABLE void sendErrorReply(const QString &errorMessage); void startTimeout(int timeout); Q_SIGNALS: void requestIdChanged(); void replyReceived(); protected: void connectNotify(const QMetaMethod &signal) override; private: IntentClientRequest(Direction direction, const QString &requestingApplicationId, const QUuid &id, const QString &intentId, const QString &applicationId, const QVariantMap ¶meters, bool broadcast); void setRequestId(const QUuid &requestId); void setResult(const QVariantMap &result); void setErrorMessage(const QString &errorMessage); void doFinish(); Direction m_direction; QUuid m_id; QString m_intentId; QString m_requestingApplicationId; QString m_applicationId; QVariantMap m_parameters; QVariantMap m_result; QString m_errorMessage; bool m_succeeded = false; // The client side of this request is finished - the object will stay in this state until // garbage collected by the JS engine. The state is entered, depending on the direction: // ToSystem: we have received the final result or errorMessage via replyReceived() // ToApplication: the request was handled and send(Error)Reply was called bool m_finished = false; bool m_broadcast = false; Q_DISABLE_COPY_MOVE(IntentClientRequest) friend class IntentClient; }; QT_END_NAMESPACE_AM Q_DECLARE_METATYPE(QtAM::IntentClientRequest *) #endif // INTENTCLIENTREQUEST_H