C

Indicators: Creating Safety-Critical UI

// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

// This file is part of the Qt Safe Renderer module
#include <QtSafeRenderer/qsafelayout.h>
#include <QtSafeRenderer/qsafelayoutresourcereader.h>
#include <QtSafeRenderer/statemanager.h>
#include <iostream>

#if defined(HOST_BUILD)
#include <QQuickView>
#include <QWindow>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#endif
#if defined(USE_OUTPUTVERIFIER)
#include <outputverifier.h>
#endif

#include <QtSafePlatformAdaptation/safewindow.h>
#include <QtSafePlatformAdaptation/eventhandler.h>

using namespace SafeRenderer;

int main(int argc, char **argv)
{
    (void)argc;
    (void)argv;
    static QSafeLayoutResourceReader layout("/layoutData/MainForm/MainForm.ui.srl");

#if defined(USE_OUTPUTVERIFIER)
    try {
#endif

#if defined(USE_OUTPUTVERIFIER)
    static OutputVerifier outputVerifier;
    SafeWindow telltaleWindow(layout.size(), QSafePoint(0U, 0U), outputVerifier);
#else
    SafeWindow telltaleWindow(layout.size(), QSafePoint(0U, 0U));
#endif
    static SafeRenderer::StateManager stateManager(telltaleWindow, layout);
    telltaleWindow.requestUpdate(); //Request is required because eventHandler is not running yet.

#if defined(USE_OUTPUTVERIFIER)
    EventHandler msgHandler(stateManager, telltaleWindow, outputVerifier);
#else
    EventHandler msgHandler(stateManager, telltaleWindow);
#endif

#if defined(HOST_BUILD)
    //Mixing the Qt and Qt Safe Renderer renderers is done here only for demonstration purposes on host, not for production purposes of any kind.
    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/ControlUI.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, qApp,
                     [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            qDebug() << "Failed to start the ControlUI.qml";
    }, Qt::QueuedConnection);
    engine.addImportPath(":/imports");
    engine.load(url);
#endif

    msgHandler.handleEvents();

#if defined(USE_OUTPUTVERIFIER)
    }
    catch (const OutputVerifierException &e) {
        std::cout << e.what();
    }
#endif

    return 0;
}