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 | #include "leadvertisementadaptor.h" |
10 | #include "leadvertisement.h" |
11 | |
12 | #include <QDBusMetaType> |
13 | #include <QDBusObjectPath> |
14 | |
15 | namespace BluezQt |
16 | { |
17 | LEAdvertisementAdaptor::LEAdvertisementAdaptor(LEAdvertisement *parent) |
18 | : QDBusAbstractAdaptor(parent) |
19 | , m_advertisement(parent) |
20 | { |
21 | qDBusRegisterMetaType<QHash<QString, QVariant>>(); |
22 | qDBusRegisterMetaType<QHash<quint16, QDBusVariant>>(); |
23 | } |
24 | |
25 | QString LEAdvertisementAdaptor::type() const |
26 | { |
27 | return QStringLiteral("peripheral"); |
28 | } |
29 | |
30 | QStringList LEAdvertisementAdaptor::serviceUuids() const |
31 | { |
32 | return m_advertisement->serviceUuids(); |
33 | } |
34 | |
35 | QHash<QString, QVariant> LEAdvertisementAdaptor::serviceData() const |
36 | { |
37 | // bluez wants the value wrapped into a variant... |
38 | QHash<QString, QVariant> data; |
39 | const auto sd = m_advertisement->serviceData(); |
40 | data.reserve(size: sd.size()); |
41 | for (auto it = sd.begin(); it != sd.end(); ++it) { |
42 | data.insert(key: it.key(), value: it.value()); |
43 | } |
44 | return data; |
45 | } |
46 | |
47 | QHash<quint16, QDBusVariant> LEAdvertisementAdaptor::manufacturerData() const |
48 | { |
49 | QHash<quint16, QDBusVariant> data; |
50 | |
51 | const auto &md = m_advertisement->manufacturerData(); |
52 | data.reserve(size: md.size()); |
53 | |
54 | for (auto it = md.cbegin(); it != md.cend(); ++it) { |
55 | data.insert(key: it.key(), value: QDBusVariant(QVariant::fromValue(value: it.value()))); |
56 | } |
57 | |
58 | return data; |
59 | } |
60 | |
61 | void LEAdvertisementAdaptor::Release() |
62 | { |
63 | m_advertisement->release(); |
64 | } |
65 | |
66 | } // namespace BluezQt |
67 | |
68 | #include "moc_leadvertisementadaptor.cpp" |
69 |