1 | /* |
2 | * BluezQt - Asynchronous Bluez wrapper library |
3 | * |
4 | * SPDX-FileCopyrightText: 2014 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 | #include "adapter.h" |
10 | #include "adapter_p.h" |
11 | #include "device.h" |
12 | #include "device_p.h" |
13 | #include "pendingcall.h" |
14 | |
15 | namespace BluezQt |
16 | { |
17 | Adapter::Adapter(const QString &path, const QVariantMap &properties) |
18 | : QObject() |
19 | , d(new AdapterPrivate(path, properties)) |
20 | { |
21 | } |
22 | |
23 | Adapter::~Adapter() = default; |
24 | |
25 | AdapterPtr Adapter::toSharedPtr() const |
26 | { |
27 | return d->q.toStrongRef(); |
28 | } |
29 | |
30 | QString Adapter::ubi() const |
31 | { |
32 | return d->m_bluezAdapter->path(); |
33 | } |
34 | |
35 | QString Adapter::address() const |
36 | { |
37 | return d->m_address; |
38 | } |
39 | |
40 | QString Adapter::name() const |
41 | { |
42 | return d->m_alias; |
43 | } |
44 | |
45 | PendingCall *Adapter::setName(const QString &name) |
46 | { |
47 | return new PendingCall(d->setDBusProperty(QStringLiteral("Alias" ), value: name), PendingCall::ReturnVoid, this); |
48 | } |
49 | |
50 | QString Adapter::systemName() const |
51 | { |
52 | return d->m_name; |
53 | } |
54 | |
55 | quint32 Adapter::adapterClass() const |
56 | { |
57 | return d->m_adapterClass; |
58 | } |
59 | |
60 | bool Adapter::isPowered() const |
61 | { |
62 | return d->m_powered; |
63 | } |
64 | |
65 | PendingCall *Adapter::setPowered(bool powered) |
66 | { |
67 | return new PendingCall(d->setDBusProperty(QStringLiteral("Powered" ), value: powered), PendingCall::ReturnVoid, this); |
68 | } |
69 | |
70 | bool Adapter::isDiscoverable() const |
71 | { |
72 | return d->m_discoverable; |
73 | } |
74 | |
75 | PendingCall *Adapter::setDiscoverable(bool discoverable) |
76 | { |
77 | return new PendingCall(d->setDBusProperty(QStringLiteral("Discoverable" ), value: discoverable), PendingCall::ReturnVoid, this); |
78 | } |
79 | |
80 | quint32 Adapter::discoverableTimeout() const |
81 | { |
82 | return d->m_discoverableTimeout; |
83 | } |
84 | |
85 | PendingCall *Adapter::setDiscoverableTimeout(quint32 timeout) |
86 | { |
87 | return new PendingCall(d->setDBusProperty(QStringLiteral("DiscoverableTimeout" ), value: timeout), PendingCall::ReturnVoid, this); |
88 | } |
89 | |
90 | bool Adapter::isPairable() const |
91 | { |
92 | return d->m_pairable; |
93 | } |
94 | |
95 | PendingCall *Adapter::setPairable(bool pairable) |
96 | { |
97 | return new PendingCall(d->setDBusProperty(QStringLiteral("Pairable" ), value: pairable), PendingCall::ReturnVoid, this); |
98 | } |
99 | |
100 | quint32 Adapter::pairableTimeout() const |
101 | { |
102 | return d->m_pairableTimeout; |
103 | } |
104 | |
105 | PendingCall *Adapter::setPairableTimeout(quint32 timeout) |
106 | { |
107 | return new PendingCall(d->setDBusProperty(QStringLiteral("PairableTimeout" ), value: timeout), PendingCall::ReturnVoid, this); |
108 | } |
109 | |
110 | bool Adapter::isDiscovering() |
111 | { |
112 | return d->m_discovering; |
113 | } |
114 | |
115 | QStringList Adapter::uuids() const |
116 | { |
117 | return d->m_uuids; |
118 | } |
119 | |
120 | QString Adapter::modalias() const |
121 | { |
122 | return d->m_modalias; |
123 | } |
124 | |
125 | GattManagerPtr Adapter::gattManager() const |
126 | { |
127 | return d->m_gattManager; |
128 | } |
129 | |
130 | LEAdvertisingManagerPtr Adapter::leAdvertisingManager() const |
131 | { |
132 | return d->m_leAdvertisingManager; |
133 | } |
134 | |
135 | MediaPtr Adapter::media() const |
136 | { |
137 | return d->m_media; |
138 | } |
139 | |
140 | QList<DevicePtr> Adapter::devices() const |
141 | { |
142 | return d->m_devices; |
143 | } |
144 | |
145 | DevicePtr Adapter::deviceForAddress(const QString &address) const |
146 | { |
147 | for (DevicePtr device : std::as_const(t&: d->m_devices)) { |
148 | if (device->address() == address) { |
149 | return device; |
150 | } |
151 | } |
152 | return DevicePtr(); |
153 | } |
154 | |
155 | PendingCall *Adapter::startDiscovery() |
156 | { |
157 | return new PendingCall(d->m_bluezAdapter->StartDiscovery(), PendingCall::ReturnVoid, this); |
158 | } |
159 | |
160 | PendingCall *Adapter::stopDiscovery() |
161 | { |
162 | return new PendingCall(d->m_bluezAdapter->StopDiscovery(), PendingCall::ReturnVoid, this); |
163 | } |
164 | |
165 | PendingCall *Adapter::removeDevice(DevicePtr device) |
166 | { |
167 | return new PendingCall(d->m_bluezAdapter->RemoveDevice(device: QDBusObjectPath(device->ubi())), PendingCall::ReturnVoid, this); |
168 | } |
169 | |
170 | PendingCall* Adapter::setDiscoveryFilter(const QVariantMap& filter) |
171 | { |
172 | return new PendingCall(d->m_bluezAdapter->SetDiscoveryFilter(filter), PendingCall::ReturnVoid, this); |
173 | } |
174 | |
175 | PendingCall* Adapter::getDiscoveryFilters() |
176 | { |
177 | return new PendingCall(d->m_bluezAdapter->GetDiscoveryFilters(), PendingCall::ReturnStringList, this); |
178 | } |
179 | |
180 | } // namespace BluezQt |
181 | |
182 | #include "moc_adapter.cpp" |
183 | |