File indexing completed on 2024-04-28 15:17:55

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #ifndef BLUEZQT_MEDIATRANSPORT_H
0010 #define BLUEZQT_MEDIATRANSPORT_H
0011 
0012 #include <QObject>
0013 
0014 #include "bluezqt_export.h"
0015 #include "mediatypes.h"
0016 #include "tpendingcall.h"
0017 
0018 namespace BluezQt
0019 {
0020 class PendingCall;
0021 
0022 /**
0023  * @class BluezQt::MediaTransport mediatransport.h <BluezQt/MediaTransport>
0024  *
0025  * Media transport.
0026  *
0027  * This class represents a media transport interface.
0028  */
0029 class BLUEZQT_EXPORT MediaTransport : public QObject
0030 {
0031     Q_OBJECT
0032     Q_PROPERTY(State state READ state NOTIFY stateChanged)
0033     Q_PROPERTY(quint16 volume READ volume NOTIFY volumeChanged)
0034 
0035 public:
0036     /** Indicates the state of the transport. */
0037     enum class State {
0038         Idle,
0039         Pending,
0040         Active,
0041     };
0042     Q_ENUM(State)
0043 
0044     /**
0045      * Destroys a MediaTransport object.
0046      */
0047     ~MediaTransport() override;
0048 
0049     /**
0050      * Returns the (audio) configuration of the transport.
0051      *
0052      * @return configuration of transport
0053      */
0054     AudioConfiguration audioConfiguration() const;
0055 
0056     /**
0057      * Returns the state of the transport.
0058      *
0059      * @return state of transport
0060      */
0061     State state() const;
0062 
0063     /**
0064      * Returns the volume of the transport.
0065      *
0066      * The volume is a percentage of the maximum. The value 0x00 corresponds to 0%.
0067      * The value 0x7F corresponds to 100%. Scaling should be applied to achieve
0068      * values between these two. The existence of this scale does not impose any
0069      * restriction on the granularity of the volume control scale on the target.
0070      * As this command specifies a percentage rather than an absolute dB level
0071      * the controller should exercise caution when sending this command.
0072      *
0073      * @return volume of transport
0074      */
0075     quint16 volume() const;
0076 
0077 public Q_SLOTS:
0078     /**
0079      * Acquire transport file descriptor and the MTU for read
0080      * and write respectively.
0081      *
0082      * Possible errors: PendingCall::NotAuthorized, PendingCall::Failed
0083      *
0084      * @return <fd, uint16, uint16> pending call
0085      */
0086     TPendingCall<QDBusUnixFileDescriptor, uint16_t, uint16_t> *acquire();
0087 
0088     /**
0089      * Acquire transport file descriptor only if the transport
0090      * is in "pending" state at the time the message is
0091      * received by BlueZ. Otherwise no request will be sent
0092      * to the remote device and the function will just fail
0093      * with org.bluez.Error.NotAvailable.
0094      *
0095      * Possible errors: PendingCall::NotAuthorized, PendingCall::Failed, PendingCall::NotAvailable
0096      *
0097      * @return <fd, uint16, uint16> pending call
0098      */
0099     TPendingCall<QDBusUnixFileDescriptor, uint16_t, uint16_t> *tryAcquire();
0100 
0101     /**
0102      * Releases file descriptor.
0103      *
0104      * @return void pending call
0105      */
0106     TPendingCall<void> *release();
0107 
0108 Q_SIGNALS:
0109     /**
0110      * Indicates that transport's state have changed.
0111      */
0112     void stateChanged(State state);
0113 
0114     /**
0115      * Indicates that transport's volume have changed.
0116      */
0117     void volumeChanged(quint16 volume);
0118 
0119 private:
0120     BLUEZQT_NO_EXPORT explicit MediaTransport(const QString &path, const QVariantMap &properties);
0121 
0122     class MediaTransportPrivate *const d;
0123 
0124     friend class MediaTransportPrivate;
0125     friend class DevicePrivate;
0126 };
0127 
0128 } // namespace BluezQt
0129 
0130 #endif