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 "BluezApiParser.h" |
10 | |
11 | BluezApiParser::BluezApiParser() |
12 | { |
13 | } |
14 | |
15 | bool BluezApiParser::parse(QTextStream &stream) |
16 | { |
17 | while (!stream.atEnd()) { |
18 | // Get next line |
19 | auto line = stream.readLine(); |
20 | // Just look for section markers |
21 | if (line.startsWith(c: QLatin1Char('='))) { |
22 | m_interfaces.emplace_back(args: Interface()); |
23 | m_currentInterface = &m_interfaces.back(); |
24 | } else if (m_currentInterface) { |
25 | if (!m_currentInterface->parse(line)) { |
26 | m_currentInterface = nullptr; |
27 | } |
28 | } |
29 | } |
30 | |
31 | return true; |
32 | } |
33 | |
34 | bool BluezApiParser::finalize() |
35 | { |
36 | bool success = true; |
37 | |
38 | m_interfaces.erase(first: std::remove_if(first: m_interfaces.begin(), |
39 | last: m_interfaces.end(), |
40 | pred: [](const Interface &interface) { |
41 | return interface.methods().methods().empty() && interface.properties().properties().empty(); |
42 | }), |
43 | last: m_interfaces.end()); |
44 | |
45 | for (auto &interface : m_interfaces) { |
46 | success &= interface.finalize(); |
47 | } |
48 | |
49 | return success; |
50 | } |
51 | |
52 | std::list<Interface> BluezApiParser::interfaces() const |
53 | { |
54 | return m_interfaces; |
55 | } |
56 |