File indexing completed on 2024-12-08 12:15:32

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2014 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 #include "adapter.h"
0010 #include "adapter_p.h"
0011 #include "device_p.h"
0012 #include "pendingcall.h"
0013 
0014 namespace BluezQt
0015 {
0016 Adapter::Adapter(const QString &path, const QVariantMap &properties)
0017     : QObject()
0018     , d(new AdapterPrivate(path, properties))
0019 {
0020 }
0021 
0022 Adapter::~Adapter()
0023 {
0024     delete d;
0025 }
0026 
0027 AdapterPtr Adapter::toSharedPtr() const
0028 {
0029     return d->q.toStrongRef();
0030 }
0031 
0032 QString Adapter::ubi() const
0033 {
0034     return d->m_bluezAdapter->path();
0035 }
0036 
0037 QString Adapter::address() const
0038 {
0039     return d->m_address;
0040 }
0041 
0042 QString Adapter::name() const
0043 {
0044     return d->m_alias;
0045 }
0046 
0047 PendingCall *Adapter::setName(const QString &name)
0048 {
0049     return new PendingCall(d->setDBusProperty(QStringLiteral("Alias"), name), PendingCall::ReturnVoid, this);
0050 }
0051 
0052 QString Adapter::systemName() const
0053 {
0054     return d->m_name;
0055 }
0056 
0057 quint32 Adapter::adapterClass() const
0058 {
0059     return d->m_adapterClass;
0060 }
0061 
0062 bool Adapter::isPowered() const
0063 {
0064     return d->m_powered;
0065 }
0066 
0067 PendingCall *Adapter::setPowered(bool powered)
0068 {
0069     return new PendingCall(d->setDBusProperty(QStringLiteral("Powered"), powered), PendingCall::ReturnVoid, this);
0070 }
0071 
0072 bool Adapter::isDiscoverable() const
0073 {
0074     return d->m_discoverable;
0075 }
0076 
0077 PendingCall *Adapter::setDiscoverable(bool discoverable)
0078 {
0079     return new PendingCall(d->setDBusProperty(QStringLiteral("Discoverable"), discoverable), PendingCall::ReturnVoid, this);
0080 }
0081 
0082 quint32 Adapter::discoverableTimeout() const
0083 {
0084     return d->m_discoverableTimeout;
0085 }
0086 
0087 PendingCall *Adapter::setDiscoverableTimeout(quint32 timeout)
0088 {
0089     return new PendingCall(d->setDBusProperty(QStringLiteral("DiscoverableTimeout"), timeout), PendingCall::ReturnVoid, this);
0090 }
0091 
0092 bool Adapter::isPairable() const
0093 {
0094     return d->m_pairable;
0095 }
0096 
0097 PendingCall *Adapter::setPairable(bool pairable)
0098 {
0099     return new PendingCall(d->setDBusProperty(QStringLiteral("Pairable"), pairable), PendingCall::ReturnVoid, this);
0100 }
0101 
0102 quint32 Adapter::pairableTimeout() const
0103 {
0104     return d->m_pairableTimeout;
0105 }
0106 
0107 PendingCall *Adapter::setPairableTimeout(quint32 timeout)
0108 {
0109     return new PendingCall(d->setDBusProperty(QStringLiteral("PairableTimeout"), timeout), PendingCall::ReturnVoid, this);
0110 }
0111 
0112 bool Adapter::isDiscovering()
0113 {
0114     return d->m_discovering;
0115 }
0116 
0117 QStringList Adapter::uuids() const
0118 {
0119     return d->m_uuids;
0120 }
0121 
0122 QString Adapter::modalias() const
0123 {
0124     return d->m_modalias;
0125 }
0126 
0127 GattManagerPtr Adapter::gattManager() const
0128 {
0129     return d->m_gattManager;
0130 }
0131 
0132 LEAdvertisingManagerPtr Adapter::leAdvertisingManager() const
0133 {
0134     return d->m_leAdvertisingManager;
0135 }
0136 
0137 MediaPtr Adapter::media() const
0138 {
0139     return d->m_media;
0140 }
0141 
0142 QList<DevicePtr> Adapter::devices() const
0143 {
0144     return d->m_devices;
0145 }
0146 
0147 DevicePtr Adapter::deviceForAddress(const QString &address) const
0148 {
0149     for (DevicePtr device : std::as_const(d->m_devices)) {
0150         if (device->address() == address) {
0151             return device;
0152         }
0153     }
0154     return DevicePtr();
0155 }
0156 
0157 PendingCall *Adapter::startDiscovery()
0158 {
0159     return new PendingCall(d->m_bluezAdapter->StartDiscovery(), PendingCall::ReturnVoid, this);
0160 }
0161 
0162 PendingCall *Adapter::stopDiscovery()
0163 {
0164     return new PendingCall(d->m_bluezAdapter->StopDiscovery(), PendingCall::ReturnVoid, this);
0165 }
0166 
0167 PendingCall *Adapter::removeDevice(DevicePtr device)
0168 {
0169     return new PendingCall(d->m_bluezAdapter->RemoveDevice(QDBusObjectPath(device->ubi())), PendingCall::ReturnVoid, this);
0170 }
0171 
0172 PendingCall* Adapter::setDiscoveryFilter(const QVariantMap& filter)
0173 {
0174     return new PendingCall(d->m_bluezAdapter->SetDiscoveryFilter(filter), PendingCall::ReturnVoid, this);
0175 }
0176 
0177 PendingCall* Adapter::getDiscoveryFilters()
0178 {
0179     return new PendingCall(d->m_bluezAdapter->GetDiscoveryFilters(), PendingCall::ReturnStringList, this);
0180 }
0181 
0182 } // namespace BluezQt
0183 
0184 #include "moc_adapter.cpp"