File indexing completed on 2024-04-21 03:52:03

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "BluezApiParser.h"
0010 
0011 BluezApiParser::BluezApiParser()
0012 {
0013 }
0014 
0015 bool BluezApiParser::parse(QTextStream &stream)
0016 {
0017     while (!stream.atEnd()) {
0018         // Get next line
0019         auto line = stream.readLine();
0020         // Just look for section markers
0021         if (line.startsWith(QLatin1Char('='))) {
0022             m_interfaces.emplace_back(Interface());
0023             m_currentInterface = &m_interfaces.back();
0024         } else if (m_currentInterface) {
0025             if (!m_currentInterface->parse(line)) {
0026                 m_currentInterface = nullptr;
0027             }
0028         }
0029     }
0030 
0031     return true;
0032 }
0033 
0034 bool BluezApiParser::finalize()
0035 {
0036     bool success = true;
0037 
0038     m_interfaces.erase(std::remove_if(m_interfaces.begin(),
0039                                       m_interfaces.end(),
0040                                       [](const Interface &interface) {
0041                                           return interface.methods().methods().empty() && interface.properties().properties().empty();
0042                                       }),
0043                        m_interfaces.end());
0044 
0045     for (auto &interface : m_interfaces) {
0046         success &= interface.finalize();
0047     }
0048 
0049     return success;
0050 }
0051 
0052 std::list<Interface> BluezApiParser::interfaces() const
0053 {
0054     return m_interfaces;
0055 }