Debian Codegraph @

tools/bluezapi2qt/BluezApiParser.cpp

raw
1 /*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <[email protected]>
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(QLatin1Char('='))) {
22 m_interfaces.emplace_back(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(std::remove_if(m_interfaces.begin(),
39 m_interfaces.end(),
40 [](const Interface &interface) {
41 return interface.methods().methods().empty() && interface.properties().properties().empty();
42 }),
43 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 }