summaryrefslogtreecommitdiffstats
path: root/src/main-lib/configuration.h
blob: 605f42440efca0d6679e7082589e2e30654aa70e (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef CONFIGURATION_H
#define CONFIGURATION_H

#include <QtAppManCommon/global.h>
#include <QtCore/QStringList>
#include <QtCore/QVariantMap>
#include <QtCore/QVector>

#include <chrono>
#include <memory>

#include "openglconfiguration.h"
#include "watchdogconfiguration.h"

QT_BEGIN_NAMESPACE_AM

// IMPORTANT: if you add/remove/change anything in this struct, you also have to adjust the
//            dataStreamVersion(), serialize() and merge() functions in the cpp file!
struct ConfigurationData
{
    QString instanceId;

    struct Runtimes {
        QStringList additionalLaunchers;
        QVariantMap configurations;
    } runtimes;

    struct {
        QVariantMap configurations;
        QList<std::pair<QString, QString>> selection;
    } containers;

    struct {
        struct {
            std::chrono::milliseconds disambiguation { 10000 };
            std::chrono::milliseconds startApplication { 3000 };
            std::chrono::milliseconds replyFromApplication { 5000 };
            std::chrono::milliseconds replyFromSystem { 20000 };
        } timeouts;
    } intents;

    struct {
        QStringList startup;
        QStringList container;
    } plugins;

    struct {
        struct {
            QString id;
            QString description;
            QString longMessageBehavior;
        } dlt;
        QStringList rules;
        QString messagePattern;
        QVariant useAMConsoleLogger; // true / false / invalid
    } logging;

    struct {
        QStringList caCertificates;
    } installer;

    struct {
        QVariantMap policies;
        QVariantMap registrations;
    } dbus;

    struct {
        double idleLoad = 0.;
        QMap<std::pair<QString, QString>, int> runtimesPerContainer;
        int failedStartLimit = 5;
        std::chrono::seconds failedStartLimitIntervalSec { 10 };
    } quicklaunch;

    struct Ui {
        OpenGLConfiguration opengl;
        QStringList iconThemeSearchPaths;
        QString iconThemeName;
        QString style;
        QStringList importPaths;
        QStringList pluginPaths;
        QString windowIcon;
        bool fullscreen = false;
        QString mainQml;
        QStringList resources;
    } ui;

    struct {
        QStringList builtinAppsManifestDir;
        QString installationDir;
        QString documentDir;
        QString installationDirMountPoint;
    } applications; // TODO: rename to package?

    struct {
        bool printBacktrace = true;
        bool printQmlStack = true;
        std::chrono::seconds waitForGdbAttach { 0 };
        bool dumpCore = true;
        struct {
            int onCrash = -1;
            int onException = -1;
        } stackFramesToIgnore;
    } crashAction;

    QVariantMap systemProperties;

    struct {
        bool forceSingleProcess = false;
        bool forceMultiProcess = false;
        bool noSecurity = false;
        bool developmentMode = false;
        bool allowUnsignedPackages = false;
        bool allowUnknownUiClients = false;
    } flags;

    struct Wayland {
        QString socketName;
        struct ExtraSocket {
            QString path;
            int permissions = -1;
            int userId = -1;
            int groupId = -1;
        };
        QList<ExtraSocket> extraSockets;
    } wayland;

    WatchdogConfiguration watchdog;
};

class ConfigurationPrivate;

class Configuration
{
public:
    Configuration(const QStringList &defaultConfigFilePaths = { },
                  const QString &buildConfigFilePath = { },
                  const char *additionalDescription = nullptr,
                  bool onlyOnePositionalArgument = true);

    virtual ~Configuration();
    virtual void parseWithArguments(const QStringList &arguments);
    QVariant buildConfig() const;

    // all command line arguments that do not map to YAML fields
    bool noCache() const;
    bool clearCache() const;
    bool verbose() const;
    void setForceVerbose(bool forceVerbose);
    bool isWatchdogDisabled() const;
    void setForceDisableWatchdog(bool forceDisableWatchdog);
    bool slowAnimations() const;
    bool noDltLogging() const;
    bool qmlDebugging() const;
    QString singleApp() const;
    QString dbus() const;
    QString waylandSocketName() const;

    // for backwards compatibility
    inline bool fullscreen() const { return yaml.ui.fullscreen; }
    inline bool noFullscreen() const { return !yaml.ui.fullscreen; }

    // the testrunner only
    QStringList testRunnerArguments() const;
    QString testRunnerSourceFile() const;

private:
    std::unique_ptr<ConfigurationPrivate> d;

public:
    // the YAML configuration, mapped (nearly) 1:1 to nested C structs
    const ConfigurationData &yaml;
};

QT_END_NAMESPACE_AM


#endif // CONFIGURATION_H