| 1 | /* |
| 2 | * BluezQt - Asynchronous BlueZ wrapper library |
| 3 | * |
| 4 | * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> |
| 5 | * |
| 6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 | */ |
| 8 | |
| 9 | #ifndef BLUEZQT_REQUEST_H |
| 10 | #define BLUEZQT_REQUEST_H |
| 11 | |
| 12 | #include <QSharedPointer> |
| 13 | |
| 14 | #include "bluezqt_export.h" |
| 15 | |
| 16 | class QDBusMessage; |
| 17 | |
| 18 | namespace BluezQt |
| 19 | { |
| 20 | |
| 21 | /*! |
| 22 | * \enum BluezQt::RequestOriginatingType |
| 23 | * \value OrgBluezAgent |
| 24 | * \value OrgBluezProfile |
| 25 | * \value OrgBluezObexAgent |
| 26 | * \value OrgBluezMediaEndpoint |
| 27 | */ |
| 28 | enum RequestOriginatingType { |
| 29 | OrgBluezAgent, |
| 30 | OrgBluezProfile, |
| 31 | OrgBluezObexAgent, |
| 32 | OrgBluezMediaEndpoint, |
| 33 | }; |
| 34 | |
| 35 | /*! |
| 36 | * \inmodule BluezQt |
| 37 | * \class BluezQt::Request |
| 38 | * \inheaderfile BluezQt/Request |
| 39 | * \brief D-Bus request. |
| 40 | * |
| 41 | * This class represents a request from a Bluetooth daemon. It is a convenient |
| 42 | * wrapper around QDBusMessage and easily allows sending replies and handling errors. |
| 43 | * |
| 44 | * \sa Agent, ObexAgent, Profile |
| 45 | */ |
| 46 | template<typename T = void> |
| 47 | class BLUEZQT_EXPORT Request |
| 48 | { |
| 49 | public: |
| 50 | /*! |
| 51 | * Creates a new Request object. |
| 52 | */ |
| 53 | explicit Request(); |
| 54 | |
| 55 | virtual ~Request(); |
| 56 | |
| 57 | /*! |
| 58 | * Constructs a new Request object from \a other. |
| 59 | */ |
| 60 | Request(const Request &other); |
| 61 | |
| 62 | /*! |
| 63 | * Copies the Request object from \a other. |
| 64 | */ |
| 65 | Request &operator=(const Request &other); |
| 66 | |
| 67 | /*! |
| 68 | * Accepts the request. |
| 69 | * |
| 70 | * This method should be called to send a reply to indicate |
| 71 | * the request was accepted. |
| 72 | * |
| 73 | * In case the request is of type void, this method does not |
| 74 | * take any parameter. |
| 75 | * |
| 76 | * \a returnValue The return value of the request. |
| 77 | */ |
| 78 | void accept(T returnValue) const; |
| 79 | |
| 80 | /*! |
| 81 | * Rejects the request. |
| 82 | * |
| 83 | * This method should be called to send an error reply to |
| 84 | * indicate the request was rejected. |
| 85 | */ |
| 86 | void reject() const; |
| 87 | |
| 88 | /*! |
| 89 | * Cancels the request. |
| 90 | * |
| 91 | * This method should be called to send an error reply to |
| 92 | * indicate the request was canceled. |
| 93 | */ |
| 94 | void cancel() const; |
| 95 | |
| 96 | private: |
| 97 | explicit Request(RequestOriginatingType type, const QDBusMessage &message); |
| 98 | |
| 99 | QSharedPointer<class RequestPrivate> d; |
| 100 | |
| 101 | friend class AgentAdaptor; |
| 102 | friend class ObexAgentAdaptor; |
| 103 | friend class ProfileAdaptor; |
| 104 | friend class MediaEndpointAdaptor; |
| 105 | }; |
| 106 | |
| 107 | // void |
| 108 | template<> |
| 109 | class BLUEZQT_EXPORT Request<void> |
| 110 | { |
| 111 | public: |
| 112 | explicit Request(); |
| 113 | virtual ~Request(); |
| 114 | |
| 115 | Request(const Request &other); |
| 116 | Request &operator=(const Request &other); |
| 117 | |
| 118 | void accept() const; |
| 119 | void reject() const; |
| 120 | void cancel() const; |
| 121 | |
| 122 | private: |
| 123 | explicit Request(RequestOriginatingType type, const QDBusMessage &message); |
| 124 | |
| 125 | QSharedPointer<class RequestPrivate> d; |
| 126 | |
| 127 | friend class AgentAdaptor; |
| 128 | friend class ObexAgentAdaptor; |
| 129 | friend class ProfileAdaptor; |
| 130 | }; |
| 131 | |
| 132 | } // namespace BluezQt |
| 133 | |
| 134 | #endif // BLUEZQT_REQUEST_H |
| 135 | |