1 | /* |
2 | * BluezQt - Asynchronous BlueZ wrapper library |
3 | * |
4 | * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de> |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
7 | */ |
8 | |
9 | #ifndef BLUEZQT_MEDIATRANSPORT_H |
10 | #define BLUEZQT_MEDIATRANSPORT_H |
11 | |
12 | #include <QObject> |
13 | |
14 | #include "bluezqt_export.h" |
15 | #include "mediatypes.h" |
16 | #include "tpendingcall.h" |
17 | |
18 | #include <memory> |
19 | |
20 | namespace BluezQt |
21 | { |
22 | class PendingCall; |
23 | |
24 | /*! |
25 | * \inmodule BluezQt |
26 | * \class BluezQt::MediaTransport |
27 | * \inheaderfile BluezQt/MediaTransport |
28 | * \brief Media transport. |
29 | * |
30 | * This class represents a media transport interface. |
31 | */ |
32 | class BLUEZQT_EXPORT MediaTransport : public QObject |
33 | { |
34 | Q_OBJECT |
35 | /*! \property BluezQt::MediaTransport::state */ |
36 | Q_PROPERTY(State state READ state NOTIFY stateChanged) |
37 | /*! \property BluezQt::MediaTransport::volume */ |
38 | Q_PROPERTY(quint16 volume READ volume NOTIFY volumeChanged) |
39 | |
40 | public: |
41 | /*! |
42 | * \enum BluezQt::MediaTransport::State |
43 | * \brief Indicates the state of the transport. |
44 | * \value Idle |
45 | * \value Pending |
46 | * \value Active |
47 | */ |
48 | enum class State { |
49 | Idle, |
50 | Pending, |
51 | Active, |
52 | }; |
53 | Q_ENUM(State) |
54 | |
55 | ~MediaTransport() override; |
56 | |
57 | /*! |
58 | * Returns the (audio) configuration of the transport. |
59 | */ |
60 | AudioConfiguration audioConfiguration() const; |
61 | |
62 | /*! |
63 | * Returns the state of the transport. |
64 | */ |
65 | State state() const; |
66 | |
67 | /*! |
68 | * Returns the volume of the transport. |
69 | * |
70 | * The volume is a percentage of the maximum. The value 0x00 corresponds to 0%. |
71 | * The value 0x7F corresponds to 100%. Scaling should be applied to achieve |
72 | * values between these two. |
73 | * |
74 | * The existence of this scale does not impose any |
75 | * restriction on the granularity of the volume control scale on the target. |
76 | * |
77 | * As this command specifies a percentage rather than an absolute dB level |
78 | * the controller should exercise caution when sending this command. |
79 | */ |
80 | quint16 volume() const; |
81 | |
82 | /*! |
83 | * Sets the \a volume of the transport. |
84 | * |
85 | * Only works when the transport was acquired by the sender. |
86 | * |
87 | * The volume of the transport should be within the range [0x00..0x7F] (0-127) |
88 | * |
89 | * Returns void pending call. |
90 | * \since 6.6 |
91 | */ |
92 | PendingCall *setVolume(quint16 volume); |
93 | |
94 | public Q_SLOTS: |
95 | /*! |
96 | * Acquires the transport file descriptor and the MTU for read |
97 | * and write respectively. |
98 | * |
99 | * Possible errors: |
100 | * |
101 | * \list |
102 | * \li PendingCall::NotAuthorized |
103 | * \li PendingCall::Failed |
104 | * \endlist |
105 | * |
106 | * Returns <fd, uint16, uint16> pending call. |
107 | */ |
108 | TPendingCall<QDBusUnixFileDescriptor, uint16_t, uint16_t> *acquire(); |
109 | |
110 | /*! |
111 | * Acquire transport file descriptor only if the transport |
112 | * is in "pending" state at the time the message is |
113 | * received by BlueZ. Otherwise no request will be sent |
114 | * to the remote device and the function will just fail |
115 | * with org.bluez.Error.NotAvailable. |
116 | * |
117 | * Possible errors: |
118 | * |
119 | * \list |
120 | * \li PendingCall::NotAuthorized |
121 | * \li PendingCall::Failed |
122 | * \li PendingCall::NotAvailable |
123 | * \endlist |
124 | * |
125 | * Returns <fd, uint16, uint16> pending call. |
126 | */ |
127 | TPendingCall<QDBusUnixFileDescriptor, uint16_t, uint16_t> *tryAcquire(); |
128 | |
129 | /*! |
130 | * Releases file descriptor. |
131 | */ |
132 | TPendingCall<void> *release(); |
133 | |
134 | Q_SIGNALS: |
135 | /*! |
136 | * Indicates that the transport's \a state has changed. |
137 | */ |
138 | void stateChanged(State state); |
139 | |
140 | /*! |
141 | * Indicates that the transport's \a volume has changed. |
142 | */ |
143 | void volumeChanged(quint16 volume); |
144 | |
145 | private: |
146 | BLUEZQT_NO_EXPORT explicit MediaTransport(const QString &path, const QVariantMap &properties); |
147 | |
148 | std::unique_ptr<class MediaTransportPrivate> const d; |
149 | |
150 | friend class MediaTransportPrivate; |
151 | friend class DevicePrivate; |
152 | }; |
153 | |
154 | } // namespace BluezQt |
155 | |
156 | #endif |
157 | |