File indexing completed on 2024-12-08 12:15:37
0001 /* 0002 * BluezQt - Asynchronous BlueZ wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef BLUEZQT_REQUEST_H 0010 #define BLUEZQT_REQUEST_H 0011 0012 #include <QSharedPointer> 0013 0014 #include "bluezqt_export.h" 0015 0016 class QDBusMessage; 0017 0018 namespace BluezQt 0019 { 0020 enum RequestOriginatingType { 0021 OrgBluezAgent, 0022 OrgBluezProfile, 0023 OrgBluezObexAgent, 0024 OrgBluezMediaEndpoint, 0025 }; 0026 0027 /** 0028 * @class BluezQt::Request request.h <BluezQt/Request> 0029 * 0030 * D-Bus request. 0031 * 0032 * This class represents a request from a Bluetooth daemon. It is a convenient 0033 * wrapper around QDBusMessage and easily allows sending replies and handling errors. 0034 * 0035 * @see Agent, ObexAgent, Profile 0036 */ 0037 template<typename T = void> 0038 class BLUEZQT_EXPORT Request 0039 { 0040 public: 0041 /** 0042 * Creates a new Request object. 0043 */ 0044 explicit Request(); 0045 0046 /** 0047 * Destroys a Request object. 0048 */ 0049 virtual ~Request(); 0050 0051 /** 0052 * Copy constructor. 0053 * 0054 * @param other 0055 */ 0056 Request(const Request &other); 0057 0058 /** 0059 * Copy assignment operator. 0060 * 0061 * @param other 0062 */ 0063 Request &operator=(const Request &other); 0064 0065 /** 0066 * Accepts the request. 0067 * 0068 * This method should be called to send a reply to indicate 0069 * the request was accepted. 0070 * 0071 * In case the request is of type void, this method does not 0072 * take any parameter. 0073 * 0074 * @param returnValue return value of request 0075 */ 0076 void accept(T returnValue) const; 0077 0078 /** 0079 * Rejects the request. 0080 * 0081 * This method should be called to send an error reply to 0082 * indicate the request was rejected. 0083 */ 0084 void reject() const; 0085 0086 /** 0087 * Cancels the request. 0088 * 0089 * This method should be called to send an error reply to 0090 * indicate the request was canceled. 0091 */ 0092 void cancel() const; 0093 0094 private: 0095 explicit Request(RequestOriginatingType type, const QDBusMessage &message); 0096 0097 QSharedPointer<class RequestPrivate> d; 0098 0099 friend class AgentAdaptor; 0100 friend class ObexAgentAdaptor; 0101 friend class ProfileAdaptor; 0102 friend class MediaEndpointAdaptor; 0103 }; 0104 0105 // void 0106 template<> 0107 class BLUEZQT_EXPORT Request<void> 0108 { 0109 public: 0110 explicit Request(); 0111 virtual ~Request(); 0112 0113 Request(const Request &other); 0114 Request &operator=(const Request &other); 0115 0116 void accept() const; 0117 void reject() const; 0118 void cancel() const; 0119 0120 private: 0121 explicit Request(RequestOriginatingType type, const QDBusMessage &message); 0122 0123 QSharedPointer<class RequestPrivate> d; 0124 0125 friend class AgentAdaptor; 0126 friend class ObexAgentAdaptor; 0127 friend class ProfileAdaptor; 0128 }; 0129 0130 } // namespace BluezQt 0131 0132 #endif // BLUEZQT_REQUEST_H