/* * BluezQt - Asynchronous BlueZ wrapper library * * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "XmlGenerator.h" #include #include #include "BluezApiParser.h" #include "TypeAnnotation.h" XmlGenerator::XmlGenerator(const Config &config) : m_config(config) { } bool XmlGenerator::generate(const BluezApiParser &parser) { // Iterate interfaces for (const auto &interface : parser.interfaces()) { // Only consider interfaces with methods if (interface.methods().methods().empty()) { continue; } // Create file QFile file(interface.name() + QStringLiteral(".xml")); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qWarning() << "Error opening file for writing:" << file.fileName(); return false; } // Write content QTextStream stream(&file); writeHeader(stream); writeInterface(stream, interface.name()); // Iterate methods for (const auto &method : interface.methods().methods()) { // Respect config if ((method.tags().isDeprecated && !m_config.useDeprecated) || (method.tags().isOptional && !m_config.useOptional) || (method.tags().isExperimental && !m_config.useExperimental)) { continue; } writeMethod(stream, method); } closeInterface(stream); writeFooter(stream); file.close(); } return true; } void XmlGenerator::writeHeader(QTextStream &stream) { stream << "\n"; stream << "\n"; stream << "\n"; } void XmlGenerator::writeFooter(QTextStream &stream) { stream << "\n"; } void XmlGenerator::writeInterface(QTextStream &stream, const QString &name) { stream << " \n"; } void XmlGenerator::closeInterface(QTextStream &stream) { stream << " \n"; } bool XmlGenerator::writeMethod(QTextStream &stream, const Method &method) { stream << " \n"; return true; } stream << ">\n"; for (const auto ¶m : method.inParameters()) { if (!writeArg(stream, param, QStringLiteral("in"))) { return false; } } for (const auto ¶m : method.outParameters()) { if (!writeArg(stream, param, QStringLiteral("out"))) { return false; } } for (int i = 0; i < method.inParameters().size(); ++i) { writeAnnotation(stream, method.inParameters().at(i), QStringLiteral("In"), i); } for (int i = 0; i < method.outParameters().size(); ++i) { writeAnnotation(stream, method.outParameters().at(i), QStringLiteral("Out"), i); } stream << " \n"; return true; } bool XmlGenerator::writeArg(QTextStream &stream, const Parameter ¶m, const QString &dir) { auto dbusType = annotateType(AnnotationType::Bluez, AnnotationType::Dbus, param.type()); if (dbusType.isEmpty()) { return false; } stream << " \n"; return true; } void XmlGenerator::writeAnnotation(QTextStream &stream, const Parameter ¶m, const QString &dir, int i) { auto qtType = annotateType(AnnotationType::Bluez, AnnotationType::Qt, param.type()); if (qtType.isEmpty()) { return; } stream << " \n"; return; }