File indexing completed on 2024-05-12 05:51:06

0001 /*
0002     SPDX-FileCopyrightText: 2022 Héctor Mesa Jiménez <wmj.py@gmx.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include <QHash>
0009 #include <QJsonObject>
0010 #include <optional>
0011 #include <utility>
0012 
0013 class QProcess;
0014 
0015 namespace dap
0016 {
0017 namespace settings
0018 {
0019 struct Command {
0020     QString command;
0021     QStringList arguments;
0022     std::optional<QHash<QString, QString>> environment;
0023 
0024     bool isValid() const;
0025     void start(QProcess &process) const;
0026 
0027     Command() = default;
0028     explicit Command(const QJsonObject &configuration);
0029 };
0030 
0031 struct Connection {
0032     int port;
0033     QString host;
0034 
0035     bool isValid() const;
0036     Connection();
0037     explicit Connection(const QJsonObject &configuration);
0038 };
0039 
0040 struct BusSettings {
0041     std::optional<Command> command;
0042     std::optional<Connection> connection;
0043 
0044     bool isValid() const;
0045     bool hasCommand() const;
0046     bool hasConnection() const;
0047 
0048     BusSettings() = default;
0049     explicit BusSettings(const QJsonObject &configuration);
0050 };
0051 
0052 struct ProtocolSettings {
0053     bool linesStartAt1;
0054     bool columnsStartAt1;
0055     bool pathFormatURI;
0056     bool redirectStderr;
0057     bool redirectStdout;
0058     bool supportsSourceRequest;
0059     QJsonObject launchRequest;
0060     QString locale;
0061 
0062     ProtocolSettings();
0063     explicit ProtocolSettings(const QJsonObject &configuration);
0064 };
0065 
0066 struct ClientSettings {
0067     BusSettings busSettings;
0068     ProtocolSettings protocolSettings;
0069 
0070     ClientSettings() = default;
0071     explicit ClientSettings(const QJsonObject &configuration);
0072     static std::optional<ClientSettings> extractFromAdapter(const QJsonObject &adapterSettings, const QString &configurationKey);
0073 };
0074 
0075 std::optional<QJsonObject> expandConfiguration(const QJsonObject &adapterSettings, const QJsonObject &configuration, bool resolvePort = false);
0076 std::optional<QJsonObject> expandConfigurations(const QJsonObject &adapterSettings, bool resolvePort = false);
0077 /**
0078  * @brief findConfiguration
0079  *
0080  * Extract a configuration from an adapter JSON definition.
0081  *
0082  * @param adapterSettings
0083  * @param key
0084  * @param resolvePort
0085  * @return
0086  */
0087 std::optional<QJsonObject> findConfiguration(const QJsonObject &adapterSettings, const QString &key, bool resolvePort = false);
0088 std::optional<QJsonObject> resolveClientPort(const QJsonObject &configuration);
0089 
0090 QHash<QString, QJsonValue> findReferences(const QJsonObject &configuration);
0091 
0092 }
0093 }