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 <QtSafeRenderer/qsafeevent.h>
#include <QtSafeRenderer/qsafechecksum.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>
#include <outputverifier_capi.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
ARGB backgroundColor = { 0xff, 0xff, 0xff, 0xff };
// SafeWindow needs to be initialized before OutputVerifier
SafeWindow telltaleWindow(layout.size(), QSafePoint(0U, 0U));
#if defined(USE_OUTPUTVERIFIER)
OutputVerifier &outputVerifier = OutputVerifier::getOutputVerifierInstance();
// Initialize the hardware device
OutputVerifier_initVerifierDevice(0, 0, layout.size().width(), layout.size().height());
#endif
static SafeRenderer::StateManager stateManager(telltaleWindow, layout, backgroundColor);
// Hide CRC check failed warning note
#if !defined(USE_OUTPUTVERIFIER)
QSafeEventVisibility hideWarning;
hideWarning.setItemId(qsafe_hash_string("infopanel"));
hideWarning.setValue(0U);
stateManager.handleEvent(hideWarning);
#endif
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;
}