Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
108 lines (98 loc) · 4.91 KB
/
Copy pathmain.cpp
File metadata and controls
108 lines (98 loc) · 4.91 KB
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
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QByteArray>
#include <QDebug>
#include "src/core/AppSettings.h"
#include "src/core/DatabaseManager.h"
#include "src/controllers/AlarmController.h"
#include "src/controllers/ClockController.h"
#include "src/controllers/PatientController.h"
#include "src/controllers/EventController.h"
#include "src/controllers/UserController.h"
#include "src/controllers/VentilatorController.h"
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
qputenv("QT_QUICK_CONTROLS_STYLE", QByteArray("Basic"));
QQuickStyle::setStyle(QStringLiteral("Basic"));
QGuiApplication app(argc, argv);
QCoreApplication::setOrganizationName(QStringLiteral("AlsonsTechnology"));
QCoreApplication::setApplicationName(QStringLiteral("SmartVentilatorDemo"));
DatabaseManager databaseManager;
const bool databaseReady = databaseManager.initialize();
if (!databaseReady)
qCritical() << "Database initialization failed:" << databaseManager.lastError();
AppSettings appSettings;
PatientController patientController(&databaseManager);
AlarmController alarmController(&databaseManager);
if (!databaseReady) {
alarmController.addAlarm(QStringLiteral("Critical"),
QStringLiteral("Storage"),
QStringLiteral("Database unavailable -- audit trail and patient persistence degraded"),
QStringLiteral("Active"));
alarmController.setActive(true);
alarmController.setPriority(QStringLiteral("Critical"));
alarmController.setHeadline(QStringLiteral("Storage Failure"));
alarmController.setDetail(QStringLiteral("Audit trail unavailable"));
}
EventController eventController(&databaseManager);
UserController userController(&databaseManager);
VentilatorController ventilatorController(&databaseManager, &alarmController);
ClockController clockController;
auto updateVentilatorPatientContext = [&]() {
ventilatorController.setPatientContext(patientController.category());
ventilatorController.setPatientIbwKg(patientController.ibw());
};
updateVentilatorPatientContext();
QObject::connect(&patientController, &PatientController::patientChanged,
&ventilatorController, updateVentilatorPatientContext);
QObject::connect(&userController, &UserController::sessionChanged,
&ventilatorController, [&]() {
ventilatorController.setOperatorId(userController.loggedIn()
? userController.currentUser()
: QStringLiteral("unauthenticated"));
});
QObject::connect(&databaseManager, &DatabaseManager::errorOccurred,
&alarmController, [&](const QString &message) {
alarmController.raiseAlarm(QStringLiteral("Critical"),
QStringLiteral("Storage"),
QStringLiteral("Storage Failure"),
message);
});
QObject::connect(&ventilatorController, &VentilatorController::backendStateChanged,
&alarmController, [&]() {
if (ventilatorController.degradedMode()) {
alarmController.raiseAlarm(QStringLiteral("Critical"),
QStringLiteral("Backend"),
QStringLiteral("Backend Disconnected"),
ventilatorController.backendState());
}
});
// Restore persisted timezone from QSettings.
clockController.setTimeZoneId(appSettings.timeZoneId());
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty(QStringLiteral("appSettings"), &appSettings);
engine.rootContext()->setContextProperty(QStringLiteral("databaseManager"), &databaseManager);
engine.rootContext()->setContextProperty(QStringLiteral("patientController"), &patientController);
engine.rootContext()->setContextProperty(QStringLiteral("alarmController"), &alarmController);
engine.rootContext()->setContextProperty(QStringLiteral("eventController"), &eventController);
engine.rootContext()->setContextProperty(QStringLiteral("userController"), &userController);
engine.rootContext()->setContextProperty(QStringLiteral("ventilatorController"), &ventilatorController);
engine.rootContext()->setContextProperty(QStringLiteral("clockController"), &clockController);
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);
return app.exec();
}