File: BluezApiParser.cpp

package info (click to toggle)
bluez-qt 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: cpp: 16,676; xml: 554; ansic: 337; sh: 13; makefile: 8
file content (55 lines) | stat: -rw-r--r-- 1,493 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * BluezQt - Asynchronous BlueZ wrapper library
 *
 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

#include "BluezApiParser.h"

BluezApiParser::BluezApiParser()
{
}

bool BluezApiParser::parse(QTextStream &stream)
{
    while (!stream.atEnd()) {
        // Get next line
        auto line = stream.readLine();
        // Just look for section markers
        if (line.startsWith(QLatin1Char('='))) {
            m_interfaces.emplace_back(Interface());
            m_currentInterface = &m_interfaces.back();
        } else if (m_currentInterface) {
            if (!m_currentInterface->parse(line)) {
                m_currentInterface = nullptr;
            }
        }
    }

    return true;
}

bool BluezApiParser::finalize()
{
    bool success = true;

    m_interfaces.erase(std::remove_if(m_interfaces.begin(),
                                      m_interfaces.end(),
                                      [](const Interface &interface) {
                                          return interface.methods().methods().empty() && interface.properties().properties().empty();
                                      }),
                       m_interfaces.end());

    for (auto &interface : m_interfaces) {
        success &= interface.finalize();
    }

    return success;
}

std::list<Interface> BluezApiParser::interfaces() const
{
    return m_interfaces;
}